Skip to content

Commit

Permalink
Removed redundant spec from order_spec and added new quantity and wei…
Browse files Browse the repository at this point in the history
…ght specs to cart_item. Still have unique values errors with Faker gem...
  • Loading branch information
Jellyfishboy committed Feb 28, 2014
1 parent 4b0ac3d commit 212afca
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 14 deletions.
6 changes: 1 addition & 5 deletions app/models/cart_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,5 @@ def update_weight quantity, weight, accessory
weight = accessory.nil? ? weight : (weight + accessory.weight)
self.weight = (weight*quantity.to_i)
end

# def update_price quantity, price, accessory
# price = accessory.nil? ? price : (price + accessory.price)
# self.price = (price*quantity.to_i)
# end

end
Binary file modified db/test.sqlite3
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions spec/factories/cart_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,20 @@
create(:cart_item_accessory, cart_item: cart_item)
end
end

factory :update_cart_item_quantity do
quantity 5
after(:create) do |cart_item, evaluator|
create(:cart_item_accessory, quantity: 5, cart_item: cart_item)
end
end

factory :update_cart_item_weight do
weight BigDecimal.new("13.5")
after(:create) do |cart_item, evaluator|
accessory = create(:accessory, weight: BigDecimal.new("2.5"))
create(:cart_item_accessory, cart_item: cart_item, accessory: accessory)
end
end
end
end
42 changes: 40 additions & 2 deletions spec/models/cart_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'bigdecimal'

describe CartItem do

Expand All @@ -15,7 +16,44 @@
expect(cart_item.total_price).to eq 84
end

it "should update the quantity of the cart item, and it's associated accessory if necessary"
it "should update the weight of the cart item, including accessory weight if necessary"
describe "Updating quantity" do
let!(:cart_item) { create(:update_cart_item_quantity) }

before(:each) do
cart_item.update_quantity(10, cart_item.cart_item_accessory)
end
it "should update the cart_item quantity" do
expect(cart_item.quantity).to eq 10
end
context "if there is a cart_item_accessory" do
it "should update the cart_item_accessory quantity" do
expect(cart_item.cart_item_accessory.quantity).to eq 10
end
end
end

describe "Update weight" do

let!(:cart_item) { create(:cart_item, weight: BigDecimal.new("20.1"))}
let!(:cart_accessory) { create(:update_cart_item_weight) }

before(:each) do
cart_item.update_weight(12, cart_item.weight, nil)
cart_accessory.update_weight(12, cart_accessory.weight, cart_accessory.cart_item_accessory.accessory)
end

context "without a cart_item_accessory" do

it "should calculate the weight of the cart_item" do
expect(cart_item.weight).to eq BigDecimal.new("241.2")
end
end

context "with a cart_item_accessory" do

it "should calculate the weight of the cart_item, including the cart_item_accessory weight" do
expect(cart_accessory.weight).to eq BigDecimal.new("192")
end
end
end
end
12 changes: 5 additions & 7 deletions spec/models/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@
}.to change(OrderItemAccessory, :count).by(3)
end
end

it "should save each order_item" do
# order.add_cart_items_from_cart(cart)
# order.order_items.each do |order_item|
# expect(order_item).to receive(:save).once
# end
end
end

describe "Calculating an order" do
Expand All @@ -53,6 +46,11 @@
it "should set the total using the sub_total, tax and order shipping price"
end

describe "Calculating the shipping tier" do

it "should return the correct shipping tier for the highest dimensions"
end

describe "Managing an order shipping" do
let(:order) { create(:order, shipping_date: nil) }
let(:order_2) { create(:order, shipping_date: Date.today) }
Expand Down

0 comments on commit 212afca

Please sign in to comment.