activerecord 3.0.5 → 3.0.6.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.

data/CHANGELOG CHANGED
@@ -1,4 +1,21 @@
1
- *Rails 3.0.5 (unreleased)*
1
+ *Rails 3.0.6 (unreleased)*
2
+
3
+ * Un-deprecate reorder method [Sebastian Martinez]
4
+
5
+ * Extensions are applied when calling +except+ or +only+ on relations.
6
+ Thanks to Iain Hecker.
7
+
8
+ * Schemas set in set_table_name are respected by the mysql adapter. LH #5322
9
+
10
+ * Fixed a bug when empty? was called on a grouped Relation that wasn't loaded.
11
+ LH #5829
12
+
13
+ * Reapply extensions when using except and only. Thanks Iain Hecker.
14
+
15
+ * Binary data is escaped when being inserted to SQLite3 Databases. Thanks
16
+ Naruse!
17
+
18
+ *Rails 3.0.5 (February 26, 2011)*
2
19
 
3
20
  * Model.where(:column => 1).where(:column => 2) will always produce an AND
4
21
  query.
@@ -30,7 +47,7 @@ query.
30
47
 
31
48
  [Jon Leighton]
32
49
 
33
- *Rails 3.0.4*
50
+ *Rails 3.0.4 (February 8, 2011)*
34
51
 
35
52
  * Added deprecation warning for has_and_belongs_to_many associations where the join table has
36
53
  additional attributes other than the keys. Access to these attributes is removed in 3.1.
@@ -1411,16 +1411,7 @@ module ActiveRecord
1411
1411
  reflection = create_has_and_belongs_to_many_reflection(association_id, options, &extension)
1412
1412
  collection_accessor_methods(reflection, HasAndBelongsToManyAssociation)
1413
1413
 
1414
- # Don't use a before_destroy callback since users' before_destroy
1415
- # callbacks will be executed after the association is wiped out.
1416
- include Module.new {
1417
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
1418
- def destroy # def destroy
1419
- super # super
1420
- #{reflection.name}.clear # posts.clear
1421
- end # end
1422
- RUBY
1423
- }
1414
+ configure_after_destroy_method_for_has_and_belongs_to_many(reflection)
1424
1415
 
1425
1416
  add_association_callbacks(reflection.name, options)
1426
1417
  end
@@ -1714,6 +1705,17 @@ module ActiveRecord
1714
1705
  end
1715
1706
  end
1716
1707
 
1708
+ def configure_after_destroy_method_for_has_and_belongs_to_many(reflection)
1709
+ method_name = :"has_and_belongs_to_many_after_destroy_for_#{reflection.name}"
1710
+ class_eval <<-eoruby, __FILE__, __LINE__ + 1
1711
+ def #{method_name}
1712
+ association = #{reflection.name}
1713
+ association.delete_all if association
1714
+ end
1715
+ eoruby
1716
+ after_destroy method_name
1717
+ end
1718
+
1717
1719
  def delete_all_has_many_dependencies(record, reflection_name, association_class, dependent_conditions)
1718
1720
  association_class.delete_all(dependent_conditions)
1719
1721
  end
@@ -48,7 +48,7 @@ module ActiveRecord
48
48
  end
49
49
 
50
50
  def respond_to?(*args)
51
- self.class.define_attribute_methods
51
+ self.class.define_attribute_methods unless self.class.attribute_methods_generated?
52
52
  super
53
53
  end
54
54
 
@@ -66,13 +66,23 @@ module ActiveRecord
66
66
  if cache_attribute?(attr_name)
67
67
  access_code = "@attributes_cache['#{attr_name}'] ||= (#{access_code})"
68
68
  end
69
- generated_attribute_methods.module_eval("def #{symbol}; #{access_code}; end", __FILE__, __LINE__)
69
+ if symbol =~ /^[a-zA-Z_]\w*[!?=]?$/
70
+ generated_attribute_methods.module_eval("def _#{symbol}; #{access_code}; end; alias #{symbol} _#{symbol}", __FILE__, __LINE__)
71
+ else
72
+ generated_attribute_methods.send(:define_method, symbol) { eval(access_code) }
73
+ end
70
74
  end
71
75
  end
72
76
 
73
77
  # Returns the value of the attribute identified by <tt>attr_name</tt> after it has been typecast (for example,
74
78
  # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
75
79
  def read_attribute(attr_name)
80
+ send "_#{attr_name}"
81
+ rescue NoMethodError
82
+ _read_attribute attr_name
83
+ end
84
+
85
+ def _read_attribute(attr_name)
76
86
  attr_name = attr_name.to_s
77
87
  attr_name = self.class.primary_key if attr_name == 'id'
78
88
  value = @attributes[attr_name]
@@ -86,8 +96,6 @@ module ActiveRecord
86
96
  else
87
97
  value
88
98
  end
89
- else
90
- nil
91
99
  end
92
100
  end
93
101
 
@@ -19,12 +19,13 @@ module ActiveRecord
19
19
  def define_method_attribute(attr_name)
20
20
  if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
21
21
  method_body, line = <<-EOV, __LINE__ + 1
22
- def #{attr_name}(reload = false)
22
+ def _#{attr_name}(reload = false)
23
23
  cached = @attributes_cache['#{attr_name}']
24
24
  return cached if cached && !reload
25
- time = read_attribute('#{attr_name}')
25
+ time = _read_attribute('#{attr_name}')
26
26
  @attributes_cache['#{attr_name}'] = time.acts_like?(:time) ? time.in_time_zone : time
27
27
  end
28
+ alias #{attr_name} _#{attr_name}
28
29
  EOV
29
30
  generated_attribute_methods.module_eval(method_body, __FILE__, line)
30
31
  else
@@ -38,12 +39,13 @@ module ActiveRecord
38
39
  if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
39
40
  method_body, line = <<-EOV, __LINE__ + 1
40
41
  def #{attr_name}=(original_time)
41
- time = original_time.dup unless original_time.nil?
42
+ time = original_time
42
43
  unless time.acts_like?(:time)
43
44
  time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time
44
45
  end
45
46
  time = time.in_time_zone rescue nil if time
46
- write_attribute(:#{attr_name}, (time || original_time))
47
+ write_attribute(:#{attr_name}, original_time)
48
+ @attributes_cache["#{attr_name}"] = time
47
49
  end
48
50
  EOV
49
51
  generated_attribute_methods.module_eval(method_body, __FILE__, line)
@@ -10,7 +10,13 @@ module ActiveRecord
10
10
  module ClassMethods
11
11
  protected
12
12
  def define_method_attribute=(attr_name)
13
- generated_attribute_methods.module_eval("def #{attr_name}=(new_value); write_attribute('#{attr_name}', new_value); end", __FILE__, __LINE__)
13
+ if attr_name =~ /^[a-zA-Z_]\w*[!?=]?$/
14
+ generated_attribute_methods.module_eval("def #{attr_name}=(new_value); write_attribute('#{attr_name}', new_value); end", __FILE__, __LINE__)
15
+ else
16
+ generated_attribute_methods.send(:define_method, "#{attr_name}=") do |new_value|
17
+ write_attribute(attr_name, new_value)
18
+ end
19
+ end
14
20
  end
15
21
  end
16
22
 
@@ -959,7 +959,7 @@ module ActiveRecord #:nodoc:
959
959
  if parent < ActiveRecord::Base && !parent.abstract_class?
960
960
  contained = parent.table_name
961
961
  contained = contained.singularize if parent.pluralize_table_names
962
- contained << '_'
962
+ contained += '_'
963
963
  end
964
964
  "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
965
965
  else
@@ -25,7 +25,11 @@ module ActiveRecord
25
25
  # Check out <tt>ActiveRecord::Transactions</tt> for more details about <tt>after_commit</tt> and
26
26
  # <tt>after_rollback</tt>.
27
27
  #
28
- # That's a total of ten callbacks, which gives you immense power to react and prepare for each state in the
28
+ # Lastly an <tt>after_find</tt> and <tt>after_initialize</tt> callback is triggered for each object that
29
+ # is found and instantiated by a finder, with <tt>after_initialize</tt> being triggered after new objects
30
+ # are instantiated as well.
31
+ #
32
+ # That's a total of twelve callbacks, which gives you immense power to react and prepare for each state in the
29
33
  # Active Record life cycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar,
30
34
  # except that each <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback.
31
35
  #
@@ -185,14 +189,6 @@ module ActiveRecord
185
189
  # 'puts "Evaluated after parents are destroyed"'
186
190
  # end
187
191
  #
188
- # == The +after_find+ and +after_initialize+ exceptions
189
- #
190
- # Because +after_find+ and +after_initialize+ are called for each object found and instantiated by a finder,
191
- # such as <tt>Base.find(:all)</tt>, we've had to implement a simple performance constraint (50% more speed
192
- # on a simple test case). Unlike all the other callbacks, +after_find+ and +after_initialize+ will only be
193
- # run if an explicit implementation is defined (<tt>def after_find</tt>). In that case, all of the
194
- # callback types will be called.
195
- #
196
192
  # == <tt>before_validation*</tt> returning statements
197
193
  #
198
194
  # If the returning value of a +before_validation+ callback can be evaluated to +false+, the process will be
@@ -402,14 +402,28 @@ module ActiveRecord
402
402
  show_variable 'collation_database'
403
403
  end
404
404
 
405
- def tables(name = nil) #:nodoc:
405
+ def tables(name = nil, database = nil) #:nodoc:
406
406
  tables = []
407
- result = execute("SHOW TABLES", name)
407
+ result = execute(["SHOW TABLES", database].compact.join(' IN '), name)
408
408
  result.each { |field| tables << field[0] }
409
409
  result.free
410
410
  tables
411
411
  end
412
412
 
413
+ def table_exists?(name)
414
+ return true if super
415
+
416
+ name = name.to_s
417
+ schema, table = name.split('.', 2)
418
+
419
+ unless table # A table was provided without a schema
420
+ table = schema
421
+ schema = nil
422
+ end
423
+
424
+ tables(nil, schema).include? table
425
+ end
426
+
413
427
  def drop_table(table_name, options = {})
414
428
  super(table_name, options)
415
429
  end
@@ -37,6 +37,14 @@ module ActiveRecord
37
37
 
38
38
  module ConnectionAdapters #:nodoc:
39
39
  class SQLite3Adapter < SQLiteAdapter # :nodoc:
40
+ def quote(value, column = nil)
41
+ if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
42
+ s = column.class.string_to_binary(value).unpack("H*")[0]
43
+ "x'#{s}'"
44
+ else
45
+ super
46
+ end
47
+ end
40
48
 
41
49
  # Returns the current database encoding format as a string, eg: 'UTF-8'
42
50
  def encoding
@@ -87,7 +87,10 @@ module ActiveRecord
87
87
 
88
88
  # Returns true if there are no records.
89
89
  def empty?
90
- loaded? ? @records.empty? : count.zero?
90
+ return @records.empty? if loaded?
91
+
92
+ c = count
93
+ c.respond_to?(:zero?) ? c.zero? : c.empty?
91
94
  end
92
95
 
93
96
  def any?
@@ -54,7 +54,6 @@ module ActiveRecord
54
54
  end
55
55
 
56
56
  def reorder(*args)
57
- ActiveSupport::Deprecation.warn "reorder is deprecated. Please use except(:order).order(...) instead", caller
58
57
  relation = clone
59
58
  unless args.blank?
60
59
  relation.order_values = args
@@ -83,6 +83,9 @@ module ActiveRecord
83
83
  result.send(:"#{method}_value=", send(:"#{method}_value"))
84
84
  end
85
85
 
86
+ # Apply scope extension modules
87
+ result.send(:apply_modules, extensions)
88
+
86
89
  result
87
90
  end
88
91
 
@@ -97,6 +100,9 @@ module ActiveRecord
97
100
  result.send(:"#{method}_value=", send(:"#{method}_value"))
98
101
  end
99
102
 
103
+ # Apply scope extension modules
104
+ result.send(:apply_modules, extensions)
105
+
100
106
  result
101
107
  end
102
108
 
@@ -2,8 +2,8 @@ module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 5
6
- PRE = nil
5
+ TINY = 6
6
+ PRE = "rc1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
4
+ hash: 15424071
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 5
10
- version: 3.0.5
9
+ - 6
10
+ - rc
11
+ - 1
12
+ version: 3.0.6.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - David Heinemeier Hansson
@@ -15,7 +17,7 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-02-26 00:00:00 -08:00
20
+ date: 2011-03-29 00:00:00 -07:00
19
21
  default_executable:
20
22
  dependencies:
21
23
  - !ruby/object:Gem::Dependency
@@ -26,12 +28,14 @@ dependencies:
26
28
  requirements:
27
29
  - - "="
28
30
  - !ruby/object:Gem::Version
29
- hash: 13
31
+ hash: 15424071
30
32
  segments:
31
33
  - 3
32
34
  - 0
33
- - 5
34
- version: 3.0.5
35
+ - 6
36
+ - rc
37
+ - 1
38
+ version: 3.0.6.rc1
35
39
  type: :runtime
36
40
  version_requirements: *id001
37
41
  - !ruby/object:Gem::Dependency
@@ -42,12 +46,14 @@ dependencies:
42
46
  requirements:
43
47
  - - "="
44
48
  - !ruby/object:Gem::Version
45
- hash: 13
49
+ hash: 15424071
46
50
  segments:
47
51
  - 3
48
52
  - 0
49
- - 5
50
- version: 3.0.5
53
+ - 6
54
+ - rc
55
+ - 1
56
+ version: 3.0.6.rc1
51
57
  type: :runtime
52
58
  version_requirements: *id002
53
59
  - !ruby/object:Gem::Dependency
@@ -208,16 +214,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
214
  required_rubygems_version: !ruby/object:Gem::Requirement
209
215
  none: false
210
216
  requirements:
211
- - - ">="
217
+ - - ">"
212
218
  - !ruby/object:Gem::Version
213
- hash: 3
219
+ hash: 25
214
220
  segments:
215
- - 0
216
- version: "0"
221
+ - 1
222
+ - 3
223
+ - 1
224
+ version: 1.3.1
217
225
  requirements: []
218
226
 
219
227
  rubyforge_project: activerecord
220
- rubygems_version: 1.5.2
228
+ rubygems_version: 1.6.1
221
229
  signing_key:
222
230
  specification_version: 3
223
231
  summary: Object-relational mapper framework (part of Rails).