mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-03 06:59:14 +00:00
Shipping method has a distributor, admin can create and edit
This commit is contained in:
6
app/models/spree/shipping_method_decorator.rb
Normal file
6
app/models/spree/shipping_method_decorator.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
Spree::ShippingMethod.class_eval do
|
||||
belongs_to :distributor, class_name: 'Enterprise'
|
||||
attr_accessible :distributor_id
|
||||
|
||||
validates_presence_of :distributor_id
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
/ insert_bottom "[data-hook='admin_shipping_method_form_availability_fields'] > fieldset"
|
||||
|
||||
= f.field_container :shipping_category do
|
||||
= f.label :distributor_id, 'Distributor'
|
||||
= f.collection_select :distributor_id, Enterprise.is_distributor, :id, :name, {include_blank: false}, {class: 'select2 fullwidth'}
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddDistributorIdToShippingMethods < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spree_shipping_methods, :distributor_id, :integer
|
||||
add_index :spree_shipping_methods, :distributor_id
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130814010857) do
|
||||
ActiveRecord::Schema.define(:version => 20130830012138) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
@@ -717,8 +717,11 @@ ActiveRecord::Schema.define(:version => 20130814010857) do
|
||||
t.boolean "match_all"
|
||||
t.boolean "match_one"
|
||||
t.datetime "deleted_at"
|
||||
t.integer "distributor_id"
|
||||
end
|
||||
|
||||
add_index "spree_shipping_methods", ["distributor_id"], :name => "index_spree_shipping_methods_on_distributor_id"
|
||||
|
||||
create_table "spree_skrill_transactions", :force => true do |t|
|
||||
t.string "email"
|
||||
t.float "amount"
|
||||
|
||||
@@ -151,6 +151,7 @@ FactoryGirl.modify do
|
||||
end
|
||||
|
||||
factory :shipping_method do
|
||||
distributor { Enterprise.is_distributor.first || FactoryGirl.create(:distributor_enterprise) }
|
||||
display_on ''
|
||||
end
|
||||
|
||||
|
||||
@@ -14,13 +14,14 @@ feature 'shipping methods' do
|
||||
distributor = create(:distributor_enterprise, name: 'Aeronautical Adventures')
|
||||
|
||||
# When I create a shipping method and set the distributor
|
||||
visit new_admin_shipping_method_path
|
||||
fill_in :name, with: 'Carrier Pidgeon'
|
||||
visit spree.new_admin_shipping_method_path
|
||||
fill_in 'shipping_method_name', with: 'Carrier Pidgeon'
|
||||
select 'Aeronautical Adventures', from: 'shipping_method_distributor_id'
|
||||
click_button 'Create'
|
||||
|
||||
# Then the shipping method should have its distributor set
|
||||
flash_message.should == 'Your shipping method has been created'
|
||||
flash_message.should == 'Shipping method "Carrier Pidgeon" has been successfully created!'
|
||||
|
||||
sm = Spree::ShippingMethod.last
|
||||
sm.name.should == 'Carrier Pidgeon'
|
||||
sm.distributor.should == distributor
|
||||
|
||||
13
spec/models/shipping_method_spec.rb
Normal file
13
spec/models/shipping_method_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe ShippingMethod do
|
||||
it "should be valid when built from factory" do
|
||||
build(:shipping_method).should be_valid
|
||||
end
|
||||
|
||||
it "should require a distributor" do
|
||||
build(:shipping_method, distributor: nil).should_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user