aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-12-28 14:07:23 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-12-28 14:07:23 -0800
commit949c8c0d0e92e6e7855dc4decc10eb4c658e0ede (patch)
tree18f556845f47bb08f14e1fbb87a97217669de7c1
parent1b91f534ce91ff5d0a4d39d96a8f19b58022d403 (diff)
downloadrails-949c8c0d0e92e6e7855dc4decc10eb4c658e0ede.tar.gz
rails-949c8c0d0e92e6e7855dc4decc10eb4c658e0ede.tar.bz2
rails-949c8c0d0e92e6e7855dc4decc10eb4c658e0ede.zip
Don't publicize with_scope for tests since it may shadow public misuse
-rw-r--r--activerecord/test/cases/associations/eager_test.rb8
-rwxr-xr-xactiverecord/test/cases/base_test.rb18
-rw-r--r--activerecord/test/cases/calculations_test.rb2
-rw-r--r--activerecord/test/cases/finder_test.rb4
-rw-r--r--activerecord/test/cases/helper.rb5
-rw-r--r--activerecord/test/cases/locking_test.rb2
-rw-r--r--activerecord/test/cases/method_scoping_test.rb174
-rw-r--r--activerecord/test/cases/readonly_test.rb8
-rw-r--r--activerecord/test/cases/validations/uniqueness_validation_test.rb2
-rw-r--r--activerecord/test/cases/validations_test.rb6
10 files changed, 112 insertions, 117 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 7fa5557b96..ffa6d45948 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -462,7 +462,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
posts = nil
- Post.with_scope(:find => {
+ Post.send(:with_scope, :find => {
:include => :comments,
:conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'"
}) do
@@ -470,7 +470,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal 2, posts.size
end
- Post.with_scope(:find => {
+ Post.send(:with_scope, :find => {
:include => [ :comments, :author ],
:conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')"
}) do
@@ -480,7 +480,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the_eagers
- Post.with_scope(:find => { :conditions => "1=1" }) do
+ Post.send(:with_scope, :find => { :conditions => "1=1" }) do
posts = authors(:david).posts.find(:all,
:include => :comments,
:conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
@@ -499,7 +499,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_with_scoped_order_using_association_limiting_without_explicit_scope
posts_with_explicit_order = Post.find(:all, :conditions => 'comments.id is not null', :include => :comments, :order => 'posts.id DESC', :limit => 2)
- posts_with_scoped_order = Post.with_scope(:find => {:order => 'posts.id DESC'}) do
+ posts_with_scoped_order = Post.send(:with_scope, :find => {:order => 'posts.id DESC'}) do
Post.find(:all, :conditions => 'comments.id is not null', :include => :comments, :limit => 2)
end
assert_equal posts_with_explicit_order, posts_with_scoped_order
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index b51c9f0cb3..ebb717812d 100755
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1825,7 +1825,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_scoped_find_conditions
- scoped_developers = Developer.with_scope(:find => { :conditions => 'salary > 90000' }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :conditions => 'salary > 90000' }) do
Developer.find(:all, :conditions => 'id < 5')
end
assert !scoped_developers.include?(developers(:david)) # David's salary is less than 90,000
@@ -1833,7 +1833,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_scoped_find_limit_offset
- scoped_developers = Developer.with_scope(:find => { :limit => 3, :offset => 2 }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :limit => 3, :offset => 2 }) do
Developer.find(:all, :order => 'id')
end
assert !scoped_developers.include?(developers(:david))
@@ -1847,17 +1847,17 @@ class BasicsTest < ActiveRecord::TestCase
def test_scoped_find_order
# Test order in scope
- scoped_developers = Developer.with_scope(:find => { :limit => 1, :order => 'salary DESC' }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :limit => 1, :order => 'salary DESC' }) do
Developer.find(:all)
end
assert_equal 'Jamis', scoped_developers.first.name
assert scoped_developers.include?(developers(:jamis))
# Test scope without order and order in find
- scoped_developers = Developer.with_scope(:find => { :limit => 1 }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :limit => 1 }) do
Developer.find(:all, :order => 'salary DESC')
end
# Test scope order + find order, find has priority
- scoped_developers = Developer.with_scope(:find => { :limit => 3, :order => 'id DESC' }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :limit => 3, :order => 'id DESC' }) do
Developer.find(:all, :order => 'salary ASC')
end
assert scoped_developers.include?(developers(:poor_jamis))
@@ -1869,7 +1869,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_scoped_find_limit_offset_including_has_many_association
- topics = Topic.with_scope(:find => {:limit => 1, :offset => 1, :include => :replies}) do
+ topics = Topic.send(:with_scope, :find => {:limit => 1, :offset => 1, :include => :replies}) do
Topic.find(:all, :order => "topics.id")
end
assert_equal 1, topics.size
@@ -1877,7 +1877,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_scoped_find_order_including_has_many_association
- developers = Developer.with_scope(:find => { :order => 'developers.salary DESC', :include => :projects }) do
+ developers = Developer.send(:with_scope, :find => { :order => 'developers.salary DESC', :include => :projects }) do
Developer.find(:all)
end
assert developers.size >= 2
@@ -1887,7 +1887,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_scoped_find_with_group_and_having
- developers = Developer.with_scope(:find => { :group => 'developers.salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do
+ developers = Developer.send(:with_scope, :find => { :group => 'developers.salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do
Developer.find(:all)
end
assert_equal 3, developers.size
@@ -1933,7 +1933,7 @@ class BasicsTest < ActiveRecord::TestCase
end
def test_find_scoped_ordered_last
- last_developer = Developer.with_scope(:find => { :order => 'developers.salary ASC' }) do
+ last_developer = Developer.send(:with_scope, :find => { :order => 'developers.salary ASC' }) do
Developer.find(:last)
end
assert_equal last_developer, Developer.find(:all, :order => 'developers.salary ASC').last
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index 004f4d0ea6..7e4c4a0913 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -42,7 +42,7 @@ class CalculationsTest < ActiveRecord::TestCase
end
def test_should_get_maximum_of_field_with_scoped_include
- Account.with_scope :find => { :include => :firm, :conditions => "companies.name != 'Summit'" } do
+ Account.send :with_scope, :find => { :include => :firm, :conditions => "companies.name != 'Summit'" } do
assert_equal 50, Account.maximum(:credit_limit)
end
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 87a9630978..d2451f24c1 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -120,7 +120,7 @@ class FinderTest < ActiveRecord::TestCase
end
def test_exists_with_scoped_include
- Developer.with_scope(:find => { :include => :projects, :order => "projects.name" }) do
+ Developer.send(:with_scope, :find => { :include => :projects, :order => "projects.name" }) do
assert Developer.exists?
end
end
@@ -1022,7 +1022,7 @@ class FinderTest < ActiveRecord::TestCase
def test_finder_with_scoped_from
all_topics = Topic.find(:all)
- Topic.with_scope(:find => { :from => 'fake_topics' }) do
+ Topic.send(:with_scope, :find => { :from => 'fake_topics' }) do
assert_equal all_topics, Topic.from('topics').to_a
end
end
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 243c05e665..479970b2fa 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -47,11 +47,6 @@ ActiveRecord::Base.connection.class.class_eval do
alias_method_chain :execute, :query_record
end
-# Make with_scope public for tests
-class << ActiveRecord::Base
- public :with_scope, :with_exclusive_scope
-end
-
unless ENV['FIXTURE_DEBUG']
module ActiveRecord::TestFixtures::ClassMethods
def try_to_load_dependency_with_silence(*args)
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index a64c01292f..dfaecf35cf 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -225,7 +225,7 @@ unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
def test_sane_find_with_scoped_lock
assert_nothing_raised do
Person.transaction do
- Person.with_scope(:find => { :lock => true }) do
+ Person.send(:with_scope, :find => { :lock => true }) do
Person.find 1
end
end
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb
index eb4ce0e774..cfc6f8772c 100644
--- a/activerecord/test/cases/method_scoping_test.rb
+++ b/activerecord/test/cases/method_scoping_test.rb
@@ -10,19 +10,19 @@ class MethodScopingTest < ActiveRecord::TestCase
fixtures :authors, :developers, :projects, :comments, :posts, :developers_projects
def test_set_conditions
- Developer.with_scope(:find => { :conditions => 'just a test...' }) do
+ Developer.send(:with_scope, :find => { :conditions => 'just a test...' }) do
assert_equal 'just a test...', Developer.send(:current_scoped_methods)[:find][:conditions]
end
end
def test_scoped_find
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
assert_nothing_raised { Developer.find(1) }
end
end
def test_scoped_find_first
- Developer.with_scope(:find => { :conditions => "salary = 100000" }) do
+ Developer.send(:with_scope, :find => { :conditions => "salary = 100000" }) do
assert_equal Developer.find(10), Developer.find(:first, :order => 'name')
end
end
@@ -30,7 +30,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_find_last
highest_salary = Developer.find(:first, :order => "salary DESC")
- Developer.with_scope(:find => { :order => "salary" }) do
+ Developer.send(:with_scope, :find => { :order => "salary" }) do
assert_equal highest_salary, Developer.last
end
end
@@ -39,38 +39,38 @@ class MethodScopingTest < ActiveRecord::TestCase
lowest_salary = Developer.find(:first, :order => "salary ASC")
highest_salary = Developer.find(:first, :order => "salary DESC")
- Developer.with_scope(:find => { :order => "salary" }) do
+ Developer.send(:with_scope, :find => { :order => "salary" }) do
assert_equal highest_salary, Developer.last
assert_equal lowest_salary, Developer.first
end
end
def test_scoped_find_combines_conditions
- Developer.with_scope(:find => { :conditions => "salary = 9000" }) do
+ Developer.send(:with_scope, :find => { :conditions => "salary = 9000" }) do
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => "name = 'Jamis'")
end
end
def test_scoped_find_sanitizes_conditions
- Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
+ Developer.send(:with_scope, :find => { :conditions => ['salary = ?', 9000] }) do
assert_equal developers(:poor_jamis), Developer.find(:first)
end
end
def test_scoped_find_combines_and_sanitizes_conditions
- Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
+ Developer.send(:with_scope, :find => { :conditions => ['salary = ?', 9000] }) do
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => ['name = ?', 'Jamis'])
end
end
def test_scoped_find_all
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
assert_equal [developers(:david)], Developer.find(:all)
end
end
def test_scoped_find_select
- Developer.with_scope(:find => { :select => "id, name" }) do
+ Developer.send(:with_scope, :find => { :select => "id, name" }) do
developer = Developer.find(:first, :conditions => "name = 'David'")
assert_equal "David", developer.name
assert !developer.has_attribute?(:salary)
@@ -78,7 +78,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_options_select_replaces_scope_select
- Developer.with_scope(:find => { :select => "id, name" }) do
+ Developer.send(:with_scope, :find => { :select => "id, name" }) do
developer = Developer.find(:first, :select => 'id, salary', :conditions => "name = 'David'")
assert_equal 80000, developer.salary
assert !developer.has_attribute?(:name)
@@ -86,11 +86,11 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_count
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
assert_equal 1, Developer.count
end
- Developer.with_scope(:find => { :conditions => 'salary = 100000' }) do
+ Developer.send(:with_scope, :find => { :conditions => 'salary = 100000' }) do
assert_equal 8, Developer.count
assert_equal 1, Developer.count(:conditions => "name LIKE 'fixture_1%'")
end
@@ -98,7 +98,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_find_include
# with the include, will retrieve only developers for the given project
- scoped_developers = Developer.with_scope(:find => { :include => :projects }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :include => :projects }) do
Developer.find(:all, :conditions => 'projects.id = 2')
end
assert scoped_developers.include?(developers(:david))
@@ -107,7 +107,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_joins
- scoped_developers = Developer.with_scope(:find => { :joins => 'JOIN developers_projects ON id = developer_id' } ) do
+ scoped_developers = Developer.send(:with_scope, :find => { :joins => 'JOIN developers_projects ON id = developer_id' } ) do
Developer.find(:all, :conditions => 'developers_projects.project_id = 2')
end
assert scoped_developers.include?(developers(:david))
@@ -117,7 +117,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_using_new_style_joins
- scoped_developers = Developer.with_scope(:find => { :joins => :projects }) do
+ scoped_developers = Developer.send(:with_scope, :find => { :joins => :projects }) do
Developer.find(:all, :conditions => 'projects.id = 2')
end
assert scoped_developers.include?(developers(:david))
@@ -127,7 +127,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_merges_old_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => 'INNER JOIN posts ON authors.id = posts.author_id ' }) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => 'INNER JOIN posts ON authors.id = posts.author_id ' }) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => 'INNER JOIN comments ON posts.id = comments.post_id', :conditions => 'comments.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -137,7 +137,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_merges_new_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => :posts }) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => :posts }) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => :comments, :conditions => 'comments.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -147,7 +147,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_merges_new_and_old_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => :posts }) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => :posts }) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => 'JOIN comments ON posts.id = comments.post_id', :conditions => 'comments.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -157,7 +157,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_merges_string_array_style_and_string_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => ["INNER JOIN posts ON posts.author_id = authors.id"]}) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => ["INNER JOIN posts ON posts.author_id = authors.id"]}) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => 'INNER JOIN comments ON posts.id = comments.post_id', :conditions => 'comments.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -167,7 +167,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_merges_string_array_style_and_hash_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => :posts}) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => :posts}) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => ['INNER JOIN comments ON posts.id = comments.post_id'], :conditions => 'comments.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -177,7 +177,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_merges_joins_and_eliminates_duplicate_string_joins
- scoped_authors = Author.with_scope(:find => { :joins => 'INNER JOIN posts ON posts.author_id = authors.id'}) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => 'INNER JOIN posts ON posts.author_id = authors.id'}) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => ["INNER JOIN posts ON posts.author_id = authors.id", "INNER JOIN comments ON posts.id = comments.post_id"], :conditions => 'comments.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -187,7 +187,7 @@ class MethodScopingTest < ActiveRecord::TestCase
end
def test_scoped_find_strips_spaces_from_string_joins_and_eliminates_duplicate_string_joins
- scoped_authors = Author.with_scope(:find => { :joins => ' INNER JOIN posts ON posts.author_id = authors.id '}) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => ' INNER JOIN posts ON posts.author_id = authors.id '}) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => ['INNER JOIN posts ON posts.author_id = authors.id'], :conditions => 'posts.id = 1')
end
assert scoped_authors.include?(authors(:david))
@@ -198,7 +198,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_count_include
# with the include, will retrieve only developers for the given project
- Developer.with_scope(:find => { :include => :projects }) do
+ Developer.send(:with_scope, :find => { :include => :projects }) do
assert_equal 1, Developer.count(:conditions => 'projects.id = 2')
end
end
@@ -206,7 +206,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_create
new_comment = nil
- VerySpecialComment.with_scope(:create => { :post_id => 1 }) do
+ VerySpecialComment.send(:with_scope, :create => { :post_id => 1 }) do
assert_equal({ :post_id => 1 }, VerySpecialComment.send(:current_scoped_methods)[:create])
new_comment = VerySpecialComment.create :body => "Wonderful world"
end
@@ -216,14 +216,14 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_immutable_scope
options = { :conditions => "name = 'David'" }
- Developer.with_scope(:find => options) do
+ Developer.send(:with_scope, :find => options) do
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
options[:conditions] = "name != 'David'"
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
end
scope = { :find => { :conditions => "name = 'David'" }}
- Developer.with_scope(scope) do
+ Developer.send(:with_scope, scope) do
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
scope[:find][:conditions] = "name != 'David'"
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
@@ -232,7 +232,7 @@ class MethodScopingTest < ActiveRecord::TestCase
def test_scoped_with_duck_typing
scoping = Struct.new(:method_scoping).new(:find => { :conditions => ["name = ?", 'David'] })
- Developer.with_scope(scoping) do
+ Developer.send(:with_scope, scoping) do
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
end
end
@@ -241,7 +241,7 @@ class MethodScopingTest < ActiveRecord::TestCase
scoped_methods = Developer.instance_eval('current_scoped_methods')
begin
- Developer.with_scope(:find => { :conditions => "name = 'Jamis'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'Jamis'" }) do
raise "an exception"
end
rescue
@@ -254,8 +254,8 @@ class NestedScopingTest < ActiveRecord::TestCase
fixtures :authors, :developers, :projects, :comments, :posts
def test_merge_options
- Developer.with_scope(:find => { :conditions => 'salary = 80000' }) do
- Developer.with_scope(:find => { :limit => 10 }) do
+ Developer.send(:with_scope, :find => { :conditions => 'salary = 80000' }) do
+ Developer.send(:with_scope, :find => { :limit => 10 }) do
merged_option = Developer.instance_eval('current_scoped_methods')[:find]
assert_equal({ :conditions => 'salary = 80000', :limit => 10 }, merged_option)
end
@@ -263,8 +263,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_merge_inner_scope_has_priority
- Developer.with_scope(:find => { :limit => 5 }) do
- Developer.with_scope(:find => { :limit => 10 }) do
+ Developer.send(:with_scope, :find => { :limit => 5 }) do
+ Developer.send(:with_scope, :find => { :limit => 10 }) do
merged_option = Developer.instance_eval('current_scoped_methods')[:find]
assert_equal({ :limit => 10 }, merged_option)
end
@@ -272,8 +272,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_replace_options
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
- Developer.with_exclusive_scope(:find => { :conditions => "name = 'Jamis'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_exclusive_scope, :find => { :conditions => "name = 'Jamis'" }) do
assert_equal({:find => { :conditions => "name = 'Jamis'" }}, Developer.instance_eval('current_scoped_methods'))
assert_equal({:find => { :conditions => "name = 'Jamis'" }}, Developer.send(:scoped_methods)[-1])
end
@@ -281,21 +281,21 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_append_conditions
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
- Developer.with_scope(:find => { :conditions => 'salary = 80000' }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => 'salary = 80000' }) do
appended_condition = Developer.instance_eval('current_scoped_methods')[:find][:conditions]
assert_equal("(name = 'David') AND (salary = 80000)", appended_condition)
assert_equal(1, Developer.count)
end
- Developer.with_scope(:find => { :conditions => "name = 'Maiha'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'Maiha'" }) do
assert_equal(0, Developer.count)
end
end
end
def test_merge_and_append_options
- Developer.with_scope(:find => { :conditions => 'salary = 80000', :limit => 10 }) do
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => 'salary = 80000', :limit => 10 }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
merged_option = Developer.instance_eval('current_scoped_methods')[:find]
assert_equal({ :conditions => "(salary = 80000) AND (name = 'David')", :limit => 10 }, merged_option)
end
@@ -303,8 +303,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find
- Developer.with_scope(:find => { :conditions => "name = 'Jamis'" }) do
- Developer.with_exclusive_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'Jamis'" }) do
+ Developer.send(:with_exclusive_scope, :find => { :conditions => "name = 'David'" }) do
assert_nothing_raised { Developer.find(1) }
assert_equal('David', Developer.find(:first).name)
end
@@ -313,8 +313,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find_include
- Developer.with_scope(:find => { :include => :projects }) do
- Developer.with_scope(:find => { :conditions => "projects.id = 2" }) do
+ Developer.send(:with_scope, :find => { :include => :projects }) do
+ Developer.send(:with_scope, :find => { :conditions => "projects.id = 2" }) do
assert_nothing_raised { Developer.find(1) }
assert_equal('David', Developer.find(:first).name)
end
@@ -323,24 +323,24 @@ class NestedScopingTest < ActiveRecord::TestCase
def test_nested_scoped_find_merged_include
# :include's remain unique and don't "double up" when merging
- Developer.with_scope(:find => { :include => :projects, :conditions => "projects.id = 2" }) do
- Developer.with_scope(:find => { :include => :projects }) do
+ Developer.send(:with_scope, :find => { :include => :projects, :conditions => "projects.id = 2" }) do
+ Developer.send(:with_scope, :find => { :include => :projects }) do
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
assert_equal('David', Developer.find(:first).name)
end
end
# the nested scope doesn't remove the first :include
- Developer.with_scope(:find => { :include => :projects, :conditions => "projects.id = 2" }) do
- Developer.with_scope(:find => { :include => [] }) do
+ Developer.send(:with_scope, :find => { :include => :projects, :conditions => "projects.id = 2" }) do
+ Developer.send(:with_scope, :find => { :include => [] }) do
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
assert_equal('David', Developer.find(:first).name)
end
end
# mixing array and symbol include's will merge correctly
- Developer.with_scope(:find => { :include => [:projects], :conditions => "projects.id = 2" }) do
- Developer.with_scope(:find => { :include => :projects }) do
+ Developer.send(:with_scope, :find => { :include => [:projects], :conditions => "projects.id = 2" }) do
+ Developer.send(:with_scope, :find => { :include => :projects }) do
assert_equal 1, Developer.instance_eval('current_scoped_methods')[:find][:include].length
assert_equal('David', Developer.find(:first).name)
end
@@ -348,21 +348,21 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find_replace_include
- Developer.with_scope(:find => { :include => :projects }) do
- Developer.with_exclusive_scope(:find => { :include => [] }) do
+ Developer.send(:with_scope, :find => { :include => :projects }) do
+ Developer.send(:with_exclusive_scope, :find => { :include => [] }) do
assert_equal 0, Developer.instance_eval('current_scoped_methods')[:find][:include].length
end
end
end
def test_three_level_nested_exclusive_scoped_find
- Developer.with_scope(:find => { :conditions => "name = 'Jamis'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'Jamis'" }) do
assert_equal('Jamis', Developer.find(:first).name)
- Developer.with_exclusive_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_exclusive_scope, :find => { :conditions => "name = 'David'" }) do
assert_equal('David', Developer.find(:first).name)
- Developer.with_exclusive_scope(:find => { :conditions => "name = 'Maiha'" }) do
+ Developer.send(:with_exclusive_scope, :find => { :conditions => "name = 'Maiha'" }) do
assert_equal(nil, Developer.find(:first))
end
@@ -377,8 +377,8 @@ 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, :order => 'id asc' }) do
+ Developer.send(:with_scope, :find => { :conditions => "salary < 100000" }) do
+ Developer.send(:with_scope, :find => { :offset => 1, :order => 'id asc' }) do
# Oracle adapter does not generated space after asc therefore trailing space removed from regex
assert_sql /ORDER BY id asc/ do
assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc'))
@@ -388,16 +388,16 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_merged_scoped_find_sanitizes_conditions
- Developer.with_scope(:find => { :conditions => ["name = ?", 'David'] }) do
- Developer.with_scope(:find => { :conditions => ['salary = ?', 9000] }) do
+ Developer.send(:with_scope, :find => { :conditions => ["name = ?", 'David'] }) do
+ Developer.send(:with_scope, :find => { :conditions => ['salary = ?', 9000] }) do
assert_raise(ActiveRecord::RecordNotFound) { developers(:poor_jamis) }
end
end
end
def test_nested_scoped_find_combines_and_sanitizes_conditions
- Developer.with_scope(:find => { :conditions => ["name = ?", 'David'] }) do
- Developer.with_exclusive_scope(:find => { :conditions => ['salary = ?', 9000] }) do
+ Developer.send(:with_scope, :find => { :conditions => ["name = ?", 'David'] }) do
+ Developer.send(:with_exclusive_scope, :find => { :conditions => ['salary = ?', 9000] }) do
assert_equal developers(:poor_jamis), Developer.find(:first)
assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => ['name = ?', 'Jamis'])
end
@@ -405,8 +405,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_merged_scoped_find_combines_and_sanitizes_conditions
- Developer.with_scope(:find => { :conditions => ["name = ?", 'David'] }) do
- Developer.with_scope(:find => { :conditions => ['salary > ?', 9000] }) do
+ Developer.send(:with_scope, :find => { :conditions => ["name = ?", 'David'] }) do
+ Developer.send(:with_scope, :find => { :conditions => ['salary > ?', 9000] }) do
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
end
end
@@ -414,8 +414,8 @@ class NestedScopingTest < ActiveRecord::TestCase
def test_nested_scoped_create
comment = nil
- Comment.with_scope(:create => { :post_id => 1}) do
- Comment.with_scope(:create => { :post_id => 2}) do
+ Comment.send(:with_scope, :create => { :post_id => 1}) do
+ Comment.send(: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
@@ -425,8 +425,8 @@ class NestedScopingTest < ActiveRecord::TestCase
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
+ Comment.send(:with_scope, :create => { :body => "Hey guys, nested scopes are broken. Please fix!" }) do
+ Comment.send(: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
@@ -437,8 +437,8 @@ class NestedScopingTest < ActiveRecord::TestCase
def test_merged_scoped_find_on_blank_conditions
[nil, " ", [], {}].each do |blank|
- Developer.with_scope(:find => {:conditions => blank}) do
- Developer.with_scope(:find => {:conditions => blank}) do
+ Developer.send(:with_scope, :find => {:conditions => blank}) do
+ Developer.send(:with_scope, :find => {:conditions => blank}) do
assert_nothing_raised { Developer.find(:first) }
end
end
@@ -447,8 +447,8 @@ class NestedScopingTest < ActiveRecord::TestCase
def test_merged_scoped_find_on_blank_bind_conditions
[ [""], ["",{}] ].each do |blank|
- Developer.with_scope(:find => {:conditions => blank}) do
- Developer.with_scope(:find => {:conditions => blank}) do
+ Developer.send(:with_scope, :find => {:conditions => blank}) do
+ Developer.send(:with_scope, :find => {:conditions => blank}) do
assert_nothing_raised { Developer.find(:first) }
end
end
@@ -458,8 +458,8 @@ class NestedScopingTest < ActiveRecord::TestCase
def test_immutable_nested_scope
options1 = { :conditions => "name = 'Jamis'" }
options2 = { :conditions => "name = 'David'" }
- Developer.with_scope(:find => options1) do
- Developer.with_exclusive_scope(:find => options2) do
+ Developer.send(:with_scope, :find => options1) do
+ Developer.send(:with_exclusive_scope, :find => options2) do
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
options1[:conditions] = options2[:conditions] = nil
assert_equal %w(David), Developer.find(:all).map { |d| d.name }
@@ -470,8 +470,8 @@ class NestedScopingTest < ActiveRecord::TestCase
def test_immutable_merged_scope
options1 = { :conditions => "name = 'Jamis'" }
options2 = { :conditions => "salary > 10000" }
- Developer.with_scope(:find => options1) do
- Developer.with_scope(:find => options2) do
+ Developer.send(:with_scope, :find => options1) do
+ Developer.send(:with_scope, :find => options2) do
assert_equal %w(Jamis), Developer.find(:all).map { |d| d.name }
options1[:conditions] = options2[:conditions] = nil
assert_equal %w(Jamis), Developer.find(:all).map { |d| d.name }
@@ -480,10 +480,10 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_ensure_that_method_scoping_is_correctly_restored
- Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'David'" }) do
scoped_methods = Developer.instance_eval('current_scoped_methods')
begin
- Developer.with_scope(:find => { :conditions => "name = 'Maiha'" }) do
+ Developer.send(:with_scope, :find => { :conditions => "name = 'Maiha'" }) do
raise "an exception"
end
rescue
@@ -493,8 +493,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find_merges_old_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => 'INNER JOIN posts ON authors.id = posts.author_id' }) do
- Author.with_scope(:find => { :joins => 'INNER JOIN comments ON posts.id = comments.post_id' }) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => 'INNER JOIN posts ON authors.id = posts.author_id' }) do
+ Author.send(:with_scope, :find => { :joins => 'INNER JOIN comments ON posts.id = comments.post_id' }) do
Author.find(:all, :select => 'DISTINCT authors.*', :conditions => 'comments.id = 1')
end
end
@@ -505,8 +505,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find_merges_new_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => :posts }) do
- Author.with_scope(:find => { :joins => :comments }) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => :posts }) do
+ Author.send(:with_scope, :find => { :joins => :comments }) do
Author.find(:all, :select => 'DISTINCT authors.*', :conditions => 'comments.id = 1')
end
end
@@ -517,8 +517,8 @@ class NestedScopingTest < ActiveRecord::TestCase
end
def test_nested_scoped_find_merges_new_and_old_style_joins
- scoped_authors = Author.with_scope(:find => { :joins => :posts }) do
- Author.with_scope(:find => { :joins => 'INNER JOIN comments ON posts.id = comments.post_id' }) do
+ scoped_authors = Author.send(:with_scope, :find => { :joins => :posts }) do
+ Author.send(:with_scope, :find => { :joins => 'INNER JOIN comments ON posts.id = comments.post_id' }) do
Author.find(:all, :select => 'DISTINCT authors.*', :joins => '', :conditions => 'comments.id = 1')
end
end
@@ -552,7 +552,7 @@ class HasManyScopingTest< ActiveRecord::TestCase
end
def test_nested_scope
- Comment.with_scope(:find => { :conditions => '1=1' }) do
+ Comment.send(:with_scope, :find => { :conditions => '1=1' }) do
assert_equal 'a comment...', @welcome.comments.what_are_you
end
end
@@ -577,7 +577,7 @@ class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase
end
def test_nested_scope
- Category.with_scope(:find => { :conditions => '1=1' }) do
+ Category.send(:with_scope, :find => { :conditions => '1=1' }) do
assert_equal 'a comment...', @welcome.comments.what_are_you
end
end
@@ -633,7 +633,7 @@ class DefaultScopingTest < ActiveRecord::TestCase
def test_nested_scope
expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary }
- received = DeveloperOrderedBySalary.with_scope(:find => { :order => 'name DESC'}) do
+ received = DeveloperOrderedBySalary.send(:with_scope, :find => { :order => 'name DESC'}) do
DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
end
assert_equal expected, received
@@ -647,7 +647,7 @@ class DefaultScopingTest < ActiveRecord::TestCase
def test_nested_exclusive_scope
expected = Developer.find(:all, :limit => 100).collect { |dev| dev.salary }
- received = DeveloperOrderedBySalary.with_exclusive_scope(:find => { :limit => 100 }) do
+ received = DeveloperOrderedBySalary.send(:with_exclusive_scope, :find => { :limit => 100 }) do
DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
end
assert_equal expected, received
diff --git a/activerecord/test/cases/readonly_test.rb b/activerecord/test/cases/readonly_test.rb
index d2ef4fd6d2..98011f40a4 100644
--- a/activerecord/test/cases/readonly_test.rb
+++ b/activerecord/test/cases/readonly_test.rb
@@ -72,13 +72,13 @@ class ReadOnlyTest < ActiveRecord::TestCase
end
def test_readonly_scoping
- Post.with_scope(:find => { :conditions => '1=1' }) do
+ Post.send(:with_scope, :find => { :conditions => '1=1' }) do
assert !Post.find(1).readonly?
assert Post.readonly(true).find(1).readonly?
assert !Post.readonly(false).find(1).readonly?
end
- Post.with_scope(:find => { :joins => ' ' }) do
+ Post.send(:with_scope, :find => { :joins => ' ' }) do
assert !Post.find(1).readonly?
assert Post.readonly.find(1).readonly?
assert !Post.readonly(false).find(1).readonly?
@@ -87,14 +87,14 @@ class ReadOnlyTest < ActiveRecord::TestCase
# Oracle barfs on this because the join includes unqualified and
# conflicting column names
unless current_adapter?(:OracleAdapter)
- Post.with_scope(:find => { :joins => ', developers' }) do
+ Post.send(:with_scope, :find => { :joins => ', developers' }) do
assert Post.find(1).readonly?
assert Post.readonly.find(1).readonly?
assert !Post.readonly(false).find(1).readonly?
end
end
- Post.with_scope(:find => { :readonly => true }) do
+ Post.send(:with_scope, :find => { :readonly => true }) do
assert Post.find(1).readonly?
assert Post.readonly.find(1).readonly?
assert !Post.readonly(false).find(1).readonly?
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb
index 17ba4e2f8a..db633339f3 100644
--- a/activerecord/test/cases/validations/uniqueness_validation_test.rb
+++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb
@@ -213,7 +213,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
def test_validates_uniqueness_inside_with_scope
Topic.validates_uniqueness_of(:title)
- Topic.with_scope(:find => { :conditions => { :author_name => "David" } }) do
+ Topic.send(:with_scope, :find => { :conditions => { :author_name => "David" } }) do
t1 = Topic.new("title" => "I'm unique!", "author_name" => "Mary")
assert t1.save
t2 = Topic.new("title" => "I'm unique!", "author_name" => "David")
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index 130231c622..7462d944e0 100644
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -98,14 +98,14 @@ class ValidationsTest < ActiveRecord::TestCase
end
def test_scoped_create_without_attributes
- Reply.with_scope(:create => {}) do
+ Reply.send(:with_scope, :create => {}) do
assert_raise(ActiveRecord::RecordInvalid) { Reply.create! }
end
end
def test_create_with_exceptions_using_scope_for_protected_attributes
assert_nothing_raised do
- ProtectedPerson.with_scope( :create => { :first_name => "Mary" } ) do
+ ProtectedPerson.send(:with_scope, :create => { :first_name => "Mary" } ) do
person = ProtectedPerson.create! :addon => "Addon"
assert_equal person.first_name, "Mary", "scope should ignore attr_protected"
end
@@ -114,7 +114,7 @@ class ValidationsTest < ActiveRecord::TestCase
def test_create_with_exceptions_using_scope_and_empty_attributes
assert_nothing_raised do
- ProtectedPerson.with_scope( :create => { :first_name => "Mary" } ) do
+ ProtectedPerson.send(:with_scope, :create => { :first_name => "Mary" } ) do
person = ProtectedPerson.create!
assert_equal person.first_name, "Mary", "should be ok when no attributes are passed to create!"
end