Add AdjustmentMetadata, for holding info about enterprise fee adjustments at time of creation

This commit is contained in:
Rohan Mitchell
2013-08-12 09:59:44 +10:00
parent ba0b3bad85
commit 149d48ff5a
7 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
class AdjustmentMetadata < ActiveRecord::Base
belongs_to :adjustment, class_name: 'Spree::Adjustment'
belongs_to :enterprise
end

View File

@@ -1,5 +1,7 @@
module Spree
Adjustment.class_eval do
has_one :metadata, class_name: 'AdjustmentMetadata'
scope :enterprise_fee, where(originator_type: 'EnterpriseFee')
end
end

View File

@@ -0,0 +1,13 @@
class CreateAdjustmentMetadata < ActiveRecord::Migration
def change
create_table :adjustment_metadata do |t|
t.integer :adjustment_id
t.integer :enterprise_id
t.string :fee_name
t.string :fee_type
t.string :enterprise_role
end
add_index :adjustment_metadata, :adjustment_id
end
end

View File

@@ -11,7 +11,17 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130809045637) do
ActiveRecord::Schema.define(:version => 20130809075103) do
create_table "adjustment_metadata", :force => true do |t|
t.integer "adjustment_id"
t.integer "enterprise_id"
t.string "fee_name"
t.string "fee_type"
t.string "enterprise_role"
end
add_index "adjustment_metadata", ["adjustment_id"], :name => "index_adjustment_metadata_on_adjustment_id"
create_table "carts", :force => true do |t|
t.integer "user_id"

View File

@@ -97,6 +97,14 @@ FactoryGirl.define do
calculator { FactoryGirl.build(:itemwise_calculator) }
end
factory :adjustment_metadata, :class => AdjustmentMetadata do
adjustment { FactoryGirl.create(:adjustment) }
enterprise { FactoryGirl.create(:distributor_enterprise) }
fee_name 'fee'
fee_type 'packing'
enterprise_role 'distributor'
end
factory :itemwise_calculator, :class => OpenFoodWeb::Calculator::Itemwise do
end

View File

@@ -0,0 +1,6 @@
describe AdjustmentMetadata do
it "is valid when build from factory" do
adjustment = create(:adjustment)
adjustment.should be_valid
end
end

View File

@@ -0,0 +1,8 @@
module Spree
describe Adjustment do
it "has metadata" do
adjustment = create(:adjustment, metadata: create(:adjustment_metadata))
adjustment.metadata.should be
end
end
end