Skip to content

Commit

Permalink
Checking that the record instance responds to the counter setter meth…
Browse files Browse the repository at this point in the history
…od before calling update_counters
  • Loading branch information
tombenner committed May 13, 2012
1 parent e7ac5e5 commit c6c17ee
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ar_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def merge!(other, options={})

#update counters, this is very basic/hacky/not secure for customized counters...
counter = "#{association_name}_count"
next unless other.respond_to?(counter)
next unless other.respond_to?(counter) && other.respond_to?("#{counter}=")
self.class.update_counters(id, counter => other.send(counter))
end

Expand Down

1 comment on commit c6c17ee

@grosser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, this should be even better :)
next unless other.respond_to?(counter) && respond_to?("#{counter}=")

Please sign in to comment.