From c037a16a595413d041bd941daaed8b676d770d7e Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Thu, 24 Dec 2015 10:16:16 -0500 Subject: [PATCH 1/7] Use factory_girl in the db:seed task I also decided to add a little randomness to the with_bidders trait for auctions --- db/seeds.rb | 11 +++-------- spec/factories/auctions.rb | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 70527406..13bf35ee 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,14 +6,9 @@ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) -auction = Auction.new({ +FactoryGirl.create( + :current_auction, issue_url: 'https://github.com/18F/mpt3500/issues/10', - start_price: 3500.0, - start_datetime: Chronic.parse("October 13 2015 at 2:15 PM"), - end_datetime: Chronic.parse("October 14 2015 at 3:00 PM"), title: 'Build a Placeholder for MPT 3500', description: 'This auction is a placeholder for MPT 3500. The MPT 3500 team needs to build the following ...', - github_repo: 'https://github.com/18F/mpt3500', - published: 0 -}) -auction.save + github_repo: 'https://github.com/18F/mpt3500') diff --git a/spec/factories/auctions.rb b/spec/factories/auctions.rb index 7dc2f062..428a6658 100644 --- a/spec/factories/auctions.rb +++ b/spec/factories/auctions.rb @@ -9,8 +9,8 @@ trait :with_bidders do after(:build) do |instance| - (1..4).each do |i| - amount = 3499 - (20 * i) - rand(10) + (1..rand(10)).each do |i| + amount = 3499 - (100 * i) - rand(30) instance.bids << FactoryGirl.create(:bid, auction: instance, amount: amount) end end From 41895f910802a214a2d2404474e1ff7e71c0ab35 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Thu, 24 Dec 2015 12:24:56 -0500 Subject: [PATCH 2/7] Make at least 2 bids in random test auctions for now --- spec/factories/auctions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/auctions.rb b/spec/factories/auctions.rb index 428a6658..23daf5f6 100644 --- a/spec/factories/auctions.rb +++ b/spec/factories/auctions.rb @@ -9,7 +9,7 @@ trait :with_bidders do after(:build) do |instance| - (1..rand(10)).each do |i| + (2..rand(10)).each do |i| amount = 3499 - (100 * i) - rand(30) instance.bids << FactoryGirl.create(:bid, auction: instance, amount: amount) end From e30fbd69f0206fd9612ed181b6aef8c256ef26dd Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Thu, 24 Dec 2015 12:38:25 -0500 Subject: [PATCH 3/7] A different approach for ensuring 2 bids --- spec/factories/auctions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/auctions.rb b/spec/factories/auctions.rb index 23daf5f6..2096c1ab 100644 --- a/spec/factories/auctions.rb +++ b/spec/factories/auctions.rb @@ -9,7 +9,7 @@ trait :with_bidders do after(:build) do |instance| - (2..rand(10)).each do |i| + (1..rand(10)+1).each do |i| amount = 3499 - (100 * i) - rand(30) instance.bids << FactoryGirl.create(:bid, auction: instance, amount: amount) end From 1300847b13892d15af753a044b61ce2fa1093ae7 Mon Sep 17 00:00:00 2001 From: Alan deLevie Date: Wed, 30 Dec 2015 12:29:04 -0500 Subject: [PATCH 4/7] Admin panel displays separate tables and counts for admins and users. Reworded spec name to be more accurate Failing spec for counting users in /admin/users Modify specs to test for counting admins as well as users. --- app/controllers/admin/users_controller.rb | 4 +++- app/models/presenter/user.rb | 8 ++++++++ app/views/admin/users/index.html.erb | 25 ++++++++++++++++++++++- spec/features/admin_users_spec.rb | 12 +++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 72173815..f3535588 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -3,7 +3,9 @@ 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 = all_users.select {|u| u.is_admin?} + @users = all_users.select {|u| !u.is_admin?} end def show diff --git a/app/models/presenter/user.rb b/app/models/presenter/user.rb index 99ff3e00..d79061cb 100644 --- a/app/models/presenter/user.rb +++ b/app/models/presenter/user.rb @@ -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 diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 501d1f07..6660e0ca 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -1,4 +1,27 @@ -

Users

+

Admins (<%= @admins.length %>)

+ + + + + + + + + + + + <% @admins.each do |user| %> + + + + + + + <% end %> + +
NameEmailDUNS NumberGitHub ID
<%= user.name %><%= user.email %><%= user.duns_number %><%= link_to(user.github_id, user.github_json_url) %>
+ +

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

diff --git a/spec/features/admin_users_spec.rb b/spec/features/admin_users_spec.rb index 4b83e81e..2dd1973e 100644 --- a/spec/features/admin_users_spec.rb +++ b/spec/features/admin_users_spec.rb @@ -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) @@ -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 From 62fd5aacf7e78079f66dffd532a5d0112524d8d1 Mon Sep 17 00:00:00 2001 From: Alan deLevie Date: Wed, 30 Dec 2015 13:56:53 -0500 Subject: [PATCH 5/7] Fixed link color contrast --- app/assets/stylesheets/main.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index a70b446d..2efee7b9 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -325,7 +325,7 @@ h1, h2, h3, h4, h5, h6, p { } a { - color: #00a6d2; + color: #0071bc; } a:visited { From ac7bbf8b0141047fa12f345102c9e2ad85ae6962 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Wed, 30 Dec 2015 14:11:32 -0500 Subject: [PATCH 6/7] No need to specify the user_id in a factory This seems to be causing an issue in Travis --- spec/models/place_bid_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/place_bid_spec.rb b/spec/models/place_bid_spec.rb index 99141a7a..86017b0b 100644 --- a/spec/models/place_bid_spec.rb +++ b/spec/models/place_bid_spec.rb @@ -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) { { From 0b6d36e1ff5806bf022264d636fc9ba3af63c802 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Wed, 30 Dec 2015 14:23:05 -0500 Subject: [PATCH 7/7] Use Array#partition to split into two subarrays --- app/controllers/admin/users_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index f3535588..c1f51604 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -4,8 +4,7 @@ class UsersController < ApplicationController def index all_users = User.all.map {|user| Presenter::User.new(user)} - @admins = all_users.select {|u| u.is_admin?} - @users = all_users.select {|u| !u.is_admin?} + @admins, @users = all_users.partition {|u| u.is_admin?} end def show