activerecord 5.0.0.beta4 → 5.0.0.racecar1

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 (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -2
  3. data/lib/active_record/associations/belongs_to_association.rb +1 -0
  4. data/lib/active_record/associations/builder/belongs_to.rb +2 -0
  5. data/lib/active_record/attributes.rb +6 -1
  6. data/lib/active_record/callbacks.rb +3 -3
  7. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +29 -47
  8. data/lib/active_record/connection_adapters/abstract_adapter.rb +18 -0
  9. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +6 -2
  10. data/lib/active_record/connection_adapters/connection_specification.rb +12 -5
  11. data/lib/active_record/connection_adapters/mysql/schema_creation.rb +5 -16
  12. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +1 -1
  13. data/lib/active_record/connection_adapters/postgresql_adapter.rb +0 -4
  14. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  15. data/lib/active_record/connection_handling.rb +22 -7
  16. data/lib/active_record/core.rb +1 -1
  17. data/lib/active_record/gem_version.rb +1 -1
  18. data/lib/active_record/locking/optimistic.rb +1 -1
  19. data/lib/active_record/migration.rb +3 -9
  20. data/lib/active_record/migration/compatibility.rb +10 -0
  21. data/lib/active_record/model_schema.rb +1 -1
  22. data/lib/active_record/querying.rb +1 -1
  23. data/lib/active_record/relation/batches/batch_enumerator.rb +1 -1
  24. data/lib/active_record/relation/delegation.rb +1 -1
  25. data/lib/active_record/relation/query_methods.rb +10 -4
  26. data/lib/active_record/tasks/database_tasks.rb +2 -2
  27. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7f29a643f71feaf240f7200a6e5c8dba8415d6e
4
- data.tar.gz: 3b934f19c6464814f9a3c63db0684e4fcd25922c
3
+ metadata.gz: 173556138a2bd53f64098516ffd9d2959550cdbd
4
+ data.tar.gz: 6ea16dbc226ccb4235309074a70ffa85580f7eef
5
5
  SHA512:
6
- metadata.gz: d024e027426b52314572c887bfaca668b290c1a21b6217d9221a7c5bd3d5d1857ed9e435dc007b3ab39767889d29741ba1f48891177def1d865f41d63c95ae72
7
- data.tar.gz: 9fbbe193fa6100f07a9a16e61b912291bc8e42d802fb53f7d63461ac34a697166cff13b01904dffe9dcbc448e8600fac934d7a1cc307db2144680f00b5085607
6
+ metadata.gz: 53e61d9bf07dc4e8a71ef43a8a5fe917d4a86c8acfd4880732ae5af279dc36f455e6f37134667e0373c66f35d309e75b1cf8e62441b48f7141dd40a65d916012
7
+ data.tar.gz: 1707472ef5f7c1bb5e1cd966da87045a48a49e34a7bc2751db39609add4fd7c2cc6cd199e1e42597a4187804b91372273c6158d686d775a483b20a69055c2823
@@ -1,3 +1,8 @@
1
+ ## Rails 5.0.0.rc1 (May 06, 2016) ##
2
+
3
+ * No changes.
4
+
5
+
1
6
  ## Rails 5.0.0.beta4 (April 27, 2016) ##
2
7
 
3
8
  * PostgreSQL: Support Expression Indexes and Operator Classes.
@@ -119,12 +124,11 @@
119
124
 
120
125
  *Jeremy Daer*
121
126
 
122
- * Delegate `empty?`, `none?` and `one?`. Now they can be invoked as model class methods.
127
+ * Delegate `none?` and `one?`. Now they can be invoked as model class methods.
123
128
 
124
129
  Example:
125
130
 
126
131
  # When no record is found on the table
127
- Topic.empty? # => true
128
132
  Topic.none? # => true
129
133
 
130
134
  # When only one record is found on the table
@@ -61,6 +61,7 @@ module ActiveRecord
61
61
 
62
62
  def update_counters_on_replace(record)
63
63
  if require_counter_update? && different_target?(record)
64
+ owner.instance_variable_set :@_after_replace_counter_called, true
64
65
  record.increment!(reflection.counter_cache_column)
65
66
  decrement_counters
66
67
  end
@@ -33,6 +33,8 @@ module ActiveRecord::Associations::Builder # :nodoc:
33
33
 
34
34
  if (@_after_create_counter_called ||= false)
35
35
  @_after_create_counter_called = false
36
+ elsif (@_after_replace_counter_called ||= false)
37
+ @_after_replace_counter_called = false
36
38
  elsif attribute_changed?(foreign_key) && !new_record?
37
39
  if reflection.polymorphic?
38
40
  model = attribute(reflection.foreign_type).try(:constantize)
@@ -67,12 +67,14 @@ module ActiveRecord
67
67
  #
68
68
  # A default can also be provided.
69
69
  #
70
+ # # db/schema.rb
70
71
  # create_table :store_listings, force: true do |t|
71
72
  # t.string :my_string, default: "original default"
72
73
  # end
73
74
  #
74
75
  # StoreListing.new.my_string # => "original default"
75
76
  #
77
+ # # app/models/store_listing.rb
76
78
  # class StoreListing < ActiveRecord::Base
77
79
  # attribute :my_string, :string, default: "new default"
78
80
  # end
@@ -89,6 +91,7 @@ module ActiveRecord
89
91
  #
90
92
  # \Attributes do not need to be backed by a database column.
91
93
  #
94
+ # # app/models/my_model.rb
92
95
  # class MyModel < ActiveRecord::Base
93
96
  # attribute :my_string, :string
94
97
  # attribute :my_int_array, :integer, array: true
@@ -131,7 +134,7 @@ module ActiveRecord
131
134
  # # config/initializers/types.rb
132
135
  # ActiveRecord::Type.register(:money, MoneyType)
133
136
  #
134
- # # /app/models/store_listing.rb
137
+ # # app/models/store_listing.rb
135
138
  # class StoreListing < ActiveRecord::Base
136
139
  # attribute :price_in_cents, :money
137
140
  # end
@@ -167,8 +170,10 @@ module ActiveRecord
167
170
  # end
168
171
  # end
169
172
  #
173
+ # # config/initializers/types.rb
170
174
  # ActiveRecord::Type.register(:money, MoneyType)
171
175
  #
176
+ # # app/models/product.rb
172
177
  # class Product < ActiveRecord::Base
173
178
  # currency_converter = ConversionRatesFromTheInternet.new
174
179
  # attribute :price_in_bitcoins, :money, currency_converter: currency_converter
@@ -53,9 +53,9 @@ module ActiveRecord
53
53
  # end
54
54
  #
55
55
  # class Firm < ActiveRecord::Base
56
- # # Destroys the associated clients and people when the firm is destroyed
57
- # before_destroy { |record| Person.destroy_all "firm_id = #{record.id}" }
58
- # before_destroy { |record| Client.destroy_all "client_of = #{record.id}" }
56
+ # # Disables access to the system, for associated clients and people when the firm is destroyed
57
+ # before_destroy { |record| Person.where(firm_id: record.id).update_all(access: 'disabled') }
58
+ # before_destroy { |record| Client.where(client_of: record.id).update_all(access: 'disabled') }
59
59
  # end
60
60
  #
61
61
  # == Inheritable callback queues
@@ -778,8 +778,7 @@ module ActiveRecord
778
778
  end
779
779
 
780
780
  # ConnectionHandler is a collection of ConnectionPool objects. It is used
781
- # for keeping separate connection pools for Active Record models that connect
782
- # to different databases.
781
+ # for keeping separate connection pools that connect to different databases.
783
782
  #
784
783
  # For example, suppose that you have 5 models, with the following hierarchy:
785
784
  #
@@ -821,6 +820,10 @@ module ActiveRecord
821
820
  # ConnectionHandler accessible via ActiveRecord::Base.connection_handler.
822
821
  # All Active Record models use this handler to determine the connection pool that they
823
822
  # should use.
823
+ #
824
+ # The ConnectionHandler class is not coupled with the Active models, as it has no knowlodge
825
+ # about the model. The model, needs to pass a specification name to the handler,
826
+ # in order to lookup the correct connection pool.
824
827
  class ConnectionHandler
825
828
  def initialize
826
829
  # These caches are keyed by klass.name, NOT klass. Keying them by klass
@@ -829,9 +832,6 @@ module ActiveRecord
829
832
  @owner_to_pool = Concurrent::Map.new(:initial_capacity => 2) do |h,k|
830
833
  h[k] = Concurrent::Map.new(:initial_capacity => 2)
831
834
  end
832
- @class_to_pool = Concurrent::Map.new(:initial_capacity => 2) do |h,k|
833
- h[k] = Concurrent::Map.new
834
- end
835
835
  end
836
836
 
837
837
  def connection_pool_list
@@ -839,10 +839,8 @@ module ActiveRecord
839
839
  end
840
840
  alias :connection_pools :connection_pool_list
841
841
 
842
- def establish_connection(owner, spec)
843
- @class_to_pool.clear
844
- raise RuntimeError, "Anonymous class is not allowed." unless owner.name
845
- owner_to_pool[owner.name] = ConnectionAdapters::ConnectionPool.new(spec)
842
+ def establish_connection(spec)
843
+ owner_to_pool[spec.name] = ConnectionAdapters::ConnectionPool.new(spec)
846
844
  end
847
845
 
848
846
  # Returns true if there are any active connections among the connection
@@ -873,18 +871,18 @@ module ActiveRecord
873
871
  # active or defined connection: if it is the latter, it will be
874
872
  # opened and set as the active connection for the class it was defined
875
873
  # for (not necessarily the current class).
876
- def retrieve_connection(klass) #:nodoc:
877
- pool = retrieve_connection_pool(klass)
878
- raise ConnectionNotEstablished, "No connection pool for #{klass}" unless pool
874
+ def retrieve_connection(spec_name) #:nodoc:
875
+ pool = retrieve_connection_pool(spec_name)
876
+ raise ConnectionNotEstablished, "No connection pool with id #{spec_name} found." unless pool
879
877
  conn = pool.connection
880
- raise ConnectionNotEstablished, "No connection for #{klass} in connection pool" unless conn
878
+ raise ConnectionNotEstablished, "No connection for #{spec_name} in connection pool" unless conn
881
879
  conn
882
880
  end
883
881
 
884
882
  # Returns true if a connection that's accessible to this class has
885
883
  # already been opened.
886
- def connected?(klass)
887
- conn = retrieve_connection_pool(klass)
884
+ def connected?(spec_name)
885
+ conn = retrieve_connection_pool(spec_name)
888
886
  conn && conn.connected?
889
887
  end
890
888
 
@@ -892,9 +890,8 @@ module ActiveRecord
892
890
  # connection and the defined connection (if they exist). The result
893
891
  # can be used as an argument for establish_connection, for easily
894
892
  # re-establishing the connection.
895
- def remove_connection(owner)
896
- if pool = owner_to_pool.delete(owner.name)
897
- @class_to_pool.clear
893
+ def remove_connection(spec_name)
894
+ if pool = owner_to_pool.delete(spec_name)
898
895
  pool.automatic_reconnect = false
899
896
  pool.disconnect!
900
897
  pool.spec.config
@@ -910,14 +907,18 @@ module ActiveRecord
910
907
  # #fetch is significantly slower than #[]. So in the nil case, no caching will
911
908
  # take place, but that's ok since the nil case is not the common one that we wish
912
909
  # to optimise for.
913
- def retrieve_connection_pool(klass)
914
- class_to_pool[klass.name] ||= begin
915
- until pool = pool_for(klass)
916
- klass = klass.superclass
917
- break unless klass <= Base
910
+ def retrieve_connection_pool(spec_name)
911
+ owner_to_pool.fetch(spec_name) do
912
+ if ancestor_pool = pool_from_any_process_for(spec_name)
913
+ # A connection was established in an ancestor process that must have
914
+ # subsequently forked. We can't reuse the connection, but we can copy
915
+ # the specification and establish a new connection with it.
916
+ establish_connection(ancestor_pool.spec).tap do |pool|
917
+ pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
918
+ end
919
+ else
920
+ owner_to_pool[spec_name] = nil
918
921
  end
919
-
920
- class_to_pool[klass.name] = pool
921
922
  end
922
923
  end
923
924
 
@@ -927,28 +928,9 @@ module ActiveRecord
927
928
  @owner_to_pool[Process.pid]
928
929
  end
929
930
 
930
- def class_to_pool
931
- @class_to_pool[Process.pid]
932
- end
933
-
934
- def pool_for(owner)
935
- owner_to_pool.fetch(owner.name) {
936
- if ancestor_pool = pool_from_any_process_for(owner)
937
- # A connection was established in an ancestor process that must have
938
- # subsequently forked. We can't reuse the connection, but we can copy
939
- # the specification and establish a new connection with it.
940
- establish_connection(owner, ancestor_pool.spec).tap do |pool|
941
- pool.schema_cache = ancestor_pool.schema_cache if ancestor_pool.schema_cache
942
- end
943
- else
944
- owner_to_pool[owner.name] = nil
945
- end
946
- }
947
- end
948
-
949
- def pool_from_any_process_for(owner)
950
- owner_to_pool = @owner_to_pool.values.find { |v| v[owner.name] }
951
- owner_to_pool && owner_to_pool[owner.name]
931
+ def pool_from_any_process_for(spec_name)
932
+ owner_to_pool = @owner_to_pool.values.find { |v| v[spec_name] }
933
+ owner_to_pool && owner_to_pool[spec_name]
952
934
  end
953
935
  end
954
936
  end
@@ -454,6 +454,24 @@ module ActiveRecord
454
454
  visitor.accept(node, collector).value
455
455
  end
456
456
 
457
+ def combine_bind_parameters(
458
+ from_clause: [],
459
+ join_clause: [],
460
+ where_clause: [],
461
+ having_clause: [],
462
+ limit: nil,
463
+ offset: nil
464
+ ) # :nodoc:
465
+ result = from_clause + join_clause + where_clause + having_clause
466
+ if limit
467
+ result << limit
468
+ end
469
+ if offset
470
+ result << offset
471
+ end
472
+ result
473
+ end
474
+
457
475
  protected
458
476
 
459
477
  def initialize_type_map(m) # :nodoc:
@@ -20,7 +20,7 @@ module ActiveRecord
20
20
  MySQL::Table.new(table_name, base)
21
21
  end
22
22
 
23
- def schema_creation
23
+ def schema_creation # :nodoc:
24
24
  MySQL::SchemaCreation.new(self)
25
25
  end
26
26
 
@@ -502,8 +502,12 @@ module ActiveRecord
502
502
  def add_index(table_name, column_name, options = {}) #:nodoc:
503
503
  index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options)
