Skip to content

Commit

Permalink
update fixed to call the respective instance method that it was invok…
Browse files Browse the repository at this point in the history
…ed upon (it used to be invoking a block from the last instance created).
  • Loading branch information
LoganBarnett committed Jul 10, 2008
1 parent f7da925 commit 4182e20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/monkeybars/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,12 @@ def close_action
public
# Calls the method that was set using Controller.set_update_method. If no method has been set defined, this call is ignored.
def update
self.class.send(:class_variable_get, :@@update_method).call if self.class.class_variables.member?("@@update_method_name")
def update
if self.class.class_variables.member?("@@update_method_name")
method_name = self.class.send(:class_variable_get, :@@update_method_name)
send(method_name)
end
end
end

# Triggers updating of the view based on the mapping and the current contents
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ class ExternalModelOverrideTestController < Monkeybars::Controller
ExternalModelOverrideTestController.send(:view_class).should == "ExternalOverrideTestView"
ExternalModelOverrideTestController.send(:model_class).should == "ExternalOverrideTestModel"
end

it "updates the correct instance on Controller#update" do
class MultipleInstanceUpdateController < Monkeybars::Controller
set_update_method :tick

def tick
object_id
end
end

begin
instance1 = MultipleInstanceUpdateController.create_instance
instance2 = MultipleInstanceUpdateController.create_instance

instance1.update.should_not == instance2.update
ensure
MultipleInstanceUpdateController.destroy_instance instance1
MultipleInstanceUpdateController.destroy_instance instance2
end
end
end

describe "Controller instantiation" do
Expand Down

0 comments on commit 4182e20

Please sign in to comment.