-
-
Save pda/5431874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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