504
504
  sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}"
505
+ execute add_sql_comment!(sql, comment)
506
+ end
507
+
508
+ def add_sql_comment!(sql, comment) # :nodoc:
505
509
  sql << " COMMENT #{quote(comment)}" if comment
506
- execute sql
510
+ sql
507
511
  end
508
512
 
509
513
  def foreign_keys(table_name)
@@ -3,10 +3,10 @@ require 'uri'
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  class ConnectionSpecification #:nodoc:
6
- attr_reader :config, :adapter_method
6
+ attr_reader :name, :config, :adapter_method
7
7
 
8
- def initialize(config, adapter_method)
9
- @config, @adapter_method = config, adapter_method
8
+ def initialize(name, config, adapter_method)
9
+ @name, @config, @adapter_method = name, config, adapter_method
10
10
  end
11
11
 
12
12
  def initialize_dup(original)
@@ -164,7 +164,7 @@ module ActiveRecord
164
164
  # spec.config
165
165
  # # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" }
166
166
  #
167
- def spec(config)
167
+ def spec(config, name = nil)
168
168
  spec = resolve(config).symbolize_keys
169
169
 
170
170
  raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
@@ -179,7 +179,14 @@ module ActiveRecord
179
179
  end
180
180
 
181
181
  adapter_method = "#{spec[:adapter]}_connection"
182
- ConnectionSpecification.new(spec, adapter_method)
182
+
183
+ name ||=
184
+ if config.is_a?(Symbol)
185
+ config.to_s
186
+ else
187
+ "primary"
188
+ end
189
+ ConnectionSpecification.new(name, spec, adapter_method)
183
190
  end
184
191
 
185
192
  private
@@ -2,8 +2,8 @@ module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module MySQL
4
4
  class SchemaCreation < AbstractAdapter::SchemaCreation
5
- delegate :quote, to: :@conn
6
- private :quote
5
+ delegate :add_sql_comment!, to: :@conn
6
+ private :add_sql_comment!
7
7
 
8
8
  private
9
9
 
@@ -26,11 +26,7 @@ module ActiveRecord
26
26
  end
27
27
 
28
28
  def add_table_options!(create_sql, options)
29
- super
30
-
31
- if comment = options[:comment]
32
- create_sql << " COMMENT #{quote(comment)}"
33
- end
29
+ add_sql_comment!(super, options[:comment])
34
30
  end
35
31
 
36
32
  def column_options(o)
@@ -48,13 +44,7 @@ module ActiveRecord
48
44
  sql << " COLLATE #{collation}"
49
45
  end
50
46
 
51
- super
52
-
53
- if comment = options[:comment]
54
- sql << " COMMENT #{quote(comment)}"
55
- end
56
-
57
- sql
47
+ add_sql_comment!(super, options[:comment])
58
48
  end
59
49
 
60
50
  def add_column_position!(sql, options)
@@ -69,8 +59,7 @@ module ActiveRecord
69
59
 
70
60
  def index_in_create(table_name, column_name, options)
71
61
  index_name, index_type, index_columns, _, _, index_using, comment = @conn.add_index_options(table_name, column_name, options)
72
- index_option = " COMMENT #{quote(comment)}" if comment
73
- "#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})#{index_option} "
62
+ add_sql_comment!("#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})", comment)
74
63
  end
75
64
  end
76
65
  end
@@ -217,7 +217,7 @@ module ActiveRecord
217
217
  ]
218
218
  end
219
219
 
220
- IndexDefinition.new(table_name, index_name, unique, columns, [], orders, where, nil, using.to_sym, comment)
220
+ IndexDefinition.new(table_name, index_name, unique, columns, [], orders, where, nil, using.to_sym, comment.presence)
221
221
  end.compact
222
222
  end
223
223
 
@@ -168,10 +168,6 @@ module ActiveRecord
168
168
  true
169
169
  end
170
170
 
171
- def supports_comments_in_create?
172
- false
173
- end
174
-
175
171
  def supports_savepoints?
176
172
  true
177
173
  end
@@ -541,7 +541,7 @@ module ActiveRecord
541
541
  result = exec_query(sql, 'SCHEMA').first
