|
2 | 2 |
|
3 | 3 | RSpec.describe Box, :type => :model do
|
4 | 4 | let(:requester) { Requester.new(first_name: "Jane", last_name: "Doe", street_address: "122 Boggie Woogie Avenue", city: "Fairfax", state: "VA", zip: "22030", ok_to_email: true, ok_to_text: false, ok_to_call: false, ok_to_mail: true, underage: false) }
|
5 |
| - let(:box_request_1) { |
6 |
| - BoxRequest.create(requester: requester, |
7 |
| - summary: "Lorem ipsum text.... Caramels tart sweet pudding pie candy lollipop.", |
8 |
| - question_re_affect: "Lorem ipsum text.... Tart jujubes candy canes pudding I love gummies.", |
9 |
| - question_re_current_situation: "Sweet roll cake pastry cookie.", |
10 |
| - question_re_referral_source: "Ice cream sesame snaps danish marzipan macaroon icing jelly beans.") } |
11 |
| - |
| 5 | + let(:box_request_1) {create(:box_request)} |
12 | 6 | let(:reviewer) { create(:user, :reviewer) }
|
13 | 7 | let(:designer) { create(:user, :designer) }
|
14 | 8 | let(:researcher) { create(:user, :researcher) }
|
|
17 | 11 | let(:follow_upper) { create(:user, :follow_upper) }
|
18 | 12 | let(:inventory_type_research_needed) { create(:inventory_type, requires_research: true) }
|
19 | 13 | let(:inventory_type_no_research_needed) { create(:inventory_type, requires_research: false) }
|
20 |
| - let(:box_request) { create(:box_request, :has_reviewer) } |
| 14 | + let(:box_request_with_reviewer) { create(:box_request, :has_reviewer) } |
21 | 15 | let(:reviewed_box_request) { create(:box_request, :review_complete) }
|
22 | 16 | let(:box) { create(:box, :is_designed) }
|
23 | 17 |
|
|
27 | 21 | end
|
28 | 22 |
|
29 | 23 | it "has state reviewed after box_request is reviewed" do
|
30 |
| - box_request.claim_review! |
31 |
| - box_request.complete_review! |
32 |
| - box = box_request.box |
| 24 | + box_request_with_reviewer.claim_review! |
| 25 | + box_request_with_reviewer.complete_review! |
| 26 | + box = box_request_with_reviewer.box |
33 | 27 | expect(box.aasm_state).to eq("reviewed")
|
34 | 28 | end
|
35 | 29 |
|
36 | 30 | it "transitions from reviewed to design_in_progress" do
|
37 |
| - box = reviewed_box_request.box |
38 |
| - box.designed_by_id = designer.id; |
39 |
| - box.save |
| 31 | + box = create(:box, :reviewed) |
40 | 32 | expect(box).to transition_from(:reviewed).to(:design_in_progress).on_event(:claim_design)
|
41 | 33 | end
|
42 | 34 |
|
43 | 35 | it "transitions from design_in_progress to designed" do
|
44 |
| - box_request_1.reviewed_by_id = reviewer.id; |
45 |
| - box_request_1.save |
46 |
| - box_request_1.claim_review! |
47 |
| - box_request_1.complete_review! |
48 |
| - box = box_request_1.box |
| 36 | + box = build(:box, :design_in_progress) |
49 | 37 | allow(box).to receive(:send_research_solicitation_email!)
|
50 |
| - box.designed_by_id = designer.id; |
51 |
| - box.save |
52 | 38 | box.claim_design!
|
53 | 39 | box.check_has_box_items # make sure there are items
|
54 |
| - # make sure at least one item needs research |
| 40 | + #add items that need research |
55 | 41 | create(:box_item, box: box, inventory_type: inventory_type_research_needed)
|
56 | 42 | expect(box).to transition_from(:design_in_progress).to(:designed).on_event(:complete_design)
|
57 | 43 | expect(box).to have_received(:send_research_solicitation_email!)
|
58 | 44 | end
|
59 | 45 |
|
60 | 46 | it "transitions from design_in_progress to researched when research not needed" do
|
61 |
| - box_request_1.reviewed_by_id = reviewer.id; |
62 |
| - box_request_1.save |
63 |
| - box_request_1.claim_review! |
64 |
| - box_request_1.complete_review! |
65 |
| - box = box_request_1.box |
| 47 | + box = build(:box, :design_in_progress) |
66 | 48 | allow(box).to receive(:send_assembly_solicitation_email!)
|
67 |
| - box.designed_by_id = designer.id; |
68 |
| - box.save |
69 |
| - box.claim_design! |
| 49 | + #box.claim_design! |
70 | 50 | box.check_has_box_items # make sure there are items
|
71 |
| - # make sure at least one item needs research |
72 |
| - create(:box_item, box: box, inventory_type: inventory_type_no_research_needed) |
| 51 | + # add item that doesn't require research |
| 52 | + create(:box_item, box: box) |
73 | 53 | expect(box).to transition_from(:design_in_progress).to(:researched).on_event(:complete_design)
|
74 | 54 | expect(box).to have_received(:send_assembly_solicitation_email!)
|
75 | 55 | end
|
76 | 56 |
|
77 | 57 | it "transitions from designed to research_in_progress" do
|
78 |
| - box_request_1.reviewed_by_id = reviewer.id; |
79 |
| - box_request_1.save |
80 |
| - box_request_1.claim_review! |
81 |
| - box_request_1.complete_review! |
82 |
| - box = box_request_1.box |
83 |
| - box.designed_by_id = designer.id; |
84 |
| - box.save |
85 |
| - box.claim_design! |
86 |
| - box.check_has_box_items # make sure there are items |
87 |
| - # make sure at least one item needs research |
88 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
89 |
| - box.complete_design! |
| 58 | + box = build(:box, :designed) |
90 | 59 | box.researched_by_id = researcher.id;
|
91 |
| - box.save |
92 | 60 | expect(box).to transition_from(:designed).to(:research_in_progress).on_event(:claim_research)
|
93 | 61 | end
|
94 | 62 |
|
95 | 63 | it "transitions from research_in_progress to researched" do
|
96 | 64 | time_now = Time.parse("Oct 11 2019")
|
97 | 65 | allow(Time).to receive(:now).and_return(time_now)
|
98 |
| - |
99 |
| - box_request_1.reviewed_by_id = reviewer.id; |
100 |
| - box_request_1.save |
101 |
| - box_request_1.claim_review! |
102 |
| - box_request_1.complete_review! |
103 |
| - box = box_request_1.box |
104 |
| - box.designed_by_id = designer.id; |
105 |
| - box.save |
106 |
| - box.claim_design! |
107 |
| - box.check_has_box_items # make sure there are items |
108 |
| - expect(box).to receive(:send_research_solicitation_email!).and_return(true) |
109 |
| - |
110 |
| - # make sure at least one item needs research |
111 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
112 |
| - box.complete_design! |
113 |
| - box.researched_by_id = researcher.id; |
114 |
| - box.save |
115 |
| - box.claim_research! |
| 66 | + box = build(:box, :research_in_progress) |
116 | 67 | box.mark_box_items_as_researched!
|
117 | 68 | expect(box).to transition_from(:research_in_progress).to(:researched).on_event(:complete_research)
|
118 | 69 | expect(box.researched_at).to eq(time_now)
|
119 | 70 | end
|
120 | 71 |
|
121 | 72 | it "transitions from researched to assembly in progress" do
|
122 |
| - box_request_1.reviewed_by_id = reviewer.id; |
123 |
| - box_request_1.save |
124 |
| - box_request_1.claim_review! |
125 |
| - box_request_1.complete_review! |
126 |
| - box = box_request_1.box |
127 |
| - box.designed_by_id = designer.id; |
128 |
| - box.save |
129 |
| - box.claim_design! |
130 |
| - box.check_has_box_items # make sure there are items |
131 |
| - # make sure at least one item needs research |
132 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
133 |
| - box.complete_design! |
134 |
| - box.researched_by_id = researcher.id; |
135 |
| - box.save |
136 |
| - box.claim_research! |
137 |
| - box.mark_box_items_as_researched! |
138 |
| - box.complete_research! |
| 73 | + box = build(:box, :researched) |
139 | 74 | box.assembled_by_id = assembler.id;
|
140 |
| - box.save |
141 | 75 | expect(box).to transition_from(:researched).to(:assembly_in_progress).on_event(:claim_assembly)
|
142 | 76 | end
|
143 | 77 |
|
144 |
| - it "transitons from assembly_in_progress to assembled" do |
145 |
| - box_request_1.reviewed_by_id = reviewer.id; |
146 |
| - box_request_1.save |
147 |
| - box_request_1.claim_review! |
148 |
| - box_request_1.complete_review! |
149 |
| - box = box_request_1.box |
| 78 | + it "transitions from assembly_in_progress to assembled" do |
| 79 | + box = build(:box, :assembly_in_progress) |
150 | 80 | allow(box).to receive(:send_shipping_solicitation_email!)
|
151 |
| - box.designed_by_id = designer.id; |
152 |
| - box.save |
153 |
| - box.claim_design! |
154 |
| - box.check_has_box_items # make sure there are items |
155 |
| - # make sure at least one item needs research |
156 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
157 |
| - box.complete_design! |
158 |
| - box.researched_by_id = researcher.id; |
159 |
| - box.save |
160 |
| - box.claim_research! |
161 |
| - box.mark_box_items_as_researched! |
162 |
| - box.complete_research! |
163 |
| - box.assembled_by_id = assembler.id; |
164 |
| - box.save |
165 |
| - box.claim_assembly! |
166 | 81 | expect(box).to transition_from(:assembly_in_progress).to(:assembled).on_event(:complete_assembly)
|
167 | 82 | expect(box).to have_received(:send_shipping_solicitation_email!)
|
168 | 83 | end
|
169 | 84 |
|
170 |
| - it "transitons from assembled to shipping_in_progress" do |
171 |
| - box_request_1.reviewed_by_id = reviewer.id; |
172 |
| - box_request_1.save |
173 |
| - box_request_1.claim_review! |
174 |
| - box_request_1.complete_review! |
175 |
| - box = box_request_1.box |
176 |
| - box.designed_by_id = designer.id; |
177 |
| - box.save |
178 |
| - box.claim_design! |
179 |
| - box.check_has_box_items # make sure there are items |
180 |
| - # make sure at least one item needs research |
181 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
182 |
| - box.complete_design! |
183 |
| - box.researched_by_id = researcher.id; |
184 |
| - box.save |
185 |
| - box.claim_research! |
186 |
| - box.mark_box_items_as_researched! |
187 |
| - box.complete_research! |
188 |
| - box.assembled_by_id = assembler.id; |
189 |
| - box.save |
190 |
| - box.claim_assembly! |
| 85 | + it "transitions from assembled to shipping_in_progress" do |
| 86 | + box = build(:box, :assembled) |
191 | 87 | box.shipped_by_id = shipper.id;
|
192 |
| - box.save |
193 |
| - box.complete_assembly! |
194 | 88 | expect(box).to transition_from(:assembled).to(:shipping_in_progress).on_event(:claim_shipping)
|
195 | 89 | end
|
196 | 90 |
|
197 |
| - it "transitons from shipping in progress to shipped" do |
198 |
| - box_request_1.reviewed_by_id = reviewer.id; |
199 |
| - box_request_1.save |
200 |
| - box_request_1.claim_review! |
201 |
| - box_request_1.complete_review! |
202 |
| - box = box_request_1.box |
203 |
| - box.designed_by_id = designer.id; |
204 |
| - box.save |
205 |
| - box.claim_design! |
206 |
| - box.check_has_box_items # make sure there are items |
207 |
| - # make sure at least one item needs research |
208 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
209 |
| - box.complete_design! |
210 |
| - box.researched_by_id = researcher.id; |
211 |
| - box.save |
212 |
| - box.claim_research! |
213 |
| - box.mark_box_items_as_researched! |
214 |
| - box.complete_research! |
215 |
| - box.assembled_by_id = assembler.id; |
216 |
| - box.save |
217 |
| - box.claim_assembly! |
218 |
| - box.shipped_by_id = shipper.id; |
219 |
| - box.save |
220 |
| - box.complete_assembly! |
221 |
| - box.claim_shipping! |
| 91 | + it "transitions from shipping in progress to shipped" do |
| 92 | + box = build(:box, :shipping_in_progress) |
222 | 93 | expect(box).to transition_from(:shipping_in_progress).to(:shipped).on_event(:complete_shipping)
|
223 | 94 | end
|
224 | 95 |
|
225 |
| - it "transitons from shipped to follow_up_in_progress" do |
226 |
| - box_request_1.reviewed_by_id = reviewer.id; |
227 |
| - box_request_1.save |
228 |
| - box_request_1.claim_review! |
229 |
| - box_request_1.complete_review! |
230 |
| - box = box_request_1.box |
231 |
| - box.designed_by_id = designer.id; |
232 |
| - box.save |
233 |
| - box.claim_design! |
234 |
| - box.check_has_box_items # make sure there are items |
235 |
| - # make sure at least one item needs research |
236 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
237 |
| - box.complete_design! |
238 |
| - box.researched_by_id = researcher.id; |
239 |
| - box.save |
240 |
| - box.claim_research! |
241 |
| - box.mark_box_items_as_researched! |
242 |
| - box.complete_research! |
243 |
| - box.assembled_by_id = assembler.id; |
244 |
| - box.save |
245 |
| - box.claim_assembly! |
246 |
| - box.shipped_by_id = shipper.id; |
247 |
| - box.save |
248 |
| - box.complete_assembly! |
249 |
| - box.claim_shipping! |
| 96 | + it "transitions from shipped to follow_up_in_progress" do |
| 97 | + box = create(:box, :shipped) |
250 | 98 | box.followed_up_by_id = follow_upper.id;
|
251 |
| - box.save |
252 | 99 | expect(box).to transition_from(:shipped).to(:follow_up_in_progress).on_event(:claim_follow_up)
|
253 | 100 | end
|
254 | 101 |
|
255 |
| - it "transitons from follow_up_in_progress to followed up" do |
256 |
| - box_request_1.reviewed_by_id = reviewer.id; |
257 |
| - box_request_1.save |
258 |
| - box_request_1.claim_review! |
259 |
| - box_request_1.complete_review! |
260 |
| - box = box_request_1.box |
261 |
| - box.designed_by_id = designer.id; |
262 |
| - box.save |
263 |
| - box.claim_design! |
264 |
| - box.check_has_box_items # make sure there are items |
265 |
| - # make sure at least one item needs research |
266 |
| - create(:box_item, box: box, inventory_type: inventory_type_research_needed) |
267 |
| - box.complete_design! |
268 |
| - box.researched_by_id = researcher.id; |
269 |
| - box.save |
270 |
| - box.claim_research! |
271 |
| - box.mark_box_items_as_researched! |
272 |
| - box.complete_research! |
273 |
| - box.assembled_by_id = assembler.id; |
274 |
| - box.save |
275 |
| - box.claim_assembly! |
276 |
| - box.shipped_by_id = shipper.id; |
277 |
| - box.save |
278 |
| - box.complete_assembly! |
279 |
| - box.claim_shipping! |
280 |
| - box.complete_shipping! |
281 |
| - box.followed_up_by_id = follow_upper.id; |
282 |
| - box.save |
283 |
| - box.claim_follow_up! |
| 102 | + it "transitions from follow_up_in_progress to followed up" do |
| 103 | + box = create(:box, :follow_up_in_progress) |
284 | 104 | expect(box).to transition_from(:follow_up_in_progress).to(:followed_up).on_event(:complete_follow_up)
|
285 | 105 | end
|
286 | 106 | end
|
|
0 commit comments