activerecord 2.3.2 → 2.3.3

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 (55) hide show
  1. data/CHANGELOG +11 -0
  2. data/Rakefile +10 -10
  3. data/lib/active_record/associations.rb +67 -30
  4. data/lib/active_record/associations/association_collection.rb +9 -5
  5. data/lib/active_record/associations/association_proxy.rb +2 -2
  6. data/lib/active_record/associations/belongs_to_association.rb +22 -4
  7. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +5 -1
  8. data/lib/active_record/associations/has_one_through_association.rb +8 -8
  9. data/lib/active_record/autosave_association.rb +11 -6
  10. data/lib/active_record/base.rb +16 -21
  11. data/lib/active_record/batches.rb +23 -15
  12. data/lib/active_record/calculations.rb +5 -13
  13. data/lib/active_record/connection_adapters/postgresql_adapter.rb +66 -22
  14. data/lib/active_record/connection_adapters/sqlite_adapter.rb +3 -0
  15. data/lib/active_record/fixtures.rb +5 -4
  16. data/lib/active_record/named_scope.rb +2 -2
  17. data/lib/active_record/schema_dumper.rb +5 -1
  18. data/lib/active_record/serialization.rb +3 -2
  19. data/lib/active_record/serializers/json_serializer.rb +8 -18
  20. data/lib/active_record/session_store.rb +9 -1
  21. data/lib/active_record/timestamp.rb +39 -9
  22. data/lib/active_record/validations.rb +1 -1
  23. data/lib/active_record/version.rb +1 -1
  24. data/test/cases/associations/belongs_to_associations_test.rb +102 -4
  25. data/test/cases/associations/eager_test.rb +12 -0
  26. data/test/cases/associations/has_many_associations_test.rb +6 -0
  27. data/test/cases/associations/has_one_through_associations_test.rb +8 -1
  28. data/test/cases/associations/inner_join_association_test.rb +5 -0
  29. data/test/cases/autosave_association_test.rb +22 -0
  30. data/test/cases/base_test.rb +2 -2
  31. data/test/cases/calculations_test.rb +8 -14
  32. data/test/cases/copy_table_test_sqlite.rb +5 -5
  33. data/test/cases/finder_test.rb +6 -0
  34. data/test/cases/fixtures_test.rb +5 -0
  35. data/test/cases/helper.rb +1 -2
  36. data/test/cases/json_serialization_test.rb +57 -57
  37. data/test/cases/method_scoping_test.rb +13 -3
  38. data/test/cases/reflection_test.rb +5 -5
  39. data/test/cases/schema_dumper_test.rb +17 -7
  40. data/test/cases/schema_test_postgresql.rb +76 -0
  41. data/test/cases/timestamp_test.rb +75 -0
  42. data/test/debug.log +415 -0
  43. data/test/fixtures/fixture_database.sqlite3 +0 -0
  44. data/test/fixtures/fixture_database_2.sqlite3 +0 -0
  45. data/test/models/author.rb +4 -0
  46. data/test/models/company.rb +7 -7
  47. data/test/models/developer.rb +10 -0
  48. data/test/models/essay.rb +3 -0
  49. data/test/models/pet.rb +1 -1
  50. data/test/models/project.rb +1 -1
  51. data/test/models/reply.rb +2 -1
  52. data/test/models/topic.rb +1 -0
  53. data/test/models/toy.rb +2 -0
  54. data/test/schema/schema.rb +15 -0
  55. metadata +6 -3
@@ -25,6 +25,8 @@ class Author < ActiveRecord::Base
25
25
  has_many :comments_with_order_and_conditions, :through => :posts, :source => :comments, :order => 'comments.body', :conditions => "comments.body like 'Thank%'"
26
26
  has_many :comments_with_include, :through => :posts, :source => :comments, :include => :post
27
27
 
28
+ has_many :thinking_posts, :class_name => 'Post', :conditions => { :title => 'So I was thinking' }, :dependent => :delete_all
29
+ has_many :welcome_posts, :class_name => 'Post', :conditions => { :title => 'Welcome to the weblog' }
28
30
 
29
31
  has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
30
32
  has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
@@ -85,6 +87,8 @@ class Author < ActiveRecord::Base
85
87
  has_many :tags, :through => :posts # through has_many :through
