Commit 65e9fc03453a1e8507a1d86505873be07346eff0
Exists in
master
and in
22 other branches
Merge commit 'refs/merge-requests/185' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/185
Showing
3 changed files
with
17 additions
and
1 deletions
Show diff stats
app/models/input.rb
| @@ -9,6 +9,8 @@ class Input < ActiveRecord::Base | @@ -9,6 +9,8 @@ class Input < ActiveRecord::Base | ||
| 9 | 9 | ||
| 10 | belongs_to :unit | 10 | belongs_to :unit |
| 11 | 11 | ||
| 12 | + named_scope :relevant_to_price, :conditions => { :relevant_to_price => true } | ||
| 13 | + | ||
| 12 | include FloatHelper | 14 | include FloatHelper |
| 13 | 15 | ||
| 14 | def price_per_unit=(value) | 16 | def price_per_unit=(value) |
app/models/product.rb
| @@ -158,7 +158,7 @@ class Product < ActiveRecord::Base | @@ -158,7 +158,7 @@ class Product < ActiveRecord::Base | ||
| 158 | 158 | ||
| 159 | def inputs_cost | 159 | def inputs_cost |
| 160 | return 0 if inputs.empty? | 160 | return 0 if inputs.empty? |
| 161 | - inputs.map(&:cost).inject { |sum,price| sum + price } | 161 | + inputs.relevant_to_price.map(&:cost).inject { |sum,price| sum + price } |
| 162 | end | 162 | end |
| 163 | 163 | ||
| 164 | def total_production_cost | 164 | def total_production_cost |
test/unit/input_test.rb
| @@ -177,4 +177,18 @@ class InputTest < ActiveSupport::TestCase | @@ -177,4 +177,18 @@ class InputTest < ActiveSupport::TestCase | ||
| 177 | assert_equal 0.00, input.cost | 177 | assert_equal 0.00, input.cost |
| 178 | end | 178 | end |
| 179 | 179 | ||
| 180 | + should 'list inputs relevants to price' do | ||
| 181 | + product_category = fast_create(ProductCategory) | ||
| 182 | + product = fast_create(Product, :product_category_id => product_category.id) | ||
| 183 | + | ||
| 184 | + i1 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => true) | ||
| 185 | + | ||
| 186 | + i2 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => false) | ||
| 187 | + | ||
| 188 | + i1.save! | ||
| 189 | + i2.save! | ||
| 190 | + assert_includes Input.relevant_to_price, i1 | ||
| 191 | + assert_not_includes Input.relevant_to_price, i2 | ||
| 192 | + end | ||
| 193 | + | ||
| 180 | end | 194 | end |