From c037a16a595413d041bd941daaed8b676d770d7e Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Thu, 24 Dec 2015 10:16:16 -0500 Subject: [PATCH 1/3] 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/3] 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/3] 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