activerecord 4.2.0.rc2 → 4.2.0.rc3

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: 28b61291529e1647dc68f482c67cb982f1412b58
4
- data.tar.gz: 5d284927108612f0bba531978c77f77ecb2ab173
3
+ metadata.gz: 4eebcaeb54fa1c3d319396f193586f7e8f27a937
4
+ data.tar.gz: a6385ce2b23243350456c81b6ab7c399efa239cf
5
5
  SHA512:
6
- metadata.gz: 53fae71b52ab612485bba69f354387d78b0a79cd5358488c3322f6e6efe38812b3467f903ba2b71c87774d7922a40935b8cd7a457423ec827cf288669a752fa7
7
- data.tar.gz: bb77f7468870ad4497ddc1f42cf0a85ef38036a60297a80af4c506899fb28aa124cb87cc679b70d1bfd73d23e87791f1c03729a7bbc0b2e011707d4ba22db6cb
6
+ metadata.gz: 90b3fbfb30d4c7854112da41d68e4f09dddff20eeb85b0c464d34916d5b0532645c7ad359a02527c88f7f29b1eec04f4241af642f58db836f56a3943099226a2
7
+ data.tar.gz: 3fca47c68e6dba5ce6fc8addcf8eff8a678f16be26f51ea9ae8dbfdc7009ab54b0a82e69480c506b9d2e422f7ae3bca41d6620842b20f0f7d2a120526be93f2c
@@ -1,3 +1,13 @@
1
+ * Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
2
+
3
+ *Ryuta Kamizono*
4
+
5
+ * Add `foreign_type` option to `has_one` and `has_many` association macros.
6
+
7
+ This option enables to define the column name of associated object's type for polymorphic associations.
8
+
9
+ *Ulisses Almeida, Kassio Borges*
10
+
1
11
  * `add_timestamps` and `remove_timestamps` now properly reversible with
2
12
  options.
3
13
 
@@ -1176,6 +1176,12 @@ module ActiveRecord
1176
1176
  # Specify the foreign key used for the association. By default this is guessed to be the name
1177
1177
  # of this class in lower-case and "_id" suffixed. So a Person class that makes a +has_many+
1178
1178
  # association will use "person_id" as the default <tt>:foreign_key</tt>.
1179
+ # [:foreign_type]
1180
+ # Specify the column used to store the associated object's type, if this is a polymorphic
1181
+ # association. By default this is guessed to be the name of the polymorphic association
1182
+ # specified on "as" option with a "_type" suffix. So a class that defines a
1183
+ # <tt>has_many :tags, as: :taggable</tt> association will use "taggable_type" as the
1184
+ # default <tt>:foreign_type</tt>.
1179
1185
  # [:primary_key]
1180
1186
  # Specify the name of the column to use as the primary key for the association. By default this is +id+.
1181
1187
  # [:dependent]
@@ -1323,6 +1329,12 @@ module ActiveRecord
1323
1329
  # Specify the foreign key used for the association. By default this is guessed to be the name
1324
1330
  # of this class in lower-case and "_id" suffixed. So a Person class that makes a +has_one+ association
1325
1331
  # will use "person_id" as the default <tt>:foreign_key</tt>.
1332
+ # [:foreign_type]
1333
+ # Specify the column used to store the associated object's type, if this is a polymorphic
1334
+ # association. By default this is guessed to be the name of the polymorphic association
1335
+ # specified on "as" option with a "_type" suffix. So a class that defines a
1336
+ # <tt>has_one :tag, as: :taggable</tt> association will use "taggable_type" as the
1337
+ # default <tt>:foreign_type</tt>.
1326
1338
  # [:primary_key]
1327
1339
  # Specify the method that returns the primary key used for the association. By default this is +id+.
1328
1340
  # [:as]
@@ -5,7 +5,7 @@ module ActiveRecord::Associations::Builder
5
5
  end
6
6
 
7
7
  def valid_options
8
- super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table]
8
+ super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type]
9
9
  end
10
10
 
11
11
  def self.valid_dependent_options
@@ -5,7 +5,7 @@ module ActiveRecord::Associations::Builder
5
5
  end
6
6
 
7
7
  def valid_options
8
- valid = super + [:as]
8
+ valid = super + [:as, :foreign_type]
9
9
  valid += [:through, :source, :source_type] if options[:through]
