ibm_db 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ require 'models/topic'
9
9
  require 'models/reply'
10
10
 
11
11
  class CascadedEagerLoadingTest < ActiveRecord::TestCase
12
- fixtures :authors, :mixins, :companies, :posts, :topics
12
+ fixtures :authors, :mixins, :companies, :posts, :topics, :accounts, :comments, :categorizations
13
13
 
14
14
  def test_eager_association_loading_with_cascaded_two_levels
15
15
  authors = Author.find(:all, :include=>{:posts=>:comments}, :order=>"authors.id")
@@ -68,6 +68,18 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
68
68
  end
69
69
  end
70
70
 
71
+ def test_eager_association_loading_with_has_many_sti_and_subclasses
72
+ silly = SillyReply.new(:title => "gaga", :content => "boo-boo", :parent_id => 1)
73
+ silly.parent_id = 1
74
+ assert silly.save
75
+
76
+ topics = Topic.find(:all, :include => :replies, :order => 'topics.id, replies_topics.id')
77
+ assert_no_queries do
78
+ assert_equal 2, topics[0].replies.size
79
+ assert_equal 0, topics[1].replies.size
80
+ end
81
+ end
82
+
71
83
  def test_eager_association_loading_with_belongs_to_sti
72
84
  replies = Reply.find(:all, :include => :topic, :order => 'topics.id')
73
85
  assert replies.include?(topics(:second))
@@ -14,11 +14,14 @@ require 'models/job'
14
14
  require 'models/subscriber'
15
15
  require 'models/subscription'
16
16
  require 'models/book'
17
+ require 'models/developer'
18
+ require 'models/project'
17
19
 
18
20
  class EagerAssociationTest < ActiveRecord::TestCase
19
21
  fixtures :posts, :comments, :authors, :categories, :categories_posts,
20
22
  :companies, :accounts, :tags, :taggings, :people, :readers,
21
- :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books
23
+ :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books,
24
+ :developers, :projects, :developers_projects
22
25
 
23
26
  def test_loading_with_one_association
24
27
  posts = Post.find(:all, :include => :comments)
@@ -35,6 +38,12 @@ class EagerAssociationTest < ActiveRecord::TestCase
35
38
  assert_equal Post.find(1).last_comment, post.last_comment
36
39
  end
37
40
 
41
+ def test_loading_with_one_association_with_non_preload
42
+ posts = Post.find(:all, :include => :last_comment, :order => 'comments.id DESC')
43
+ post = posts.find { |p| p.id == 1 }
44
+ assert_equal Post.find(1).last_comment, post.last_comment
45
+ end
46
+
38
47
  def test_loading_conditions_with_or
39
48
  posts = authors(:david).posts.find(:all, :include => :comments, :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE} = 'SpecialComment'")
40
49
  assert_nil posts.detect { |p| p.author_id != authors(:david).id },
@@ -107,6 +116,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
107
116
  assert_equal 2, posts.first.comments.size
108
117
  end
109
118
 
119
+ def test_loading_from_an_association_that_has_a_hash_of_conditions
120
+ assert_nothing_raised do
121
+ Author.find(:all, :include => :hello_posts_with_hash_conditions)
122
+ end
123
+ assert !Author.find(authors(:david).id, :include => :hello_posts_with_hash_conditions).hello_posts.empty?
124
+ end
125
+
110
126
  def test_loading_with_no_associations
111
127
  assert_nil Post.find(posts(:authorless).id, :include => :author).author
112
128
  end
@@ -560,6 +576,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
560
576
  assert_nothing_raised { Post.find(:all, :include => 'comments') }
561
577
  end
562
578
 
579
+ def test_eager_with_floating_point_numbers
580
+ assert_queries(2) do
581
+ # Before changes, the floating point numbers will be interpreted as table names and will cause this to run in one query
582
+ Comment.find :all, :conditions => "123.456 = 123.456", :include => :post
583
+ end
584
+ end
585
+
563
586
  def test_preconfigured_includes_with_belongs_to
564
587
  author = posts(:welcome).author_with_posts
565
588
  assert_no_queries {assert_equal 5, author.posts.size}
@@ -613,4 +636,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
613
636
  Comment.find :all, :include => :post
614
637
  end
615
638
  end
