diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2009-04-04 16:13:18 +1000 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2009-04-04 16:13:18 +1000 |
commit | e878c3e44a8dba19c1188b636e25ec1bc2165116 (patch) | |
tree | 3d06b83492653b6b73422cbf37014fc5c89e9685 /activerecord/test/cases/method_scoping_test.rb | |
parent | ab55ddcc4c5cf31bcaf7720b52dc55d6d54cb150 (diff) | |
parent | 9e9469e83f6144310115124cdecc5cb65db5128e (diff) | |
download | rails-e878c3e44a8dba19c1188b636e25ec1bc2165116.tar.gz rails-e878c3e44a8dba19c1188b636e25ec1bc2165116.tar.bz2 rails-e878c3e44a8dba19c1188b636e25ec1bc2165116.zip |
Merge branch 'master' of git@github.com:lifo/docrails
* 'master' of git@github.com:lifo/docrails: (319 commits)
deletes screencast promo in prologue, its proper place is the References section
Typo fix
list -> index
in caching guide, RESTifies some examples, revised conventions here and there
Tech edit of caching guide from Gregg Pollack
Fix typo in comment: hide_actions -> hide_action
Fix two typos in a comment in config/initializers/backtrace_silencers.rb
With -> with in a title
Clear up a little confusing wording in Routing Guide.
copyedited minor details in the rack on rails guide
remove piece of UrlWriter documentation claiming that you can access named routes as its class methods
Add note about change to session options
TRUNCATE is also a MySQL DDL statement, so document this is a possible caveat when using transactions and savepoints.
Improve documentation for ActiveResource::Validations, fix typos
Fix typos in ActiveResource::Base documentation, use present tense, reword confusing sentences
Update ActiveResource::Connection documentation to use present tense
Fix typos in Active Resource README
Fix a small typo
ensure authors get warnings about broken links, and ensure end users don't
in guides generator, warn about duplicate header IDs only if WARN_DUPLICATE_HEADERS
...
Diffstat (limited to 'activerecord/test/cases/method_scoping_test.rb')
-rw-r--r-- | activerecord/test/cases/method_scoping_test.rb | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 71e2ce8790..3c34cdeade 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -262,6 +262,15 @@ class NestedScopingTest < ActiveRecord::TestCase end end + def test_merge_inner_scope_has_priority + Developer.with_scope(:find => { :limit => 5 }) do + Developer.with_scope(:find => { :limit => 10 }) do + merged_option = Developer.instance_eval('current_scoped_methods')[:find] + assert_equal({ :limit => 10 }, merged_option) + end + end + end + def test_replace_options Developer.with_scope(:find => { :conditions => "name = 'David'" }) do Developer.with_exclusive_scope(:find => { :conditions => "name = 'Jamis'" }) do @@ -369,8 +378,10 @@ class NestedScopingTest < ActiveRecord::TestCase def test_merged_scoped_find poor_jamis = developers(:poor_jamis) Developer.with_scope(:find => { :conditions => "salary < 100000" }) do - Developer.with_scope(:find => { :offset => 1 }) do - assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc')) + Developer.with_scope(:find => { :offset => 1, :order => 'id asc' }) do + assert_sql /ORDER BY id asc / do + assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc')) + end end end end @@ -400,6 +411,29 @@ class NestedScopingTest < ActiveRecord::TestCase end end + def test_nested_scoped_create + comment = nil + Comment.with_scope(:create => { :post_id => 1}) do + Comment.with_scope(:create => { :post_id => 2}) do + assert_equal({ :post_id => 2 }, Comment.send(:current_scoped_methods)[:create]) + comment = Comment.create :body => "Hey guys, nested scopes are broken. Please fix!" + end + end + assert_equal 2, comment.post_id + end + + def test_nested_exclusive_scope_for_create + comment = nil + Comment.with_scope(:create => { :body => "Hey guys, nested scopes are broken. Please fix!" }) do + Comment.with_exclusive_scope(:create => { :post_id => 1 }) do + assert_equal({ :post_id => 1 }, Comment.send(:current_scoped_methods)[:create]) + comment = Comment.create :body => "Hey guys" + end + end + assert_equal 1, comment.post_id + assert_equal 'Hey guys', comment.body + end + def test_merged_scoped_find_on_blank_conditions [nil, " ", [], {}].each do |blank| Developer.with_scope(:find => {:conditions => blank}) do @@ -523,7 +557,6 @@ class HasManyScopingTest< ActiveRecord::TestCase end end - class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase fixtures :posts, :categories, :categories_posts @@ -549,7 +582,6 @@ class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase end end - class DefaultScopingTest < ActiveRecord::TestCase fixtures :developers @@ -577,7 +609,7 @@ class DefaultScopingTest < ActiveRecord::TestCase # Scopes added on children should append to parent scope expected_klass_scope = [{ :create => {}, :find => { :order => 'salary DESC' }}, { :create => {}, :find => {} }] assert_equal expected_klass_scope, klass.send(:scoped_methods) - + # Parent should still have the original scope assert_equal scope, DeveloperOrderedBySalary.send(:scoped_methods) end @@ -597,7 +629,7 @@ class DefaultScopingTest < ActiveRecord::TestCase end def test_named_scope - expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary } + expected = Developer.find(:all, :order => 'salary DESC, name DESC').collect { |dev| dev.salary } received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.salary } assert_equal expected, received end @@ -620,7 +652,6 @@ end =begin # We disabled the scoping for has_one and belongs_to as we can't think of a proper use case - class BelongsToScopingTest< ActiveRecord::TestCase fixtures :comments, :posts @@ -640,7 +671,6 @@ class BelongsToScopingTest< ActiveRecord::TestCase end - class HasOneScopingTest< ActiveRecord::TestCase fixtures :comments, :posts |