542
542
 
543
543
  if result
544
- # Splitting with left parantheses and picking up last will return all
544
+ # Splitting with left parentheses and picking up last will return all
545
545
  # columns separated with comma(,).
546
546
  columns_string = result["sql"].split('(').last
547
547
 
@@ -45,16 +45,20 @@ module ActiveRecord
45
45
  # The exceptions AdapterNotSpecified, AdapterNotFound and +ArgumentError+
46
46
  # may be returned on an error.
47
47
  def establish_connection(spec = nil)
48
+ raise RuntimeError, "Anonymous class is not allowed." unless name
49
+
48
50
  spec ||= DEFAULT_ENV.call.to_sym
49
51
  resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new configurations
50
- spec = resolver.spec(spec)
52
+ # TODO: uses name on establish_connection, for backwards compatibility
53
+ spec = resolver.spec(spec, self == Base ? "primary" : name)
54
+ self.connection_specification_name = spec.name
51
55
 
52
56
  unless respond_to?(spec.adapter_method)
53
57
  raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
54
58
  end
55
59
 
56
60
  remove_connection
57
- connection_handler.establish_connection self, spec
61
+ connection_handler.establish_connection spec
58
62
  end
59
63
 
60
64
  class MergeAndResolveDefaultUrlConfig # :nodoc:
@@ -87,6 +91,17 @@ module ActiveRecord
87
91
  retrieve_connection
88
92
  end
89
93
 
94
+ attr_writer :connection_specification_name
95
+
96
+ # Return the specification id from this class otherwise look it up
97
+ # in the parent.
98
+ def connection_specification_name
99
+ unless defined?(@connection_specification_name)
100
+ @connection_specification_name = self == Base ? "primary" : superclass.connection_specification_name
101
+ end
102
+ @connection_specification_name
103
+ end
104
+
90
105
  def connection_id
