Commit cca9b1edceeb7ddee0f90806aa68b33dca0d0f65

Authored by Rodrigo Souto
1 parent 2cc91ce2

rails3: fix input tests

Showing 1 changed file with 18 additions and 18 deletions   Show diff stats
test/unit/input_test.rb
... ... @@ -31,10 +31,10 @@ class InputTest < ActiveSupport::TestCase
31 31 product_category = fast_create(ProductCategory)
32 32 product = fast_create(Product, :product_category_id => product_category.id)
33 33  
34   - first_input = Input.create!(:product => product, :product_category => product_category)
  34 + first_input = create(Input, :product => product, :product_category => product_category)
35 35 assert_equal 1, first_input.position
36 36  
37   - second_input = Input.create!(:product => product, :product_category => product_category)
  37 + second_input = create(Input, :product => product, :product_category => product_category)
38 38 assert_equal 2, second_input.position
39 39 end
40 40  
... ... @@ -42,9 +42,9 @@ class InputTest < ActiveSupport::TestCase
42 42 product_category = fast_create(ProductCategory)
43 43 product = fast_create(Product, :product_category_id => product_category.id)
44 44  
45   - first_input = Input.create!(:product => product, :product_category => product_category)
46   - second_input = Input.create!(:product => product, :product_category => product_category)
47   - last_input = Input.create!(:product => product, :product_category => product_category)
  45 + first_input = create(Input, :product => product, :product_category => product_category)
  46 + second_input = create(Input, :product => product, :product_category => product_category)
  47 + last_input = create(Input, :product => product, :product_category => product_category)
48 48  
49 49 assert_equal [first_input, second_input, last_input], product.inputs(true)
50 50  
... ... @@ -68,17 +68,17 @@ class InputTest < ActiveSupport::TestCase
68 68 end
69 69  
70 70 should 'has price details if price_per_unit filled' do
71   - input = Input.new(:price_per_unit => 10.0)
  71 + input = build(Input, :price_per_unit => 10.0)
72 72 assert input.has_price_details?
73 73 end
74 74  
75 75 should 'has price details if amount_used filled' do
76   - input = Input.new(:amount_used => 10)
  76 + input = build(Input, :amount_used => 10)
77 77 assert input.has_price_details?
78 78 end
79 79  
80 80 should 'not have price details if only unit is filled' do
81   - input = Input.new(:unit => Unit.new)
  81 + input = build(Input, :unit => Unit.new)
82 82 assert !input.has_price_details?
83 83 end
84 84  
... ... @@ -92,7 +92,7 @@ class InputTest < ActiveSupport::TestCase
92 92 ["12.345.678", 12345678.00],
93 93 ["12,345,678", 12345678.00]
94 94 ].each do |input, output|
95   - new_input = Input.new(:price_per_unit => input)
  95 + new_input = build(Input, :price_per_unit => input)
96 96 assert_equal output, new_input.price_per_unit
97 97 end
98 98 end
... ... @@ -107,7 +107,7 @@ class InputTest < ActiveSupport::TestCase
107 107 ["12.345.678", 12345678.00],
108 108 ["12,345,678", 12345678.00]
109 109 ].each do |input, output|
110   - new_input = Input.new(:amount_used => input)
  110 + new_input = build(Input, :amount_used => input)
111 111 assert_equal output, new_input.amount_used
112 112 end
113 113 end
... ... @@ -117,7 +117,7 @@ class InputTest < ActiveSupport::TestCase
117 117 product_category = fast_create(ProductCategory, :name => 'Products')
118 118 product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id)
119 119  
120   - input = Input.new(:product => product)
  120 + input = build(Input, :product => product)
121 121 input.amount_used = 10.45
122 122 assert_equal '10.45', input.formatted_amount
123 123 end
... ... @@ -136,7 +136,7 @@ class InputTest < ActiveSupport::TestCase
136 136 product_category = fast_create(ProductCategory, :name => 'Products')
137 137 product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id)
138 138  
139   - input = Input.new(:product => product)
  139 + input = build(Input, :product => product)
140 140 input.amount_used = 10.00
141 141 assert_equal '10', input.formatted_amount
142 142 end
... ... @@ -146,7 +146,7 @@ class InputTest < ActiveSupport::TestCase
146 146 product_category = fast_create(ProductCategory, :name => 'Products')
147 147 product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id)
148 148  
149   - input = Input.new(:product => product)
  149 + input = build(Input, :product => product)
150 150 input.price_per_unit = 1.45
151 151 assert_equal '1.45', input.formatted_value(:price_per_unit)
152 152  
... ... @@ -163,17 +163,17 @@ class InputTest < ActiveSupport::TestCase
163 163 end
164 164  
165 165 should 'calculate cost of input' do
166   - input = Input.new(:amount_used => 10, :price_per_unit => 2.00)
  166 + input = build(Input, :amount_used => 10, :price_per_unit => 2.00)
167 167 assert_equal 20.00, input.cost
168 168 end
169 169  
170 170 should 'cost 0 if amount not defined' do
171   - input = Input.new(:price_per_unit => 2.00)
  171 + input = build(Input, :price_per_unit => 2.00)
172 172 assert_equal 0.00, input.cost
173 173 end
174 174  
175 175 should 'cost 0 if price_per_unit is not defined' do
176   - input = Input.new(:amount_used => 10)
  176 + input = build(Input, :amount_used => 10)
177 177 assert_equal 0.00, input.cost
178 178 end
179 179  
... ... @@ -181,9 +181,9 @@ class InputTest < ActiveSupport::TestCase
181 181 product_category = fast_create(ProductCategory)
182 182 product = fast_create(Product, :product_category_id => product_category.id)
183 183  
184   - i1 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => true)
  184 + i1 = create(Input, :product => product, :product_category => product_category, :relevant_to_price => true)
185 185  
186   - i2 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => false)
  186 + i2 = create(Input, :product => product, :product_category => product_category, :relevant_to_price => false)
187 187  
188 188 i1.save!
189 189 i2.save!
... ...