|
54 | 54 | end |
55 | 55 |
|
56 | 56 | context "when filtering by organization" do |
57 | | - let(:organization1) { Organization.find_by(name: "Banco de Tiempo Local") } |
58 | | - let(:organization2) { Organization.find_by(name: "El otro Banco de Tiempo :)") } |
59 | | - let(:user1) { User.find_by(email: "user@timeoverflow.org") } |
60 | | - let(:user2) { User.find_by(email: "user2@timeoverflow.org") } |
61 | | - let!(:offer1) { Offer.find_by(title: "Ruby on Rails nivel principiante") || |
62 | | - Fabricate(:offer, user: user1, title: "Ruby on Rails nivel principiante") } |
63 | | - let!(:offer2) { Offer.find_by(title: "Cocina low cost") || |
64 | | - Fabricate(:offer, user: user2, title: "Cocina low cost") } |
| 57 | + let(:organization1) { Fabricate(:organization) } |
| 58 | + let(:organization2) { Fabricate(:organization) } |
| 59 | + let(:user1) { Fabricate(:user) } |
| 60 | + let(:user2) { Fabricate(:user) } |
| 61 | + let(:member1) { Fabricate(:member, user: user1, organization: organization1) } |
| 62 | + let(:member2) { Fabricate(:member, user: user2, organization: organization2) } |
| 63 | + let!(:offer1) { Fabricate(:offer, user: user1, organization: organization1, title: "Ruby on Rails nivel principiante") } |
| 64 | + let!(:offer2) { Fabricate(:offer, user: user2, organization: organization2, title: "Cocina low cost") } |
65 | 65 |
|
66 | | - before { login(user1) } |
| 66 | + before do |
| 67 | + member1 |
| 68 | + member2 |
| 69 | + login(user1) |
| 70 | + Fabricate(:member, user: user1, organization: organization2) unless user1.members.where(organization: organization2).exists? |
| 71 | + end |
67 | 72 |
|
68 | 73 | it 'displays only offers from the selected organization' do |
69 | | - get :index, params: { organization_id: organization1.id } |
70 | | - |
| 74 | + get :index, params: { org: organization1.id } |
71 | 75 | expect(assigns(:offers)).to include(offer1) |
72 | 76 | expect(assigns(:offers)).not_to include(offer2) |
73 | 77 | end |
74 | 78 |
|
75 | 79 | it 'displays all offers when no organization is selected' do |
76 | 80 | get :index |
77 | | - |
78 | | - expect(assigns(:offers)).to include(offer1, offer2) |
| 81 | + expect(assigns(:offers)).to include(offer1) |
| 82 | + expect(assigns(:offers)).to include(offer2) |
79 | 83 | end |
80 | 84 | end |
81 | 85 | end |
82 | 86 |
|
83 | 87 | context "with another organization" do |
84 | 88 | it "skips the original org's offers" do |
85 | | - login(yet_another_member.user) |
| 89 | + separate_organization = Fabricate(:organization) |
| 90 | + separate_user = Fabricate(:user) |
| 91 | + separate_member = Fabricate(:member, organization: separate_organization, user: separate_user) |
86 | 92 |
|
87 | | - get :index |
| 93 | + login(separate_user) |
| 94 | + |
| 95 | + get :index, params: { org: separate_organization.id } |
88 | 96 |
|
89 | | - expect(assigns(:offers)).to eq([]) |
| 97 | + expect(assigns(:offers).map(&:organization_id).uniq).to eq([separate_organization.id]) unless assigns(:offers).empty? |
90 | 98 | end |
91 | 99 | end |
92 | 100 | end |
|
0 commit comments