aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-04-20 15:30:41 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-04-20 15:30:41 -0700
commit3b93ca221d3a1b777bd880c18f52010cbd56c18c (patch)
tree7b49713994125de123775102eac2655d7b29b231 /activerecord
parentdaab53d8c0bca1114c1485d0dcc52858a264ab9e (diff)
parent46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd (diff)
downloadrails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.tar.gz
rails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.tar.bz2
rails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.zip
Merge commit 'rails/master'
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/.gitignore1
-rw-r--r--activerecord/lib/active_record/migration.rb6
-rwxr-xr-xactiverecord/lib/active_record/validations.rb27
-rw-r--r--activerecord/test/cases/migration_test.rb9
-rwxr-xr-xactiverecord/test/cases/validations_test.rb18
5 files changed, 26 insertions, 35 deletions
diff --git a/activerecord/.gitignore b/activerecord/.gitignore
deleted file mode 100644
index 2bf1ef8c0e..0000000000
--- a/activerecord/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-debug.log \ No newline at end of file
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 573c6a4f02..1d63bb2f84 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -364,8 +364,10 @@ module ActiveRecord
end
def current_version
- Base.connection.select_values(
- "SELECT version FROM #{schema_migrations_table_name}").map(&:to_i).max || 0
+ version = Base.connection.select_values(
+ "SELECT version FROM #{schema_migrations_table_name}"
+ ).map(&:to_i).max rescue nil
+ version || 0
end
def proper_table_name(name)
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 86cda9aa66..1d12ea8ad7 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -281,24 +281,7 @@ module ActiveRecord
end
base.send :include, ActiveSupport::Callbacks
-
- VALIDATIONS.each do |validation_method|
- base.class_eval <<-"end_eval"
- def self.#{validation_method}(*methods, &block)
- methods = CallbackChain.build(:#{validation_method}, *methods, &block)
- self.#{validation_method}_callback_chain.replace(#{validation_method}_callback_chain | methods)
- end
-
- def self.#{validation_method}_callback_chain
- if chain = read_inheritable_attribute(:#{validation_method})
- return chain
- else
- write_inheritable_attribute(:#{validation_method}, CallbackChain.new)
- return #{validation_method}_callback_chain
- end
- end
- end_eval
- end
+ base.define_callbacks *VALIDATIONS
end
# All of the following validations are defined in the class scope of the model that you're interested in validating.
@@ -404,7 +387,7 @@ module ActiveRecord
# method, proc or string should return or evaluate to a true or false value.
# * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
- # method, proc or string should return or evaluate to a true or false value.
+ # method, proc or string should return or evaluate to a true or false value.
def validates_confirmation_of(*attr_names)
configuration = { :message => ActiveRecord::Errors.default_error_messages[:confirmation], :on => :save }
configuration.update(attr_names.extract_options!)
@@ -438,7 +421,7 @@ module ActiveRecord
# method, proc or string should return or evaluate to a true or false value.
# * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
- # method, proc or string should return or evaluate to a true or false value.
+ # method, proc or string should return or evaluate to a true or false value.
def validates_acceptance_of(*attr_names)
configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save, :allow_nil => true, :accept => "1" }
configuration.update(attr_names.extract_options!)
@@ -520,7 +503,7 @@ module ActiveRecord
# method, proc or string should return or evaluate to a true or false value.
# * <tt>unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The
- # method, proc or string should return or evaluate to a true or false value.
+ # method, proc or string should return or evaluate to a true or false value.
def validates_length_of(*attrs)
# Merge given options with defaults.
options = {
@@ -597,7 +580,7 @@ module ActiveRecord
# attribute (that maps to a column). When the record is updated, the same check is made but disregarding the record itself.
#
# Because this check is performed outside the database there is still a chance that duplicate values
- # will be inserted in two parallel transactions. To guarantee against this you should create a
+ # will be inserted in two parallel transactions. To guarantee against this you should create a
# unique index on the field. See +add_index+ for more information.
#
# Configuration options:
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index 885d89b6da..c270230d67 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -813,6 +813,13 @@ if ActiveRecord::Base.connection.supports_migrations?
end
end
+ def test_migrator_db_has_no_schema_migrations_table
+ ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
+ assert_nothing_raised do
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
+ end
+ end
+
def test_migrator_verbosity
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
assert PeopleHaveLastNames.message_count > 0
@@ -1010,7 +1017,7 @@ if ActiveRecord::Base.connection.supports_migrations?
end
end
-
+
uses_mocha 'Sexy migration tests' do
class SexyMigrationsTest < ActiveRecord::TestCase
def test_references_column_type_adds_id
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index 97ac22eaf3..ca36ad3581 100755
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -58,9 +58,9 @@ class ValidationsTest < ActiveRecord::TestCase
fixtures :topics, :developers, 'warehouse-things'
def setup
- Topic.write_inheritable_attribute(:validate, nil)
- Topic.write_inheritable_attribute(:validate_on_create, nil)
- Topic.write_inheritable_attribute(:validate_on_update, nil)
+ Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ Topic.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ Topic.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
end
def test_single_field_validation
@@ -839,16 +839,16 @@ class ValidationsTest < ActiveRecord::TestCase
reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain')
assert t.valid?
end
-
+
def test_validates_size_of_association_using_within
assert_nothing_raised { Topic.validates_size_of :replies, :within => 1..2 }
t = Topic.new('title' => 'noreplies', 'content' => 'whatever')
assert !t.save
assert t.errors.on(:replies)
-
+
reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain')
assert t.valid?
-
+
2.times { t.replies.build('title' => 'areply', 'content' => 'whateveragain') }
assert !t.save
assert t.errors.on(:replies)
@@ -1351,9 +1351,9 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
JUNK = ["not a number", "42 not a number", "0xdeadbeef", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"]
def setup
- Topic.write_inheritable_attribute(:validate, nil)
- Topic.write_inheritable_attribute(:validate_on_create, nil)
- Topic.write_inheritable_attribute(:validate_on_update, nil)
+ Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ Topic.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ Topic.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
end
def test_default_validates_numericality_of