From 14268b7be0ae34a97d472918bc9bf53cb83f4e77 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 12 Aug 2013 10:00:10 +1000 Subject: [PATCH] Create adjustment metadata when creating adjustment --- app/models/product_distribution.rb | 3 ++- spec/models/product_distribution_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/product_distribution.rb b/app/models/product_distribution.rb index 7ef2a90cdf..a5c1438605 100644 --- a/app/models/product_distribution.rb +++ b/app/models/product_distribution.rb @@ -25,7 +25,8 @@ class ProductDistribution < ActiveRecord::Base end def create_adjustment_for(line_item) - enterprise_fee.create_adjustment(adjustment_label_for(line_item), line_item.order, line_item, true) + a = enterprise_fee.create_adjustment(adjustment_label_for(line_item), line_item.order, line_item, true) + AdjustmentMetadata.create! adjustment: a, enterprise: enterprise_fee.enterprise, fee_name: enterprise_fee.name, fee_type: enterprise_fee.fee_type, enterprise_role: 'distributor' end def clear_all_enterprise_fee_adjustments_for(line_item) diff --git a/spec/models/product_distribution_spec.rb b/spec/models/product_distribution_spec.rb index a1f92d2cb3..ad18e3f8ad 100644 --- a/spec/models/product_distribution_spec.rb +++ b/spec/models/product_distribution_spec.rb @@ -57,7 +57,11 @@ describe ProductDistribution do adjustment.amount.should == 1.23 # And it should have some associated metadata - pending 'Needs metadata spec' + md = adjustment.metadata + md.enterprise.should == distributor + md.fee_name.should == enterprise_fee.name + md.fee_type.should == enterprise_fee.fee_type + md.enterprise_role.should == 'distributor' end end @@ -152,6 +156,12 @@ describe ProductDistribution do adjustment.source.should == line_item adjustment.originator.should == pd.enterprise_fee adjustment.should be_mandatory + + md = adjustment.metadata + md.enterprise.should == pd.distributor + md.fee_name.should == pd.enterprise_fee.name + md.fee_type.should == pd.enterprise_fee.fee_type + md.enterprise_role.should == 'distributor' end end