Skip to content

Commit

Permalink
add line item specs
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Boertien <[email protected]>
  • Loading branch information
Cluster444 committed Dec 7, 2011
1 parent 77c329d commit 4df9849
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/line_item_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
before_update :check_volume_pricing

private

def check_volume_pricing
if changed? && changes.keys.include?("quantity")
self.price = variant.volume_price(quantity)
end
end
end

18 changes: 18 additions & 0 deletions spec/models/line_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'

describe LineItem do
before :each do
@order = Factory(:order)
@variant = Factory(:variant, :price => 10)
@variant.volume_prices.create! :amount => 9, :range => '(2+)'
@order.add_variant(@variant, 1)
@line_item = @order.line_items.first
end

it 'should update the line item price when the quantity changes to match a range' do
@line_item.price.to_f.should == 10.00
@order.add_variant(@variant, 1)
@line_item.price.to_f.should == 9.00
end
end

0 comments on commit 4df9849

Please sign in to comment.