aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-04-14 01:40:42 +0900
committerGitHub <noreply@github.com>2019-04-14 01:40:42 +0900
commit98d4a68a80468429f1da5414772ee6644975a04f (patch)
tree7a99967c0865438615a823ae4c5975d02c5489a6
parent877376eba155969d66fc243306ea4a9bd9abb54a (diff)
parent42a8340aa8b68a2dafaf7d611ba889a807ec278f (diff)
downloadrails-98d4a68a80468429f1da5414772ee6644975a04f.tar.gz
rails-98d4a68a80468429f1da5414772ee6644975a04f.tar.bz2
rails-98d4a68a80468429f1da5414772ee6644975a04f.zip
Merge pull request #35966 from shioyama/define_validator_on_topic_subclass
Add validation to subclass in tests to avoid polluting parent class
-rw-r--r--activerecord/test/cases/validations_test.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index 9a70934b7e..4f98a6b7fc 100644
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -145,15 +145,17 @@ class ValidationsTest < ActiveRecord::TestCase
end
def test_validates_acceptance_of_with_undefined_attribute_methods
- Topic.validates_acceptance_of(:approved)
- topic = Topic.new(approved: true)
- Topic.undefine_attribute_methods
+ klass = Class.new(Topic)
+ klass.validates_acceptance_of(:approved)
+ topic = klass.new(approved: true)
+ klass.undefine_attribute_methods
assert topic.approved
end
def test_validates_acceptance_of_as_database_column
- Topic.validates_acceptance_of(:approved)
- topic = Topic.create("approved" => true)
+ klass = Class.new(Topic)
+ klass.validates_acceptance_of(:approved)
+ topic = klass.create("approved" => true)
assert topic["approved"]
end