mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Reduce line length of PaymentMethod class
Rubocop was complaining. So I found code that could be simplified and specced it before refactoring.
This commit is contained in:
@@ -28,14 +28,12 @@ module Spree
|
||||
scope :production, -> { where(environment: 'production') }
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
where(nil)
|
||||
else
|
||||
joins(:distributors).
|
||||
where('distributors_payment_methods.distributor_id IN (?)',
|
||||
user.enterprises.select(&:id)).
|
||||
select('DISTINCT spree_payment_methods.*')
|
||||
end
|
||||
return where(nil) if user.admin?
|
||||
|
||||
joins(:distributors).
|
||||
where('distributors_payment_methods.distributor_id IN (?)',
|
||||
user.enterprises.select(&:id)).
|
||||
select('DISTINCT spree_payment_methods.*')
|
||||
}
|
||||
|
||||
scope :for_distributors, ->(distributors) {
|
||||
|
||||
@@ -6,6 +6,25 @@ class Spree::Gateway::Test < Spree::Gateway
|
||||
end
|
||||
|
||||
describe Spree::PaymentMethod do
|
||||
describe ".managed_by scope" do
|
||||
subject! { create(:payment_method) }
|
||||
let(:owner) { subject.distributors.first.owner }
|
||||
let(:other_user) { create(:user) }
|
||||
let(:admin) { create(:admin_user) }
|
||||
|
||||
it "returns everything for admins" do
|
||||
expect(Spree::PaymentMethod.managed_by(admin)).to eq [subject]
|
||||
end
|
||||
|
||||
it "returns payment methods of managed enterprises" do
|
||||
expect(Spree::PaymentMethod.managed_by(owner)).to eq [subject]
|
||||
end
|
||||
|
||||
it "returns nothing for other users" do
|
||||
expect(Spree::PaymentMethod.managed_by(other_user)).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
describe "#available" do
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user