91
106
  ActiveRecord::RuntimeRegistry.connection_id ||= Thread.current.object_id
92
107
  end
@@ -106,20 +121,20 @@ module ActiveRecord
106
121
  end
107
122
 
108
123
  def connection_pool
109
- connection_handler.retrieve_connection_pool(self) or raise ConnectionNotEstablished
124
+ connection_handler.retrieve_connection_pool(connection_specification_name) or raise ConnectionNotEstablished
110
125
  end
111
126
 
112
127
  def retrieve_connection
113
- connection_handler.retrieve_connection(self)
128
+ connection_handler.retrieve_connection(connection_specification_name)
114
129
  end
115
130
 
116
131
  # Returns +true+ if Active Record is connected.
117
132
  def connected?
118
- connection_handler.connected?(self)
133
+ connection_handler.connected?(connection_specification_name)
119
134
  end
120
135
 
121
- def remove_connection(klass = self)
122
- connection_handler.remove_connection(klass)
136
+ def remove_connection(name = connection_specification_name)
137
+ connection_handler.remove_connection(name)
123
138
  end
124
139
 
125
140
  def clear_cache! # :nodoc:
@@ -257,7 +257,7 @@ module ActiveRecord
257
257
  # Returns the Arel engine.
258
258
  def arel_engine # :nodoc:
259
259
  @arel_engine ||=
260
- if Base == self || connection_handler.retrieve_connection_pool(self)
260
+ if Base == self || connection_handler.retrieve_connection_pool(connection_specification_name)
261
261
  self
262
262
  else
263
263
  superclass.arel_engine
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
10
  TINY = 0
11
- PRE = "beta4"
11
+ PRE = "racecar1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -150,7 +150,7 @@ module ActiveRecord
150
150
 
151
151
  # The version column used for optimistic locking. Defaults to +lock_version+.
152
152
  def locking_column
153
- reset_locking_column unless defined?(@locking_column)
153
+ @locking_column = DEFAULT_LOCKING_COLUMN unless defined?(@locking_column)
154
154
  @locking_column
155
155
  end
156
156
 
@@ -277,7 +277,7 @@ module ActiveRecord
277
277
  # * <tt>change_column(table_name, column_name, type, options)</tt>: Changes
278
278
  # the column to a different type using the same parameters as add_column.
279
279
  # * <tt>change_column_default(table_name, column_name, default)</tt>: Sets a
280
- # default value for +column_name+ definded by +default+ on +table_name+.
280
+ # default value for +column_name+ defined by +default+ on +table_name+.
281
281
  # * <tt>change_column_null(table_name, column_name, null, default = nil)</tt>:
282
282
  # Sets or removes a +NOT NULL+ constraint on +column_name+. The +null+ flag
283
283
  # indicates whether the value can be +NULL+. See
@@ -524,17 +524,11 @@ module ActiveRecord
524
524
  end
525
525
 
526
526
  def self.[](version)
527
- version = version.to_s
528
- name = "V#{version.tr('.', '_')}"
529
- unless Compatibility.const_defined?(name)
530
- versions = Compatibility.constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect }
531
- raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
532
- end
533
- Compatibility.const_get(name)
527
+ Compatibility.find(version)
534
528
  end
535
529
 
536
530
  def self.current_version
537
- Rails.version.to_f
531
+ ActiveRecord::VERSION::STRING.to_f
538
532
  end
539
533
 
