aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb5
-rw-r--r--activerecord/test/cases/associations_test.rb5
-rw-r--r--activerecord/test/cases/relation/merging_test.rb4
-rw-r--r--activerecord/test/cases/relation/where_chain_test.rb12
-rw-r--r--activerecord/test/cases/relation_test.rb12
-rw-r--r--activerecord/test/cases/scoping/default_scoping_test.rb6
-rw-r--r--activerecord/test/models/author.rb2
7 files changed, 24 insertions, 22 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index db8fd92c1f..fdb437d11d 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1328,7 +1328,6 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
test "eager-loading readonly association" do
- skip "eager_load does not yet preserve readonly associations"
# has-one
firm = Firm.where(id: "1").eager_load(:readonly_account).first!
assert firm.readonly_account.readonly?
@@ -1340,6 +1339,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
# has-many :through
david = Author.where(id: "1").eager_load(:readonly_comments).first!
assert david.readonly_comments.first.readonly?
+
+ # belongs_to
+ post = Post.where(id: "1").eager_load(:author).first!
+ assert post.author.readonly?
end
test "preloading a polymorphic association with references to the associated table" do
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index c6769edcbf..72963fd56c 100644
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -264,6 +264,11 @@ class AssociationProxyTest < ActiveRecord::TestCase
end
end
+ test "first! works on loaded associations" do
+ david = authors(:david)
+ assert_equal david.posts.first, david.posts.reload.first!
+ end
+
def test_reset_unloads_target
david = authors(:david)
david.posts.reload
diff --git a/activerecord/test/cases/relation/merging_test.rb b/activerecord/test/cases/relation/merging_test.rb
index aa56df62fd..eb76ef6328 100644
--- a/activerecord/test/cases/relation/merging_test.rb
+++ b/activerecord/test/cases/relation/merging_test.rb
@@ -25,8 +25,8 @@ class RelationMergingTest < ActiveRecord::TestCase
end
def test_relation_merging_with_arel_equalities_keeps_last_equality
- devs = Developer.where(Developer.arel_table[:salary].eq(Arel::Nodes::Quoted.new(80000))).merge(
- Developer.where(Developer.arel_table[:salary].eq(Arel::Nodes::Quoted.new(9000)))
+ devs = Developer.where(Developer.arel_table[:salary].eq(80000)).merge(
+ Developer.where(Developer.arel_table[:salary].eq(9000))
)
assert_equal [developers(:poor_jamis)], devs.to_a
end
diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb
index 24f6f1d2ab..619055f1e7 100644
--- a/activerecord/test/cases/relation/where_chain_test.rb
+++ b/activerecord/test/cases/relation/where_chain_test.rb
@@ -24,7 +24,7 @@ module ActiveRecord
end
def test_not_null
- expected = Post.arel_table[@name].not_eq(Arel::Nodes::Quoted.new(nil))
+ expected = Post.arel_table[@name].not_eq(nil)
relation = Post.where.not(title: nil)
assert_equal([expected], relation.where_values)
end
@@ -36,14 +36,13 @@ module ActiveRecord
end
def test_not_in
- values = %w[hello goodbye].map { |v| Arel::Nodes::Quoted.new(v) }
- expected = Post.arel_table[@name].not_in(values)
+ expected = Post.arel_table[@name].not_in(%w[hello goodbye])
relation = Post.where.not(title: %w[hello goodbye])
assert_equal([expected], relation.where_values)
end
def test_association_not_eq
- expected = Comment.arel_table[@name].not_eq(Arel::Nodes::Quoted.new('hello'))
+ expected = Comment.arel_table[@name].not_eq('hello')
relation = Post.joins(:comments).where.not(comments: {title: 'hello'})
assert_equal(expected.to_sql, relation.where_values.first.to_sql)
end
@@ -91,10 +90,7 @@ module ActiveRecord
def test_chaining_multiple
relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails')
- expected = Post.arel_table['author_id'].not_in([
- Arel::Nodes::Quoted.new(1),
- Arel::Nodes::Quoted.new(2),
- ])
+ expected = Post.arel_table['author_id'].not_in([1, 2])
assert_equal(expected, relation.where_values[0])
value = relation.where_values[1]
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
index 0819b6b11a..f7cb471984 100644
--- a/activerecord/test/cases/relation_test.rb
+++ b/activerecord/test/cases/relation_test.rb
@@ -64,21 +64,21 @@ module ActiveRecord
def test_has_values
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
- relation.where! relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
+ relation.where! relation.table[:id].eq(10)
assert_equal({:id => 10}, relation.where_values_hash)
end
def test_values_wrong_table
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
- relation.where! Comment.arel_table[:id].eq(Arel::Nodes::Quoted.new(10))
+ relation.where! Comment.arel_table[:id].eq(10)
assert_equal({}, relation.where_values_hash)
end
def test_tree_is_not_traversed
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
- left = relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
- right = relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
+ left = relation.table[:id].eq(10)
+ right = relation.table[:id].eq(10)
combine = left.and right
relation.where! combine
assert_equal({}, relation.where_values_hash)
@@ -104,7 +104,7 @@ module ActiveRecord
def test_create_with_value_with_wheres
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
- relation.where! relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
+ relation.where! relation.table[:id].eq(10)
relation.create_with_value = {:hello => 'world'}
assert_equal({:hello => 'world', :id => 10}, relation.scope_for_create)
end
@@ -115,7 +115,7 @@ module ActiveRecord
assert_equal({}, relation.scope_for_create)
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
- relation.where! relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
+ relation.where! relation.table[:id].eq(10)
assert_equal({}, relation.scope_for_create)
relation.create_with_value = {:hello => 'world'}
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb
index d56f998622..0738df1b54 100644
--- a/activerecord/test/cases/scoping/default_scoping_test.rb
+++ b/activerecord/test/cases/scoping/default_scoping_test.rb
@@ -145,13 +145,11 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal expected_5, received_5
expected_6 = Developer.order('salary DESC').collect(&:name)
- # FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
- received_6 = DeveloperOrderedBySalary.where(Developer.arel_table['name'].eq(Arel::Nodes::Quoted.new('David'))).unscope(where: :name).collect(&:name)
+ received_6 = DeveloperOrderedBySalary.where(Developer.arel_table['name'].eq('David')).unscope(where: :name).collect(&:name)
assert_equal expected_6, received_6
expected_7 = Developer.order('salary DESC').collect(&:name)
- # FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
- received_7 = DeveloperOrderedBySalary.where(Developer.arel_table[:name].eq(Arel::Nodes::Quoted.new('David'))).unscope(where: :name).collect(&:name)
+ received_7 = DeveloperOrderedBySalary.where(Developer.arel_table[:name].eq('David')).unscope(where: :name).collect(&:name)
assert_equal expected_7, received_7
end
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
index 9b740e405a..8c1f14bd36 100644
--- a/activerecord/test/models/author.rb
+++ b/activerecord/test/models/author.rb
@@ -34,7 +34,7 @@ class Author < ActiveRecord::Base
-> { where(title: 'Welcome to the weblog').where('comments_count = ?', 1) },
class_name: 'Post'
has_many :welcome_posts_with_comments,
- -> { where(title: 'Welcome to the weblog').where(Post.arel_table[:comments_count].gt(Arel::Nodes::Quoted.new(0))) },
+ -> { where(title: 'Welcome to the weblog').where(Post.arel_table[:comments_count].gt(0)) },
class_name: 'Post'
has_many :comments_desc, -> { order('comments.id DESC') }, :through => :posts, :source => :comments