activerecord 1.5.0 → 1.5.1

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,3 +1,10 @@
1
+ *1.5.1* (January 18th, 2005)
2
+
3
+ * Fixed that the belongs_to and has_one proxy would fail a test like 'if project.manager' -- this unfortunately also means that you can't call methods like project.manager.build unless there already is a manager on the project #492 [Tim Bates]
4
+
5
+ * Fixed that the Ruby/MySQL adapter wouldn't connect if the password was empty #503 [Pelle]
6
+
7
+
1
8
  *1.5.0* (January 17th, 2005)
2
9
 
3
10
  * Fixed that unit tests for MySQL are now run as the "rails" user instead of root #455 [Eric Hodel]
@@ -228,7 +228,7 @@ module ActiveRecord
228
228
 
229
229
  add_multiple_associated_save_callbacks(association_name)
230
230
 
231
- association_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, HasManyAssociation)
231
+ collection_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, HasManyAssociation)
232
232
 
233
233
  # deprecated api
234
234
  deprecated_collection_count_method(association_name)
@@ -289,7 +289,7 @@ module ActiveRecord
289
289
  module_eval do
290
290
  after_save <<-EOF
291
291
  association = instance_variable_get("@#{association_name}")
292
- if (true or @new_record_before_save) and association.respond_to?(:loaded?) and not association.nil?
292
+ unless association.nil?
293
293
  association["#{association_class_primary_key_name}"] = id
294
294
  association.save(true)
295
295
  association.send(:construct_sql)
@@ -364,7 +364,7 @@ module ActiveRecord
364
364
  module_eval do
365
365
  before_save <<-EOF
366
366
  association = instance_variable_get("@#{association_name}")
367
- if association.respond_to?(:loaded?) and not association.nil? and association.new_record?
367
+ if not association.nil? and association.new_record?
368
368
  association.save(true)
369
369
  self["#{association_class_primary_key_name}"] = association.id
370
370
  association.send(:construct_sql)
@@ -469,7 +469,7 @@ module ActiveRecord
469
469
 
470
470
  add_multiple_associated_save_callbacks(association_name)
471
471
 
472
- association_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, HasAndBelongsToManyAssociation)
472
+ collection_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, HasAndBelongsToManyAssociation)
473
473
 
474
474
  before_destroy_sql = "DELETE FROM #{options[:join_table]} WHERE #{association_class_primary_key_name} = \\\#{self.quoted_id}"
475
475
  module_eval(%{before_destroy "self.connection.delete(%{#{before_destroy_sql}})"}) # "
@@ -512,6 +512,43 @@ module ActiveRecord
512
512
  end
513
513
 
514
514
  def association_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class)
515
+ define_method(association_name) do |*params|
516
+ force_reload = params.first unless params.empty?
517
+ association = instance_variable_get("@#{association_name}")
518
+ if association.nil? or force_reload
519
+ association = association_proxy_class.new(self,
520
+ association_name, association_class_name,
521
+ association_class_primary_key_name, options)
522
+ retval = association.reload
523
+ unless retval.nil?
524
+ instance_variable_set("@#{association_name}", association)
525
+ else
526
+ instance_variable_set("@#{association_name}", nil)
527
+ return nil
528
+ end
529
+ end
530
+ association
531
+ end
532
+
533
+ define_method("#{association_name}=") do |new_value|
534
+ association = instance_variable_get("@#{association_name}")
535
+ if association.nil?
536
+ association = association_proxy_class.new(self,
537
+ association_name, association_class_name,
538
+ association_class_primary_key_name, options)
539
+ end
540
+ association.replace(new_value)
541
+ unless new_value.nil?
542
+ instance_variable_set("@#{association_name}", association)
543
+ else
544
+ instance_variable_set("@#{association_name}", nil)
545
+ return nil
546
+ end
547
+ association
548
+ end
549
+ end
550
+
551
+ def collection_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class)
515
552
  define_method(association_name) do |*params|
516
553
  force_reload = params.first unless params.empty?
517
554
  association = instance_variable_get("@#{association_name}")
