Extract method to remove some copy pasted code in order_factory_spec

This commit is contained in:
luisramos0
2019-06-10 20:39:29 +01:00
parent 567196fe0e
commit 05a15d9441

View File

@@ -32,8 +32,7 @@ describe OrderFactory do
end
it "builds a new order based on the provided attributes" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.line_items.count).to eq 2
expect(order.customer).to eq customer
expect(order.user).to eq user
@@ -64,8 +63,7 @@ describe OrderFactory do
before { customer.update_attribute(:user_id, nil) }
it "initialises the order without a user_id" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.user).to be nil
end
end
@@ -79,8 +77,7 @@ describe OrderFactory do
context "when skip_stock_check is not requested" do
it "initialises the order but limits stock to the available amount" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).quantity).to eq 2
end
@@ -88,8 +85,7 @@ describe OrderFactory do
before { variant1.update_attribute(:on_demand, true) }
it "initialises the order with the requested quantity regardless of stock" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).quantity).to eq 5
end
end
@@ -99,8 +95,7 @@ describe OrderFactory do
let(:opts) { { skip_stock_check: true } }
it "initialises the order with the requested quantity regardless" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).quantity).to eq 5
end
end
@@ -112,8 +107,7 @@ describe OrderFactory do
context "when skip_stock_check is not requested" do
it "initialised the order but limits stock to the available amount" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).quantity).to eq 3
end
end
@@ -122,8 +116,7 @@ describe OrderFactory do
let(:opts) { { skip_stock_check: true } }
it "initialises the order with the requested quantity regardless" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).quantity).to eq 6
end
end
@@ -133,7 +126,7 @@ describe OrderFactory do
describe "determining the price for line items" do
context "when no override is present" do
it "uses the price from the variant" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).price).to eq 5.0
expect(order.total).to eq 38.0
end
@@ -143,11 +136,16 @@ describe OrderFactory do
let!(:override) { create(:variant_override, hub_id: shop.id, variant_id: variant1.id, price: 3.0) }
it "uses the price from the override" do
expect{ order }.to change{ Spree::Order.count }.by(1)
expect_new_order
expect(order.line_items.find_by_variant_id(variant1.id).price).to eq 3.0
expect(order.total).to eq 34.0
end
end
end
def expect_new_order
expect{ order }.to change{ Spree::Order.count }.by(1)
expect(order).to be_a Spree::Order
end
end
end