Skip to content

Instantly share code, notes, and snippets.

@pda
Forked from mipearson/line_item.rb
Created April 22, 2013 01:29
Show Gist options
  • Save pda/5431874 to your computer and use it in GitHub Desktop.
Save pda/5431874 to your computer and use it in GitHub Desktop.
class LineItem < ActiveRecord::Base
belongs_to :invoice
def allocated?
status == 'allocated'
end
def refundable?
allocated? && invoice.refundable?
end
def cancellable?
allocated? && invoice.cancellable?
end
end
describe LineItem do
describe "permissions" do
subject do
LineItem.new(status: status, invoice: stub_model(Invoice, invoice_attr))
end
context "with an invoice that allows for refunds and cancellations" do
let(:invoice_attr) { {refundable?: true, cancellable?: true} }
context "and allocated" do
let(:status) { "allocated" }
it { should be_refundable }
it { should be_cancellable }
end
context "and not allocated" do
let(:status) { "cancelled" }
it { should_not be_refundable }
it { should_not be_cancellable }
end
end
context "with an invoice that doesn't allow for refunds and cancellations" do
let(:invoice_attr) { {refundable?: false, cancellable?: false} }
let(:status) { "allocated" }
it { should_not be_refundable }
it { should_not be_cancellable }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment