Skip to content

Instantly share code, notes, and snippets.

@braidn
Created April 17, 2014 16:21
Show Gist options
  • Save braidn/10995681 to your computer and use it in GitHub Desktop.
Save braidn/10995681 to your computer and use it in GitHub Desktop.
require 'spec_helper'
module Spree
describe PaidOrderFactory do
let(:user){ create(:quarterly_user) }
let(:address){ create(:address) }
let(:variant) {
create(:variant) do |v|
v.product.update_attributes!({shipping_category: shipping_category}, without_protection: true)
end
}
let(:valid_credit_card) { create(:credit_card, number: '4111111111111111',
gateway_customer_profile_id: 'cus_848484') }
let(:invalid_credit_card) { create(:credit_card, number: '4242424242424242',
gateway_customer_profile_id: 'cus_848484') }
let(:payment_method) { create(:bogus_payment_method) }
let(:shipping_category) {
shipping_method = create(:shipping_method_with_category, match_one: true)
shipping_method.calculator.set_preference(:amount, 10.0)
shipping_method.shipping_category
}
subject { PaidOrderFactory.new(payment_method) }
context "given a valid credit card" do
before do
@order ||= do_create(valid_credit_card)
binding.pry
end
describe "#create" do
it "assigns a bill address" do
expect(order.bill_address).to eq(address)
end
it "assigns a ship address" do
expect(order.ship_address).to eq(address)
end
xit "assigns an email" do
expect(order.email).to eq(user.email)
end
xit "assigns variant" do
expect(order.line_item.variant.id).to eq(variant.id)
end
xit "assigns a shipping method" do
expect(order.shipping_method).to be_present
end
xit "assigns a payment" do
expect(order.payment).to be_present
end
xit "creates a completed order" do
expect(order).to be_complete
end
xit "creates a paid order" do
expect(order).to be_paid
end
xit "creates a shipment" do
expect(order.shipment).to be_ready
end
xit "creates a system generated order" do
expect(order).to be_system_generated
end
end
end
context "with listeners" do
let(:listener) { double(:listener) }
before do
listener.as_null_object
subject.add_listener(listener)
end
xit "notifies the listener the order is ready for payment" do
listener.should_receive(:ready_for_payment)
do_create(valid_credit_card)
end
context "given a valid credit card" do
xit "notifies the listener the order is created" do
listener.should_receive(:order_created)
do_create(valid_credit_card)
end
xit "notifies the listener the order is completed" do
listener.should_receive(:order_completed)
do_create(valid_credit_card)
end
end
context "given an invalid credit card" do
xit "notifies the listener the payment failed" do
listener.should_receive(:payment_failed)
do_create(invalid_credit_card)
end
end
end
def do_create(credit_card)
subject.create(
user: user,
bill_address: address,
ship_address: address,
variant: variant,
payment_source: credit_card,
shipping_methods: shipping_category.shipping_methods
)
end
def order
@order
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment