aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-04-27 10:08:59 -0700
committerGitHub <noreply@github.com>2017-04-27 10:08:59 -0700
commit2064c61f4b1f52dfe20bbe544db34c9fff1930b3 (patch)
tree60f562ed30068f0ff2dd6dedd9b9bb2df8e8b287 /activerecord/test/cases
parent5974334aeb23c21100af5bf877b385dbbe762bc6 (diff)
parent4f8f5f59fc37a6adb71979eec66488f4ad08bffa (diff)
downloadrails-2064c61f4b1f52dfe20bbe544db34c9fff1930b3.tar.gz
rails-2064c61f4b1f52dfe20bbe544db34c9fff1930b3.tar.bz2
rails-2064c61f4b1f52dfe20bbe544db34c9fff1930b3.zip
Merge pull request #28906 from georgeclaghorn/fix-belongs-to-default-with-lambda
Evaluate belongs_to :default option against the owner, not the association
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 5b08ba1358..c8b26232b6 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -136,6 +136,24 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal david, ship.developer
end
+ def test_default_with_lambda
+ model = Class.new(ActiveRecord::Base) do
+ self.table_name = "ships"
+ def self.name; "Temp"; end
+ belongs_to :developer, default: -> { default_developer }
+
+ def default_developer
+ Developer.first
+ end
+ end
+
+ ship = model.create!
+ assert_equal developers(:david), ship.developer
+
+ ship = model.create!(developer: developers(:jamis))
+ assert_equal developers(:jamis), ship.developer
+ end
+
def test_default_scope_on_relations_is_not_cached
counter = 0