Skip to content

Commit 5d0ec9e

Browse files
committed
Specs++
1 parent e09469c commit 5d0ec9e

File tree

1 file changed

+80
-9
lines changed

1 file changed

+80
-9
lines changed

spec/controllers/offers_controller_spec.rb

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
organization: organization,
1313
category: test_category)
1414
end
15+
let!(:other_offer) do
16+
Fabricate(:offer,
17+
user: another_member.user,
18+
organization: organization,
19+
category: test_category)
20+
end
1521

1622
include_context "stub browser locale"
1723

@@ -22,34 +28,99 @@
2228
it "populates an array of offers" do
2329
login(another_member.user)
2430

25-
get "index"
26-
expect(assigns(:offers)).to eq([offer])
31+
get :index
32+
33+
expect(assigns(:offers)).to eq([other_offer, offer])
34+
end
35+
36+
context "when one offer is not active" do
37+
before do
38+
other_offer.active = false
39+
other_offer.save!
40+
end
41+
42+
it "only returns active offers" do
43+
login(another_member.user)
44+
45+
get :index
46+
47+
expect(assigns(:offers)).to eq([offer])
48+
end
49+
end
50+
51+
context "when one offer's user is not active" do
52+
before do
53+
member.active = false
54+
member.save!
55+
end
56+
57+
it "only returns offers from active users" do
58+
login(another_member.user)
59+
60+
get :index
61+
62+
expect(assigns(:offers)).to eq([other_offer])
63+
end
2764
end
2865
end
2966
context "with another organization" do
3067
it "skips the original org's offers" do
3168
login(yet_another_member.user)
32-
get "index"
69+
70+
get :index
71+
3372
expect(assigns(:offers)).to eq([])
3473
end
3574
end
3675
end
3776

3877
describe "GET #index (search)" do
3978
before { login(another_member.user) }
79+
before do
80+
offer.title = "Queridos compañeros"
81+
offer.save!
82+
end
4083

4184
it "populates an array of offers" do
42-
get "index", q: offer.title.split(/\s/).first
85+
get :index, q: 'compañeros'
4386

44-
expect(assigns(:offers).size).to eq 1
45-
expect(assigns(:offers)[0]).to eq offer
46-
expect(assigns(:offers).to_a).to eq([offer])
87+
expect(assigns(:offers)).to eq([offer])
4788
end
4889

4990
it "allows to search by partial word" do
50-
get :index, q: offer.title.split(/\s/).first[0..-2]
91+
get :index, q: 'compañ'
92+
93+
expect(assigns(:offers)).to eq([offer])
94+
end
95+
96+
context "when one offer is not active" do
97+
before do
98+
other_offer.active = false
99+
other_offer.save!
100+
end
101+
102+
it "only returns active offers" do
103+
login(another_member.user)
104+
105+
get :index
51106

52-
expect(assigns(:offers)).to include offer
107+
expect(assigns(:offers)).to eq([offer])
108+
end
109+
end
110+
111+
context "when one offer's user is not active" do
112+
before do
113+
member.active = false
114+
member.save!
115+
end
116+
117+
it "only returns offers from active users" do
118+
login(another_member.user)
119+
120+
get :index
121+
122+
expect(assigns(:offers)).to eq([other_offer])
123+
end
53124
end
54125
end
55126

0 commit comments

Comments
 (0)