mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Require payment_methods to be associated with at least one hub
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
module Spree
|
||||
module Admin
|
||||
PaymentMethodsController.class_eval do
|
||||
before_filter :load_hubs, only: [:new, :edit, :create, :update]
|
||||
before_filter :load_hubs, only: [:new, :edit, :update]
|
||||
create.before :load_hubs
|
||||
|
||||
# Only show payment methods that user has access to and sort by distributor name
|
||||
# ! Redundant code copied from Spree::Admin::ResourceController with modifications marked
|
||||
|
||||
@@ -4,6 +4,8 @@ Spree::PaymentMethod.class_eval do
|
||||
|
||||
attr_accessible :distributor_ids
|
||||
|
||||
validates :distributors, presence: { message: "^At least one hub must be selected" }
|
||||
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
|
||||
@@ -46,14 +46,18 @@ feature %q{
|
||||
login_to_admin_as enterprise_user
|
||||
end
|
||||
|
||||
it "creates payment methods" do
|
||||
it "I can get to the new enterprise page" do
|
||||
click_link 'Enterprises'
|
||||
within(".enterprise-#{distributor1.id}") { click_link 'Payment Methods' }
|
||||
click_link 'New Payment Method'
|
||||
current_path.should == spree.new_admin_payment_method_path
|
||||
end
|
||||
|
||||
it "creates payment methods" do
|
||||
visit spree.new_admin_payment_method_path
|
||||
fill_in 'payment_method_name', :with => 'Cheque payment method'
|
||||
|
||||
select distributor1.name, :from => 'payment_method_distributor_ids'
|
||||
check "payment_method_distributor_ids_#{distributor1.id}"
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Payment Method has been successfully created!'
|
||||
|
||||
@@ -9,5 +9,11 @@ module Spree
|
||||
|
||||
PaymentMethod.by_name.should == [pm2, pm3, pm1]
|
||||
end
|
||||
|
||||
it "raises errors when required fields are missing" do
|
||||
pm = PaymentMethod.new()
|
||||
pm.save
|
||||
pm.errors.to_a.should == ["Name can't be blank", "At least one hub must be selected"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user