Skip to content

Instantly share code, notes, and snippets.

@davetron5000
Last active January 2, 2023 14:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davetron5000/a2abeedc1fc42c876780a07ad425d611 to your computer and use it in GitHub Desktop.
Save davetron5000/a2abeedc1fc42c876780a07ad425d611 to your computer and use it in GitHub Desktop.
# Assume that create_invoice(customer, order) should:
# - create a row in the invoices table
# - that row should be charged_at nil
# - the amount should be the order's amount
describe "#create_invoice" do
let(:customer) { create(:customer) }
let(:order) { create(:order, customer: customer, price: 123_56) }
before do
subject.create_invoice(customer, order)
end
it "should create a row in the invoices table" do
expect(customer.invoices.size).to eq(1)
end
it "should set the invoice as not having been charged yet" do
expect(customer.invoices.first.charged_at).to be_nil
end
it "should use the order's price for the invoice's amount" do
expect(customer.invoices.first.amount_cents).to eq(123_56)
end
end
# Assume that create_invoice(customer, order) should:
# - create a row in the invoices table
# - that row should be charged_at nil
# - the amount should be the order's amount
describe "#create_invoice" do
subject(:invoice_creator) { described_class.new }
it "creates an uncharged invoice using the order's price as the amount" do
customer = create(:customer)
order = create(:order, customer: customer, price: 123_56)
invoice_creator.create_invoice(customer, order)
aggregate_failures do
expect(customer.invoices.size).to eq(1)
expect(customer.invoices.first.charged_at).to eq(nil)
expect(customer.invoices.first.amount_cents).to eq(123_56)
end
end
end
# Assume that create_invoice(customer, order) should:
# - create a row in the invoices table
# - that row should be charged_at nil
# - the amount should be the order's amount
describe "#create_invoice" do
subject(:invoice_creator) { described_class.new }
it "creates an uncharged invoice using the order's price as the amount" do
customer = create(:customer)
order = create(:order, customer: customer, price: 123_56)
invoice_creator.create_invoice(customer, order)
expect(customer.invoices.size).to eq(1)
invoice = customer.invoices.first
aggregate_failures do
expect(invoice.charged_at).to eq(nil)
expect(invoice.amount_cents).to eq(123_56)
end
end
end
# Assume that create_invoice(customer, order) should:
# - create a row in the invoices table
# - that row should be charged_at nil
# - the amount should be the order's amount
# - create a return_label on the invoice
# - set the return_label from address to the customer's
# - set the return_label to address to the company's
describe "#create_invoice" do
subject(:invoice_creator) { described_class.new }
it "creates an uncharged invoice using the order's price as the amount with a return label" do
customer = create(:customer)
order = create(:order, customer: customer, price: 123_56)
invoice_creator.create_invoice(customer, order)
expect(customer.invoices.size).to eq(1)
invoice = customer.invoices.first
aggregate_failures do
expect(invoice.charged_at).to eq(nil)
expect(invoice.amount_cents).to eq(123_56)
end
expect(invoice.return_label).not_to eq(nil)
return_label = invoice.return_label
aggregate_failures do
expect(return_label.to_address).to eq(Company.address)
expect(return_label.from_address).to eq(customer.address)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment