activerecord 4.0.0.beta1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +573 -30
  3. data/README.rdoc +3 -3
  4. data/lib/active_record.rb +8 -2
  5. data/lib/active_record/associations.rb +16 -9
  6. data/lib/active_record/associations/association.rb +8 -6
  7. data/lib/active_record/associations/association_scope.rb +2 -1
  8. data/lib/active_record/associations/belongs_to_association.rb +2 -2
  9. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
  10. data/lib/active_record/associations/builder/belongs_to.rb +37 -5
  11. data/lib/active_record/associations/collection_association.rb +38 -14
  12. data/lib/active_record/associations/collection_proxy.rb +18 -15
  13. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +3 -3
  14. data/lib/active_record/associations/has_many_association.rb +4 -3
  15. data/lib/active_record/associations/has_many_through_association.rb +1 -1
  16. data/lib/active_record/associations/has_one_association.rb +1 -1
  17. data/lib/active_record/associations/join_dependency.rb +29 -8
  18. data/lib/active_record/associations/join_dependency/join_association.rb +26 -6
  19. data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
  20. data/lib/active_record/associations/join_dependency/join_part.rb +6 -6
  21. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +1 -1
  22. data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
  23. data/lib/active_record/associations/through_association.rb +1 -1
  24. data/lib/active_record/attribute_assignment.rb +5 -5
  25. data/lib/active_record/attribute_methods.rb +20 -5
  26. data/lib/active_record/attribute_methods/dirty.rb +5 -1
  27. data/lib/active_record/attribute_methods/primary_key.rb +1 -1
  28. data/lib/active_record/attribute_methods/serialization.rb +9 -2
  29. data/lib/active_record/autosave_association.rb +19 -5
  30. data/lib/active_record/base.rb +3 -3
  31. data/lib/active_record/callbacks.rb +1 -1
  32. data/lib/active_record/coders/yaml_column.rb +8 -13
  33. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +3 -9
  34. data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -1
  35. data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -1
  36. data/lib/active_record/connection_adapters/abstract/quoting.rb +2 -8
  37. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +60 -61
  38. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +13 -2
  39. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +291 -153
  40. data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -1
  41. data/lib/active_record/connection_adapters/abstract_adapter.rb +92 -1
  42. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +55 -29
  43. data/lib/active_record/connection_adapters/column.rb +4 -4
  44. data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
  45. data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -3
  46. data/lib/active_record/connection_adapters/mysql_adapter.rb +5 -5
  47. data/lib/active_record/connection_adapters/postgresql/cast.rb +22 -2
  48. data/lib/active_record/connection_adapters/postgresql/oid.rb +25 -6
  49. data/lib/active_record/connection_adapters/postgresql/quoting.rb +26 -13
  50. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +50 -9
  51. data/lib/active_record/connection_adapters/postgresql_adapter.rb +53 -24
  52. data/lib/active_record/connection_adapters/schema_cache.rb +35 -7
  53. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +13 -5
  54. data/lib/active_record/connection_handling.rb +7 -7
  55. data/lib/active_record/core.rb +43 -8
  56. data/lib/active_record/counter_cache.rb +2 -1
  57. data/lib/active_record/errors.rb +11 -10
  58. data/lib/active_record/explain.rb +9 -7
  59. data/lib/active_record/explain_registry.rb +30 -0
  60. data/lib/active_record/explain_subscriber.rb +3 -2
  61. data/lib/active_record/fixture_set/file.rb +1 -2
  62. data/lib/active_record/fixtures.rb +13 -7
  63. data/lib/active_record/inheritance.rb +12 -4
  64. data/lib/active_record/integration.rb +3 -3
  65. data/lib/active_record/locking/optimistic.rb +2 -2
  66. data/lib/active_record/log_subscriber.rb +2 -2
  67. data/lib/active_record/migration.rb +69 -21
  68. data/lib/active_record/model_schema.rb +1 -1
  69. data/lib/active_record/nested_attributes.rb +98 -46
  70. data/lib/active_record/persistence.rb +3 -3
  71. data/lib/active_record/querying.rb +1 -1
  72. data/lib/active_record/railtie.rb +18 -4
  73. data/lib/active_record/railties/console_sandbox.rb +3 -2
  74. data/lib/active_record/railties/controller_runtime.rb +2 -1
  75. data/lib/active_record/railties/databases.rake +38 -80
  76. data/lib/active_record/reflection.rb +36 -3
  77. data/lib/active_record/relation.rb +18 -8
  78. data/lib/active_record/relation/calculations.rb +10 -5
  79. data/lib/active_record/relation/delegation.rb +3 -5
  80. data/lib/active_record/relation/finder_methods.rb +27 -14
  81. data/lib/active_record/relation/merger.rb +30 -2
  82. data/lib/active_record/relation/predicate_builder.rb +1 -6
  83. data/lib/active_record/relation/query_methods.rb +113 -16
  84. data/lib/active_record/runtime_registry.rb +17 -0
  85. data/lib/active_record/schema_dumper.rb +5 -1
  86. data/lib/active_record/schema_migration.rb +8 -5
  87. data/lib/active_record/scoping.rb +56 -2
  88. data/lib/active_record/scoping/default.rb +12 -11
  89. data/lib/active_record/scoping/named.rb +7 -3
  90. data/lib/active_record/serialization.rb +1 -1
  91. data/lib/active_record/statement_cache.rb +26 -0
  92. data/lib/active_record/tasks/database_tasks.rb +55 -10
  93. data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
  94. data/lib/active_record/tasks/mysql_database_tasks.rb +7 -2
  95. data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
  96. data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
  97. data/lib/active_record/timestamp.rb +6 -0
  98. data/lib/active_record/transactions.rb +7 -3
  99. data/lib/active_record/validations.rb +1 -2
  100. data/lib/active_record/validations/uniqueness.rb +7 -3
  101. data/lib/active_record/version.rb +7 -6
  102. data/lib/rails/generators/active_record/migration/migration_generator.rb +9 -2
  103. data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
  104. data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
  105. data/lib/rails/generators/active_record/model/templates/model.rb +4 -1
  106. metadata +17 -12
  107. data/examples/associations.png +0 -0