639
+
640
+ def test_conditions_on_join_table_with_include_and_limit
641
+ assert_equal 3, Developer.find(:all, :include => 'projects', :conditions => 'developers_projects.access_level = 1', :limit => 5).size
642
+ end
643
+
644
+ unless current_adapter?(:IBM_DBAdapter) #refer db2 ? SQL0214N
645
+ def test_order_on_join_table_with_include_and_limit
646
+ assert_equal 5, Developer.find(:all, :include => 'projects', :order => 'developers_projects.joined_on DESC', :limit => 5).size
647
+ end
648
+ end
616
649
  end
@@ -70,7 +70,7 @@ end
70
70
 
71
71
  class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
72
72
  fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects,
73
- :parrots, :pirates, :treasures, :price_estimates
73
+ :parrots, :pirates, :treasures, :price_estimates, :tags, :taggings
74
74
 
75
75
  def test_has_and_belongs_to_many
76
76
  david = Developer.find(1)
@@ -299,6 +299,17 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
299
299
  assert_equal 3, projects(:active_record, :reload).developers.size
300
300
  end
301
301
 
302
+ def test_uniq_option_prevents_duplicate_push
303
+ project = projects(:active_record)
304
+ project.developers << developers(:jamis)
305
+ project.developers << developers(:david)
306
+ assert_equal 3, project.developers.size
307
+
308
+ project.developers << developers(:david)
309
+ project.developers << developers(:jamis)
310
+ assert_equal 3, project.developers.size
311
+ end
312
+
302
313
  def test_deleting
303
314
  david = Developer.find(1)
304
315
  active_record = Project.find(1)
@@ -439,6 +450,13 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
439
450
  assert_equal developers(:david), active_record.developers_with_finder_sql.find(developers(:david).id), "Ruby find"
440
451
  end
441
452
 
453
+ def test_find_in_association_with_custom_finder_sql_and_multiple_interpolations
454
+ # interpolate once:
455
+ assert_equal [developers(:david), developers(:jamis), developers(:poor_jamis)], projects(:active_record).developers_with_finder_sql, "first interpolation"
456
+ # interpolate again, for a different project id
457
+ assert_equal [developers(:david)], projects(:action_controller).developers_with_finder_sql, "second interpolation"
458
+ end
459
+
442
460
  def test_find_in_association_with_custom_finder_sql_and_string_id
443
461
  assert_equal developers(:david), projects(:active_record).developers_with_finder_sql.find(developers(:david).id.to_s), "SQL find"
444
462
  end
@@ -629,8 +647,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
629
647
  developer.save
630
648
  developer.reload
631
649
  assert_equal 2, developer.projects.length
632
- assert_equal projects(:active_record), developer.projects[0]
633
- assert_equal projects(:action_controller), developer.projects[1]
650
+ assert_equal [projects(:active_record), projects(:action_controller)].map(&:id).sort, developer.project_ids.sort
634
651
  end
635
652
 
636
653
  def test_assign_ids_ignoring_blanks
@@ -639,8 +656,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
639
656
  developer.save
640
657
  developer.reload
641
658
  assert_equal 2, developer.projects.length
642
- assert_equal projects(:active_record), developer.projects[0]
643
- assert_equal projects(:action_controller), developer.projects[1]
659
+ assert_equal [projects(:active_record), projects(:action_controller)].map(&:id).sort, developer.project_ids.sort
644
660
  end
645
661
 
646
662
  unless current_adapter?(:IBM_DBAdapter)
@@ -683,4 +699,12 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
683
699
  assert_equal developer, project.developers.find(:first)
684
700
  assert_equal project, developer.projects.find(:first)
685
701
  end
702
+
703
+ unless current_adapter?(:IBM_DBAdapter)#refer SQL0214N
704
+ def test_dynamic_find_should_respect_association_include
705
+ # SQL error in sort clause if :include is not included
706
+ # due to Unknown column 'authors.id'
707
+ assert Category.find(1).posts_with_authors_sorted_by_author_id.find_by_title('Welcome to the weblog')
708
+ end
709
+ end
686
710
  end
@@ -0,0 +1,202 @@
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/person'
4
+ require 'models/reader'
5
+
6
+ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
7
+ fixtures :posts, :readers, :people
8
+
9
+ def test_associate_existing
10
+ assert_queries(2) { posts(:thinking);people(:david) }
11
+
12
+ assert_queries(1) do
13
+ posts(:thinking).people << people(:david)
14
+ end
15
+
16
+ assert_queries(1) do
17
+ assert posts(:thinking).people.include?(people(:david))
18
+ end
19
+
20
+ assert posts(:thinking).reload.people(true).include?(people(:david))
21
+ end
22
+
23
+ def test_associating_new
24
+ assert_queries(1) { posts(:thinking) }
25
+ new_person = nil # so block binding catches it
26
+
27
+ assert_queries(0) do
28
+ new_person = Person.new :first_name => 'bob'
29
+ end
30
+
31
+ # Associating new records always saves them
32
+ # Thus, 1 query for the new person record, 1 query for the new join table record
33
+ assert_queries(2) do
34
+ posts(:thinking).people << new_person
35
+ end
36
+
37
+ assert_queries(1) do
38
+ assert posts(:thinking).people.include?(new_person)
39
+ end
40
+
41
+ assert posts(:thinking).reload.people(true).include?(new_person)
42
+ end
43
+
44
+ def test_associate_new_by_building
45
+ assert_queries(1) { posts(:thinking) }
46
+
47
+ assert_queries(0) do
48
+ posts(:thinking).people.build(:first_name=>"Bob")
49
+ posts(:thinking).people.new(:first_name=>"Ted")
50
+ end
51
+
52
+ # Should only need to load the association once
53
+ assert_queries(1) do
54
+ assert posts(:thinking).people.collect(&:first_name).include?("Bob")
55
+ assert posts(:thinking).people.collect(&:first_name).include?("Ted")
56
+ end
57
+
58
+ # 2 queries for each new record (1 to save the record itself, 1 for the join model)
59
+ # * 2 new records = 4
60
+ # + 1 query to save the actual post = 5
61
+ assert_queries(5) do
62
+ posts(:thinking).body += '-changed'
63
+ posts(:thinking).save
64
+ end
65
+
66
+ assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Bob")
67
+ assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Ted")
68
+ end
69
+
70
+ def test_delete_association
71
+ assert_queries(2){posts(:welcome);people(:michael); }
72
+
73
+ assert_queries(1) do
74
+ posts(:welcome).people.delete(people(:michael))
75
+ end
76
+
77
+ assert_queries(1) do
78
+ assert posts(:welcome).people.empty?
79
+ end
80
+
81
+ assert posts(:welcome).reload.people(true).empty?
82
+ end
83
+
84
+ def test_replace_association
85
+ assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)}
86
+
87
+ # 1 query to delete the existing reader (michael)
88
+ # 1 query to associate the new reader (david)
89
+ assert_queries(2) do
90
+ posts(:welcome).people = [people(:david)]
91
+ end
92
+
93
+ assert_queries(0){
94
+ assert posts(:welcome).people.include?(people(:david))
95
+ assert !posts(:welcome).people.include?(people(:michael))
96
+ }
97
+
98
+ assert posts(:welcome).reload.people(true).include?(people(:david))
99
+ assert !posts(:welcome).reload.people(true).include?(people(:michael))
100
+ end
101
+
102
+ def test_associate_with_create
103
+ assert_queries(1) { posts(:thinking) }
104
+
105
+ # 1 query for the new record, 1 for the join table record
106
+ # No need to update the actual collection yet!
107
+ assert_queries(2) do
108
+ posts(:thinking).people.create(:first_name=>"Jeb")
109
+ end
110
+
111
+ # *Now* we actually need the collection so it's loaded
112
+ assert_queries(1) do
113
+ assert posts(:thinking).people.collect(&:first_name).include?("Jeb")
114
+ end
115
+
116
+ assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb")
117
+ end
118
+
119
+ def test_associate_with_create_and_no_options
120
+ peeps = posts(:thinking).people.count
121
+ posts(:thinking).people.create(:first_name => 'foo')
122
+ assert_equal peeps + 1, posts(:thinking).people.count
123
+ end
124
+
125
+ def test_associate_with_create_exclamation_and_no_options
126
+ peeps = posts(:thinking).people.count
127
+ posts(:thinking).people.create!(:first_name => 'foo')
128
+ assert_equal peeps + 1, posts(:thinking).people.count
129
+ end
130
+
131
+ def test_clear_associations
132
+ assert_queries(2) { posts(:welcome);posts(:welcome).people(true) }
133
+
134
+ assert_queries(1) do
135
+ posts(:welcome).people.clear
136
+ end
137
+
138
+ assert_queries(0) do
139
+ assert posts(:welcome).people.empty?
140
+ end
141
+
142
+ assert posts(:welcome).reload.people(true).empty?
143
+ end
144
+
145
+ def test_association_callback_ordering
146
+ Post.reset_log
147
+ log = Post.log
148
+ post = posts(:thinking)
149
+
150
+ post.people_with_callbacks << people(:michael)
151
+ assert_equal [
152
+ [:added, :before, "Michael"],
153
+ [:added, :after, "Michael"]
154
+ ], log.last(2)
155
+
156
+ post.people_with_callbacks.push(people(:david), Person.create!(:first_name => "Bob"), Person.new(:first_name => "Lary"))
157
+ assert_equal [
158
+ [:added, :before, "David"],
159
+ [:added, :after, "David"],
160
+ [:added, :before, "Bob"],
161
+ [:added, :after, "Bob"],
162
+ [:added, :before, "Lary"],
163
+ [:added, :after, "Lary"]
164
+ ],log.last(6)
165
+
166
+ post.people_with_callbacks.build(:first_name => "Ted")
167
+ assert_equal [
168
+ [:added, :before, "Ted"],
169
+ [:added, :after, "Ted"]
170
+ ], log.last(2)
171
+
172
+ post.people_with_callbacks.create(:first_name => "Sam")
173
+ assert_equal [
174
+ [:added, :before, "Sam"],
175
+ [:added, :after, "Sam"]
176
+ ], log.last(2)
177
+
178
+ post.people_with_callbacks = [people(:michael),people(:david), Person.new(:first_name => "Julian"), Person.create!(:first_name => "Roger")]
179
+ assert_equal (%w(Ted Bob Sam Lary) * 2).sort, log[-12..-5].collect(&:last).sort
180
+ assert_equal [
181
+ [:added, :before, "Julian"],
182
+ [:added, :after, "Julian"],
183
+ [:added, :before, "Roger"],
184
+ [:added, :after, "Roger"]
185
+ ], log.last(4)
186
+
187
+ post.people_with_callbacks.clear
188
+ assert_equal (%w(Michael David Julian Roger) * 2).sort, log.last(8).collect(&:last).sort
189
+ end
190
+
191
+ unless current_adapter?(:IBM_DBAdapter) #refer db2 ? SQL0214N
192
+ def test_dynamic_find_should_respect_association_include
193
+ # SQL error in sort clause if :include is not included
194
+ # due to Unknown column 'comments.id'
195
+ assert Person.find(1).posts_with_comments_sorted_by_comment_id.find_by_title('Welcome to the weblog')
196
+ end
197
+ end
198
+
199
+ def test_count_with_include_should_alias_join_table
200
+ assert_equal 2, people(:michael).posts.count(:include => :readers)
201
+ end
202
+ end
@@ -783,6 +783,12 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
783
783
  assert ! david.categories.include?(category)
784
784
  end
785
785
  end
786
+ def test_has_many_through_goes_through_all_sti_classes
787
+ sub_sti_post = SubStiPost.create!(:title => 'test', :body => 'test', :author_id => 1)
788
+ new_comment = sub_sti_post.comments.create(:body => 'test')
789
+
790
+ assert_equal [9, 10, new_comment.id], authors(:david).sti_post_comments.map(&:id).sort
791
+ end
786
792
 
787
793
  private
788
794
  # create dynamic Post models to allow different dependency options
@@ -19,6 +19,7 @@ require 'models/warehouse_thing'
19
19
  require 'rexml/document'
20
20
 
21
21
  class Category < ActiveRecord::Base; end
22
+ class Categorization < ActiveRecord::Base; end
22
23
  class Smarts < ActiveRecord::Base; end
23
24
  class CreditCard < ActiveRecord::Base
24
25
  class PinNumber < ActiveRecord::Base
@@ -75,8 +76,8 @@ class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
75
76
  end
76
77
 
77
78
  class BasicsTest < ActiveRecord::TestCase
78
- fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, :warehouse_things, :authors
79
-
79
+ fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, :warehouse_things, :authors, :categorizations, :categories
80
+
80
81
  def test_table_exists
81
82
  assert !NonExistentTable.table_exists?
82
83
  assert Topic.table_exists?
@@ -130,7 +131,7 @@ class BasicsTest < ActiveRecord::TestCase
130
131
 
131
132
  def test_read_attributes_before_type_cast
