mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Sort payment methods by name
This commit is contained in:
@@ -6,14 +6,14 @@ Spree::Admin::PaymentMethodsController.class_eval do
|
||||
collection = if model_class.respond_to?(:accessible_by) &&
|
||||
!current_ability.has_block?(params[:action], model_class)
|
||||
|
||||
model_class.accessible_by(current_ability, action).
|
||||
managed_by(spree_current_user).by_distributor # This line added
|
||||
model_class.accessible_by(current_ability, action)
|
||||
|
||||
else
|
||||
model_class.scoped.
|
||||
managed_by(spree_current_user).by_distributor # This line added
|
||||
model_class.scoped
|
||||
end
|
||||
|
||||
collection = collection.managed_by(spree_current_user).by_name # This line added
|
||||
|
||||
# This block added
|
||||
if params.key? :enterprise_id
|
||||
distributor = Enterprise.find params[:enterprise_id]
|
||||
|
||||
@@ -19,11 +19,7 @@ Spree::PaymentMethod.class_eval do
|
||||
where('enterprises.id = ?', distributor)
|
||||
}
|
||||
|
||||
scope :by_distributor, lambda {
|
||||
joins(:distributors).
|
||||
order('enterprises.name, spree_payment_methods.name').
|
||||
select('enterprises.*, spree_payment_methods.*')
|
||||
}
|
||||
scope :by_name, order('spree_payment_methods.name ASC')
|
||||
|
||||
def has_distributor?(distributor)
|
||||
self.distributors.include?(distributor)
|
||||
|
||||
@@ -35,8 +35,10 @@ feature %q{
|
||||
let(:enterprise_user) { create_enterprise_user }
|
||||
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
|
||||
let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') }
|
||||
let(:distributor3) { create(:distributor_enterprise, name: 'Third Distributor') }
|
||||
let(:pm1) { create(:payment_method, name: 'One', distributors: [distributor1]) }
|
||||
let(:pm2) { create(:payment_method, name: 'Two', distributors: [distributor2]) }
|
||||
let(:pm2) { create(:payment_method, name: 'Two', distributors: [distributor1, distributor2]) }
|
||||
let(:pm3) { create(:payment_method, name: 'Three', distributors: [distributor3]) }
|
||||
|
||||
before(:each) do
|
||||
enterprise_user.enterprise_roles.build(enterprise: distributor1).save
|
||||
@@ -60,6 +62,27 @@ feature %q{
|
||||
payment_method.distributors.should == [distributor1]
|
||||
end
|
||||
|
||||
it "shows me only payment methods I have access to" do
|
||||
pm1
|
||||
pm2
|
||||
pm3
|
||||
|
||||
visit spree.admin_payment_methods_path
|
||||
|
||||
page.should have_content pm1.name
|
||||
page.should have_content pm2.name
|
||||
page.should_not have_content pm3.name
|
||||
end
|
||||
|
||||
it "does not show duplicates of payment methods" do
|
||||
pm1
|
||||
pm2
|
||||
|
||||
visit spree.admin_payment_methods_path
|
||||
page.all('td', text: 'Two').count.should == 1
|
||||
end
|
||||
|
||||
|
||||
it "shows me only payment methods for the enterprise I select" do
|
||||
pm1
|
||||
pm2
|
||||
@@ -67,7 +90,7 @@ feature %q{
|
||||
click_link 'Enterprises'
|
||||
within(".enterprise-#{distributor1.id}") { click_link 'Payment Methods' }
|
||||
page.should have_content pm1.name
|
||||
page.should_not have_content pm2.name
|
||||
page.should have_content pm2.name
|
||||
|
||||
click_link 'Enterprises'
|
||||
within(".enterprise-#{distributor2.id}") { click_link 'Payment Methods' }
|
||||
|
||||
@@ -2,13 +2,12 @@ require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe PaymentMethod do
|
||||
it "finds payment methods for a particular distributor" do
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
pm1 = create(:payment_method, distributors: [d1])
|
||||
pm2 = create(:payment_method, distributors: [d2])
|
||||
it "orders payment methods by name" do
|
||||
pm1 = create(:payment_method, name: 'ZZ')
|
||||
pm2 = create(:payment_method, name: 'AA')
|
||||
pm3 = create(:payment_method, name: 'BB')
|
||||
|
||||
PaymentMethod.for_distributor(d1).should == [pm1]
|
||||
PaymentMethod.by_name.should == [pm2, pm3, pm1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user