Sha256: 47e7ce0979ab9b8ecb8bc686efde0df8132ceb86f532c6b2252b5029a984ded4

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

require 'test_helper'

class InvoiceBar::ItemTest < ActiveSupport::TestCase
  should allow_mass_assignment_of :name
  should allow_mass_assignment_of :number
  should allow_mass_assignment_of :price
  should allow_mass_assignment_of :unit
  should_not allow_mass_assignment_of :amount
  should validate_presence_of :name
  should belong_to :itemable
  should allow_mass_assignment_of :itemable_id
  should allow_mass_assignment_of :itemable_type
  
  test "item should create a copy of self" do
    item = FactoryGirl.build(:invoice_bar_item)   
    copy = item.copy
    
    assert_equal item.name, copy.name
    assert_equal item.number, copy.number
    assert_equal item.price, copy.price
    assert_equal item.unit, copy.unit
    assert_equal item.amount, copy.amount
  end
  
  test "should count total amount for item" do
    item = FactoryGirl.build(:invoice_bar_item, :name => 'Item', :price => 100, :number => 5)
    
    item.update_amount
    
    assert_equal 500, item.amount
    
    item.price = 100
    item.number = 10
    
    assert_equal 1000, item.total
  end

  test "should show human price " do
    item = FactoryGirl.build(:invoice_bar_item, :name => 'Item', :price => 100, :number => 5)
    
    item.update_amount
    
    assert_equal FormattedMoney.amount(100), item.human_price
    assert_equal FormattedMoney.amount(500), item.human_amount
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
invoice_bar-0.0.6 test/unit/invoice_bar/item_test.rb
invoice_bar-0.0.5 test/unit/invoice_bar/item_test.rb
invoice_bar-0.0.4 test/unit/invoice_bar/item_test.rb
invoice_bar-0.0.3 test/unit/invoice_bar/item_test.rb
invoice_bar-0.0.2 test/unit/invoice_bar/item_test.rb
invoice_bar-0.0.1 test/unit/invoice_bar/item_test.rb