diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 23 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 23 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 4 |
5 files changed, 51 insertions, 13 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 9dd041af81..05ab86105c 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -705,4 +705,27 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal toy, sponsor.reload.sponsorable end + + test "stale tracking doesn't care about the type" do + apple = Firm.create("name" => "Apple") + citibank = Account.create("credit_limit" => 10) + + citibank.firm_id = apple.id + citibank.firm # load it + + citibank.firm_id = apple.id.to_s + + assert !citibank.association(:firm).stale_target? + end + + def test_reflect_the_most_recent_change + author1, author2 = Author.limit(2) + post = Post.new(:title => "foo", :body=> "bar") + + post.author = author1 + post.author_id = author2.id + + assert post.save + assert_equal post.author_id, author2.id + end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index ef22936e18..024225b813 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2087,4 +2087,9 @@ class BasicsTest < ActiveRecord::TestCase assert_equal record, klass.public_send(meth, :foo, :bar) end end + + test "scoped can take a values hash" do + klass = Class.new(ActiveRecord::Base) + assert_equal ['foo'], klass.scoped(select: 'foo').select_values + end end diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 0d3c0b20a4..06d076943e 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -460,21 +460,16 @@ class NamedScopeTest < ActiveRecord::TestCase klass.table_name = 'posts' assert_deprecated do - klass.scope :welcome, { :conditions => { :id => posts(:welcome).id } } - end - assert_equal [posts(:welcome).title], klass.welcome.map(&:title) - - assert_deprecated do klass.scope :welcome_2, klass.where(:id => posts(:welcome).id) end assert_equal [posts(:welcome).title], klass.welcome_2.map(&:title) end - def test_eager_default_scope_hashes_are_deprecated + def test_eager_default_scope_hashes_are_not_deprecated klass = Class.new(ActiveRecord::Base) klass.table_name = 'posts' - assert_deprecated do + assert_not_deprecated do klass.send(:default_scope, :conditions => { :id => posts(:welcome).id }) end assert_equal [posts(:welcome).title], klass.all.map(&:title) diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 9ef703fd9b..8a7a2441d4 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -130,9 +130,9 @@ module ActiveRecord test 'merging a hash into a relation' do relation = Relation.new :a, :b - relation = relation.merge where: ['lol'], readonly: true + relation = relation.merge where: :lol, readonly: true - assert_equal ['lol'], relation.where_values + assert_equal [:lol], relation.where_values assert_equal true, relation.readonly_value end @@ -156,6 +156,21 @@ module ActiveRecord relation = Relation.new(:a, :b, where: [:foo]) assert_equal [:foo], relation.where_values end + + test 'merging a single where value' do + relation = Relation.new(:a, :b) + relation.merge!(where: :foo) + assert_equal [:foo], relation.where_values + end + + test 'merging a hash interpolates conditions' do + klass = stub + klass.stubs(:sanitize_sql).with(['foo = ?', 'bar']).returns('foo = bar') + + relation = Relation.new(klass, :b) + relation.merge!(where: ['foo = ?', 'bar']) + assert_equal ['foo = bar'], relation.where_values + end end class RelationMutationTest < ActiveSupport::TestCase @@ -221,8 +236,8 @@ module ActiveRecord end test 'merge!' do - assert relation.merge!(where: ['foo']).equal?(relation) - assert_equal ['foo'], relation.where_values + assert relation.merge!(where: :foo).equal?(relation) + assert_equal [:foo], relation.where_values end end end diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 785839be75..0625b8d296 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -45,8 +45,8 @@ class Topic < ActiveRecord::Base 2 end end - scope :named_extension, -> { { :extend => NamedExtension } } - scope :multiple_extensions, -> { { :extend => [MultipleExtensionTwo, MultipleExtensionOne] } } + scope :named_extension, :extend => NamedExtension + scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne] has_many :replies, :dependent => :destroy, :foreign_key => "parent_id" has_many :replies_with_primary_key, :class_name => "Reply", :dependent => :destroy, :primary_key => "title", :foreign_key => "parent_title" |