From 30b26259785133f6ef935a3578bb6fc88c47d280 Mon Sep 17 00:00:00 2001 From: askl56 Date: Mon, 10 Sep 2018 11:45:17 +0100 Subject: [PATCH 1/2] Try .any? to prevent error in dashboard on online users --- app/views/alchemy/admin/dashboard/index.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/dashboard/index.html.erb b/app/views/alchemy/admin/dashboard/index.html.erb index 2889f9a33c..d21980c6de 100644 --- a/app/views/alchemy/admin/dashboard/index.html.erb +++ b/app/views/alchemy/admin/dashboard/index.html.erb @@ -34,9 +34,10 @@ <%= render 'recent_pages' %>
- <% if @online_users.any? %> + <% if @online_users.try(:any?) %> <%= render 'users' %> <% end %> + <% if multi_site? %> <%= render 'sites' %> <% end %> From 1f8d2adde06cc73c38875078c324d51f7a46b607 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 18 Sep 2018 10:47:35 +0200 Subject: [PATCH 2/2] Add spec for users dashboard widget --- .../alchemy/admin/dashboard/_users.html.erb | 2 +- spec/dummy/app/models/dummy_user.rb | 4 +++ spec/features/admin/dashboard_spec.rb | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/dashboard/_users.html.erb b/app/views/alchemy/admin/dashboard/_users.html.erb index ab775191f8..7e92d6df86 100644 --- a/app/views/alchemy/admin/dashboard/_users.html.erb +++ b/app/views/alchemy/admin/dashboard/_users.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/spec/dummy/app/models/dummy_user.rb b/spec/dummy/app/models/dummy_user.rb index 35e076a4f6..ab60542797 100644 --- a/spec/dummy/app/models/dummy_user.rb +++ b/spec/dummy/app/models/dummy_user.rb @@ -19,4 +19,8 @@ def alchemy_roles def name @name || email end + + def human_roles_string + alchemy_roles.map(&:humanize) + end end diff --git a/spec/features/admin/dashboard_spec.rb b/spec/features/admin/dashboard_spec.rb index a242767125..e47d0d31d2 100644 --- a/spec/features/admin/dashboard_spec.rb +++ b/spec/features/admin/dashboard_spec.rb @@ -79,4 +79,39 @@ end end end + + describe 'Online users' do + context 'with alchemy users' do + let(:other_user) { build_stubbed(:alchemy_dummy_user) } + + before do + expect(Alchemy.user_class).to receive(:logged_in) { [other_user] } + end + + it "lists all online users besides current user" do + visit admin_dashboard_path + users_widget = all('div[@class="widget users"]').first + expect(users_widget).to have_content other_user.name + expect(users_widget).to have_content "Member" + expect(users_widget).not_to have_content user.name + end + end + + context 'with non alchemy user class' do + class SomeUser; end + before do + Alchemy.user_class_name = 'SomeUser' + end + + it "does not list online users" do + visit admin_dashboard_path + users_widget = all('div[@class="widget users"]').first + expect(users_widget).to be_nil + end + + after do + Alchemy.user_class_name = 'DummyUser' + end + end + end end
<%= Alchemy.t('Who else is online') %>