activerecord 5.0.0.racecar1 → 5.0.0.rc2

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 173556138a2bd53f64098516ffd9d2959550cdbd
4
- data.tar.gz: 6ea16dbc226ccb4235309074a70ffa85580f7eef
3
+ metadata.gz: dc45d894d780ffebc6f29bcd1e8feb12fb26ad7c
4
+ data.tar.gz: 2ea5b1c2b180b590e26691ed7537ee25923e63d6
5
5
  SHA512:
6
- metadata.gz: 53e61d9bf07dc4e8a71ef43a8a5fe917d4a86c8acfd4880732ae5af279dc36f455e6f37134667e0373c66f35d309e75b1cf8e62441b48f7141dd40a65d916012
7
- data.tar.gz: 1707472ef5f7c1bb5e1cd966da87045a48a49e34a7bc2751db39609add4fd7c2cc6cd199e1e42597a4187804b91372273c6158d686d775a483b20a69055c2823
6
+ metadata.gz: ed32348fc0c4c9682cecaafcb536017483c0843aa2b16f46e7278114b3f002ca6c694e215c83afed0190fb7da1cda654e571668e65feb035689e056bf026a4fe
7
+ data.tar.gz: 867d75f157567877d823c751b7148cd26710dd2090c83b908111effac3bb777c1f24e1655535f0a4ce1d48ffdffbd5bc20be10ae6aa61d80780fa56df20a516b
@@ -1,3 +1,21 @@
1
+ ## Rails 5.0.0.rc2 (June 22, 2016) ##
2
+
3
+ * Ensure hashes can be assigned to attributes created using `composed_of`.
4
+ Fixes #25210.
5
+
6
+ *Sean Griffin*
7
+
8
+ * Fix logging edge case where if an attribute was of the binary type and
9
+ was provided as a Hash.
10
+
11
+ *Jon Moss*
12
+
13
+ * Handle JSON deserialization correctly if the column default from database
14
+ adapter returns `''` instead of `nil`.
15
+
16
+ *Johannes Opper*
17
+
18
+
1
19
  ## Rails 5.0.0.rc1 (May 06, 2016) ##
2
20
 
3
21
  * No changes.
@@ -679,11 +697,12 @@
679
697
 
680
698
  *Bigxiang*
681
699
 
682
- * Add option to index errors in nested attributes
700
+ * Add option to index errors in nested attributes.
683
701
 
684
702
  For models which have nested attributes, errors within those models will
685
- now be indexed if `:index_errors` is specified when defining a
686
- has_many relationship, or if its set in the global config.
703
+ now be indexed if `:index_errors` option is set to true when defining a
704
+ `has_many` relationship or by setting the configuration option
705
+ `config.active_record.index_nested_attribute_errors` to true.
687
706
 
688
707
  Example:
689
708
 
@@ -697,10 +716,10 @@
697
716
  validates_numericality_of :pitch
698
717
  end
699
718
 
700
- # Old style
719
+ # Before
701
720
  guitar.errors["tuning_pegs.pitch"] = ["is not a number"]
702
721
 
703
- # New style (if defined globally, or set in has_many_relationship)
722
+ # After
704
723
  guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]
705
724
 
706
725
  *Michael Probber*, *Terence Sun*
@@ -256,15 +256,16 @@ module ActiveRecord
256
256
  def writer_method(name, class_name, mapping, allow_nil, converter)
257
257
  define_method("#{name}=") do |part|
258
258
  klass = class_name.constantize
259
- if part.is_a?(Hash)
260
- raise ArgumentError unless part.size == part.keys.max
261
- part = klass.new(*part.sort.map(&:last))
262
- end
263
259
 
264
260
  unless part.is_a?(klass) || converter.nil? || part.nil?
265
261
  part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
266
262
  end
267
263
 
264
+ if part.is_a?(Hash)
265
+ raise ArgumentError unless part.size == part.keys.max
266
+ part = klass.new(*part.sort.map(&:last))
267
+ end
268
+
268
269
  if part.nil? && allow_nil
269
270
  mapping.each { |key, _| self[key] = nil }
270
271
  @aggregation_cache[name] = nil
@@ -280,7 +280,7 @@ module ActiveRecord
280
280
  _options = records.extract_options!
281
281
  dependent = _options[:dependent] || options[:dependent]
282
282
 
283
- records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
283
+ records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
284
284
  delete_or_destroy(records, dependent)
285
285
  end
286
286
 
@@ -291,7 +291,7 @@ module ActiveRecord
291
291
  # +:dependent+ option.
