spree/spree — pull request #2327 by huoxito (2012-12-17 06:36:02+00:00)
Title: Fixes PercentPerItem calculator equation

There's a bug when using the PercentPerItem calculator.

To reproduce:

Create a promotion with Add to Cart event. Save
Set a product rule and choose one product. Update
Set a create adjustment action. Update. Choose Percent Per Item calculator. Update
Enter **10** in the percent input. Update

Add the same product above to the cart
You should see the order total is 0.00

It happens because when creating the adjustment Spree tries to doesn't allow the discount to exceed the sum of order total.

```ruby
def compute_amount(calculable)
[(calculable.item_total + calculable.ship_total), super.to_f.abs].min * -1
end
```

The compute_amount in PercentPerItem is broken because it expects input like "0.10" if you want to give 10% on every product. But I believe, as it is expected in every other calculator, input should be "10" not "0.10".

This test case can reproduce the issue. I ran it on current 1-3-stable (promo/spec/requests/promotions_adjustments_spec.rb)

```ruby
it "should allow an admin to create an product promo with percent per item discount" do
visit spree.admin_path
click_link "Promotions"
click_link "New Promotion"

fill_in "Name", :with => "Percent Per Item"
select2 "Add to cart", :from => "Event Name"
click_button "Create"
page.should have_content("Editing Promotion")

select2 "Product(s)", :from => "Add rule of type"
within("#rule_fields") { click_button "Add" }
select2_search "RoR Mug", :from => "Choose products"
within('#rule_fields') { click_button "Update" }

select2 "Create adjustment", :from => "Add action of type"
within('#action_fields') { click_button "Add" }
select2 "Percent Per Item", :from => "Calculator"
within('#actions_container') { click_button "Update" }
within('.calculator-fields') { fill_in "Percent", :with => "10" }
within('#actions_container') { click_button "Update" }

visit spree.root_path
click_link "RoR Mug"
click_button "Add To Cart"

Spree::Order.last.total.to_f.should == 0.00
end
```

It passes when it shouldn't. The order total should be 36.00