whats the use for reload? and how it works ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 5, 2007, at 12:37 PM, prabu wrote:> whats the use for reload? and how it works ?Class reloading, if enabled, is triggered by some code at the end of each request cycle. In the console, however, there are no requests going on so code changes are not refreshed. The reload! method is offered as a way to refresh classes manually. -- fxn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
prabu wrote:> whats the use for reload? and how it works ?Try this test case: assert_difference @tygr.props, :count, -1 do xhr :get, ''apply_prop'', :prop_id => potion.id, :user_id => @tygr.id @tygr.reload end Before calling xhr :get, the @tygr model object has one prop. xhr :get tests the ''apply_prop'' action, which must load its own copy of the same tygr model object, to consume its prop and save the new list. So, before assert_difference detects the prop count increases by -1, the @tygr object gets a reload to refresh its prop list. Maybe @tygr.props.reload would be cleaner. And if my tests have too many reloads, I should bottle them up, like this: def assert_model_difference(model, method, difference) assert_difference model, method, difference do yield model.reload end end ... assert_model_difference @tygr.props, :count, -1 do xhr :get, ''apply_prop'', :prop_id => potion.id, :user_id => @tygr.id end Those are all test-side reloads, because the testing code often cannot pass the same model object into the production code as it will use. sessions and params should only pass IDs. So we get an "alias" situation, with two in-memory copies of the same model object identity, and we need save on one side and reload on the other to synchronize them. In production code, I suspect that too many ''reload'' calls are a "design smell" - a hint that something else in the design should improve. An event-driven program should not alias the same model objects all over the place; it should load them up once, mess with them once, and save them once. I will crack down on y''all abusing that guideline as soon as I figure out how to follow it myself! -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
def test_invalid_first_week_ship_score Swap.find(1).update_attributes(:swap_status_id => 1) users(:jacob).update_attribute(:score, 1) old_score = users(:jacob).reload.score login_as :jacob send_shipment_test(old_score) end the above example how the reload works users(:jacob) is a fixture actually what happened whether the fixture data is reload or update_attribute data is reload? please explain --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---