@@ -0,0 +1,48 @@
1
+ require 'shellwords'
2
+
3
+ module ActiveRecord
4
+ module Tasks # :nodoc:
5
+ class SqlserverDatabaseTasks # :nodoc:
6
+ delegate :connection, :establish_connection, to: ActiveRecord::Base
7
+
8
+ def initialize(configuration)
9
+ ActiveSupport::Deprecation.warn "This database tasks were deprecated, because this tasks should be served by the 3rd party adapter."
10
+ @configuration = configuration
11
+ end
12
+
13
+ def create
14
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
15
+ end
16
+
17
+ def drop
18
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
19
+ end
20
+
21
+ def purge
22
+ test = configuration.deep_dup
23
+ test_database = test['database']
24
+ test['database'] = 'master'
25
+ establish_connection(test)
26
+ connection.recreate_database!(test_database)
27
+ end
28
+
29
+ def charset
30
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
31
+ end
32
+
33
+ def structure_dump(filename)
34
+ Kernel.system("smoscript -s #{configuration['host']} -d #{configuration['database']} -u #{configuration['username']} -p #{configuration['password']} -f #{filename} -A -U")
35
+ end
36
+
37
+ def structure_load(filename)
38
+ Kernel.system("sqlcmd -S #{configuration['host']} -d #{configuration['database']} -U #{configuration['username']} -P #{configuration['password']} -i #{filename}")
39
+ end
40
+
41
+ private
42
+
43
+ def configuration
44
+ @configuration
45
+ end
46
+ end
47
+ end
48
+ end
@@ -98,6 +98,12 @@ module ActiveRecord
98
98
  timestamp_attributes_for_create + timestamp_attributes_for_update
99
99
  end
100
100
 
101
+ def max_updated_column_timestamp
102
+ if (timestamps = timestamp_attributes_for_update.map { |attr| self[attr] }.compact).present?
103
+ timestamps.map { |ts| ts.to_time }.max
104
+ end
105
+ end
106
+
101
107
  def current_time_from_proper_timezone
102
108
  self.class.default_timezone == :utc ? Time.now.utc : Time.now
103
109
  end
@@ -160,7 +160,7 @@ module ActiveRecord
160
160
  # end
161
161
  # end
162
162
  #
163
- # only "Kotori" is created. (This works on MySQL and PostgreSQL, but not on SQLite3.)
163
+ # only "Kotori" is created. This works on MySQL and PostgreSQL. SQLite3 version >= '3.6.8' also supports it.
164
164
  #
165
165
  # Most databases don't support true nested transactions. At the time of
166
166
  # writing, the only database that we're aware of that supports true nested
@@ -339,8 +339,12 @@ module ActiveRecord
339
339
  # Save the new record state and id of a record so it can be restored later if a transaction fails.
340
340
  def remember_transaction_record_state #:nodoc:
341
341
  @_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key)
342
- @_start_transaction_state[:new_record] = @new_record
343
- @_start_transaction_state[:destroyed] = @destroyed
342
+ unless @_start_transaction_state.include?(:new_record)
343
+ @_start_transaction_state[:new_record] = @new_record
344
+ end
345
+ unless @_start_transaction_state.include?(:destroyed)
346
+ @_start_transaction_state[:destroyed] = @destroyed
347
+ end
344
348
  @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
