aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/CHANGELOG17
-rw-r--r--activemodel/activemodel.gemspec25
-rw-r--r--activemodel/lib/active_model/dirty.rb24
-rw-r--r--activemodel/lib/active_model/errors.rb2
-rw-r--r--activemodel/lib/active_model/version.rb2
-rw-r--r--activemodel/test/cases/dirty_test.rb1
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb10
7 files changed, 54 insertions, 27 deletions
diff --git a/activemodel/CHANGELOG b/activemodel/CHANGELOG
index eae337e737..8c458b6091 100644
--- a/activemodel/CHANGELOG
+++ b/activemodel/CHANGELOG
@@ -1,4 +1,19 @@
-*Edge*
+*Rails 3.0.0 [beta 2] (April 1st, 2010)*
+
+* #new_record? and #destroyed? were removed from ActiveModel::Lint. Use
+ persisted? instead. A model is persisted if it's not a new_record? and it was
+ not destroyed? [MG]
+
+* Added validations reflection in ActiveModel::Validations [JV]
+
+ Model.validators
+ Model.validators_on(:field)
+
+* #to_key was added to ActiveModel::Lint so we can generate DOM IDs for
+ AMo objects with composite keys [MG]
+
+
+*Rails 3.0.0 [beta 1] (February 4, 2010)*
* ActiveModel::Observer#add_observer!
diff --git a/activemodel/activemodel.gemspec b/activemodel/activemodel.gemspec
index eb9ef7b7c0..9695911398 100644
--- a/activemodel/activemodel.gemspec
+++ b/activemodel/activemodel.gemspec
@@ -1,22 +1,23 @@
-version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
+version = File.read(File.expand_path('../../RAILS_VERSION', __FILE__)).strip
Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = 'activemodel'
- s.version = version
- s.summary = 'A toolkit for building modeling frameworks (part of Rails).'
+ s.platform = Gem::Platform::RUBY
+ s.name = 'activemodel'
+ s.version = version
+ s.summary = 'A toolkit for building modeling frameworks (part of Rails).'
s.description = 'A toolkit for building modeling frameworks like Active Record and Active Resource. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.'
+
s.required_ruby_version = '>= 1.8.7'
- s.author = "David Heinemeier Hansson"
- s.email = "david@loudthinking.com"
- s.rubyforge_project = "activemodel"
- s.homepage = "http://www.rubyonrails.org"
+ s.author = 'David Heinemeier Hansson'
+ s.email = 'david@loudthinking.com'
+ s.homepage = 'http://www.rubyonrails.org'
+ s.rubyforge_project = 'activemodel'
+
+ s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README', 'lib/**/*']
+ s.require_path = 'lib'
s.has_rdoc = true
s.add_dependency('activesupport', version)
-
- s.require_path = 'lib'
- s.files = Dir["CHANGELOG", "MIT-LICENSE", "README", "lib/**/*"]
end
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index 2d5acdfced..a7ee15a7f6 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -91,17 +91,12 @@ module ActiveModel
attribute_method_affix :prefix => 'reset_', :suffix => '!'
end
- def initialize(*)
- @changed_attributes = {}
- super
- end
-
# Do any attributes have unsaved changes?
# person.changed? # => false
# person.name = 'bob'
# person.changed? # => true
def changed?
- !@changed_attributes.empty?
+ !changed_attributes.empty?
end
# List of attributes with unsaved changes.
@@ -109,7 +104,7 @@ module ActiveModel
# person.name = 'bob'
# person.changed # => ['name']
def changed
- @changed_attributes.keys
+ changed_attributes.keys
end
# Map of changed attrs => [original value, new value].
@@ -130,19 +125,24 @@ module ActiveModel
end
private
+ # Map of change <tt>attr => original value</tt>.
+ def changed_attributes
+ @changed_attributes ||= {}
+ end
+
# Handle <tt>*_changed?</tt> for +method_missing+.
def attribute_changed?(attr)
- @changed_attributes.include?(attr)
+ changed_attributes.include?(attr)
end
# Handle <tt>*_change</tt> for +method_missing+.
def attribute_change(attr)
- [@changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
+ [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
end
# Handle <tt>*_was</tt> for +method_missing+.
def attribute_was(attr)
- attribute_changed?(attr) ? @changed_attributes[attr] : __send__(attr)
+ attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
end
# Handle <tt>*_will_change!</tt> for +method_missing+.
@@ -153,12 +153,12 @@ module ActiveModel
rescue TypeError, NoMethodError
end
- @changed_attributes[attr] = value
+ changed_attributes[attr] = value
end
# Handle <tt>reset_*!</tt> for +method_missing+.
def reset_attribute!(attr)
- __send__("#{attr}=", @changed_attributes[attr]) if attribute_changed?(attr)
+ __send__("#{attr}=", changed_attributes[attr]) if attribute_changed?(attr)
end
end
end
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 8d28040c32..64b28f6def 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/object/blank'
diff --git a/activemodel/lib/active_model/version.rb b/activemodel/lib/active_model/version.rb
index 85d0eed180..a33657626f 100644
--- a/activemodel/lib/active_model/version.rb
+++ b/activemodel/lib/active_model/version.rb
@@ -3,7 +3,7 @@ module ActiveModel
MAJOR = 3
MINOR = 0
TINY = 0
- BUILD = "beta1"
+ BUILD = "beta2"
STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
end
diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb
index 0883363baf..c910cb43d4 100644
--- a/activemodel/test/cases/dirty_test.rb
+++ b/activemodel/test/cases/dirty_test.rb
@@ -6,7 +6,6 @@ class DirtyTest < ActiveModel::TestCase
define_attribute_methods [:name]
def initialize
- super
@name = nil
end
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index 38844bb1fa..7dd82e711d 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
require "cases/helper"
require 'cases/tests_database'
require 'models/person'
@@ -41,6 +43,14 @@ class I18nValidationTest < ActiveModel::TestCase
@person.errors.add_on_blank :title, 'custom'
end
+ def test_full_message_encoding
+ I18n.backend.store_translations('en', :errors => {
+ :messages => { :too_short => '猫舌' }})
+ Person.validates_length_of :title, :within => 3..5
+ @person.valid?
+ assert_equal ['Title 猫舌'], @person.errors.full_messages
+ end
+
def test_errors_full_messages_translates_human_attribute_name_for_model_attributes
@person.errors.add(:name, 'not found')
Person.expects(:human_attribute_name).with(:name, :default => 'Name').returns("Person's name")