mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Move single-used variables to their own example
They were created three times each, but only used once.
This commit is contained in:
@@ -72,7 +72,6 @@ describe Customer, type: :model do
|
||||
|
||||
describe 'scopes' do
|
||||
context 'managed_by' do
|
||||
let!(:admin) { create(:admin_user) }
|
||||
let!(:user) { create(:user) }
|
||||
let!(:enterprise) { create(:enterprise, owner: user) }
|
||||
let!(:customer) { create(:customer, enterprise: enterprise, user: user) }
|
||||
@@ -82,27 +81,27 @@ describe Customer, type: :model do
|
||||
let!(:enterprise1) { create(:enterprise, owner: user1) }
|
||||
let!(:customer2) { create(:customer, enterprise: enterprise1, user: user1) }
|
||||
|
||||
# manager of enterprise1
|
||||
let!(:user2) { create(:user) }
|
||||
context 'with user who has edit profile permission on enterprise via enterprise2' do
|
||||
let!(:user3) { create(:user) }
|
||||
let!(:enterprise2) { create(:enterprise, owner: user3) }
|
||||
|
||||
# user who has edit profile permission on enterprise via enterprise2
|
||||
let!(:user3) { create(:user) }
|
||||
let!(:enterprise2) { create(:enterprise, owner: user3) }
|
||||
|
||||
it 'returns customers managed by the user' do
|
||||
EnterpriseRelationship.create!(parent: enterprise2, child: enterprise,
|
||||
permissions_list: [:edit_profile])
|
||||
expect(Customer.managed_by(user)).to match_array [customer, customer1]
|
||||
expect(Customer.managed_by(user1)).to match_array(customer2)
|
||||
expect(Customer.managed_by(user3)).to match_array([])
|
||||
it 'returns customers managed by the user' do
|
||||
EnterpriseRelationship.create!(parent: enterprise2, child: enterprise,
|
||||
permissions_list: [:edit_profile])
|
||||
expect(Customer.managed_by(user)).to match_array [customer, customer1]
|
||||
expect(Customer.managed_by(user1)).to match_array(customer2)
|
||||
expect(Customer.managed_by(user3)).to match_array([])
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns customers of managed enterprises' do
|
||||
user2 = create(:user)
|
||||
EnterpriseRole.create!(user: user2, enterprise: enterprise)
|
||||
expect(Customer.managed_by(user2)).to match_array [customer, customer1]
|
||||
end
|
||||
|
||||
it 'returns all customers if the user is an admin' do
|
||||
admin = create(:admin_user)
|
||||
expect(Customer.managed_by(admin)).to match_array [customer, customer1, customer2]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user