Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #177 from 18F/display-number-of-users-in-admin
Browse files Browse the repository at this point in the history
Display number of users in admin
  • Loading branch information
Jacob Harris committed Dec 30, 2015
2 parents 03c71ed + 0b6d36e commit 92095d3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class UsersController < ApplicationController
before_filter :require_admin

def index
@users = User.all.map {|user| Presenter::User.new(user)}
all_users = User.all.map {|user| Presenter::User.new(user)}
@admins, @users = all_users.partition {|u| u.is_admin?}
end

def show
Expand Down
8 changes: 8 additions & 0 deletions app/models/presenter/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ class User < SimpleDelegator
def github_json_url
"https://api.github.com/user/#{github_id}"
end

def is_admin?
Admins.verify?(model.github_id)
end

def model
__getobj__
end
end
end
25 changes: 24 additions & 1 deletion app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
<h1>Users</h1>
<h2>Admins (<%= @admins.length %>)</h2>

<table class="usa-table-borderless">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">DUNS Number</th>
<th scope="col">GitHub ID</th>
</tr>
</thead>
<tbody>
<% @admins.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td><%= user.duns_number %></td>
<td><%= link_to(user.github_id, user.github_json_url) %></td>
</tr>
<% end %>
</tbody>
</table>

<h2>Users (<%= @users.length %>)</h2>

<table class="usa-table-borderless">
<thead>
Expand Down
12 changes: 10 additions & 2 deletions spec/features/admin_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

RSpec.feature "AdminUsers", type: :feature do
before do
create_user
sign_in_admin
end

scenario "visiting the admin users list and then a user" do
scenario "visiting the admin users list" do
create_user
visit "/admin/users"
expect(page).not_to have_text('must be an admin')
user = Presenter::User.new(@user)
Expand All @@ -16,4 +16,12 @@
expect(page).to have_text(user.name)
expect(page).to have_text(user.github_id)
end

scenario "counting the number of users and admins" do
number_of_users = 11
number_of_users.times { create_user }
visit "/admin/users"
expect(page).to have_text("Users (#{number_of_users}")
expect(page).to have_text("Admins (#{1}")
end
end
2 changes: 1 addition & 1 deletion spec/models/place_bid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe PlaceBid do
let(:place_bid) { PlaceBid.new(params, current_user) }
let(:current_user) { FactoryGirl.create(:user, id: 111) }
let(:current_user) { FactoryGirl.create(:user) }
let(:amount) { 1005 }
let(:params) {
{
Expand Down

0 comments on commit 92095d3

Please sign in to comment.