132
133
  category = Category.new({:name=>"Test categoty", :type => nil})
133
- category_attrs = {"name"=>"Test categoty", "type" => nil}
134
+ category_attrs = {"name"=>"Test categoty", "type" => nil, "categorizations_count" => nil}
134
135
  assert_equal category_attrs , category.attributes_before_type_cast
135
136
  end
136
137
 
@@ -434,12 +435,12 @@ class BasicsTest < ActiveRecord::TestCase
434
435
  # Sybase ctlib does not (yet?) support the date type; use datetime instead.
435
436
  # Oracle treats all dates/times as Time.
436
437
  assert_kind_of(
437
- Time, Topic.find(1).last_read,
438
+ Time, Topic.find(1).last_read,
438
439
  "The last_read attribute should be of the Time class"
439
440
  )
440
441
  else
441
442
  assert_kind_of(
442
- Date, Topic.find(1).last_read,
443
+ Date, Topic.find(1).last_read,
443
444
  "The last_read attribute should be of the Date class"
444
445
  )
445
446
  end
@@ -447,12 +448,12 @@ class BasicsTest < ActiveRecord::TestCase
447
448
 
448
449
  def test_preserving_time_objects
449
450
  assert_kind_of(
450
- Time, Topic.find(1).bonus_time,
451
+ Time, Topic.find(1).bonus_time,
451
452
  "The bonus_time attribute should be of the Time class"
452
453
  )
453
454
 
454
455
  assert_kind_of(
455
- Time, Topic.find(1).written_on,
456
+ Time, Topic.find(1).written_on,
456
457
  "The written_on attribute should be of the Time class"
457
458
  )
458
459
 
@@ -613,7 +614,23 @@ class BasicsTest < ActiveRecord::TestCase
613
614
  Topic.decrement_counter("replies_count", 2)
614
615
  assert_equal -2, Topic.find(2).replies_count
615
616
  end
616
-
617
+
618
+ def test_update_counter
619
+ category = categories(:general)
620
+ assert_nil category.categorizations_count
621
+ assert_equal 2, category.categorizations.count
622
+
623
+ Category.update_counters(category.id, "categorizations_count" => category.categorizations.count)
624
+ category.reload
625
+ assert_not_nil category.categorizations_count
626
+ assert_equal 2, category.categorizations_count
627
+
628
+ Category.update_counters(category.id, "categorizations_count" => category.categorizations.count)
629
+ category.reload
630
+ assert_not_nil category.categorizations_count
631
+ assert_equal 4, category.categorizations_count
632
+ end
633
+
617
634
  def test_update_all
618
635
  assert_equal Topic.count, Topic.update_all("content = 'bulk updated!'")
619
636
  assert_equal "bulk updated!", Topic.find(1).content
@@ -863,7 +880,7 @@ class BasicsTest < ActiveRecord::TestCase
863
880
 
864
881
  def test_mass_assignment_protection_against_class_attribute_writers
865
882
  [:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :colorize_logging,
866
- :default_timezone, :allow_concurrency, :schema_format, :verification_timeout, :lock_optimistically, :record_timestamps].each do |method|
883
+ :default_timezone, :allow_concurrency, :schema_format, :verification_timeout, :lock_optimistically, :record_timestamps].each do |method|
867
884
  assert Task.respond_to?(method)
868
885
  assert Task.respond_to?("#{method}=")
869
886
  assert Task.new.respond_to?(method)
@@ -998,7 +1015,7 @@ class BasicsTest < ActiveRecord::TestCase
998
1015
  def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
999
1016
  ActiveRecord::Base.time_zone_aware_attributes = true
1000
1017
  ActiveRecord::Base.default_timezone = :utc
