diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-14 20:46:51 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-15 12:06:45 +0900 |
commit | cdb8697b4a654aad2e65590d58c5f581a53d6b33 (patch) | |
tree | 8ac091bcf825ff2bc8dbdca92a0e612fb930a847 /activerecord/test | |
parent | 79b8b626216b4f8f24b5606f3edd43d5b14cd2a6 (diff) | |
download | rails-cdb8697b4a654aad2e65590d58c5f581a53d6b33.tar.gz rails-cdb8697b4a654aad2e65590d58c5f581a53d6b33.tar.bz2 rails-cdb8697b4a654aad2e65590d58c5f581a53d6b33.zip |
Revert "Merge pull request #35186 from kamipo/fix_leaking_scope_on_relation_create"
This reverts commit b67d5c6dedbf033515a96a95d24d085bf99a0d07, reversing
changes made to 2e018361c7c51e36d1d98bf770b7456d78dee68b.
Reason: #35186 may cause that silently leaking information when people
upgrade the app.
We need deprecation first before making this.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 42 | ||||
-rw-r--r-- | activerecord/test/models/bird.rb | 4 |
3 files changed, 36 insertions, 12 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 1b8f748bad..d560b4e519 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1536,7 +1536,7 @@ class BasicsTest < ActiveRecord::TestCase Bird.create!(name: "Bluejay") ActiveRecord::Base.connection.while_preventing_writes do - assert_nothing_raised { Bird.where(name: "Bluejay").explain } + assert_queries(2) { Bird.where(name: "Bluejay").explain } end end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 857d743605..98ba47f1b8 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1167,13 +1167,21 @@ class RelationTest < ActiveRecord::TestCase assert_equal "green", parrot.color end + def test_first_or_create_with_after_initialize + Bird.create!(color: "yellow", name: "canary") + parrot = Bird.where(color: "green").first_or_create do |bird| + bird.name = "parrot" + bird.enable_count = true + end + assert_equal 0, parrot.total_count + end + def test_first_or_create_with_block - canary = Bird.create!(color: "yellow", name: "canary") + Bird.create!(color: "yellow", name: "canary") parrot = Bird.where(color: "green").first_or_create do |bird| bird.name = "parrot" - assert_equal canary, Bird.find_by!(name: "canary") + assert_equal 0, Bird.count end - assert_equal 1, parrot.total_count assert_kind_of Bird, parrot assert_predicate parrot, :persisted? assert_equal "green", parrot.color @@ -1214,13 +1222,21 @@ class RelationTest < ActiveRecord::TestCase assert_raises(ActiveRecord::RecordInvalid) { Bird.where(color: "green").first_or_create! } end + def test_first_or_create_bang_with_after_initialize + Bird.create!(color: "yellow", name: "canary") + parrot = Bird.where(color: "green").first_or_create! do |bird| + bird.name = "parrot" + bird.enable_count = true + end + assert_equal 0, parrot.total_count + end + def test_first_or_create_bang_with_valid_block - canary = Bird.create!(color: "yellow", name: "canary") + Bird.create!(color: "yellow", name: "canary") parrot = Bird.where(color: "green").first_or_create! do |bird| bird.name = "parrot" - assert_equal canary, Bird.find_by!(name: "canary") + assert_equal 0, Bird.count end - assert_equal 1, parrot.total_count assert_kind_of Bird, parrot assert_predicate parrot, :persisted? assert_equal "green", parrot.color @@ -1269,13 +1285,21 @@ class RelationTest < ActiveRecord::TestCase assert_equal "green", parrot.color end + def test_first_or_initialize_with_after_initialize + Bird.create!(color: "yellow", name: "canary") + parrot = Bird.where(color: "green").first_or_initialize do |bird| + bird.name = "parrot" + bird.enable_count = true + end + assert_equal 0, parrot.total_count + end + def test_first_or_initialize_with_block - canary = Bird.create!(color: "yellow", name: "canary") + Bird.create!(color: "yellow", name: "canary") parrot = Bird.where(color: "green").first_or_initialize do |bird| bird.name = "parrot" - assert_equal canary, Bird.find_by!(name: "canary") + assert_equal 0, Bird.count end - assert_equal 1, parrot.total_count assert_kind_of Bird, parrot assert_not_predicate parrot, :persisted? assert_predicate parrot, :valid? diff --git a/activerecord/test/models/bird.rb b/activerecord/test/models/bird.rb index c9f6759c7d..20af7c6122 100644 --- a/activerecord/test/models/bird.rb +++ b/activerecord/test/models/bird.rb @@ -17,8 +17,8 @@ class Bird < ActiveRecord::Base throw(:abort) end - attr_accessor :total_count + attr_accessor :total_count, :enable_count after_initialize do - self.total_count = Bird.count + self.total_count = Bird.count if enable_count end end |