540
534
  MigrationFilenameRegexp = /\A([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/ # :nodoc:
@@ -1,6 +1,16 @@
1
1
  module ActiveRecord
2
2
  class Migration
3
3
  module Compatibility # :nodoc: all
4
+ def self.find(version)
5
+ version = version.to_s
6
+ name = "V#{version.tr('.', '_')}"
7
+ unless const_defined?(name)
8
+ versions = constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect }
9
+ raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
10
+ end
11
+ const_get(name)
12
+ end
13
+
4
14
  V5_0 = Current
5
15
 
6
16
  module FourTwoShared
@@ -238,7 +238,7 @@ module ActiveRecord
238
238
  end
239
239
 
240
240
  # Returns the next value that will be used as the primary key on
241
- # an insert statment.
241
+ # an insert statement.
242
242
  def next_sequence_value
243
243
  connection.next_sequence_value(sequence_name)
244
244
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module Querying
3
- delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, :empty?, :none?, :one?, to: :all
3
+ delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, :none?, :one?, to: :all
4
4
  delegate :second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!, :forty_two, :forty_two!, :third_to_last, :third_to_last!, :second_to_last, :second_to_last!, to: :all
5
5
  delegate :first_or_create, :first_or_create!, :first_or_initialize, to: :all
6
6
  delegate :find_or_create_by, :find_or_create_by!, :find_or_initialize_by, to: :all
@@ -42,7 +42,7 @@ module ActiveRecord
42
42
  # Delegates #delete_all, #update_all, #destroy_all methods to each batch.
43
43
  #
44
44
  # People.in_batches.delete_all
45
- # People.in_batches.destroy_all('age < 10')
45
+ # People.where('age < 10').in_batches.destroy_all
46
46
  # People.in_batches.update_all('age = age + 1')
47
47
  [:delete_all, :update_all, :destroy_all].each do |method|
48
48
  define_method(method) do |*args, &block|
@@ -35,7 +35,7 @@ module ActiveRecord
35
35
  # may vary depending on the klass of a relation, so we create a subclass of Relation
36
36
  # for each different klass, and the delegations are compiled into that subclass only.
37
37
 
38
- delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join,
38
+ delegate :to_xml, :encode_with, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join,
39
39
  :[], :&, :|, :+, :-, :sample, :reverse, :compact, :in_groups, :in_groups_of,
40
40
  :shuffle, :split, to: :records
41
41
 
@@ -99,22 +99,28 @@ module ActiveRecord
99
99
  end
100
100
 
101
101
  def bound_attributes
102
- result = from_clause.binds + arel.bind_values + where_clause.binds + having_clause.binds
103
102
  if limit_value && !string_containing_comma?(limit_value)
104
- result << Attribute.with_cast_value(
103
+ limit_bind = Attribute.with_cast_value(
105
104
  "LIMIT".freeze,
106
105
  connection.sanitize_limit(limit_value),
107
106
  Type::Value.new,
108
107
  )
109
108
  end
110
109
  if offset_value
111
- result << Attribute.with_cast_value(
110
+ offset_bind = Attribute.with_cast_value(
112
111
  "OFFSET".freeze,
113
112
  offset_value.to_i,
114
113
  Type::Value.new,
115
114
  )
116
115
  end
117
- result
116
+ connection.combine_bind_parameters(
117
+ from_clause: from_clause.binds,
118
+ join_clause: arel.bind_values,
119
+ where_clause: where_clause.binds,
120
+ having_clause: having_clause.binds,
121
+ limit: limit_bind,
122
+ offset: offset_bind,
123
+ )
118
124
  end
119
125
 
120
126
  FROZEN_EMPTY_HASH = {}.freeze
@@ -117,10 +117,10 @@ module ActiveRecord
117
117
  end
118
118
 
119
119
  def create_all
120
- old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base)
120
+ old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base.connection_specification_name)
121
121
  each_local_configuration { |configuration| create configuration }
122
122
  if old_pool
123
- ActiveRecord::Base.connection_handler.establish_connection(ActiveRecord::Base, old_pool.spec)
123
+ ActiveRecord::Base.connection_handler.establish_connection(old_pool.spec)
124
124
  end
125
125
  end
126
126
 
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: 5.0.0.beta4
4
+ version: 5.0.0.racecar1
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: 2016-04-27 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0.beta4
19
+ version: 5.0.0.racecar1
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: 5.0.0.beta4
26
+ version: 5.0.0.racecar1
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: 5.0.0.beta4
33
+ version: 5.0.0.racecar1
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: 5.0.0.beta4
40
+ version: 5.0.0.racecar1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -328,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
328
  version: 1.3.1
329
329
  requirements: []
330
330
  rubyforge_project:
331
- rubygems_version: 2.6.4
331
+ rubygems_version: 2.5.1
332
332
  signing_key:
333
333
  specification_version: 4
334
334
  summary: Object-relational mapper framework (part of Rails).