This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
auctions.rb
191 lines (159 loc) · 4.31 KB
/
auctions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
FactoryGirl.define do
factory :auction do
association :user, factory: :admin_user
billable_to "Project (billable)"
started_at { quartile_minute(Time.now - 3.days) }
ended_at { quartile_minute(Time.now + 3.days) }
result :not_applicable
title { Faker::Company.catch_phrase }
type :reverse
published :published
summary Faker::Lorem.paragraph
description Faker::Lorem.paragraphs(3, true).join("\n\n")
delivery_due_at { quartile_minute(Time.now + 10.days) }
purchase_card :default
trait :sealed_bid_with_tie do
sealed_bid
after(:create) do |auction|
Timecop.freeze(auction.started_at) do
Timecop.scale(3600)
2.times do
create(:bid, auction: auction, amount: 3000)
end
end
end
end
trait :winning_vendor_is_small_business do
after(:create) do |auction|
create(:bid, :from_small_business, auction: auction)
end
end
trait :winning_vendor_is_non_small_business do
after(:create) do |auction|
create(:bid, :from_non_small_business, auction: auction)
end
end
trait :with_bidders do
published
transient do
bidder_ids []
end
after(:build) do |instance|
Timecop.freeze(instance.started_at) do
Timecop.scale(3600)
(1..2).each do |i|
amount = 3499 - (20 * i) - rand(10)
instance.bids << create(:bid, auction: instance, amount: amount)
end
end
end
after(:create) do |auction, evaluator|
evaluator.bidder_ids.each_with_index do |bidder_id, index|
lowest_bid = auction.bids.sort_by(&:amount).first
amount = lowest_bid.amount - (10 * index) - rand(10)
auction.bids << create(:bid, bidder_id: bidder_id, auction: auction, amount: amount)
end
end
end
trait :between_micropurchase_and_sat_threshold do
association :user, factory: :contracting_officer
start_price do
rand(AuctionThreshold::MICROPURCHASE + 1..AuctionThreshold::SAT)
end
end
trait :below_micropurchase_threshold do
start_price { rand(1..AuctionThreshold::MICROPURCHASE) }
end
trait :available do
started_at { quartile_minute(Time.now - 2.days) }
ended_at { quartile_minute(Time.now + 2.days) }
end
trait :closed do
ended_at { quartile_minute(Time.now - 2.days) }
end
trait :delivered do
ended_at { quartile_minute(Time.now - 2.days) }
delivery_due_at { quartile_minute(Time.now - 1.day) }
delivery_url 'https://github.com/foo/bar'
end
trait :not_delivered do
delivery_url nil
end
trait :paid do
delivered
paid_at { Time.current }
end
trait :running do
with_bidders
end
trait :expiring do
ended_at { quartile_minute(Time.now + 3.hours) }
end
trait :future do
started_at { quartile_minute(Time.now + 1.day) }
end
trait :delivery_due_at_expired do
closed
delivery_due_at { quartile_minute(ended_at + 1.day) }
end
trait :accepted do
ended_at { Time.now - 1.days }
result :accepted
accepted_at { Time.now }
end
trait :rejected do
result :rejected
rejected_at { Time.now }
end
trait :not_paid do
paid_at nil
end
trait :c2_approved do
c2_proposal_url 'https://c2-dev.18f.gov/proposals/2486'
c2_approval_status :approved
end
trait :published do
published :published
end
trait :unpublished do
published :unpublished
end
trait :sealed_bid do
type :sealed_bid
end
trait :reverse do
type :reverse
end
trait :completed do
published
delivery_due_at_expired
end
trait :complete_and_successful do
with_bidders
delivery_due_at_expired
delivered
accepted
c2_approved
paid
end
trait :payment_needed do
delivery_due_at_expired
accepted
delivered
c2_approved
not_paid
end
trait :evaluation_needed do
delivered
pending_acceptance
delivery_due_at_expired
end
trait :pending_acceptance do
result :pending_acceptance
end
trait :delivery_past_due do
not_delivered
delivery_due_at_expired
end
end
end