10
10
  valid
11
11
  end
@@ -12,7 +12,7 @@ module ActiveRecord
12
12
  if value.is_a?(Array)
13
13
  value.map { |v| type_cast_from_user(v) }
14
14
  elsif value.respond_to?(:in_time_zone)
15
- value.in_time_zone
15
+ value.in_time_zone || super
16
16
  end
17
17
  end
18
18
 
@@ -76,7 +76,9 @@ module ActiveRecord
76
76
  unless @materialized
77
77
  values.each_key { |key| self[key] }
78
78
  types.each_key { |key| self[key] }
79
- @materialized = true
79
+ unless frozen?
80
+ @materialized = true
81
+ end
80
82
  end
81
83
  delegate_hash
82
84
  end
@@ -656,14 +656,15 @@ module ActiveRecord
656
656
  m.register_type %r(mediumblob)i, Type::Binary.new(limit: 2**24 - 1)
657
657
  m.register_type %r(longtext)i, Type::Text.new(limit: 2**32 - 1)
658
658
  m.register_type %r(longblob)i, Type::Binary.new(limit: 2**32 - 1)
659
- m.register_type %r(^bigint)i, Type::Integer.new(limit: 8)
660
- m.register_type %r(^int)i, Type::Integer.new(limit: 4)
661
- m.register_type %r(^mediumint)i, Type::Integer.new(limit: 3)
662
- m.register_type %r(^smallint)i, Type::Integer.new(limit: 2)
663
- m.register_type %r(^tinyint)i, Type::Integer.new(limit: 1)
664
659
  m.register_type %r(^float)i, Type::Float.new(limit: 24)
665
660
  m.register_type %r(^double)i, Type::Float.new(limit: 53)
666
661
 
662
+ register_integer_type m, %r(^bigint)i, limit: 8
663
+ register_integer_type m, %r(^int)i, limit: 4
664
+ register_integer_type m, %r(^mediumint)i, limit: 3
665
+ register_integer_type m, %r(^smallint)i, limit: 2
666
+ register_integer_type m, %r(^tinyint)i, limit: 1
667
+
667
668
  m.alias_type %r(tinyint\(1\))i, 'boolean' if emulate_booleans
668
669
  m.alias_type %r(set)i, 'varchar'
669
670
  m.alias_type %r(year)i, 'integer'
@@ -676,6 +677,16 @@ module ActiveRecord
676
677
  end
677
678
  end
678
679
 
680
+ def register_integer_type(mapping, key, options) # :nodoc:
681
+ mapping.register_type(key) do |sql_type|
682
+ if /unsigned/i =~ sql_type
683
+ Type::UnsignedInteger.new(options)
684
+ else
685
+ Type::Integer.new(options)
686
+ end
687
+ end
688
+ end
689
+
679
690
  # MySQL is too stupid to create a temporary table for use subquery, so we have
680
691
  # to give it some prompting in the form of a subsubquery. Ugh!
681
692
  def subquery_for(key, select)
@@ -34,6 +34,9 @@ module ActiveRecord
34
34
  end
35
35
 
36
36
  def type_cast_from_user(value)
37
+ if value.is_a?(::String)
38
+ value = parse_pg_array(value)
39
+ end
37
40
  type_cast_array(value, :type_cast_from_user)
38
41
  end
39
42
 
@@ -8,7 +8,7 @@ module ActiveRecord
8
8
  MAJOR = 4
9
9
  MINOR = 2
10
10
  TINY = 0
11
- PRE = "rc2"
11
+ PRE = "rc3"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -277,7 +277,7 @@ module ActiveRecord
277
277
  def initialize(name, scope, options, active_record)
278
278
  super
279
279
  @automatic_inverse_of = nil
280
- @type = options[:as] && "#{options[:as]}_type"
280
+ @type = options[:as] && (options[:foreign_type] || "#{options[:as]}_type")
281
281
  @foreign_type = options[:foreign_type] || "#{name}_type"
282
282
  @constructable = calculate_constructable(macro, options)
283
283
  @association_scope_cache = {}
@@ -177,7 +177,7 @@ module ActiveRecord
177
177
  relation.select_values = column_names.map { |cn|
178
178
  columns_hash.key?(cn) ? arel_table[cn] : cn
179
179
  }
