Sha256: b590b950967c5959041297e46f07814791d0480bcee1921cb97ee6c31e598ec6
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
require "rails_helper" describe ::Dorsale::BillingMachine::InvoiceLine, type: :model do it { is_expected.to belong_to :invoice } it { is_expected.to validate_presence_of :invoice } it { is_expected.to respond_to :quantity } it { is_expected.to respond_to :label } it { is_expected.to respond_to :vat_rate } it { is_expected.to respond_to :total } it { is_expected.to respond_to :unit } it { is_expected.to respond_to :unit_price } it "should have a valid factory" do expect(build(:billing_machine_invoice_line)).to be_valid end describe "default values" do it "quantity should be 0" do expect(::Dorsale::BillingMachine::InvoiceLine.new.quantity).to eq 0 end it "unit_price should be 0" do expect(::Dorsale::BillingMachine::InvoiceLine.new.unit_price).to eq 0 end it "vat_rate should be 0" do expect(::Dorsale::BillingMachine::InvoiceLine.new.vat_rate).to eq ::Dorsale::BillingMachine::DEFAULT_VAT_RATE end end it "should be sorted by created_at" do line1 = create(:billing_machine_invoice_line, :created_at => DateTime.now + 1.seconds) line2 = create(:billing_machine_invoice_line, :created_at => DateTime.now + 2.seconds) line3 = create(:billing_machine_invoice_line, :created_at => DateTime.now + 3.seconds) line4 = create(:billing_machine_invoice_line, :created_at => DateTime.now + 4.seconds) line3.update(:created_at => DateTime.now+5.seconds) lines = ::Dorsale::BillingMachine::InvoiceLine.all expect(lines).to eq [line1, line2, line4, line3] end it "should update the total upon save" do invoice = create(:billing_machine_invoice_line, quantity: 10, unit_price: 10, total: 0) expect(invoice.total).to eq(100) end it "should update the total gracefully with invalid data" do invoice = create(:billing_machine_invoice_line, quantity: nil, unit_price: nil, total: 0) expect(invoice.total).to eq(0) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dorsale-2.7.3 | spec/models/dorsale/billing_machine/invoice_line_spec.rb |