1001
- Time.zone = TimeZone[-28800]
1018
+ Time.zone = ActiveSupport::TimeZone[-28800]
1002
1019
  attributes = {
1003
1020
  "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
1004
1021
  "written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
@@ -1016,7 +1033,7 @@ class BasicsTest < ActiveRecord::TestCase
1016
1033
 
1017
1034
  def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
1018
1035
  ActiveRecord::Base.time_zone_aware_attributes = false
1019
- Time.zone = TimeZone[-28800]
1036
+ Time.zone = ActiveSupport::TimeZone[-28800]
1020
1037
  attributes = {
1021
1038
  "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
1022
1039
  "written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
@@ -1032,7 +1049,7 @@ class BasicsTest < ActiveRecord::TestCase
1032
1049
  def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_attributes
1033
1050
  ActiveRecord::Base.time_zone_aware_attributes = true
1034
1051
  ActiveRecord::Base.default_timezone = :utc
1035
- Time.zone = TimeZone[-28800]
1052
+ Time.zone = ActiveSupport::TimeZone[-28800]
1036
1053
  Topic.skip_time_zone_conversion_for_attributes = [:written_on]
1037
1054
  attributes = {
1038
1055
  "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
@@ -1049,6 +1066,24 @@ class BasicsTest < ActiveRecord::TestCase
1049
1066
  Topic.skip_time_zone_conversion_for_attributes = []
1050
1067
  end
1051
1068
 
1069
+ def test_multiparameter_attributes_on_time_only_column_with_time_zone_aware_attributes_does_not_do_time_zone_conversion
1070
+ ActiveRecord::Base.time_zone_aware_attributes = true
1071
+ ActiveRecord::Base.default_timezone = :utc
1072
+ Time.zone = ActiveSupport::TimeZone[-28800]
1073
+ attributes = {
1074
+ "bonus_time(1i)" => "2000", "bonus_time(2i)" => "1", "bonus_time(3i)" => "1",
1075
+ "bonus_time(4i)" => "16", "bonus_time(5i)" => "24"
1076
+ }
1077
+ topic = Topic.find(1)
1078
+ topic.attributes = attributes
1079
+ assert_equal Time.utc(2000, 1, 1, 16, 24, 0), topic.bonus_time
1080
+ assert topic.bonus_time.utc?
1081
+ ensure
1082
+ ActiveRecord::Base.time_zone_aware_attributes = false
1083
+ ActiveRecord::Base.default_timezone = :local
1084
+ Time.zone = nil
1085
+ end
1086
+
1052
1087
  def test_multiparameter_attributes_on_time_with_empty_seconds
1053
1088
  attributes = {
1054
1089
  "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
@@ -1197,13 +1232,13 @@ class BasicsTest < ActiveRecord::TestCase
1197
1232
  # values can be a mix of float or integer
1198
1233
 
1199
1234
  g = Geometric.new(
1200
- :a_point => '(5.0, 6.1)',
1201
- #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
1202
- :a_line_segment => '(2.0, 3), (5.5, 7.0)',
1203
- :a_box => '2.0, 3, 5.5, 7.0',
1204
- :a_path => '[(2.0, 3), (5.5, 7.0), (8.5, 11.0)]', # [ ] is an open path
1205
- :a_polygon => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))',
1206
- :a_circle => '<(5.3, 10.4), 2>'
1235
+ :a_point => '(5.0, 6.1)',
1236
+ #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
1237
+ :a_line_segment => '(2.0, 3), (5.5, 7.0)',
1238
+ :a_box => '2.0, 3, 5.5, 7.0',
1239
+ :a_path => '[(2.0, 3), (5.5, 7.0), (8.5, 11.0)]', # [ ] is an open path
1240
+ :a_polygon => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))',
1241
+ :a_circle => '<(5.3, 10.4), 2>'
1207
1242
  )
1208
1243
 
1209
1244
  assert g.save
@@ -1225,13 +1260,13 @@ class BasicsTest < ActiveRecord::TestCase
1225
1260
  # test alternate formats when defining the geometric types
1226
1261
 
1227
1262
  g = Geometric.new(
1228
- :a_point => '5.0, 6.1',
1229
- #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
1230
- :a_line_segment => '((2.0, 3), (5.5, 7.0))',
1231
- :a_box => '(2.0, 3), (5.5, 7.0)',
1232
- :a_path => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))', # ( ) is a closed path
1233
- :a_polygon => '2.0, 3, 5.5, 7.0, 8.5, 11.0',
1234
- :a_circle => '((5.3, 10.4), 2)'
1263
+ :a_point => '5.0, 6.1',
1264
+ #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
1265
+ :a_line_segment => '((2.0, 3), (5.5, 7.0))',
1266
+ :a_box => '(2.0, 3), (5.5, 7.0)',
1267
+ :a_path => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))', # ( ) is a closed path
1268
+ :a_polygon => '2.0, 3, 5.5, 7.0, 8.5, 11.0',
1269
+ :a_circle => '((5.3, 10.4), 2)'
1235
1270
  )