292
292
  def destroy(*records)
293
293
  return if records.empty?
294
- records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
294
+ records = find(records) if records.any? { |record| record.kind_of?(Integer) || record.kind_of?(String) }
295
295
  delete_or_destroy(records, :destroy)
296
296
  end
297
297
 
@@ -597,7 +597,7 @@ module ActiveRecord
597
597
  # Pet.find(1)
598
598
  # # => ActiveRecord::RecordNotFound: Couldn't find Pet with 'id'=1
599
599
  #
600
- # You can pass +Fixnum+ or +String+ values, it finds the records
600
+ # You can pass +Integer+ or +String+ values, it finds the records
601
601
  # responding to the +id+ and executes delete on them.
602
602
  #
603
603
  # class Person < ActiveRecord::Base
@@ -661,7 +661,7 @@ module ActiveRecord
661
661
  #
662
662
  # Pet.find(1, 2, 3) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with 'id': (1, 2, 3)
663
663
  #
664
- # You can pass +Fixnum+ or +String+ values, it finds the records
664
+ # You can pass +Integer+ or +String+ values, it finds the records
665
665
  # responding to the +id+ and then deletes them from the database.
666
666
  #
667
667
  # person.pets.size # => 3
@@ -170,7 +170,7 @@ module ActiveRecord
170
170
  super(name, nil, Type::Value.new)
171
171
  end
172
172
 
173
- def value
173
+ def type_cast(*)
174
174
  nil
175
175
  end
176
176
 
@@ -185,6 +185,8 @@ module ActiveRecord
185
185
  end
186
186
 
187
187
  class Uninitialized < Attribute # :nodoc:
188
+ UNINITIALIZED_ORIGINAL_VALUE = Object.new
189
+
188
190
  def initialize(name, type)
189
191
  super(name, nil, type)
190
192
  end
@@ -195,6 +197,10 @@ module ActiveRecord
195
197
  end
196
198
  end
197
199
 
200
+ def original_value
201
+ UNINITIALIZED_ORIGINAL_VALUE
202
+ end
203
+
198
204
  def value_for_database
199
205
  end
200
206
 
@@ -38,7 +38,7 @@ module ActiveRecord
38
38
  # by calling new on the column type or aggregation type (through composed_of) object with these parameters.
39
39
  # So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate
40
40
  # written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the
41
- # parentheses to have the parameters typecasted before they're used in the constructor. Use i for Fixnum and
41
+ # parentheses to have the parameters typecasted before they're used in the constructor. Use i for Integer and
42
42
  # f for Float. If all the values for a given attribute are empty, the attribute will be set to +nil+.
43
43
  def assign_multiparameter_attributes(pairs)