@@ -11,10 +11,6 @@ module ActiveRecord
11
11
  @loaded = false
12
12
  end
13
13
 
14
- def reload
15
- reset
16
- end
17
-
18
14
  # Add +records+ to this association. Returns +self+ so method calls may be chained.
19
15
  # Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
20
16
  def <<(*records)
@@ -14,6 +14,11 @@ module ActiveRecord
14
14
  reset
15
15
  end
16
16
 
17
+ def reload
18
+ reset
19
+ load_target
20
+ end
21
+
17
22
  def method_missing(symbol, *args, &block)
18
23
  load_target
19
24
  @target.send(symbol, *args, &block)
@@ -7,11 +7,6 @@ module ActiveRecord
7
7
  @loaded = false
8
8
  end
9
9
 
10
- def reload
11
- reset
12
- load_target
13
- end
14
-
15
10
  def create(attributes = {})
16
11
  record = build(attributes)
17
12
  record.save
@@ -34,12 +29,8 @@ module ActiveRecord
34
29
  @owner[@association_class_primary_key_name] = obj.id unless obj.new_record?
35
30
  end
36
31
  @loaded = true
37
- end
38
32
 
39
- # Ugly workaround - .nil? is done in C and the method_missing trick doesn't work when we pretend to be nil
40
- def nil?
41
- load_target
42
- @target.nil?
33
+ return (@target.nil? ? nil : self)
43
34
  end
44
35
 
45
36
  private
@@ -65,10 +56,3 @@ module ActiveRecord
65
56
  end
66
57
  end
67
58
  end
68
-
69
- class NilClass #:nodoc:
70
- # Ugly workaround - nil comparison is usually done in C and so a proxy object pretending to be nil doesn't work.
71
- def ==(other)
72
- other.nil?
73
- end
74
- end
@@ -25,9 +25,9 @@ module ActiveRecord
25
25
 
26
26
  @loaded = true
27
27
  unless @owner.new_record? or obj.nil? or dont_save
28
- return (obj.save ? obj : false)
28
+ return (obj.save ? self : false)
29
29
  else
30
- return obj
30
+ return (obj.nil? ? nil : self)
31
31
  end
32
32
  end
33
33
 
@@ -565,7 +565,7 @@ module ActiveRecord #:nodoc:
565
565
  # Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
566
566
  # Person.human_attribute_name("first_name") # => "First name"
567
567
  def human_attribute_name(attribute_key_name)
568
- attribute_key_name.gsub(/_/, " ").capitalize unless attribute_key_name.nil?
568
+ attribute_key_name.humanize
569
569
  end
570
570
 
571
571
  def descends_from_active_record? # :nodoc:
@@ -2,7 +2,7 @@ begin
2
2
  require 'simplecc'
3
3
  rescue LoadError
4
4
  class Continuation #:nodoc:
5
- def create(*args, &block)
5
+ def self.create(*args, &block)
6
6
  cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
7
7
  result ||= args
8
8
  return *[cc, *result]
@@ -36,7 +36,7 @@ class Binding #:nodoc:
36
36
  # If you don't do this an Exception will be raised. Because of
37
37
  # the way that Binding.of_caller is implemented it has to be
38
38
  # done this way.
39
- def of_caller(&block)
39
+ def self.of_caller(&block)
40
40
  old_critical = Thread.critical
41
41
  Thread.critical = true
42
42
  count = 0
@@ -31,6 +31,10 @@ module ActiveSupport #:nodoc:
31
31
  def classify
32
32
  Inflector.classify(self)
33
33
  end
34
+
35
+ def humanize
36
+ Inflector.humanize(self)
37
+ end
34
38
 
35
39
  def foreign_key(separate_class_name_and_id_with_underscore = true)
36
40
  Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
@@ -27,6 +27,10 @@ module Inflector
27
27
  camel_cased_word.to_s.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
28
28
  end
29
29
 
30
+ def humanize(lower_case_and_underscored_word)
31
+ lower_case_and_underscored_word.to_s.gsub(/_/, " ").capitalize
32
+ end
33
+
30
34
  def demodulize(class_name_in_module)
