Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try .any? to prevent error in dashboard on online users #1469

Merged
merged 2 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/dashboard/_users.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="widget">
<div class="widget users">
<table class="list">
<tr>
<th colspan="2"><%= Alchemy.t('Who else is online') %></th>
Expand Down
3 changes: 2 additions & 1 deletion app/views/alchemy/admin/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
<%= render 'recent_pages' %>
</div>
<div class="column right">
<% if @online_users.any? %>
<% if @online_users.try(:any?) %>
<%= render 'users' %>
<% end %>

<% if multi_site? %>
<%= render 'sites' %>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/app/models/dummy_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def alchemy_roles
def name
@name || email
end

def human_roles_string
alchemy_roles.map(&:humanize)
end
end
35 changes: 35 additions & 0 deletions spec/features/admin/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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