Require shipping methods to have at least one distributor

This commit is contained in:
Rob H
2014-07-04 14:05:44 +10:00
parent 6a1f8dccfb
commit 3da2461af5
3 changed files with 8 additions and 4 deletions

View File

@@ -3,6 +3,8 @@ Spree::ShippingMethod.class_eval do
attr_accessible :distributor_ids, :description
attr_accessible :require_ship_address
validates :distributors, presence: { message: "^At least one hub must be selected" }
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
scoped

View File

@@ -1,10 +1,11 @@
- hubs_color = @hubs.count > 0 ? "blue" : "red"
- hubs_color = 'red' if (controller.action_name == 'create' || controller.action_name == 'update') && @object.errors.full_messages.include?("At least one hub must be selected")
.sidebar_item.omega.four.columns#hubs
.four.columns.alpha.header{ class: "#{hubs_color}" }
%span.four.columns.alpha.centered Distributors
%span.four.columns.alpha.centered Hubs
.four.columns.alpha.list{ class: "#{hubs_color}" }
- if @hubs.count > 0
-# = hidden_field_tag "enterprise[hub_ids][]", []
= f.hidden_field :distributor_ids, :multiple => true, value: nil
- @hubs.each do |hub|
%a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(hub)}" }
%span.three.columns.alpha

View File

@@ -110,16 +110,17 @@ feature %q{
scenario "editing an existing enterprise" do
@enterprise = create(:enterprise)
e2 = create(:enterprise)
eg1 = create(:enterprise_group, name: 'eg1')
eg2 = create(:enterprise_group, name: 'eg2')
payment_method = create(:payment_method, distributors: [])
shipping_method = create(:shipping_method, distributors: [])
shipping_method = create(:shipping_method, distributors: [e2])
enterprise_fee = create(:enterprise_fee, enterprise: @enterprise )
login_to_admin_section
click_link 'Enterprises'
click_link 'Edit Profile'
all("a", text:'Edit Profile').first.click
fill_in 'enterprise_name', :with => 'Eaterprises'
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'