86
88
  has_many :post_categories, :through => :posts, :source => :categories
87
89
 
90
+ has_one :essay, :primary_key => :name, :as => :writer
91
+
88
92
  belongs_to :author_address, :dependent => :destroy
89
93
  belongs_to :author_address_extra, :dependent => :delete, :class_name => "AuthorAddress"
90
94
 
@@ -78,19 +78,13 @@ class DependentFirm < Company
78
78
  has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
79
79
  end
80
80
 
81
- class ExclusivelyDependentFirm < Company
82
- has_one :account, :foreign_key => "firm_id", :dependent => :delete
83
- has_many :dependent_sanitized_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => "name = 'BigShot Inc.'"
84
- has_many :dependent_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => ["name = ?", 'BigShot Inc.']
85
- has_many :dependent_hash_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => {:name => 'BigShot Inc.'}
86
- end
87
-
88
81
  class Client < Company
89
82
  belongs_to :firm, :foreign_key => "client_of"
90
83
  belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
91
84
  belongs_to :firm_with_select, :class_name => "Firm", :foreign_key => "firm_id", :select => "id"
92
85
  belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
93
86
  belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
87
+ belongs_to :firm_with_primary_key, :class_name => "Firm", :primary_key => "name", :foreign_key => "firm_name"
94
88
  belongs_to :readonly_firm, :class_name => "Firm", :foreign_key => "firm_id", :readonly => true
95
89
 
96
90
  # Record destruction so we can test whether firm.clients.clear has
@@ -125,6 +119,12 @@ class Client < Company
125
119
  end
126
120
  end
127
121
 
122
+ class ExclusivelyDependentFirm < Company
123
+ has_one :account, :foreign_key => "firm_id", :dependent => :delete
124
+ has_many :dependent_sanitized_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => "name = 'BigShot Inc.'"
125
+ has_many :dependent_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => ["name = ?", 'BigShot Inc.']
126
+ has_many :dependent_hash_conditional_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all, :conditions => {:name => 'BigShot Inc.'}
127
+ end
128
128
 
129
129
  class SpecialClient < Client
130
130
  end
@@ -89,3 +89,13 @@ class DeveloperOrderedBySalary < ActiveRecord::Base
89
89
  end
90
90
  end
91
91
  end
92
+
93
+ class DeveloperCalledDavid < ActiveRecord::Base
94
+ self.table_name = 'developers'
95
+ default_scope :conditions => "name = 'David'"
96
+ end
97
+
98
+ class DeveloperCalledJamis < ActiveRecord::Base
99
+ self.table_name = 'developers'
100
+ default_scope :conditions => { :name => 'Jamis' }
101
+ end
@@ -0,0 +1,3 @@
1
+ class Essay < ActiveRecord::Base
2
+ belongs_to :writer, :primary_key => :name, :polymorphic => true
3
+ end
@@ -1,5 +1,5 @@
1
1
  class Pet < ActiveRecord::Base
2
2
  set_primary_key :pet_id
3
- belongs_to :owner
3
+ belongs_to :owner, :touch => true
4
4
  has_many :toys
5
5
  end
@@ -13,7 +13,7 @@ class Project < ActiveRecord::Base
13
13
  :after_add => Proc.new {|o, r| o.developers_log << "after_adding#{r.id || '<new>'}"},
14
14
  :before_remove => Proc.new {|o, r| o.developers_log << "before_removing#{r.id}"},
15
15
  :after_remove => Proc.new {|o, r| o.developers_log << "after_removing#{r.id}"}
16
- has_and_belongs_to_many :well_payed_salary_groups, :class_name => "Developer", :group => "salary", :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary"
16
+ has_and_belongs_to_many :well_payed_salary_groups, :class_name => "Developer", :group => "developers.salary", :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary"
17
17
 
18
18
  attr_accessor :developers_log
19
19
 
@@ -4,12 +4,13 @@ class Reply < Topic
4
4
  named_scope :base
5
5
 
6
6
  belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
7
+ belongs_to :topic_with_primary_key, :class_name => "Topic", :primary_key => "title", :foreign_key => "parent_title", :counter_cache => "replies_count"
7
8
  has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
8
9
 
9
10
  validate :errors_on_empty_content
10
11
  validate_on_create :title_is_wrong_create
11
12
 