31
35
  class_name_in_module.to_s.gsub(/^.*::/, '')
32
36
  end
@@ -139,6 +139,7 @@ class Mysql
139
139
  # candidate_hash2=sha1(hash_stage1)
140
140
  # check(candidate_hash2==hash_stage2)
141
141
  def scramble411( password, seed, old_ver )
142
+ return "" if password == nil or password == ""
142
143
  raise "old version password is not implemented" if old_ver
143
144
 
144
145
  # print "Seed Bytes = "
@@ -302,4 +303,4 @@ class Mysql
302
303
  end
303
304
  self
304
305
  end
305
- end
306
+ end
data/rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/contrib/rubyforgepublisher'
8
8
 
9
9
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
10
  PKG_NAME = 'activerecord'
11
- PKG_VERSION = '1.5.0' + PKG_BUILD
11
+ PKG_VERSION = '1.5.1' + PKG_BUILD
12
12
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
13
 
14
14
  PKG_FILES = FileList[
@@ -105,7 +105,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase
105
105
  firm = Firm.new("name" => "GlobalMegaCorp")
106
106
  firm.save
107
107
 
108
- account = firm.account.build("credit_limit" => 1000)
108
+ firm.account = account = Account.new("credit_limit" => 1000)
109
109
  assert_equal account, firm.account
110
110
  assert account.save
111
111
  assert_equal account, firm.account
@@ -125,7 +125,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase
125
125
  def test_build_before_either_saved
126
126
  firm = Firm.new("name" => "GlobalMegaCorp")
127
127
 
128
- account = firm.account.build("credit_limit" => 1000)
128
+ firm.account = account = Account.new("credit_limit" => 1000)
129
129
  assert_equal account, firm.account
130
130
  assert account.new_record?
131
131
  assert firm.save
@@ -137,7 +137,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase
137
137
  firm = Firm.new("name" => "GlobalMegaCorp")
138
138
  firm.save
139
139
 
140
- account = firm.account.build
140
+ firm.account = account = Account.new
141
141
  assert_equal account, firm.account
142
142
  assert !account.save
143
143
  assert_equal account, firm.account
@@ -147,12 +147,14 @@ class HasOneAssociationsTest < Test::Unit::TestCase
147
147
  def test_create
148
148
  firm = Firm.new("name" => "GlobalMegaCorp")
149
149
  firm.save
150
- assert_equal firm.account.create("credit_limit" => 1000), firm.account
150
+ firm.account = account = Account.create("credit_limit" => 1000)
151
+ assert_equal account, firm.account
151
152
  end
152
153
 
153
154
  def test_create_before_save
154
155
  firm = Firm.new("name" => "GlobalMegaCorp")
155
- assert_equal firm.account.create("credit_limit" => 1000), firm.account
156
+ firm.account = account = Account.create("credit_limit" => 1000)
157
+ assert_equal account, firm.account
156
158
  end
157
159
 
158
160
  def test_dependence_with_missing_association
@@ -243,6 +245,21 @@ class HasManyAssociationsTest < Test::Unit::TestCase
243
245
  assert_equal 1, Firm.find_first.clients_using_counter_sql.size
244
246
  assert_equal 0, Firm.find_first.clients_using_zero_counter_sql.size
245
247
  end
248
+
249
+ def test_belongs_to_sanity
250
+ c = Client.new
251
+ assert_nil c.firm
252
+
253
+ if c.firm
254
+ assert false, "belongs_to failed if check"
255
+ end
256
+
257
+ unless c.firm
258
+ else
259
+ assert false, "belongs_to failed unless check"
260
+ end
261
+
262
+ end
246
263
 
247
264
  def test_find_ids
248
265
  firm = Firm.find_first
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.4
3
3
  specification_version: 1
4
4
  name: activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.5.0
7
- date: 2005-01-17
6
+ version: 1.5.1
7
+ date: 2005-01-18
8
8
  summary: Implements the ActiveRecord pattern for ORM.
9
9
  require_paths:
10
10
  - lib