345
349
  @_start_transaction_state[:frozen?] = @attributes.frozen?
346
350
  end
@@ -74,8 +74,7 @@ module ActiveRecord
74
74
  protected
75
75
 
76
76
  def perform_validations(options={}) # :nodoc:
77
- perform_validation = options[:validate] != false
78
- perform_validation ? valid?(options[:context]) : true
77
+ options[:validate] == false || valid?(options[:context])
79
78
  end
80
79
  end
81
80
  end
@@ -2,6 +2,10 @@ module ActiveRecord
2
2
  module Validations
3
3
  class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
4
4
  def initialize(options)
5
+ if options[:conditions] && !options[:conditions].respond_to?(:call)
6
+ raise ArgumentError, "#{options[:conditions]} was passed as :conditions but is not callable. " \
7
+ "Pass a callable instead: `conditions: -> { where(approved: true) }`"
8
+ end
5
9
  super({ case_sensitive: true }.merge!(options))
6
10
  end
7
11
 
@@ -19,7 +23,7 @@ module ActiveRecord
19
23
  relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.id)) if record.persisted?
20
24
  relation = scope_relation(record, table, relation)
21
25
  relation = finder_class.unscoped.where(relation)
22
- relation.merge!(options[:conditions]) if options[:conditions]
26
+ relation = relation.merge(options[:conditions]) if options[:conditions]
23
27
 
24
28
  if relation.exists?
25
29
  error_options = options.except(:case_sensitive, :scope, :conditions)
@@ -116,7 +120,7 @@ module ActiveRecord
116
120
  # of the title attribute:
117
121
  #
118
122
  # class Article < ActiveRecord::Base
119
- # validates_uniqueness_of :title, conditions: where('status != ?', 'archived')
123
+ # validates_uniqueness_of :title, conditions: -> { where.not(status: 'archived') }
120
124
  # end
121
125
  #
122
126
  # When the record is created, a check is performed to make sure that no
@@ -132,7 +136,7 @@ module ActiveRecord
132
136
  # the uniqueness constraint.
133
137
  # * <tt>:conditions</tt> - Specify the conditions to be included as a
134
138
  # <tt>WHERE</tt> SQL fragment to limit the uniqueness constraint lookup
135
- # (e.g. <tt>conditions: where('status = ?', 'active')</tt>).
139
+ # (e.g. <tt>conditions: -> { where(status: 'active') }</tt>).
136
140
  # * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by
137
141
  # non-text columns (+true+ by default).
138
142
  # * <tt>:allow_nil</tt> - If set to +true+, skips this validation if the
@@ -1,10 +1,11 @@
1
1
  module ActiveRecord
2
- module VERSION #:nodoc:
3
- MAJOR = 4
4
- MINOR = 0
5
- TINY = 0
6
- PRE = "beta1"
2
+ # Returns the version of the currently loaded ActiveRecord as a Gem::Version
3
+ def self.version
4
+ Gem::Version.new "4.0.0.rc1"
5
+ end
7
6
 
8
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
7
+ module VERSION #:nodoc:
8
+ MAJOR, MINOR, TINY, PRE = ActiveRecord.version.segments
9
+ STRING = ActiveRecord.version.to_s
9
10
  end
10
11
  end
@@ -8,13 +8,14 @@ module ActiveRecord
8
8
  def create_migration_file
9
9
  set_local_assigns!
10
10
  validate_file_name!
11
- migration_template "migration.rb", "db/migrate/#{file_name}.rb"
11
+ migration_template @migration_template, "db/migrate/#{file_name}.rb"
12
12
  end
13
13
 
14
14
  protected
15
15
  attr_reader :migration_action, :join_tables
16
16
 
17
17
  def set_local_assigns!
18
+ @migration_template = "migration.rb"
18
19
  case file_name
19
20
  when /^(add|remove)_.*_(?:to|from)_(.*)/
20
21
  @migration_action = $1
@@ -26,6 +27,9 @@ module ActiveRecord
26
27
 
27
28
  set_index_names
28
29
  end
30
+ when /^create_(.+)/
31
+ @table_name = $1.pluralize
32
+ @migration_template = "create_table_migration.rb"
29
33
  end
30
34
  end
31
35
 
@@ -44,7 +48,10 @@ module ActiveRecord
44
48
  end
45
49
 
46
50
  private
47
-
51
+ def attributes_with_index
52
+ attributes.select { |a| !a.reference? && a.has_index? }
53
+ end
54
+
48
55
  def validate_file_name!
49
56
  unless file_name =~ /^[_a-z0-9]+$/
50
57
  raise IllegalMigrationNameError.new(file_name)
