aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-02-27 11:25:15 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-02-27 11:25:15 -0800
commit26306420a6f483f23172d84176bf6aa57548651f (patch)
treef3968bf35da8e33ae98d2b63eaa2cc0e401fe794 /activemodel
parentbf3ddfa28da8ca837ddce8c6744a6c1fd9a51243 (diff)
parent14e697cf2a1f2a4d223463839f6748fca4658bcf (diff)
downloadrails-26306420a6f483f23172d84176bf6aa57548651f.tar.gz
rails-26306420a6f483f23172d84176bf6aa57548651f.tar.bz2
rails-26306420a6f483f23172d84176bf6aa57548651f.zip
Merge branch 'master' into adequaterecord
* master: modify model generator warning message. refs [#174c9f0] Replace "data store" with database [ci skip] Return a hash rather than array from fetch_multi Fix concerning module reference [ci skip] Fixes docs typo in nested resource path helpers [skip ci] Fix some validators when used on model instance Pass strings to demodulize method pass strings to the underscore method speed up `underscore` in cases that don't need to do anything pass the class name to `tableize` [ci skip] Update list of files extensions in rake notes guide Fix controller test not resetting @_url_options
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/conversion.rb4
-rw-r--r--activemodel/lib/active_model/validations/with.rb2
-rw-r--r--activemodel/test/cases/validations_test.rb3
-rw-r--r--activemodel/test/models/automobile.rb3
4 files changed, 8 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb
index 0a19ef686d..374265f0d8 100644
--- a/activemodel/lib/active_model/conversion.rb
+++ b/activemodel/lib/active_model/conversion.rb
@@ -83,8 +83,8 @@ module ActiveModel
# internal method and should not be accessed directly.
def _to_partial_path #:nodoc:
@_to_partial_path ||= begin
- element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self))
- collection = ActiveSupport::Inflector.tableize(self)
+ element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(name))
+ collection = ActiveSupport::Inflector.tableize(name)
"#{collection}/#{element}".freeze
end
end
diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb
index 16bd6670d1..7022f9bee5 100644
--- a/activemodel/lib/active_model/validations/with.rb
+++ b/activemodel/lib/active_model/validations/with.rb
@@ -139,6 +139,8 @@ module ActiveModel
# class version of this method for more information.
def validates_with(*args, &block)
options = args.extract_options!
+ options[:class] = self.class
+
args.each do |klass|
validator = klass.new(options, &block)
validator.validate(self)
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb
index bee8ece992..cfce8fb8e6 100644
--- a/activemodel/test/cases/validations_test.rb
+++ b/activemodel/test/cases/validations_test.rb
@@ -284,10 +284,11 @@ class ValidationsTest < ActiveModel::TestCase
auto = Automobile.new
assert auto.invalid?
- assert_equal 2, auto.errors.size
+ assert_equal 3, auto.errors.size
auto.make = 'Toyota'
auto.model = 'Corolla'
+ auto.approved = '1'
assert auto.valid?
end
diff --git a/activemodel/test/models/automobile.rb b/activemodel/test/models/automobile.rb
index ece644c40c..4df2fe8b3a 100644
--- a/activemodel/test/models/automobile.rb
+++ b/activemodel/test/models/automobile.rb
@@ -3,10 +3,11 @@ class Automobile
validate :validations
- attr_accessor :make, :model
+ attr_accessor :make, :model, :approved
def validations
validates_presence_of :make
validates_length_of :model, within: 2..10
+ validates_acceptance_of :approved, allow_nil: false
end
end