44
44
  execute_callstack_for_multiparameter_attributes(
@@ -360,7 +360,7 @@ module ActiveRecord
360
360
  # person = Person.new
361
361
  # person[:age] = '22'
362
362
  # person[:age] # => 22
363
- # person[:age] # => Fixnum
363
+ # person[:age].class # => Integer
364
364
  def []=(attr_name, value)
365
365
  write_attribute(attr_name, value)
366
366
  end
@@ -26,7 +26,7 @@ module ActiveRecord
26
26
  end
27
27
 
28
28
  # Updates the attribute identified by <tt>attr_name</tt> with the
29
- # specified +value+. Empty strings for fixnum and float columns are
29
+ # specified +value+. Empty strings for Integer and Float columns are
30
30
  # turned into +nil+.
31
31
  def write_attribute(attr_name, value)
32
32
  write_attribute_with_type_cast(attr_name, value, true)
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
  end
7
7
 
8
8
  def self.load(json)
9
- ActiveSupport::JSON.decode(json) unless json.nil?
9
+ ActiveSupport::JSON.decode(json) unless json.blank?
10
10
  end
11
11
  end
12
12
  end
@@ -826,9 +826,7 @@ module ActiveRecord
826
826
  # in order to lookup the correct connection pool.
827
827
  class ConnectionHandler
828
828
  def initialize
829
- # These caches are keyed by klass.name, NOT klass. Keying them by klass
830
- # alone would lead to memory leaks in development mode as all previous
831
- # instances of the class would stay in memory.
829
+ # These caches are keyed by spec.name (ConnectionSpecification#name).
832
830
  @owner_to_pool = Concurrent::Map.new(:initial_capacity => 2) do |h,k|
833
831
  h[k] = Concurrent::Map.new(:initial_capacity => 2)
834
832
  end
@@ -707,7 +707,7 @@ module ActiveRecord
707
707
  case length
708
708
  when Hash
709
709
  column_names.each {|name| option_strings[name] += "(#{length[name]})" if length.has_key?(name) && length[name].present?}
710
- when Fixnum
710
+ when Integer
711
711
  column_names.each {|name| option_strings[name] += "(#{length})"}
712
712
  end
713
713
  end
@@ -832,7 +832,7 @@ module ActiveRecord
832
832
 
833
833
  # Increase timeout so the server doesn't disconnect us.
834
834
  wait_timeout = @config[:wait_timeout]
835
- wait_timeout = 2147483 unless wait_timeout.is_a?(Fixnum)
835
+ wait_timeout = 2147483 unless wait_timeout.is_a?(Integer)
836
836
  variables['wait_timeout'] = self.class.type_cast_config_to_integer(wait_timeout)
837
837
 
838
838
  defaults = [':default', :default].to_set
@@ -641,7 +641,7 @@ module ActiveRecord
641
641
  when 1, 2; 'smallint'
642
642
  when nil, 3, 4; 'integer'
643
643
  when 5..8; 'bigint'
644
- else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
644
+ else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with scale 0 instead.")
645
645
  end
646
646
  else
647
647
  super(type, limit, precision, scale)
@@ -51,13 +51,13 @@ module ActiveRecord
51
51
  resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new configurations
52
52
  # TODO: uses name on establish_connection, for backwards compatibility
53
53
  spec = resolver.spec(spec, self == Base ? "primary" : name)
54
- self.connection_specification_name = spec.name
55
54
 
56
55
  unless respond_to?(spec.adapter_method)
57
56
  raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
58
57
  end
59
58
 
60
- remove_connection
59
+ remove_connection(spec.name)
60
+ self.connection_specification_name = spec.name
61
61
  connection_handler.establish_connection spec
62
62
  end
63
63
 
@@ -96,8 +96,8 @@ module ActiveRecord
96
96
  # Return the specification id from this class otherwise look it up
97
97
  # in the parent.
98
98
  def connection_specification_name
99
- unless defined?(@connection_specification_name)
100
- @connection_specification_name = self == Base ? "primary" : superclass.connection_specification_name
99
+ if !defined?(@connection_specification_name) || @connection_specification_name.nil?
100
+ return self == Base ? "primary" : superclass.connection_specification_name
101
101
  end
102
102
  @connection_specification_name
103
103
  end
@@ -133,7 +133,15 @@ module ActiveRecord
133
133
  connection_handler.connected?(connection_specification_name)
134
134
  end
135
135
 
136
- def remove_connection(name = connection_specification_name)
136
+ def remove_connection(name = nil)
137
+ name ||= @connection_specification_name if defined?(@connection_specification_name)
138
+ # if removing a connection that have a pool, we reset the
139
+ # connection_specification_name so it will use the parent
140
+ # pool.
141
+ if connection_handler.retrieve_connection_pool(name)
142
+ self.connection_specification_name = nil
143
+ end
144
+
137
145
  connection_handler.remove_connection(name)
138
146
  end
139
147
 
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
10
  TINY = 0
11
- PRE = "racecar1"
11
+ PRE = "rc2"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -19,7 +19,7 @@ module ActiveRecord
19
19
  end
20
20
 
21
21
  def []=(key, value)
22
- first_or_initialize(key: key).update_attributes!(value: value)
22
+ find_or_initialize_by(key: key).update_attributes!(value: value)
23
23
  end
24
24
 
25
25
  def [](key)
@@ -22,7 +22,11 @@ module ActiveRecord
22
22
 
23
23
  def render_bind(attribute)
24
24
  value = if attribute.type.binary? && attribute.value
25
- "<#{attribute.value.bytesize} bytes of binary data>"
25
+ if attribute.value.is_a?(Hash)
26
+ "<#{attribute.value_for_database.to_s.bytesize} bytes of binary data>"
27
+ else
28
+ "<#{attribute.value.bytesize} bytes of binary data>"
29
+ end
26
30
  else
27
31
  attribute.value_for_database
28
32
  end
@@ -166,13 +166,13 @@ module ActiveRecord
166
166
  class EnvironmentMismatchError < ActiveRecordError
167
167
  def initialize(current: nil, stored: nil)
168
168
  msg = "You are attempting to modify a database that was last run in `#{ stored }` environment.\n"
169
- msg << "You are running in `#{ current }` environment."
169
+ msg << "You are running in `#{ current }` environment. "
170
170
  msg << "If you are sure you want to continue, first set the environment using:\n\n"
171
171
  msg << "\tbin/rails db:environment:set"
172
172
  if defined?(Rails.env)
173
- super("#{msg} RAILS_ENV=#{::Rails.env}")
173
+ super("#{msg} RAILS_ENV=#{::Rails.env}\n\n")
174
174
  else
175
- super(msg)
175
+ super("#{msg}\n\n")
176
176
  end
177
177
  end
178
178
  end
@@ -5,7 +5,7 @@ module ActiveRecord
5
5
  # Enable the query cache within the block if Active Record is configured.
6
6
  # If it's not, it will execute the given block.
7
7
  def cache(&block)
8
- if ActiveRecord::Base.connected?
8
+ if connected?
9
9
  connection.cache(&block)
10
10
  else
11
11
  yield
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  # Disable the query cache within the block if Active Record is configured.
16
16
  # If it's not, it will execute the given block.
17
17
  def uncached(&block)
18
- if ActiveRecord::Base.connected?
18
+ if connected?
19
19
  connection.uncached(&block)
20
20
  else
21
21
  yield
@@ -89,7 +89,7 @@ module ActiveRecord
89
89
  #
90
90
  # There are two basic forms of output:
91
91
  #
92
- # * Single aggregate value: The single value is type cast to Fixnum for COUNT, Float
92
+ # * Single aggregate value: The single value is type cast to Integer for COUNT, Float
93
93
  # for AVG, and the given column's type for everything else.
94
94
  #
95
95
  # * Grouped values: This returns an ordered hash of the values and groups them. It
@@ -50,10 +50,6 @@ module ActiveRecord
50
50
  def header(stream)
51
51
  define_params = @version ? "version: #{@version}" : ""
52
52
 
53
- if stream.respond_to?(:external_encoding) && stream.external_encoding
54
- stream.puts "# encoding: #{stream.external_encoding.name}"
55
- end
56
-
57
53
  stream.puts <<HEADER
58
54
  # This file is auto-generated from the current state of the database. Instead
59
55
  # of editing this file, please use the migrations feature of Active Record to
@@ -32,7 +32,7 @@ module ActiveRecord
32
32
 
33
33
  def changed_in_place?(raw_old_value, value)
34
34
  return false if value.nil?
35
- raw_new_value = serialize(value)
35
+ raw_new_value = encoded(value)
36
36
  raw_old_value.nil? != raw_new_value.nil? ||
37
37
  subtype.changed_in_place?(raw_old_value, raw_new_value)
38
38
  end
@@ -52,6 +52,12 @@ module ActiveRecord
52
52
  def default_value?(value)
53
53
  value == coder.load(nil)
54
54
  end
55
+
56
+ def encoded(value)
57
+ unless default_value?(value)
58
+ coder.dump(value)
59
+ end
60
+ end
55
61
  end
56
62
  end
57
63
  end
@@ -21,14 +21,14 @@ module ActiveRecord
21
21
  end
22
22
 
23
23
  def create_model_file
24
- template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
25
24
  generate_application_record
25
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
26
26
  end
27
27
 
28
28
  def create_module_file
29
29
  return if regular_class_path.empty?
30
- template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
31
30
  generate_application_record
31
+ template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
32
32
  end
33
33
 
34
34
  hook_for :test_framework
@@ -48,7 +48,7 @@ module ActiveRecord
48
48
 
49
49
  # Used by the migration template to determine the parent name of the model
50
50
  def parent_class_name
51
- options[:parent] || determine_default_parent_class
51
+ options[:parent] || 'ApplicationRecord'
52
52
  end
53
53
 
54
54
  def application_record_exist?
@@ -64,14 +64,6 @@ module ActiveRecord
64
64
  'app/models/application_record.rb'
65
65
  end
66
66
  end
67
-
68
- def determine_default_parent_class
69
- if application_record_exist?
70
- "ApplicationRecord"
71
- else
72
- "ActiveRecord::Base"
73
- end
74
- end
75
67
  end
76
68
  end
77
69
  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: 5.0.0.racecar1
4
+ version: 5.0.0.rc2
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-05-06 00:00:00.000000000 Z
11
+ date: 2016-06-22 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.racecar1
19
+ version: 5.0.0.rc2
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.racecar1
26
+ version: 5.0.0.rc2
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.racecar1
33
+ version: 5.0.0.rc2
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.racecar1
40
+ version: 5.0.0.rc2
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.5.1
331
+ rubygems_version: 2.6.4
332
332
  signing_key:
333
333
  specification_version: 4
334
334
  summary: Object-relational mapper framework (part of Rails).