12
- attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
13
+ attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read, :parent_title
13
14
 
14
15
  def validate
15
16
  errors.add("title", "Empty") unless attribute_present? "title"
@@ -39,6 +39,7 @@ class Topic < ActiveRecord::Base
39
39
  named_scope :by_rejected_ids, lambda {{ :conditions => { :id => all(:conditions => {:approved => false}).map(&:id) } }}
40
40
 
41
41
  has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
42
+ has_many :replies_with_primary_key, :class_name => "Reply", :dependent => :destroy, :primary_key => "title", :foreign_key => "parent_title"
42
43
  serialize :content
43
44
 
44
45
  before_create :default_written_on
@@ -1,4 +1,6 @@
1
1
  class Toy < ActiveRecord::Base
2
2
  set_primary_key :toy_id
3
3
  belongs_to :pet
4
+
5
+ named_scope :with_name, lambda { |name| {:conditions => {:name => name}} }
4
6
  end
@@ -68,6 +68,10 @@ ActiveRecord::Schema.define do
68
68
  t.boolean :value
69
69
  end
70
70
 
71
+ create_table "CamelCase", :force => true do |t|
72
+ t.string :name
73
+ end
74
+
71
75
  create_table :categories, :force => true do |t|
72
76
  t.string :name, :null => false
73
77
  t.string :type
@@ -114,6 +118,8 @@ ActiveRecord::Schema.define do
114
118
  t.integer :rating, :default => 1
115
119
  end
116
120
 
121
+ add_index :companies, [:firm_id, :type, :rating, :ruby_type], :name => "company_index"
122
+
117
123
  create_table :computers, :force => true do |t|
118
124
  t.integer :developer, :null => false
119
125
  t.integer :extendedWarranty, :null => false
@@ -155,6 +161,12 @@ ActiveRecord::Schema.define do
155
161
  t.integer :course_id, :null => false
156
162
  end
157
163
 
164
+ create_table :essays, :force => true do |t|
165
+ t.string :name
166
+ t.string :writer_id
167
+ t.string :writer_type
168
+ end
169
+
158
170
  create_table :events, :force => true do |t|
159
171
  t.string :title, :limit => 5
160
172
  end
@@ -281,6 +293,8 @@ ActiveRecord::Schema.define do
281
293
 
282
294
  create_table :owners, :primary_key => :owner_id ,:force => true do |t|
283
295
  t.string :name
296
+ t.column :updated_at, :datetime
297
+ t.column :happy_at, :datetime
284
298
  end
285
299
 
286
300
 
@@ -410,6 +424,7 @@ ActiveRecord::Schema.define do
410
424
  t.boolean :approved, :default => true
411
425
  t.integer :replies_count, :default => 0
412
426
  t.integer :parent_id
427
+ t.string :parent_title
413
428
  t.string :type
414
429
  end
415
430
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ autorequire: active_record
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-15 00:00:00 -05:00
12
+ date: 2009-07-20 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.3.2
23
+ version: 2.3.3
24
24
  version:
25
25
  description: Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties database tables and classes together for business objects, like Customer or Subscription, that can find, save, and destroy themselves without resorting to manual SQL.
26
26
  email: david@loudthinking.com
@@ -181,6 +181,7 @@ files:
181
181
  - test/cases/schema_test_postgresql.rb
182
182
  - test/cases/serialization_test.rb
183
183
  - test/cases/synonym_test_oracle.rb
184
+ - test/cases/timestamp_test.rb
184
185
  - test/cases/transactions_test.rb
185
186
  - test/cases/unconnected_test.rb
186
187
  - test/cases/validations_i18n_test.rb
@@ -221,6 +222,7 @@ files:
221
222
  - test/connections/native_sqlite3/in_memory_connection.rb
222
223
  - test/connections/native_sybase
223
224
  - test/connections/native_sybase/connection.rb
225
+ - test/debug.log
224
226
  - test/fixtures
225
227
  - test/fixtures/accounts.yml
226
228
  - test/fixtures/all
@@ -357,6 +359,7 @@ files:
357
359
  - test/models/developer.rb
358
360
  - test/models/edge.rb
359
361
  - test/models/entrant.rb
362
+ - test/models/essay.rb
360
363
  - test/models/event.rb
361
364
  - test/models/guid.rb
362
365
  - test/models/item.rb