aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-27 16:38:54 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-27 16:38:54 -0300
commit7b0402fabb2ed9801108b060434f83e6f25a4748 (patch)
treefd072e553f7f006b7e41811f9538f99acd6ddd8d /activerecord/test
parente7438501d69f266aca4ba5d6f511b9fe5264862f (diff)
parent72de8946515725b8827939d90698e2a082a5eae1 (diff)
downloadrails-7b0402fabb2ed9801108b060434f83e6f25a4748.tar.gz
rails-7b0402fabb2ed9801108b060434f83e6f25a4748.tar.bz2
rails-7b0402fabb2ed9801108b060434f83e6f25a4748.zip
Merge pull request #9274 from KrzysiekJ/spaces_in_scope_names
Use define_method when method name contains weird characters.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/named_scope_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index b593270352..42361cfbcb 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -271,6 +271,20 @@ class NamedScopeTest < ActiveRecord::TestCase
assert_equal 'lifo', topic.author_name
end
+ # Method delegation for scope names which look like /\A[a-zA-Z_]\w*[!?]?\z/
+ # has been done by evaluating a string with a plain def statement. For scope
+ # names which contain spaces this approach doesn't work.
+ def test_spaces_in_scope_names
+ klass = Class.new(ActiveRecord::Base) do
+ self.table_name = "topics"
+ scope :"title containing space", -> { where("title LIKE '% %'") }
+ scope :approved, -> { where(:approved => true) }
+ end
+ assert_equal klass.send(:"title containing space"), klass.where("title LIKE '% %'")
+ assert_equal klass.approved.send(:"title containing space"), klass.approved.where("title LIKE '% %'")
+ end
+ end
+
def test_find_all_should_behave_like_select
assert_equal Topic.base.to_a.select(&:approved), Topic.base.to_a.find_all(&:approved)
end