@@ -2,8 +2,12 @@ class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :<%= table_name %> do |t|
4
4
  <% attributes.each do |attribute| -%>
5
+ <% if attribute.password_digest? -%>
6
+ t.string :password_digest<%= attribute.inject_options %>
7
+ <% else -%>
5
8
  t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
6
9
  <% end -%>
10
+ <% end -%>
7
11
  <% if options[:timestamps] %>
8
12
  t.timestamps
9
13
  <% end -%>
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  def create_migration_file
16
16
  return unless options[:migration] && options[:parent].nil?
17
17
  attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
18
- migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
18
+ migration_template "../../migration/templates/create_table_migration.rb", "db/migrate/create_#{table_name}.rb"
19
19
  end
20
20
 
21
21
  def create_model_file
@@ -1,7 +1,10 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= class_name %> < <%= parent_class_name.classify %>
3
- <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
3
+ <% attributes.select(&:reference?).each do |attribute| -%>
4
4
  belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
5
5
  <% end -%>
6
+ <% if attributes.any?(&:password_digest?) -%>
7
+ has_secure_password
8
+ <% end -%>
6
9
  end
7
10
  <% end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta1
4
+ version: 4.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-02-26 00:00:00.000000000 Z
11
+ date: 2013-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0.beta1
19
+ version: 4.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0.beta1
26
+ version: 4.0.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.0.beta1
33
+ version: 4.0.0.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.0.beta1
40
+ version: 4.0.0.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.0.beta1
47
+ version: 4.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.0.beta1
54
+ version: 4.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord-deprecated_finders
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.3
61
+ version: 1.0.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.3
68
+ version: 1.0.2
69
69
  description: Databases on Rails. Build a persistent domain model by mapping database
70
70
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
71
71
  migrations, and testing come baked-in.
@@ -78,7 +78,6 @@ files:
78
78
  - CHANGELOG.md
79
79
  - MIT-LICENSE
80
80
  - README.rdoc
81
- - examples/associations.png
82
81
  - examples/performance.rb
83
82
  - examples/simple.rb
84
83
  - lib/active_record/aggregations.rb
@@ -166,6 +165,7 @@ files:
166
165
  - lib/active_record/dynamic_matchers.rb
167
166
  - lib/active_record/errors.rb
168
167
  - lib/active_record/explain.rb
168
+ - lib/active_record/explain_registry.rb
169
169
  - lib/active_record/explain_subscriber.rb
170
170
  - lib/active_record/fixture_set/file.rb
171
171
  - lib/active_record/fixtures.rb
@@ -201,6 +201,7 @@ files:
201
201
  - lib/active_record/relation/spawn_methods.rb
202
202
  - lib/active_record/relation.rb
203
203
  - lib/active_record/result.rb
204
+ - lib/active_record/runtime_registry.rb
204
205
  - lib/active_record/sanitization.rb
205
206
  - lib/active_record/schema.rb
206
207
  - lib/active_record/schema_dumper.rb
@@ -210,11 +211,15 @@ files:
210
211
  - lib/active_record/scoping.rb
211
212
  - lib/active_record/serialization.rb
212
213
  - lib/active_record/serializers/xml_serializer.rb
214
+ - lib/active_record/statement_cache.rb
213
215
  - lib/active_record/store.rb
214
216
  - lib/active_record/tasks/database_tasks.rb
217
+ - lib/active_record/tasks/firebird_database_tasks.rb
215
218
  - lib/active_record/tasks/mysql_database_tasks.rb
219
+ - lib/active_record/tasks/oracle_database_tasks.rb
216
220
  - lib/active_record/tasks/postgresql_database_tasks.rb
217
221
  - lib/active_record/tasks/sqlite_database_tasks.rb
222
+ - lib/active_record/tasks/sqlserver_database_tasks.rb
218
223
  - lib/active_record/test_case.rb
219
224
  - lib/active_record/timestamp.rb
220
225
  - lib/active_record/transactions.rb
@@ -226,9 +231,9 @@ files:
226
231
  - lib/active_record/version.rb
227
232
  - lib/active_record.rb
228
233
  - lib/rails/generators/active_record/migration/migration_generator.rb
234
+ - lib/rails/generators/active_record/migration/templates/create_table_migration.rb
229
235
  - lib/rails/generators/active_record/migration/templates/migration.rb
230
236
  - lib/rails/generators/active_record/model/model_generator.rb
231
- - lib/rails/generators/active_record/model/templates/migration.rb
232
237
  - lib/rails/generators/active_record/model/templates/model.rb
233
238
  - lib/rails/generators/active_record/model/templates/module.rb
234
239
  - lib/rails/generators/active_record.rb
Binary file