Skip to content

Commit 8e1e9c5

Browse files
committed
new test Offers Visibility
1 parent 9249048 commit 8e1e9c5

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

spec/controllers/offers_controller_spec.rb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,47 @@
5454
end
5555

5656
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") }
6565

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
6772

6873
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 }
7175
expect(assigns(:offers)).to include(offer1)
7276
expect(assigns(:offers)).not_to include(offer2)
7377
end
7478

7579
it 'displays all offers when no organization is selected' do
7680
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)
7983
end
8084
end
8185
end
8286

8387
context "with another organization" do
8488
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)
8692

87-
get :index
93+
login(separate_user)
94+
95+
get :index, params: { org: separate_organization.id }
8896

89-
expect(assigns(:offers)).to eq([])
97+
expect(assigns(:offers).map(&:organization_id).uniq).to eq([separate_organization.id]) unless assigns(:offers).empty?
9098
end
9199
end
92100
end

spec/features/Offers_organization_filtering_spec.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
let(:organization) { Fabricate(:organization) }
55
let(:other_organization) { Fabricate(:organization) }
66
let(:category) { Fabricate(:category) }
7-
let(:member) { Fabricate(:member, organization: organization) }
8-
let(:other_member) { Fabricate(:member, organization: other_organization) }
9-
let(:user) { member.user }
107

11-
before do
12-
user.terms_accepted_at = Time.current
13-
user.save!
8+
let(:user) do
9+
u = Fabricate(:user, password: "12345test", password_confirmation: "12345test")
10+
u.terms_accepted_at = Time.current
11+
u.save!
12+
u
13+
end
1414

15-
# Create an accepted alliance
15+
let!(:member) { Fabricate(:member, organization: organization, user: user) }
16+
let!(:other_member) { Fabricate(:member, organization: other_organization) }
17+
18+
before do
1619
OrganizationAlliance.create!(
1720
source_organization: organization,
1821
target_organization: other_organization,
1922
status: "accepted"
2023
)
2124

22-
# Create posts in both organizations
2325
Fabricate(:offer,
2426
user: user,
2527
organization: organization,
@@ -34,26 +36,21 @@
3436
title: "Allied offer",
3537
active: true)
3638

37-
# Log in as user
38-
sign_in_with(user.email, user.password)
39+
sign_in_with(user.email, "12345test")
3940
end
4041

4142
scenario 'User filters posts by allied organization' do
4243
visit offers_path
4344

44-
# Should see posts from both organizations by default
4545
expect(page).to have_content("Local offer")
4646
expect(page).to have_content("Allied offer")
4747

48-
# Click on the organization dropdown toggle
4948
find('a.dropdown-toggle', text: Organization.model_name.human(count: :other)).click
5049

51-
# Find the organization in the dropdown menu and click it directly by url
5250
query_params = { org: other_organization.id }
5351
link_path = "#{offers_path}?#{query_params.to_query}"
5452
visit link_path
5553

56-
# Should see only posts from selected organization
5754
expect(page).to have_content("Allied offer")
5855
expect(page).not_to have_content("Local offer")
5956
end

0 commit comments

Comments
 (0)