180
- result = klass.connection.select_all(relation.arel, nil, bind_values)
180
+ result = klass.connection.select_all(relation.arel, nil, relation.arel.bind_values + bind_values)
181
181
  result.cast_values(klass.column_types)
182
182
  end
183
183
  end
@@ -317,7 +317,7 @@ module ActiveRecord
317
317
  relation.group_values = group
318
318
  relation.select_values = select_values
319
319
 
320
- calculated_data = @klass.connection.select_all(relation, nil, bind_values)
320
+ calculated_data = @klass.connection.select_all(relation, nil, relation.arel.bind_values + bind_values)
321
321
 
322
322
  if association
323
323
  key_ids = calculated_data.collect { |row| row[group_aliases.first] }
@@ -265,7 +265,7 @@ module ActiveRecord
265
265
 
266
266
  def assert_valid_transaction_action(actions)
267
267
  if (actions - ACTIONS).any?
268
- raise ArgumentError, ":on conditions for after_commit and after_rollback callbacks have to be one of #{ACTIONS.join(",")}"
268
+ raise ArgumentError, ":on conditions for after_commit and after_rollback callbacks have to be one of #{ACTIONS}"
269
269
  end
270
270
  end
271
271
  end
@@ -17,6 +17,7 @@ require 'active_record/type/serialized'
17
17
  require 'active_record/type/string'
18
18
  require 'active_record/type/text'
19
19
  require 'active_record/type/time'
20
+ require 'active_record/type/unsigned_integer'
20
21
 
21
22
  require 'active_record/type/type_map'
22
23
  require 'active_record/type/hash_lookup_type_map'
@@ -5,7 +5,7 @@ module ActiveRecord
5
5
 
6
6
  def initialize(*)
7
7
  super
8
- @range = -max_value...max_value
8
+ @range = min_value...max_value
9
9
  end
10
10
 
11
11
  def type
@@ -46,6 +46,10 @@ module ActiveRecord
46
46
  limit = self.limit || 4
47
47
  1 << (limit * 8 - 1) # 8 bits per byte with one bit for sign
48
48
  end
49
+
50
+ def min_value
51
+ -max_value
52
+ end
49
53
  end
50
54
  end
51
55
  end
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module Type
3
+ class UnsignedInteger < Integer # :nodoc:
4
+ private
5
+
6
+ def max_value
7
+ super * 2
8
+ end
9
+
10
+ def min_value
11
+ 0
12
+ end
13
+ end
14
+ end
15
+ 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.2.0.rc2
4
+ version: 4.2.0.rc3
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: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0.rc2
19
+ version: 4.2.0.rc3
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.2.0.rc2
26
+ version: 4.2.0.rc3
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.2.0.rc2
33
+ version: 4.2.0.rc3
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.2.0.rc2
40
+ version: 4.2.0.rc3
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
47
  version: '6.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
54
  version: '6.0'
55
55
  description: Databases on Rails. Build a persistent domain model by mapping database
@@ -265,6 +265,7 @@ files:
265
265
  - lib/active_record/type/time.rb
266
266
  - lib/active_record/type/time_value.rb
267
267
  - lib/active_record/type/type_map.rb
268
+ - lib/active_record/type/unsigned_integer.rb
268
269
  - lib/active_record/type/value.rb
269
270
  - lib/active_record/validations.rb
270
271
  - lib/active_record/validations/associated.rb
@@ -285,23 +286,23 @@ licenses:
285
286
  metadata: {}
286
287
  post_install_message:
287
288
  rdoc_options:
288
- - --main
289
+ - "--main"
289
290
  - README.rdoc
290
291
  require_paths:
291
292
  - lib
292
293
  required_ruby_version: !ruby/object:Gem::Requirement
293
294
  requirements:
294
- - - '>='
295
+ - - ">="
295
296
  - !ruby/object:Gem::Version
296
297
  version: 1.9.3
297
298
  required_rubygems_version: !ruby/object:Gem::Requirement
298
299
  requirements:
299
- - - '>'
300
+ - - ">"
300
301
  - !ruby/object:Gem::Version
301
302
  version: 1.3.1
302
303
  requirements: []
303
304
  rubyforge_project:
304
- rubygems_version: 2.2.1
305
+ rubygems_version: 2.2.2
305
306
  signing_key:
306
307
  specification_version: 4
307
308
  summary: Object-relational mapper framework (part of Rails).