Commit cca9b1edceeb7ddee0f90806aa68b33dca0d0f65
1 parent
2cc91ce2
Exists in
master
and in
29 other branches
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,10 +31,10 @@ class InputTest < ActiveSupport::TestCase | ||
31 | product_category = fast_create(ProductCategory) | 31 | product_category = fast_create(ProductCategory) |
32 | product = fast_create(Product, :product_category_id => product_category.id) | 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 | assert_equal 1, first_input.position | 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 | assert_equal 2, second_input.position | 38 | assert_equal 2, second_input.position |
39 | end | 39 | end |
40 | 40 | ||
@@ -42,9 +42,9 @@ class InputTest < ActiveSupport::TestCase | @@ -42,9 +42,9 @@ class InputTest < ActiveSupport::TestCase | ||
42 | product_category = fast_create(ProductCategory) | 42 | product_category = fast_create(ProductCategory) |
43 | product = fast_create(Product, :product_category_id => product_category.id) | 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 | assert_equal [first_input, second_input, last_input], product.inputs(true) | 49 | assert_equal [first_input, second_input, last_input], product.inputs(true) |
50 | 50 | ||
@@ -68,17 +68,17 @@ class InputTest < ActiveSupport::TestCase | @@ -68,17 +68,17 @@ class InputTest < ActiveSupport::TestCase | ||
68 | end | 68 | end |
69 | 69 | ||
70 | should 'has price details if price_per_unit filled' do | 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 | assert input.has_price_details? | 72 | assert input.has_price_details? |
73 | end | 73 | end |
74 | 74 | ||
75 | should 'has price details if amount_used filled' do | 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 | assert input.has_price_details? | 77 | assert input.has_price_details? |
78 | end | 78 | end |
79 | 79 | ||
80 | should 'not have price details if only unit is filled' do | 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 | assert !input.has_price_details? | 82 | assert !input.has_price_details? |
83 | end | 83 | end |
84 | 84 | ||
@@ -92,7 +92,7 @@ class InputTest < ActiveSupport::TestCase | @@ -92,7 +92,7 @@ class InputTest < ActiveSupport::TestCase | ||
92 | ["12.345.678", 12345678.00], | 92 | ["12.345.678", 12345678.00], |
93 | ["12,345,678", 12345678.00] | 93 | ["12,345,678", 12345678.00] |
94 | ].each do |input, output| | 94 | ].each do |input, output| |
95 | - new_input = Input.new(:price_per_unit => input) | 95 | + new_input = build(Input, :price_per_unit => input) |
96 | assert_equal output, new_input.price_per_unit | 96 | assert_equal output, new_input.price_per_unit |
97 | end | 97 | end |
98 | end | 98 | end |
@@ -107,7 +107,7 @@ class InputTest < ActiveSupport::TestCase | @@ -107,7 +107,7 @@ class InputTest < ActiveSupport::TestCase | ||
107 | ["12.345.678", 12345678.00], | 107 | ["12.345.678", 12345678.00], |
108 | ["12,345,678", 12345678.00] | 108 | ["12,345,678", 12345678.00] |
109 | ].each do |input, output| | 109 | ].each do |input, output| |
110 | - new_input = Input.new(:amount_used => input) | 110 | + new_input = build(Input, :amount_used => input) |
111 | assert_equal output, new_input.amount_used | 111 | assert_equal output, new_input.amount_used |
112 | end | 112 | end |
113 | end | 113 | end |
@@ -117,7 +117,7 @@ class InputTest < ActiveSupport::TestCase | @@ -117,7 +117,7 @@ class InputTest < ActiveSupport::TestCase | ||
117 | product_category = fast_create(ProductCategory, :name => 'Products') | 117 | product_category = fast_create(ProductCategory, :name => 'Products') |
118 | product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) | 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 | input.amount_used = 10.45 | 121 | input.amount_used = 10.45 |
122 | assert_equal '10.45', input.formatted_amount | 122 | assert_equal '10.45', input.formatted_amount |
123 | end | 123 | end |
@@ -136,7 +136,7 @@ class InputTest < ActiveSupport::TestCase | @@ -136,7 +136,7 @@ class InputTest < ActiveSupport::TestCase | ||
136 | product_category = fast_create(ProductCategory, :name => 'Products') | 136 | product_category = fast_create(ProductCategory, :name => 'Products') |
137 | product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) | 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 | input.amount_used = 10.00 | 140 | input.amount_used = 10.00 |
141 | assert_equal '10', input.formatted_amount | 141 | assert_equal '10', input.formatted_amount |
142 | end | 142 | end |
@@ -146,7 +146,7 @@ class InputTest < ActiveSupport::TestCase | @@ -146,7 +146,7 @@ class InputTest < ActiveSupport::TestCase | ||
146 | product_category = fast_create(ProductCategory, :name => 'Products') | 146 | product_category = fast_create(ProductCategory, :name => 'Products') |
147 | product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) | 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 | input.price_per_unit = 1.45 | 150 | input.price_per_unit = 1.45 |
151 | assert_equal '1.45', input.formatted_value(:price_per_unit) | 151 | assert_equal '1.45', input.formatted_value(:price_per_unit) |
152 | 152 | ||
@@ -163,17 +163,17 @@ class InputTest < ActiveSupport::TestCase | @@ -163,17 +163,17 @@ class InputTest < ActiveSupport::TestCase | ||
163 | end | 163 | end |
164 | 164 | ||
165 | should 'calculate cost of input' do | 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 | assert_equal 20.00, input.cost | 167 | assert_equal 20.00, input.cost |
168 | end | 168 | end |
169 | 169 | ||
170 | should 'cost 0 if amount not defined' do | 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 | assert_equal 0.00, input.cost | 172 | assert_equal 0.00, input.cost |
173 | end | 173 | end |
174 | 174 | ||
175 | should 'cost 0 if price_per_unit is not defined' do | 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 | assert_equal 0.00, input.cost | 177 | assert_equal 0.00, input.cost |
178 | end | 178 | end |
179 | 179 | ||
@@ -181,9 +181,9 @@ class InputTest < ActiveSupport::TestCase | @@ -181,9 +181,9 @@ class InputTest < ActiveSupport::TestCase | ||
181 | product_category = fast_create(ProductCategory) | 181 | product_category = fast_create(ProductCategory) |
182 | product = fast_create(Product, :product_category_id => product_category.id) | 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 | i1.save! | 188 | i1.save! |
189 | i2.save! | 189 | i2.save! |