Skip to content

Commit 2fb7ad3

Browse files
author
RachelWyatt
committed
update box_spec to use new factory bot traits
1 parent b082ca7 commit 2fb7ad3

File tree

1 file changed

+25
-205
lines changed

1 file changed

+25
-205
lines changed

spec/models/box_spec.rb

Lines changed: 25 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
RSpec.describe Box, :type => :model do
44
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)}
126
let(:reviewer) { create(:user, :reviewer) }
137
let(:designer) { create(:user, :designer) }
148
let(:researcher) { create(:user, :researcher) }
@@ -17,7 +11,7 @@
1711
let(:follow_upper) { create(:user, :follow_upper) }
1812
let(:inventory_type_research_needed) { create(:inventory_type, requires_research: true) }
1913
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) }
2115
let(:reviewed_box_request) { create(:box_request, :review_complete) }
2216
let(:box) { create(:box, :is_designed) }
2317

@@ -27,260 +21,86 @@
2721
end
2822

2923
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
3327
expect(box.aasm_state).to eq("reviewed")
3428
end
3529

3630
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)
4032
expect(box).to transition_from(:reviewed).to(:design_in_progress).on_event(:claim_design)
4133
end
4234

4335
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)
4937
allow(box).to receive(:send_research_solicitation_email!)
50-
box.designed_by_id = designer.id;
51-
box.save
5238
box.claim_design!
5339
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
5541
create(:box_item, box: box, inventory_type: inventory_type_research_needed)
5642
expect(box).to transition_from(:design_in_progress).to(:designed).on_event(:complete_design)
5743
expect(box).to have_received(:send_research_solicitation_email!)
5844
end
5945

6046
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)
6648
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!
7050
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)
7353
expect(box).to transition_from(:design_in_progress).to(:researched).on_event(:complete_design)
7454
expect(box).to have_received(:send_assembly_solicitation_email!)
7555
end
7656

7757
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)
9059
box.researched_by_id = researcher.id;
91-
box.save
9260
expect(box).to transition_from(:designed).to(:research_in_progress).on_event(:claim_research)
9361
end
9462

9563
it "transitions from research_in_progress to researched" do
9664
time_now = Time.parse("Oct 11 2019")
9765
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)
11667
box.mark_box_items_as_researched!
11768
expect(box).to transition_from(:research_in_progress).to(:researched).on_event(:complete_research)
11869
expect(box.researched_at).to eq(time_now)
11970
end
12071

12172
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)
13974
box.assembled_by_id = assembler.id;
140-
box.save
14175
expect(box).to transition_from(:researched).to(:assembly_in_progress).on_event(:claim_assembly)
14276
end
14377

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)
15080
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!
16681
expect(box).to transition_from(:assembly_in_progress).to(:assembled).on_event(:complete_assembly)
16782
expect(box).to have_received(:send_shipping_solicitation_email!)
16883
end
16984

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)
19187
box.shipped_by_id = shipper.id;
192-
box.save
193-
box.complete_assembly!
19488
expect(box).to transition_from(:assembled).to(:shipping_in_progress).on_event(:claim_shipping)
19589
end
19690

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)
22293
expect(box).to transition_from(:shipping_in_progress).to(:shipped).on_event(:complete_shipping)
22394
end
22495

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)
25098
box.followed_up_by_id = follow_upper.id;
251-
box.save
25299
expect(box).to transition_from(:shipped).to(:follow_up_in_progress).on_event(:claim_follow_up)
253100
end
254101

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)
284104
expect(box).to transition_from(:follow_up_in_progress).to(:followed_up).on_event(:complete_follow_up)
285105
end
286106
end

0 commit comments

Comments
 (0)