|
12 | 12 | organization: organization,
|
13 | 13 | category: test_category)
|
14 | 14 | end
|
| 15 | + let!(:other_offer) do |
| 16 | + Fabricate(:offer, |
| 17 | + user: another_member.user, |
| 18 | + organization: organization, |
| 19 | + category: test_category) |
| 20 | + end |
15 | 21 |
|
16 | 22 | include_context "stub browser locale"
|
17 | 23 |
|
|
22 | 28 | it "populates an array of offers" do
|
23 | 29 | login(another_member.user)
|
24 | 30 |
|
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 |
27 | 64 | end
|
28 | 65 | end
|
29 | 66 | context "with another organization" do
|
30 | 67 | it "skips the original org's offers" do
|
31 | 68 | login(yet_another_member.user)
|
32 |
| - get "index" |
| 69 | + |
| 70 | + get :index |
| 71 | + |
33 | 72 | expect(assigns(:offers)).to eq([])
|
34 | 73 | end
|
35 | 74 | end
|
36 | 75 | end
|
37 | 76 |
|
38 | 77 | describe "GET #index (search)" do
|
39 | 78 | before { login(another_member.user) }
|
| 79 | + before do |
| 80 | + offer.title = "Queridos compañeros" |
| 81 | + offer.save! |
| 82 | + end |
40 | 83 |
|
41 | 84 | it "populates an array of offers" do
|
42 |
| - get "index", q: offer.title.split(/\s/).first |
| 85 | + get :index, q: 'compañeros' |
43 | 86 |
|
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]) |
47 | 88 | end
|
48 | 89 |
|
49 | 90 | 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 |
51 | 106 |
|
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 |
53 | 124 | end
|
54 | 125 | end
|
55 | 126 |
|
|
0 commit comments