1236
1271
 
1237
1272
  assert g.save
@@ -1258,10 +1293,10 @@ class BasicsTest < ActiveRecord::TestCase
1258
1293
 
1259
1294
  def test_numeric_fields
1260
1295
  m = NumericData.new(
1261
- :bank_balance => 1586.43,
1262
- :big_bank_balance => BigDecimal("1000234000567.95"),
1263
- :world_population => 6000000000,
1264
- :my_house_population => 3
1296
+ :bank_balance => 1586.43,
1297
+ :big_bank_balance => BigDecimal("1000234000567.95"),
1298
+ :world_population => 6000000000,
1299
+ :my_house_population => 3
1265
1300
  )
1266
1301
  assert m.save
1267
1302
 
@@ -1342,7 +1377,13 @@ class BasicsTest < ActiveRecord::TestCase
1342
1377
  Topic.serialize("content", MyObject)
1343
1378
  assert_equal(myobj, topic.content)
1344
1379
  end
1345
-
1380
+
1381
+ def test_serialized_time_attribute
1382
+ myobj = Time.local(2008,1,1,1,0)
1383
+ topic = Topic.create("content" => myobj).reload
1384
+ assert_equal(myobj, topic.content)
1385
+ end
1386
+
1346
1387
  def test_nil_serialized_attribute_with_class_constraint
1347
1388
  myobj = MyObject.new('value1', 'value2')
1348
1389
  topic = Topic.new
@@ -1533,7 +1574,7 @@ class BasicsTest < ActiveRecord::TestCase
1533
1574
  res3 = nil
1534
1575
  assert_nothing_raised do
1535
1576
  res3 = Post.count(:conditions => "posts.#{QUOTED_TYPE} = 'Post'",
1536
- :joins => "LEFT JOIN comments ON posts.id=comments.post_id")
1577
+ :joins => "LEFT JOIN comments ON posts.id=comments.post_id")
1537
1578
  end
1538
1579
  assert_equal res, res3
1539
1580
 
@@ -1552,9 +1593,9 @@ class BasicsTest < ActiveRecord::TestCase
1552
1593
  res7 = nil
1553
1594
  assert_nothing_raised do
1554
1595
  res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id",
1555
- :joins => "p, comments co",
1556
- :select => "p.id",
1557
- :distinct => true)
1596
+ :joins => "p, comments co",
1597
+ :select => "p.id",
1598
+ :distinct => true)
1558
1599
  end
1559
1600
  assert_equal res6, res7
1560
1601
  end
@@ -1569,17 +1610,17 @@ class BasicsTest < ActiveRecord::TestCase
1569
1610
  end
1570
1611
 
1571
1612
  def test_clear_association_cache_new_record
1572
- firm = Firm.new
1573
- client_stored = Client.find(3)
1574
- client_new = Client.new
1575
- client_new.name = "The Joneses"
1576
- clients = [ client_stored, client_new ]
1577
-
1578
- firm.clients << clients
1579
- assert_equal clients.map(&:name).to_set, firm.clients.map(&:name).to_set
1580
-
1581
- firm.clear_association_cache
1582
- assert_equal clients.map(&:name).to_set, firm.clients.map(&:name).to_set
1613
+ firm = Firm.new
1614
+ client_stored = Client.find(3)
1615
+ client_new = Client.new
1616
+ client_new.name = "The Joneses"
1617
+ clients = [ client_stored, client_new ]
1618
+
1619
+ firm.clients << clients
1620
+ assert_equal clients.map(&:name).to_set, firm.clients.map(&:name).to_set
1621
+
1622
+ firm.clear_association_cache
1623
+ assert_equal clients.map(&:name).to_set, firm.clients.map(&:name).to_set
1583
1624
  end
1584
1625
 
1585
1626
  def test_interpolate_sql
@@ -1856,8 +1897,8 @@ class BasicsTest < ActiveRecord::TestCase
1856
1897
 
1857
1898
  def test_to_xml_including_multiple_associations_with_options
1858
1899
  xml = companies(:first_firm).to_xml(
1859
- :indent => 0, :skip_instruct => true,
1860
- :include => { :clients => { :only => :name } }
1900
+ :indent => 0, :skip_instruct => true,
1901
+ :include => { :clients => { :only => :name } }
1861
1902
  )
1862
1903
 
1863
1904
  assert_equal "<firm>", xml.first(6)