| Issue 102: | PATCH Delete previous promotion and assign a new one properly. | |
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
1. Its not reproductible by the web interface.
What version of the product are you using? On what operating system?
Trunk. Ubuntu 7.10
Please provide any additional information below.
Problem 1:
Do that:
self.order_line_items.delete(self.promotion_line_item) if
self.promotion_line_item
instead of
self.promotion_line_item.destroy if self.promotion_line_item
Its not a good thing to nuke an object inside a collection, the collection
has the delete method (Things start to behave strange until the object is
reloaded).
Problem 2:
Assign an object:
self.promotion = promo
instead of just its id:
self.promotion_id = promo.id
when possible.
Same reason, it behaves wrong unless reloaded and in some situation. (if
you use an object then an id, the relation isn't even saved and doesn't
give any error).
These errors happens when testing the set_promo_code method alone, and
doesn't happen using the web interface because on checkout the controller
reloads all objects again. (I think that a model method should not rely on
the app flow to do its job and work properly)
The following three tests illustrates the problem 2, very odd. Its really a
generic problem, and happens in other places too.
# Always use the object and nothing more is needed.
def test_associate_using_object_all_times
a = Order.new
a.order_status_code = order_status_codes(:cart)
a.save
assert_equal a.order_status_code, order_status_codes(:cart)
a.order_status_code = order_status_codes(:to_charge)
a.save
assert_equal a.order_status_code, order_status_codes(:to_charge)
end
# When using the object then the id, the parent need to be reloaded first
or it will simply ignore the change.
def test_associate_using_object_then_id
a = Order.new
a.order_status_code = order_status_codes(:cart)
a.save
assert_equal a.order_status_code, order_status_codes(:cart)
a.order_status_code_id = 2
a.save
assert_not_equal a.order_status_code, order_status_codes(:to_charge)
a.reload
a.order_status_code_id = 2
a.save
assert_equal a.order_status_code, order_status_codes(:to_charge)
end
# When using the id then the object, nothing more is needed.
def test_associate_using_id_then_object
a = Order.new
a.order_status_code_id = 1
a.save
assert_equal a.order_status_code, order_status_codes(:cart)
a.order_status_code = order_status_codes(:to_charge)
a.save
assert_equal a.order_status_code, order_status_codes(:to_charge)
end
Aug 11, 2008
Project Member
#1
subim...@gmail.com
Status:
Fixed
|