spec/models/expense_spec.rb in expense_gun-1.0.0 vs spec/models/expense_spec.rb in expense_gun-1.0.1

- old
+ new

@@ -140,32 +140,42 @@ it "#total_all_taxes should return sum of lines" do expense = FactoryGirl.build(:expense, expense_lines: []) expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10) expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10) - expect(expense.total_all_taxes).to be 20.0 + expect(expense.total_all_taxes).to eq 20.0 end it "#total_employee_payback should return sum of lines" do expense = FactoryGirl.build(:expense, expense_lines: []) expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10, company_part: 100) expense.expense_lines << FactoryGirl.build(:expense_line, total_all_taxes: 10, company_part: 50) - expect(expense.total_employee_payback).to be 15.0 + expect(expense.total_employee_payback).to eq 15.0 end it "#total_vat_deductible should return sum of lines" do expense = FactoryGirl.build(:expense, expense_lines: []) category1 = FactoryGirl.build(:category, vat_deductible: true) category2 = FactoryGirl.build(:category, vat_deductible: false) expense.expense_lines << FactoryGirl.build(:expense_line, vat: 10, category: category1) expense.expense_lines << FactoryGirl.build(:expense_line, vat: 10, category: category2) - expect(expense.total_vat_deductible).to be 10.0 + expect(expense.total_vat_deductible).to eq 10.0 end it "#may_edit? should return false unless expense is not submited" do expect(ExpenseGun::Expense.new(state: :new).may_edit?).to be true expect(ExpenseGun::Expense.new(state: :submited).may_edit?).to be false expect(ExpenseGun::Expense.new(state: :acceped).may_edit?).to be false expect(ExpenseGun::Expense.new(state: :refused).may_edit?).to be false expect(ExpenseGun::Expense.new(state: :canceled).may_edit?).to be false + end + + it "destroy an expense should destroy associated expense lines" do + expense = FactoryGirl.create(:expense) + expense_line_ids = expense.expense_lines.map(&:id) + expect(expense_line_ids.any?).to be true + expense.destroy + expense_line_ids.map do |id| + expect(ExpenseGun::ExpenseLine.exists?(id)).to be false + end end end \ No newline at end of file