diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-08-03 10:50:49 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-08-03 11:05:31 +0100 |
commit | bf2df6e7ba495ac4d2264e0e2558c366f217ee5d (patch) | |
tree | 775ae427819b2200b0ae3c85619d4f5cc8f8c203 /activerecord/test/cases | |
parent | c391919180a19a31a04b9483396d0543a4bed961 (diff) | |
download | rails-bf2df6e7ba495ac4d2264e0e2558c366f217ee5d.tar.gz rails-bf2df6e7ba495ac4d2264e0e2558c366f217ee5d.tar.bz2 rails-bf2df6e7ba495ac4d2264e0e2558c366f217ee5d.zip |
Allow Relation#merge to take a proc.
This was requested by DHH to allow creating of one's own custom
association macros.
For example:
module Commentable
def has_many_comments(extra)
has_many :comments, -> { where(:foo).merge(extra) }
end
end
class Post < ActiveRecord::Base
extend Commentable
has_many_comments -> { where(:bar) }
end
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 034339e413..5fb54b1ca1 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -247,5 +247,9 @@ module ActiveRecord assert relation.merge!(where: :foo).equal?(relation) assert_equal [:foo], relation.where_values end + + test 'merge with a proc' do + assert_equal [:foo], relation.merge(-> { where(:foo) }).where_values + end end end |