mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add AdjustmentMetadata, for holding info about enterprise fee adjustments at time of creation
This commit is contained in:
4
app/models/adjustment_metadata.rb
Normal file
4
app/models/adjustment_metadata.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class AdjustmentMetadata < ActiveRecord::Base
|
||||
belongs_to :adjustment, class_name: 'Spree::Adjustment'
|
||||
belongs_to :enterprise
|
||||
end
|
||||
@@ -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
|
||||
|
||||
13
db/migrate/20130809075103_create_adjustment_metadata.rb
Normal file
13
db/migrate/20130809075103_create_adjustment_metadata.rb
Normal 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
|
||||
12
db/schema.rb
12
db/schema.rb
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
6
spec/models/adjustment_metadata_spec.rb
Normal file
6
spec/models/adjustment_metadata_spec.rb
Normal 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
|
||||
8
spec/models/adjustment_spec.rb
Normal file
8
spec/models/adjustment_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user