aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb4
-rw-r--r--activerecord/lib/active_record/migration.rb4
-rw-r--r--activerecord/lib/active_record/schema.rb6
-rw-r--r--activerecord/lib/active_record/validations/associated.rb3
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb9
5 files changed, 18 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index e731bc84f0..86ba7d72c3 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -344,12 +344,12 @@ module ActiveRecord
end
end
- def assume_migrated_upto_version(version)
+ def assume_migrated_upto_version(version, migrations_path = ActiveRecord::Migrator.migrations_path)
version = version.to_i
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
- versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename|
+ versions = Dir["#{migrations_path}/[0-9]*_*.rb"].map do |filename|
filename.split('/').last.split('_').first.to_i
end
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 0022e8cc37..aeeed24881 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -407,6 +407,10 @@ module ActiveRecord
self.new(direction, migrations_path, target_version).run
end
+ def migrations_path
+ 'db/migrate'
+ end
+
def schema_migrations_table_name
Base.table_name_prefix + 'schema_migrations' + Base.table_name_suffix
end
diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb
index 8a32cf1ca2..a996a0ebac 100644
--- a/activerecord/lib/active_record/schema.rb
+++ b/activerecord/lib/active_record/schema.rb
@@ -28,6 +28,10 @@ module ActiveRecord
class Schema < Migration
private_class_method :new
+ def self.migrations_path
+ ActiveRecord::Migrator.migrations_path
+ end
+
# Eval the given block. All methods available to the current connection
# adapter are available within the block, so you can easily use the
# database definition DSL to build up your schema (+create_table+,
@@ -44,7 +48,7 @@ module ActiveRecord
unless info[:version].blank?
initialize_schema_migrations_table
- assume_migrated_upto_version info[:version]
+ assume_migrated_upto_version(info[:version], migrations_path)
end
end
end
diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb
index 66b78682ad..e41635134c 100644
--- a/activerecord/lib/active_record/validations/associated.rb
+++ b/activerecord/lib/active_record/validations/associated.rb
@@ -40,8 +40,7 @@ module ActiveRecord
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_associated(*attr_names)
- options = attr_names.extract_options!
- validates_with AssociatedValidator, options.merge(:attributes => attr_names)
+ validates_with AssociatedValidator, _merge_attributes(attr_names)
end
end
end
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 7efd312357..4ff851dfa1 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -2,10 +2,14 @@ module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator
def initialize(options)
- @klass = options.delete(:klass)
super(options.reverse_merge(:case_sensitive => true))
end
+ # Unfortunately, we have to tie Uniqueness validators to a class.
+ def setup(klass)
+ @klass = klass
+ end
+
def validate_each(record, attribute, value)
finder_class = find_finder_class_for(record)
table = finder_class.active_relation
@@ -170,8 +174,7 @@ module ActiveRecord
# such a case.
#
def validates_uniqueness_of(*attr_names)
- options = attr_names.extract_options!
- validates_with UniquenessValidator, options.merge(:attributes => attr_names, :klass => self)
+ validates_with UniquenessValidator, _merge_attributes(attr_names)
end
end
end