Fix warnings in AMo

This commit is contained in:
Joshua Peek 2009-09-05 19:10:21 -05:00
parent c6e0923245
commit 6dc9ad80e6
8 changed files with 10 additions and 51 deletions

View File

@ -15,12 +15,13 @@ Rake::TestTask.new do |t|
t.libs << "test" t.libs << "test"
t.test_files = Dir.glob("test/cases/**/*_test.rb").sort t.test_files = Dir.glob("test/cases/**/*_test.rb").sort
t.verbose = true t.verbose = true
t.warning = true
end end
task :isolated_test do task :isolated_test do
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
Dir.glob("test/**/*_test.rb").all? do |file| Dir.glob("test/**/*_test.rb").all? do |file|
system(ruby, '-Ilib:test', file) system(ruby, '-w', '-Ilib:test', file)
end or raise "Failures" end or raise "Failures"
end end

View File

@ -181,7 +181,7 @@ module ActiveModel
end end
def attribute_methods_generated? def attribute_methods_generated?
@attribute_methods_generated ? true : false @attribute_methods_generated ||= nil
end end
protected protected

View File

@ -7,7 +7,8 @@ module ActiveModel
model_classes.inject({}) do |repair, klass| model_classes.inject({}) do |repair, klass|
repair[klass] ||= {} repair[klass] ||= {}
[:validate, :validate_on_create, :validate_on_update].each do |callback| [:validate, :validate_on_create, :validate_on_update].each do |callback|
the_callback = klass.instance_variable_get("@#{callback.to_s}_callbacks") ivar = "@#{callback.to_s}_callbacks"
the_callback = klass.instance_variable_get(ivar) if klass.instance_variable_defined?(ivar)
repair[klass][callback] = (the_callback.nil? ? nil : the_callback.dup) repair[klass][callback] = (the_callback.nil? ? nil : the_callback.dup)
end end
repair repair

View File

@ -78,6 +78,7 @@ class ObserverTest < ActiveModel::TestCase
def teardown def teardown
FooObserver.instance_eval do FooObserver.instance_eval do
undef_method :observed_classes
alias_method :observed_classes, :original_observed_classes alias_method :observed_classes, :original_observed_classes
end end
end end

View File

@ -8,7 +8,7 @@ class Contact
def attributes def attributes
instance_values instance_values
end end unless method_defined?(:attributes)
end end
class JsonSerializationTest < ActiveModel::TestCase class JsonSerializationTest < ActiveModel::TestCase

View File

@ -8,7 +8,7 @@ class Contact
def attributes def attributes
instance_values instance_values
end end unless method_defined?(:attributes)
end end
module Admin module Admin

View File

@ -107,32 +107,6 @@ class I18nValidationTest < ActiveModel::TestCase
@person.valid? @person.valid?
end end
def test_validates_length_of_within_generates_message_with_title_too_short
Person.validates_length_of :title, :within => 3..5
@person.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
@person.valid?
end
def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message
Person.validates_length_of :title, :within => 3..5, :too_short => 'custom'
@person.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'})
@person.valid?
end
def test_validates_length_of_within_generates_message_with_title_too_long
Person.validates_length_of :title, :within => 3..5
@person.title = 'this title is too long'
@person.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil})
@person.valid?
end
def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message
Person.validates_length_of :title, :within => 3..5, :too_long => 'custom'
@person.title = 'this title is too long'
@person.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'})
@person.valid?
end
# validates_length_of :within w/ mocha # validates_length_of :within w/ mocha
def test_validates_length_of_within_generates_message_with_title_too_short def test_validates_length_of_within_generates_message_with_title_too_short
@ -280,7 +254,7 @@ class I18nValidationTest < ActiveModel::TestCase
@person.valid? @person.valid?
end end
def test_validates_numericality_of_odd_generates_message_with_custom_default_message def test_validates_numericality_of_less_than_odd_generates_message_with_custom_default_message
Person.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom' Person.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom'
@person.title = 1 @person.title = 1
@person.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => 'custom'}) @person.errors.expects(:generate_message).with(:title, :less_than, {:value => 1, :count => 0, :default => 'custom'})
@ -384,24 +358,6 @@ class I18nValidationTest < ActiveModel::TestCase
assert_equal ['global message'], @person.errors[:title] assert_equal ['global message'], @person.errors[:title]
end end
def test_validates_length_of_is_finds_custom_model_key_translation
I18n.backend.store_translations 'en', :activemodel => {:errors => {:models => {:person => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
I18n.backend.store_translations 'en', :activemodel => {:errors => {:messages => {:wrong_length => 'global message'}}}
Person.validates_length_of :title, :is => 5
@person.valid?
assert_equal ['custom message'], @person.errors[:title]
end
def test_validates_length_of_is_finds_global_default_translation
I18n.backend.store_translations 'en', :activemodel => {:errors => {:messages => {:wrong_length => 'global message'}}}
Person.validates_length_of :title, :is => 5
@person.valid?
assert_equal ['global message'], @person.errors[:title]
end
# validates_format_of w/o mocha # validates_format_of w/o mocha
def test_validates_format_of_finds_custom_model_key_translation def test_validates_format_of_finds_custom_model_key_translation

View File

@ -227,7 +227,7 @@ module ActiveRecord
end end
include ActiveSupport::Callbacks include ActiveSupport::Callbacks
define_callbacks *CALLBACKS define_callbacks(*CALLBACKS)
end end
# Is called when the object was instantiated by one of the finders, like <tt>Base.find</tt>. # Is called when the object was instantiated by one of the finders, like <tt>Base.find</tt>.