activerecord 2.3.3 → 2.3.4
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 +8 -1
- data/Rakefile +32 -15
- data/examples/performance.rb +162 -0
- data/lib/active_record/associations.rb +37 -5
- data/lib/active_record/associations/association_collection.rb +1 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +16 -0
- data/lib/active_record/associations/has_many_association.rb +1 -0
- data/lib/active_record/associations/has_many_through_association.rb +13 -3
- data/lib/active_record/associations/has_one_through_association.rb +8 -2
- data/lib/active_record/autosave_association.rb +4 -3
- data/lib/active_record/base.rb +18 -10
- data/lib/active_record/calculations.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +16 -2
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +2 -2
- data/lib/active_record/connection_adapters/abstract_adapter.rb +7 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +17 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +32 -13
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +12 -0
- data/lib/active_record/dirty.rb +1 -1
- data/lib/active_record/fixtures.rb +9 -7
- data/lib/active_record/i18n_interpolation_deprecation.rb +1 -1
- data/lib/active_record/locale/en.yml +4 -0
- data/lib/active_record/named_scope.rb +1 -6
- data/lib/active_record/reflection.rb +1 -1
- data/lib/active_record/schema_dumper.rb +1 -2
- data/lib/active_record/serializers/json_serializer.rb +5 -3
- data/lib/active_record/serializers/xml_serializer.rb +6 -2
- data/lib/active_record/validations.rb +148 -79
- data/lib/active_record/version.rb +1 -1
- data/test/cases/adapter_test.rb +12 -0
- data/test/cases/associations/belongs_to_associations_test.rb +0 -18
- data/test/cases/associations/eager_load_nested_include_test.rb +5 -5
- data/test/cases/associations/habtm_join_table_test.rb +56 -0
- data/test/cases/associations/has_many_associations_test.rb +56 -2
- data/test/cases/associations/has_many_through_associations_test.rb +46 -1
- data/test/cases/associations/has_one_through_associations_test.rb +10 -0
- data/test/cases/associations/join_model_test.rb +4 -4
- data/test/cases/base_test.rb +49 -4
- data/test/cases/calculations_test.rb +6 -0
- data/test/cases/column_definition_test.rb +34 -0
- data/test/cases/dirty_test.rb +10 -0
- data/test/cases/finder_test.rb +15 -50
- data/test/cases/fixtures_test.rb +1 -1
- data/test/cases/i18n_test.rb +5 -0
- data/test/cases/method_scoping_test.rb +1 -1
- data/test/cases/migration_test.rb +39 -11
- data/test/cases/modules_test.rb +42 -0
- data/test/cases/named_scope_test.rb +6 -4
- data/test/cases/pk_test.rb +18 -0
- data/test/cases/reflection_test.rb +2 -2
- data/test/cases/schema_dumper_test.rb +19 -1
- data/test/cases/validations_i18n_test.rb +656 -624
- data/test/cases/validations_test.rb +12 -2
- data/test/cases/xml_serialization_test.rb +20 -0
- data/test/fixtures/fixture_database.sqlite +0 -0
- data/test/fixtures/fixture_database.sqlite3 +0 -0
- data/test/fixtures/fixture_database_2.sqlite +0 -0
- data/test/fixtures/fixture_database_2.sqlite3 +0 -0
- data/test/fixtures/posts.yml +3 -0
- data/test/models/author.rb +1 -0
- data/test/models/comment.rb +5 -1
- data/test/models/company.rb +2 -0
- data/test/models/company_in_module.rb +1 -1
- data/test/models/contract.rb +5 -0
- data/test/models/organization.rb +2 -0
- data/test/models/topic.rb +0 -2
- data/test/schema/postgresql_specific_schema.rb +13 -2
- data/test/schema/schema.rb +4 -0
- metadata +12 -54
- data/test/debug.log +0 -415
data/test/cases/adapter_test.rb
CHANGED
@@ -63,6 +63,18 @@ class AdapterTest < ActiveRecord::TestCase
|
|
63
63
|
def test_show_nonexistent_variable_returns_nil
|
64
64
|
assert_nil @connection.show_variable('foo_bar_baz')
|
65
65
|
end
|
66
|
+
|
67
|
+
def test_not_specifying_database_name_for_cross_database_selects
|
68
|
+
assert_nothing_raised do
|
69
|
+
ActiveRecord::Base.establish_connection({
|
70
|
+
:adapter => 'mysql',
|
71
|
+
:username => 'rails'
|
72
|
+
})
|
73
|
+
ActiveRecord::Base.connection.execute "SELECT activerecord_unittest.pirates.*, activerecord_unittest2.courses.* FROM activerecord_unittest.pirates, activerecord_unittest2.courses"
|
74
|
+
end
|
75
|
+
|
76
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
77
|
+
end
|
66
78
|
end
|
67
79
|
|
68
80
|
if current_adapter?(:PostgreSQLAdapter)
|
@@ -249,24 +249,6 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
249
249
|
assert_equal 1, Topic.find(topic.id)[:replies_count]
|
250
250
|
end
|
251
251
|
|
252
|
-
def test_belongs_to_counter_after_save
|
253
|
-
topic = Topic.create("title" => "monday night")
|
254
|
-
topic.replies.create("title" => "re: monday night", "content" => "football")
|
255
|
-
assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count")
|
256
|
-
|
257
|
-
topic.save
|
258
|
-
assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count")
|
259
|
-
end
|
260
|
-
|
261
|
-
def test_belongs_to_counter_after_update_attributes
|
262
|
-
topic = Topic.create("title" => "37s")
|
263
|
-
topic.replies.create("title" => "re: 37s", "content" => "rails")
|
264
|
-
assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count")
|
265
|
-
|
266
|
-
topic.update_attributes("title" => "37signals")
|
267
|
-
assert_equal 1, Topic.find(topic.id).send(:read_attribute, "replies_count")
|
268
|
-
end
|
269
|
-
|
270
252
|
def test_assignment_before_child_saved
|
271
253
|
final_cut = Client.new("name" => "Final Cut")
|
272
254
|
firm = Firm.find(1)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'cases/helper'
|
2
|
-
require 'models/author'
|
3
2
|
require 'models/post'
|
3
|
+
require 'models/author'
|
4
4
|
require 'models/comment'
|
5
5
|
require 'models/category'
|
6
6
|
require 'models/categorization'
|
@@ -66,13 +66,13 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
|
|
66
66
|
def setup
|
67
67
|
generate_test_object_graphs
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def teardown
|
71
|
-
[Circle, Square, Triangle, PaintColor, PaintTexture,
|
71
|
+
[Circle, Square, Triangle, PaintColor, PaintTexture,
|
72
72
|
ShapeExpression, NonPolyOne, NonPolyTwo].each do |c|
|
73
73
|
c.delete_all
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
end
|
77
77
|
|
78
78
|
|
@@ -127,4 +127,4 @@ class EagerLoadNestedIncludeWithMissingDataTest < ActiveRecord::TestCase
|
|
127
127
|
Author.all :include => includes, :conditions => {:authors => {:name => @davey_mcdave.name}}, :order => 'categories.name'
|
128
128
|
end
|
129
129
|
end
|
130
|
-
end
|
130
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
|
3
|
+
class MyReader < ActiveRecord::Base
|
4
|
+
has_and_belongs_to_many :my_books
|
5
|
+
end
|
6
|
+
|
7
|
+
class MyBook < ActiveRecord::Base
|
8
|
+
has_and_belongs_to_many :my_readers
|
9
|
+
end
|
10
|
+
|
11
|
+
class HabtmJoinTableTest < ActiveRecord::TestCase
|
12
|
+
def setup
|
13
|
+
ActiveRecord::Base.connection.create_table :my_books, :force => true do |t|
|
14
|
+
t.string :name
|
15
|
+
end
|
16
|
+
assert ActiveRecord::Base.connection.table_exists?(:my_books)
|
17
|
+
|
18
|
+
ActiveRecord::Base.connection.create_table :my_readers, :force => true do |t|
|
19
|
+
t.string :name
|
20
|
+
end
|
21
|
+
assert ActiveRecord::Base.connection.table_exists?(:my_readers)
|
22
|
+
|
23
|
+
ActiveRecord::Base.connection.create_table :my_books_my_readers, :force => true do |t|
|
24
|
+
t.integer :my_book_id
|
25
|
+
t.integer :my_reader_id
|
26
|
+
end
|
27
|
+
assert ActiveRecord::Base.connection.table_exists?(:my_books_my_readers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
ActiveRecord::Base.connection.drop_table :my_books
|
32
|
+
ActiveRecord::Base.connection.drop_table :my_readers
|
33
|
+
ActiveRecord::Base.connection.drop_table :my_books_my_readers
|
34
|
+
end
|
35
|
+
|
36
|
+
uses_transaction :test_should_raise_exception_when_join_table_has_a_primary_key
|
37
|
+
def test_should_raise_exception_when_join_table_has_a_primary_key
|
38
|
+
if ActiveRecord::Base.connection.supports_primary_key?
|
39
|
+
assert_raise ActiveRecord::ConfigurationError do
|
40
|
+
jaime = MyReader.create(:name=>"Jaime")
|
41
|
+
jaime.my_books << MyBook.create(:name=>'Great Expectations')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
uses_transaction :test_should_cache_result_of_primary_key_check
|
47
|
+
def test_should_cache_result_of_primary_key_check
|
48
|
+
if ActiveRecord::Base.connection.supports_primary_key?
|
49
|
+
ActiveRecord::Base.connection.stubs(:primary_key).with('my_books_my_readers').returns(false).once
|
50
|
+
weaz = MyReader.create(:name=>'Weaz')
|
51
|
+
|
52
|
+
weaz.my_books << MyBook.create(:name=>'Great Expectations')
|
53
|
+
weaz.my_books << MyBook.create(:name=>'Greater Expectations')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -10,11 +10,12 @@ require 'models/author'
|
|
10
10
|
require 'models/comment'
|
11
11
|
require 'models/person'
|
12
12
|
require 'models/reader'
|
13
|
+
require 'models/tagging'
|
13
14
|
|
14
15
|
class HasManyAssociationsTest < ActiveRecord::TestCase
|
15
16
|
fixtures :accounts, :categories, :companies, :developers, :projects,
|
16
17
|
:developers_projects, :topics, :authors, :comments, :author_addresses,
|
17
|
-
:people, :posts, :readers
|
18
|
+
:people, :posts, :readers, :taggings
|
18
19
|
|
19
20
|
def setup
|
20
21
|
Client.destroyed_client_ids.clear
|
@@ -279,6 +280,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|
279
280
|
assert_equal client2, firm.clients.find(:first, :conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }])
|
280
281
|
end
|
281
282
|
|
283
|
+
def test_find_all_with_include_and_conditions
|
284
|
+
assert_nothing_raised do
|
285
|
+
Developer.find(:all, :joins => :audit_logs, :conditions => {'audit_logs.message' => nil, :name => 'Smith'})
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
282
289
|
def test_find_in_collection
|
283
290
|
assert_equal Client.find(2).name, companies(:first_firm).clients.find(2).name
|
284
291
|
assert_raise(ActiveRecord::RecordNotFound) { companies(:first_firm).clients.find(6) }
|
@@ -502,6 +509,23 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|
502
509
|
assert_equal 0, new_firm.clients_of_firm.size
|
503
510
|
end
|
504
511
|
|
512
|
+
def test_deleting_updates_counter_cache
|
513
|
+
topic = Topic.first
|
514
|
+
assert_equal topic.replies.to_a.size, topic.replies_count
|
515
|
+
|
516
|
+
topic.replies.delete(topic.replies.first)
|
517
|
+
topic.reload
|
518
|
+
assert_equal topic.replies.to_a.size, topic.replies_count
|
519
|
+
end
|
520
|
+
|
521
|
+
def test_deleting_updates_counter_cache_without_dependent_destroy
|
522
|
+
post = posts(:welcome)
|
523
|
+
|
524
|
+
assert_difference "post.reload.taggings_count", -1 do
|
525
|
+
post.taggings.delete(post.taggings.first)
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
505
529
|
def test_deleting_a_collection
|
506
530
|
force_signal37_to_load_all_clients_of_firm
|
507
531
|
companies(:first_firm).clients_of_firm.create("name" => "Another Client")
|
@@ -547,6 +571,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|
547
571
|
end
|
548
572
|
end
|
549
573
|
|
574
|
+
def test_clearing_updates_counter_cache
|
575
|
+
topic = Topic.first
|
576
|
+
|
577
|
+
topic.replies.clear
|
578
|
+
topic.reload
|
579
|
+
assert_equal 0, topic.replies_count
|
580
|
+
end
|
581
|
+
|
550
582
|
def test_clearing_a_dependent_association_collection
|
551
583
|
firm = companies(:first_firm)
|
552
584
|
client_id = firm.dependent_clients_of_firm.first.id
|
@@ -691,6 +723,28 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|
691
723
|
assert_equal 0, companies(:first_firm).clients_of_firm(true).size
|
692
724
|
end
|
693
725
|
|
726
|
+
def test_destroying_by_fixnum_id
|
727
|
+
force_signal37_to_load_all_clients_of_firm
|
728
|
+
|
729
|
+
assert_difference "Client.count", -1 do
|
730
|
+
companies(:first_firm).clients_of_firm.destroy(companies(:first_firm).clients_of_firm.first.id)
|
731
|
+
end
|
732
|
+
|
733
|
+
assert_equal 0, companies(:first_firm).reload.clients_of_firm.size
|
734
|
+
assert_equal 0, companies(:first_firm).clients_of_firm(true).size
|
735
|
+
end
|
736
|
+
|
737
|
+
def test_destroying_by_string_id
|
738
|
+
force_signal37_to_load_all_clients_of_firm
|
739
|
+
|
740
|
+
assert_difference "Client.count", -1 do
|
741
|
+
companies(:first_firm).clients_of_firm.destroy(companies(:first_firm).clients_of_firm.first.id.to_s)
|
742
|
+
end
|
743
|
+
|
744
|
+
assert_equal 0, companies(:first_firm).reload.clients_of_firm.size
|
745
|
+
assert_equal 0, companies(:first_firm).clients_of_firm(true).size
|
746
|
+
end
|
747
|
+
|
694
748
|
def test_destroying_a_collection
|
695
749
|
force_signal37_to_load_all_clients_of_firm
|
696
750
|
companies(:first_firm).clients_of_firm.create("name" => "Another Client")
|
@@ -861,7 +915,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|
861
915
|
lambda { authors(:mary).comments = [comments(:greetings), comments(:more_greetings)] },
|
862
916
|
lambda { authors(:mary).comments << Comment.create!(:body => "Yay", :post_id => 424242) },
|
863
917
|
lambda { authors(:mary).comments.delete(authors(:mary).comments.first) },
|
864
|
-
].each {|block| assert_raise(ActiveRecord::
|
918
|
+
].each {|block| assert_raise(ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection, &block) }
|
865
919
|
end
|
866
920
|
|
867
921
|
def test_dynamic_find_should_respect_association_order_for_through
|
@@ -11,9 +11,13 @@ require 'models/author'
|
|
11
11
|
require 'models/owner'
|
12
12
|
require 'models/pet'
|
13
13
|
require 'models/toy'
|
14
|
+
require 'models/contract'
|
15
|
+
require 'models/company'
|
16
|
+
require 'models/developer'
|
14
17
|
|
15
18
|
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
16
|
-
fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys
|
19
|
+
fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys,
|
20
|
+
:companies
|
17
21
|
|
18
22
|
def test_associate_existing
|
19
23
|
assert_queries(2) { posts(:thinking);people(:david) }
|
@@ -157,6 +161,30 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
157
161
|
assert_equal peeps + 1, posts(:thinking).people.count
|
158
162
|
end
|
159
163
|
|
164
|
+
def test_associate_with_create_and_invalid_options
|
165
|
+
peeps = companies(:first_firm).developers.count
|
166
|
+
assert_nothing_raised { companies(:first_firm).developers.create(:name => '0') }
|
167
|
+
assert_equal peeps, companies(:first_firm).developers.count
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_associate_with_create_and_valid_options
|
171
|
+
peeps = companies(:first_firm).developers.count
|
172
|
+
assert_nothing_raised { companies(:first_firm).developers.create(:name => 'developer') }
|
173
|
+
assert_equal peeps + 1, companies(:first_firm).developers.count
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_associate_with_create_bang_and_invalid_options
|
177
|
+
peeps = companies(:first_firm).developers.count
|
178
|
+
assert_raises(ActiveRecord::RecordInvalid) { companies(:first_firm).developers.create!(:name => '0') }
|
179
|
+
assert_equal peeps, companies(:first_firm).developers.count
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_associate_with_create_bang_and_valid_options
|
183
|
+
peeps = companies(:first_firm).developers.count
|
184
|
+
assert_nothing_raised { companies(:first_firm).developers.create!(:name => 'developer') }
|
185
|
+
assert_equal peeps + 1, companies(:first_firm).developers.count
|
186
|
+
end
|
187
|
+
|
160
188
|
def test_clear_associations
|
161
189
|
assert_queries(2) { posts(:welcome);posts(:welcome).people(true) }
|
162
190
|
|
@@ -276,4 +304,21 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
276
304
|
def test_has_many_association_through_a_has_many_association_with_nonstandard_primary_keys
|
277
305
|
assert_equal 1, owners(:blackbeard).toys.count
|
278
306
|
end
|
307
|
+
|
308
|
+
def test_find_on_has_many_association_collection_with_include_and_conditions
|
309
|
+
post_with_no_comments = people(:michael).posts_with_no_comments.first
|
310
|
+
assert_equal post_with_no_comments, posts(:authorless)
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_has_many_through_has_one_reflection
|
314
|
+
assert_equal [comments(:eager_sti_on_associations_vs_comment)], authors(:david).very_special_comments
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_modifying_has_many_through_has_one_reflection_should_raise
|
318
|
+
[
|
319
|
+
lambda { authors(:david).very_special_comments = [VerySpecialComment.create!(:body => "Gorp!", :post_id => 1011), VerySpecialComment.create!(:body => "Eep!", :post_id => 1012)] },
|
320
|
+
lambda { authors(:david).very_special_comments << VerySpecialComment.create!(:body => "Hoohah!", :post_id => 1013) },
|
321
|
+
lambda { authors(:david).very_special_comments.delete(authors(:david).very_special_comments.first) },
|
322
|
+
].each {|block| assert_raise(ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection, &block) }
|
323
|
+
end
|
279
324
|
end
|
@@ -28,6 +28,16 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
|
28
28
|
assert_not_nil new_member.current_membership
|
29
29
|
assert_not_nil new_member.club
|
30
30
|
end
|
31
|
+
|
32
|
+
def test_creating_association_builds_through_record_for_new
|
33
|
+
new_member = Member.new(:name => "Jane")
|
34
|
+
new_member.club = clubs(:moustache_club)
|
35
|
+
assert new_member.current_membership
|
36
|
+
assert_equal clubs(:moustache_club), new_member.current_membership.club
|
37
|
+
assert_equal clubs(:moustache_club), new_member.club
|
38
|
+
assert new_member.save
|
39
|
+
assert_equal clubs(:moustache_club), new_member.club
|
40
|
+
end
|
31
41
|
|
32
42
|
def test_replace_target_record
|
33
43
|
new_club = Club.create(:name => "Marx Bros")
|
@@ -317,11 +317,11 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
|
317
317
|
end
|
318
318
|
|
319
319
|
def test_belongs_to_polymorphic_with_counter_cache
|
320
|
-
assert_equal
|
320
|
+
assert_equal 1, posts(:welcome)[:taggings_count]
|
321
321
|
tagging = posts(:welcome).taggings.create(:tag => tags(:general))
|
322
|
-
assert_equal
|
322
|
+
assert_equal 2, posts(:welcome, :reload)[:taggings_count]
|
323
323
|
tagging.destroy
|
324
|
-
|
324
|
+
assert_equal 1, posts(:welcome, :reload)[:taggings_count]
|
325
325
|
end
|
326
326
|
|
327
327
|
def test_unavailable_through_reflection
|
@@ -377,7 +377,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
|
377
377
|
end
|
378
378
|
|
379
379
|
def test_has_many_through_polymorphic_has_one
|
380
|
-
|
380
|
+
assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging
|
381
381
|
end
|
382
382
|
|
383
383
|
def test_has_many_through_polymorphic_has_many
|
data/test/cases/base_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "cases/helper"
|
2
|
+
require 'models/post'
|
2
3
|
require 'models/author'
|
3
4
|
require 'models/topic'
|
4
5
|
require 'models/reply'
|
@@ -12,7 +13,6 @@ require 'models/auto_id'
|
|
12
13
|
require 'models/column_name'
|
13
14
|
require 'models/subscriber'
|
14
15
|
require 'models/keyboard'
|
15
|
-
require 'models/post'
|
16
16
|
require 'models/comment'
|
17
17
|
require 'models/minimalistic'
|
18
18
|
require 'models/warehouse_thing'
|
@@ -1012,7 +1012,25 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1012
1012
|
assert_date_from_db Date.new(2004, 6, 24), topic.last_read.to_date
|
1013
1013
|
end
|
1014
1014
|
|
1015
|
-
def
|
1015
|
+
def test_multiparameter_attributes_on_date_with_empty_year
|
1016
|
+
attributes = { "last_read(1i)" => "", "last_read(2i)" => "6", "last_read(3i)" => "24" }
|
1017
|
+
topic = Topic.find(1)
|
1018
|
+
topic.attributes = attributes
|
1019
|
+
# note that extra #to_date call allows test to pass for Oracle, which
|
1020
|
+
# treats dates/times the same
|
1021
|
+
assert_date_from_db Date.new(1, 6, 24), topic.last_read.to_date
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
def test_multiparameter_attributes_on_date_with_empty_month
|
1025
|
+
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "", "last_read(3i)" => "24" }
|
1026
|
+
topic = Topic.find(1)
|
1027
|
+
topic.attributes = attributes
|
1028
|
+
# note that extra #to_date call allows test to pass for Oracle, which
|
1029
|
+
# treats dates/times the same
|
1030
|
+
assert_date_from_db Date.new(2004, 1, 24), topic.last_read.to_date
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
def test_multiparameter_attributes_on_date_with_empty_day
|
1016
1034
|
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" }
|
1017
1035
|
topic = Topic.find(1)
|
1018
1036
|
topic.attributes = attributes
|
@@ -1021,6 +1039,33 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1021
1039
|
assert_date_from_db Date.new(2004, 6, 1), topic.last_read.to_date
|
1022
1040
|
end
|
1023
1041
|
|
1042
|
+
def test_multiparameter_attributes_on_date_with_empty_day_and_year
|
1043
|
+
attributes = { "last_read(1i)" => "", "last_read(2i)" => "6", "last_read(3i)" => "" }
|
1044
|
+
topic = Topic.find(1)
|
1045
|
+
topic.attributes = attributes
|
1046
|
+
# note that extra #to_date call allows test to pass for Oracle, which
|
1047
|
+
# treats dates/times the same
|
1048
|
+
assert_date_from_db Date.new(1, 6, 1), topic.last_read.to_date
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
def test_multiparameter_attributes_on_date_with_empty_day_and_month
|
1052
|
+
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "", "last_read(3i)" => "" }
|
1053
|
+
topic = Topic.find(1)
|
1054
|
+
topic.attributes = attributes
|
1055
|
+
# note that extra #to_date call allows test to pass for Oracle, which
|
1056
|
+
# treats dates/times the same
|
1057
|
+
assert_date_from_db Date.new(2004, 1, 1), topic.last_read.to_date
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
def test_multiparameter_attributes_on_date_with_empty_year_and_month
|
1061
|
+
attributes = { "last_read(1i)" => "", "last_read(2i)" => "", "last_read(3i)" => "24" }
|
1062
|
+
topic = Topic.find(1)
|
1063
|
+
topic.attributes = attributes
|
1064
|
+
# note that extra #to_date call allows test to pass for Oracle, which
|
1065
|
+
# treats dates/times the same
|
1066
|
+
assert_date_from_db Date.new(1, 1, 24), topic.last_read.to_date
|
1067
|
+
end
|
1068
|
+
|
1024
1069
|
def test_multiparameter_attributes_on_date_with_all_empty
|
1025
1070
|
attributes = { "last_read(1i)" => "", "last_read(2i)" => "", "last_read(3i)" => "" }
|
1026
1071
|
topic = Topic.find(1)
|
@@ -1115,7 +1160,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1115
1160
|
Time.zone = nil
|
1116
1161
|
Topic.skip_time_zone_conversion_for_attributes = []
|
1117
1162
|
end
|
1118
|
-
|
1163
|
+
|
1119
1164
|
def test_multiparameter_attributes_on_time_only_column_with_time_zone_aware_attributes_does_not_do_time_zone_conversion
|
1120
1165
|
ActiveRecord::Base.time_zone_aware_attributes = true
|
1121
1166
|
ActiveRecord::Base.default_timezone = :utc
|
@@ -1439,7 +1484,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1439
1484
|
topic = Topic.create("content" => myobj).reload
|
1440
1485
|
assert_equal(myobj, topic.content)
|
1441
1486
|
end
|
1442
|
-
|
1487
|
+
|
1443
1488
|
def test_serialized_string_attribute
|
1444
1489
|
myobj = "Yes"
|
1445
1490
|
topic = Topic.create("content" => myobj).reload
|
@@ -5,6 +5,8 @@ require 'models/edge'
|
|
5
5
|
require 'models/owner'
|
6
6
|
require 'models/pet'
|
7
7
|
require 'models/toy'
|
8
|
+
require 'models/club'
|
9
|
+
require 'models/organization'
|
8
10
|
|
9
11
|
Company.has_many :accounts
|
10
12
|
|
@@ -226,6 +228,10 @@ class CalculationsTest < ActiveRecord::TestCase
|
|
226
228
|
assert_equal 15, companies(:rails_core).companies.sum(:id)
|
227
229
|
end
|
228
230
|
|
231
|
+
def test_should_sum_scoped_field_with_from
|
232
|
+
assert_equal Club.count, Organization.clubs.count
|
233
|
+
end
|
234
|
+
|
229
235
|
def test_should_sum_scoped_field_with_conditions
|
230
236
|
assert_equal 8, companies(:rails_core).companies.sum(:id, :conditions => 'id > 7')
|
231
237
|
end
|