ibm_db 2.5.9-x86-mingw32 → 2.5.10-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,15 +17,16 @@ require 'rexml/document'
17
17
  require 'active_support/core_ext/exception'
18
18
 
19
19
  class PersistencesTest < ActiveRecord::TestCase
20
+ fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics,
21
+ 'warehouse_things', :authors, :categorizations, :categories, :posts, :minivans
20
22
 
21
- fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse_things', :authors, :categorizations, :categories, :posts, :minivans
22
-
23
- # Oracle UPDATE does not support ORDER BY
24
- unless current_adapter?(:OracleAdapter)
23
+ # Skip databases that don't support UPDATE + ORDER BY
24
+ unless current_adapter?(:OracleAdapter, :PostgreSQLAdapter)
25
25
  def test_update_all_ignores_order_without_limit_from_association
26
26
  author = authors(:david)
27
27
  assert_nothing_raised do
28
- assert_equal author.posts_with_comments_and_categories.length, author.posts_with_comments_and_categories.update_all([ "body = ?", "bulk update!" ])
28
+ assert_equal author.posts_with_comments_and_categories.length,
29
+ author.posts_with_comments_and_categories.update_all([ "body = ?", "bulk update!" ])
29
30
  end
30
31
  end
31
32
 
@@ -203,9 +204,12 @@ class PersistencesTest < ActiveRecord::TestCase
203
204
  end
204
205
 
205
206
  def test_create_columns_not_equal_attributes
206
- topic = Topic.new
207
- topic.title = 'Another New Topic'
208
- topic.send :write_attribute, 'does_not_exist', 'test'
207
+ topic = Topic.allocate.init_with(
208
+ 'attributes' => {
209
+ 'title' => 'Another New Topic',
210
+ 'does_not_exist' => 'test'
211
+ }
212
+ )
209
213
  assert_nothing_raised { topic.save }
210
214
  end
211
215
 
@@ -250,9 +254,11 @@ class PersistencesTest < ActiveRecord::TestCase
250
254
  topic.title = "Still another topic"
251
255
  topic.save
252
256
 
253
- topicReloaded = Topic.find(topic.id)
254
- topicReloaded.title = "A New Topic"
255
- topicReloaded.send :write_attribute, 'does_not_exist', 'test'
257
+ topicReloaded = Topic.allocate
258
+ topicReloaded.init_with(
259
+ 'attributes' => topic.attributes.merge('does_not_exist' => 'test')
260
+ )
261
+ topicReloaded.title = 'A New Topic'
256
262
  assert_nothing_raised { topicReloaded.save }
257
263
  end
258
264
 
@@ -147,13 +147,16 @@ class QueryCacheTest < ActiveRecord::TestCase
147
147
  end
148
148
 
149
149
  def test_cache_does_not_wrap_string_results_in_arrays
150
- require 'sqlite3/version' if current_adapter?(:SQLite3Adapter)
150
+ if current_adapter?(:SQLite3Adapter)
151
+ require 'sqlite3/version'
152
+ sqlite3_version = RUBY_PLATFORM =~ /java/ ? Jdbc::SQLite3::VERSION : SQLite3::VERSION
153
+ end
151
154
 
152
155
  Task.cache do
153
156
  # Oracle adapter returns count() as Fixnum or Float
154
157
  if current_adapter?(:OracleAdapter,:IBM_DBAdapter)
155
158
  assert_kind_of Numeric, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
156
- elsif current_adapter?(:SQLite3Adapter) && SQLite3::VERSION > '1.2.5' || current_adapter?(:Mysql2Adapter) || current_adapter?(:MysqlAdapter)
159
+ elsif current_adapter?(:SQLite3Adapter) && sqlite3_version > '1.2.5' || current_adapter?(:Mysql2Adapter) || current_adapter?(:MysqlAdapter)
157
160
  # Future versions of the sqlite3 adapter will return numeric
158
161
  assert_instance_of Fixnum,
159
162
  Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
@@ -167,6 +170,18 @@ end
167
170
  class QueryCacheExpiryTest < ActiveRecord::TestCase
168
171
  fixtures :tasks, :posts, :categories, :categories_posts
169
172
 
173
+ def test_cache_gets_cleared_after_migration
174
+ # warm the cache
175
+ Post.find(1)
176
+
177
+ # change the column definition
178
+ Post.connection.change_column :posts, :title, :string, :limit => 80
179
+ assert_nothing_raised { Post.find(1) }
180
+
181
+ # restore the old definition
182
+ Post.connection.change_column :posts, :title, :string
183
+ end
184
+
170
185
  def test_find
171
186
  Task.connection.expects(:clear_query_cache).times(1)
172
187
 
@@ -234,7 +249,7 @@ class QueryCacheBodyProxyTest < ActiveRecord::TestCase
234
249
 
235
250
  test "is polite to it's body and responds to it" do
236
251
  body = Class.new(String) { def to_path; "/path"; end }.new
237
- proxy = ActiveRecord::QueryCache::BodyProxy.new(nil, body)
252
+ proxy = ActiveRecord::QueryCache::BodyProxy.new(nil, body, ActiveRecord::Base.connection_id)
238
253
  assert proxy.respond_to?(:to_path)
239
254
  assert_equal proxy.to_path, "/path"
240
255
  end
@@ -391,6 +391,15 @@ class RelationTest < ActiveRecord::TestCase
391
391
  assert_equal Post.find(1).last_comment, post.last_comment
392
392
  end
393
393
 
394
+ def test_dynamic_find_by_attributes_should_yield_found_object
395
+ david = authors(:david)
396
+ yielded_value = nil
397
+ Author.find_by_name(david.name) do |author|
398
+ yielded_value = author
399
+ end
400
+ assert_equal david, yielded_value
401
+ end
402
+
394
403
  def test_dynamic_find_by_attributes
395
404
  david = authors(:david)
396
405
  author = Author.preload(:taggings).find_by_id(david.id)
@@ -440,6 +449,18 @@ class RelationTest < ActiveRecord::TestCase
440
449
  assert_equal authors(:david), authors.find_or_create_by_name(:name => 'David')
441
450
  end
442
451
 
452
+ def test_dynamic_find_or_create_by_attributes_bang
453
+ authors = Author.scoped
454
+
455
+ assert_raises(ActiveRecord::RecordInvalid) { authors.find_or_create_by_name!('') }
456
+
457
+ lifo = authors.find_or_create_by_name!('Lifo')
458
+ assert_equal "Lifo", lifo.name
459
+ assert lifo.persisted?
460
+
461
+ assert_equal authors(:david), authors.find_or_create_by_name!(:name => 'David')
462
+ end
463
+
443
464
  def test_find_id
444
465
  authors = Author.scoped
445
466
 
@@ -653,7 +674,7 @@ class RelationTest < ActiveRecord::TestCase
653
674
  def test_relation_merging_with_preload
654
675
  ActiveRecord::IdentityMap.without do
655
676
  [Post.scoped.merge(Post.preload(:author)), Post.preload(:author).merge(Post.scoped)].each do |posts|
656
- assert_queries(2) { assert posts.first.author }
677
+ assert_queries(2) { assert posts.order(:id).first.author }
657
678
  end
658
679
  end
659
680
  end
@@ -854,6 +875,128 @@ class RelationTest < ActiveRecord::TestCase
854
875
  assert_equal 'hen', hen.name
855
876
  end
856
877
 
878
+ def test_first_or_create
879
+ parrot = Bird.where(:color => 'green').first_or_create(:name => 'parrot')
880
+ assert_kind_of Bird, parrot
881
+ assert parrot.persisted?
882
+ assert_equal 'parrot', parrot.name
883
+ assert_equal 'green', parrot.color
884
+
885
+ same_parrot = Bird.where(:color => 'green').first_or_create(:name => 'parakeet')
886
+ assert_kind_of Bird, same_parrot
887
+ assert same_parrot.persisted?
888
+ assert_equal parrot, same_parrot
889
+ end
890
+
891
+ def test_first_or_create_with_no_parameters
892
+ parrot = Bird.where(:color => 'green').first_or_create
893
+ assert_kind_of Bird, parrot
894
+ assert !parrot.persisted?
895
+ assert_equal 'green', parrot.color
896
+ end
897
+
898
+ def test_first_or_create_with_block
899
+ parrot = Bird.where(:color => 'green').first_or_create { |bird| bird.name = 'parrot' }
900
+ assert_kind_of Bird, parrot
901
+ assert parrot.persisted?
902
+ assert_equal 'green', parrot.color
903
+ assert_equal 'parrot', parrot.name
904
+
905
+ same_parrot = Bird.where(:color => 'green').first_or_create { |bird| bird.name = 'parakeet' }
906
+ assert_equal parrot, same_parrot
907
+ end
908
+
909
+ def test_first_or_create_with_array
910
+ several_green_birds = Bird.where(:color => 'green').first_or_create([{:name => 'parrot'}, {:name => 'parakeet'}])
911
+ assert_kind_of Array, several_green_birds
912
+ several_green_birds.each { |bird| assert bird.persisted? }
913
+
914
+ same_parrot = Bird.where(:color => 'green').first_or_create([{:name => 'hummingbird'}, {:name => 'macaw'}])
915
+ assert_kind_of Bird, same_parrot
916
+ assert_equal several_green_birds.first, same_parrot
917
+ end
918
+
919
+ def test_first_or_create_bang_with_valid_options
920
+ parrot = Bird.where(:color => 'green').first_or_create!(:name => 'parrot')
921
+ assert_kind_of Bird, parrot
922
+ assert parrot.persisted?
923
+ assert_equal 'parrot', parrot.name
924
+ assert_equal 'green', parrot.color
925
+
926
+ same_parrot = Bird.where(:color => 'green').first_or_create!(:name => 'parakeet')
927
+ assert_kind_of Bird, same_parrot
928
+ assert same_parrot.persisted?
929
+ assert_equal parrot, same_parrot
930
+ end
931
+
932
+ def test_first_or_create_bang_with_invalid_options
933
+ assert_raises(ActiveRecord::RecordInvalid) { Bird.where(:color => 'green').first_or_create!(:pirate_id => 1) }
934
+ end
935
+
936
+ def test_first_or_create_bang_with_no_parameters
937
+ assert_raises(ActiveRecord::RecordInvalid) { Bird.where(:color => 'green').first_or_create! }
938
+ end
939
+
940
+ def test_first_or_create_bang_with_valid_block
941
+ parrot = Bird.where(:color => 'green').first_or_create! { |bird| bird.name = 'parrot' }
942
+ assert_kind_of Bird, parrot
943
+ assert parrot.persisted?
944
+ assert_equal 'green', parrot.color
945
+ assert_equal 'parrot', parrot.name
946
+
947
+ same_parrot = Bird.where(:color => 'green').first_or_create! { |bird| bird.name = 'parakeet' }
948
+ assert_equal parrot, same_parrot
949
+ end
950
+
951
+ def test_first_or_create_bang_with_invalid_block
952
+ assert_raise(ActiveRecord::RecordInvalid) do
953
+ Bird.where(:color => 'green').first_or_create! { |bird| bird.pirate_id = 1 }
954
+ end
955
+ end
956
+
957
+ def test_first_or_create_with_valid_array
958
+ several_green_birds = Bird.where(:color => 'green').first_or_create!([{:name => 'parrot'}, {:name => 'parakeet'}])
959
+ assert_kind_of Array, several_green_birds
960
+ several_green_birds.each { |bird| assert bird.persisted? }
961
+
962
+ same_parrot = Bird.where(:color => 'green').first_or_create!([{:name => 'hummingbird'}, {:name => 'macaw'}])
963
+ assert_kind_of Bird, same_parrot
964
+ assert_equal several_green_birds.first, same_parrot
965
+ end
966
+
967
+ def test_first_or_create_with_invalid_array
968
+ assert_raises(ActiveRecord::RecordInvalid) { Bird.where(:color => 'green').first_or_create!([ {:name => 'parrot'}, {:pirate_id => 1} ]) }
969
+ end
970
+
971
+ def test_first_or_initialize
972
+ parrot = Bird.where(:color => 'green').first_or_initialize(:name => 'parrot')
973
+ assert_kind_of Bird, parrot
974
+ assert !parrot.persisted?
975
+ assert parrot.valid?
976
+ assert parrot.new_record?
977
+ assert_equal 'parrot', parrot.name
978
+ assert_equal 'green', parrot.color
979
+ end
980
+
981
+ def test_first_or_initialize_with_no_parameters
982
+ parrot = Bird.where(:color => 'green').first_or_initialize
983
+ assert_kind_of Bird, parrot
984
+ assert !parrot.persisted?
985
+ assert !parrot.valid?
986
+ assert parrot.new_record?
987
+ assert_equal 'green', parrot.color
988
+ end
989
+
990
+ def test_first_or_initialize_with_block
991
+ parrot = Bird.where(:color => 'green').first_or_initialize { |bird| bird.name = 'parrot' }
992
+ assert_kind_of Bird, parrot
993
+ assert !parrot.persisted?
994
+ assert parrot.valid?
995
+ assert parrot.new_record?
996
+ assert_equal 'green', parrot.color
997
+ assert_equal 'parrot', parrot.name
998
+ end
999
+
857
1000
  def test_explicit_create_scope
858
1001
  hens = Bird.where(:name => 'hen')
859
1002
  assert_equal 'hen', hens.new.name
@@ -976,6 +1119,10 @@ class RelationTest < ActiveRecord::TestCase
976
1119
  assert scope.eager_loading?
977
1120
  end
978
1121
 
1122
+ def test_ordering_with_extra_spaces
1123
+ assert_equal authors(:david), Author.order('id DESC , name DESC').last
1124
+ end
1125
+
979
1126
  def test_update_all_with_joins
980
1127
  comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id)
981
1128
  count = comments.count
@@ -996,24 +1143,40 @@ class RelationTest < ActiveRecord::TestCase
996
1143
  assert_equal posts(:welcome), comments(:more_greetings).post
997
1144
  end
998
1145
 
999
- unless current_adapter?(:IBM_DBAdapter)
1146
+ unless current_adapter?(:IBM_DBAdapter)
1000
1147
  #IBM_DB does not support offset on subselect of the update statement
1001
- def test_update_all_with_joins_and_offset
1002
- all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id)
1003
- count = all_comments.count
1004
- comments = all_comments.offset(1)
1148
+ def test_update_all_with_joins_and_offset
1149
+ all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id)
1150
+ count = all_comments.count
1151
+ comments = all_comments.offset(1)
1005
1152
 
1006
- assert_equal count - 1, comments.update_all(:post_id => posts(:thinking).id)
1007
- end
1153
+ assert_equal count - 1, comments.update_all(:post_id => posts(:thinking).id)
1154
+ end
1155
+
1156
+ def test_update_all_with_joins_and_offset_and_order
1157
+ all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id).order('posts.id', 'comments.id')
1158
+ count = all_comments.count
1159
+ comments = all_comments.offset(1)
1008
1160
 
1009
- def test_update_all_with_joins_and_offset_and_order
1010
- all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id).order('posts.id', 'comments.id')
1011
- count = all_comments.count
1012
- comments = all_comments.offset(1)
1161
+ assert_equal count - 1, comments.update_all(:post_id => posts(:thinking).id)
1162
+ assert_equal posts(:thinking), comments(:more_greetings).post
1163
+ assert_equal posts(:welcome), comments(:greetings).post
1164
+ end
1165
+ end
1013
1166
 
1014
- assert_equal count - 1, comments.update_all(:post_id => posts(:thinking).id)
1015
- assert_equal posts(:thinking), comments(:more_greetings).post
1016
- assert_equal posts(:welcome), comments(:greetings).post
1167
+ def test_uniq
1168
+ tag1 = Tag.create(:name => 'Foo')
1169
+ tag2 = Tag.create(:name => 'Foo')
1170
+
1171
+ query = Tag.select(:name).where(:id => [tag1.id, tag2.id])
1172
+
1173
+ assert_equal ['Foo', 'Foo'], query.map(&:name)
1174
+ assert_sql(/DISTINCT/) do
1175
+ assert_equal ['Foo'], query.uniq.map(&:name)
1176
+ end
1177
+ assert_sql(/DISTINCT/) do
1178
+ assert_equal ['Foo'], query.uniq(true).map(&:name)
1017
1179
  end
1180
+ assert_equal ['Foo', 'Foo'], query.uniq(true).uniq(false).map(&:name)
1018
1181
  end
1019
1182
  end
@@ -1,5 +1,4 @@
1
1
  require "cases/helper"
2
- require 'active_support/core_ext/string/encoding'
3
2
 
4
3
 
5
4
  class SchemaDumperTest < ActiveRecord::TestCase
@@ -249,4 +248,9 @@ class SchemaDumperTest < ActiveRecord::TestCase
249
248
  assert_match %r(:id => false), match[1], "no table id not preserved"
250
249
  assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
251
250
  end
251
+
252
+ def test_schema_dump_keeps_id_false_when_id_is_false_and_unique_not_null_column_added
253
+ output = standard_dump
254
+ assert_match %r{create_table "subscribers", :id => false}, output
255
+ end
252
256
  end
@@ -6,7 +6,7 @@ class TransactionCallbacksTest < ActiveRecord::TestCase
6
6
  fixtures :topics
7
7
 
8
8
  class TopicWithCallbacks < ActiveRecord::Base
9
- set_table_name :topics
9
+ self.table_name = :topics
10
10
 
11
11
  after_commit{|record| record.send(:do_after_commit, nil)}
12
12
  after_commit(:on => :create){|record| record.send(:do_after_commit, :create)}
@@ -260,7 +260,7 @@ class TransactionObserverCallbacksTest < ActiveRecord::TestCase
260
260
  fixtures :topics
261
261
 
262
262
  class TopicWithObserverAttached < ActiveRecord::Base
263
- set_table_name :topics
263
+ self.table_name = :topics
264
264
  def history
265
265
  @history ||= []
266
266
  end
@@ -5,6 +5,9 @@ require 'models/author'
5
5
  require 'models/comment'
6
6
  require 'models/company_in_module'
7
7
  require 'models/toy'
8
+ require 'models/topic'
9
+ require 'models/reply'
10
+ require 'models/company'
8
11
 
9
12
  class XmlSerializationTest < ActiveRecord::TestCase
10
13
  def test_should_serialize_default_root
@@ -50,6 +53,23 @@ class XmlSerializationTest < ActiveRecord::TestCase
50
53
  end
51
54
  assert_match %r{<creator>David</creator>}, @xml
52
55
  end
56
+
57
+ def test_to_xml_with_block
58
+ value = "Rockin' the block"
59
+ xml = Contact.new.to_xml(:skip_instruct => true) do |_xml|
60
+ _xml.tag! "arbitrary-element", value
61
+ end
62
+ assert_equal "<contact>", xml.first(9)
63
+ assert xml.include?(%(<arbitrary-element>#{value}</arbitrary-element>))
64
+ end
65
+
66
+ def test_should_skip_instruct_for_included_records
67
+ @contact = Contact.new
68
+ @contact.alternative = Contact.new(:name => 'Copa Cabana')
69
+ @xml = @contact.to_xml(:include => [ :alternative ])
70
+ assert_equal @xml.index('<?xml '), 0
71
+ assert_nil @xml.index('<?xml ', 1)
72
+ end
53
73
  end
54
74
 
55
75
  class DefaultXmlSerializationTest < ActiveRecord::TestCase
@@ -156,7 +176,63 @@ class NilXmlSerializationTest < ActiveRecord::TestCase
156
176
  end
157
177
 
158
178
  class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase
159
- fixtures :authors, :posts, :projects
179
+ fixtures :topics, :companies, :accounts, :authors, :posts, :projects
180
+
181
+ def test_to_xml
182
+ xml = REXML::Document.new(topics(:first).to_xml(:indent => 0))
183
+ bonus_time_in_current_timezone = topics(:first).bonus_time.xmlschema
184
+ written_on_in_current_timezone = topics(:first).written_on.xmlschema
185
+ last_read_in_current_timezone = topics(:first).last_read.xmlschema
186
+
187
+ assert_equal "topic", xml.root.name
188
+ assert_equal "The First Topic" , xml.elements["//title"].text
189
+ assert_equal "David" , xml.elements["//author-name"].text
190
+ assert_match "Have a nice day", xml.elements["//content"].text
191
+
192
+ assert_equal "1", xml.elements["//id"].text
193
+ assert_equal "integer" , xml.elements["//id"].attributes['type']
194
+
195
+ assert_equal "1", xml.elements["//replies-count"].text
196
+ assert_equal "integer" , xml.elements["//replies-count"].attributes['type']
197
+
198
+ assert_equal written_on_in_current_timezone, xml.elements["//written-on"].text
199
+ assert_equal "datetime" , xml.elements["//written-on"].attributes['type']
200
+
201
+ assert_equal "david@loudthinking.com", xml.elements["//author-email-address"].text
202
+
203
+ assert_equal nil, xml.elements["//parent-id"].text
204
+ assert_equal "integer", xml.elements["//parent-id"].attributes['type']
205
+ assert_equal "true", xml.elements["//parent-id"].attributes['nil']
206
+
207
+ if current_adapter?(:SybaseAdapter)
208
+ assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text
209
+ assert_equal "datetime" , xml.elements["//last-read"].attributes['type']
210
+ else
211
+ # Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
212
+ assert_equal "2004-04-15", xml.elements["//last-read"].text
213
+ assert_equal "date" , xml.elements["//last-read"].attributes['type']
214
+ end
215
+
216
+ # Oracle and DB2 don't have true boolean or time-only fields
217
+ unless current_adapter?(:OracleAdapter, :DB2Adapter)
218
+ assert_equal "false", xml.elements["//approved"].text
219
+ assert_equal "boolean" , xml.elements["//approved"].attributes['type']
220
+
221
+ assert_equal bonus_time_in_current_timezone, xml.elements["//bonus-time"].text
222
+ assert_equal "datetime" , xml.elements["//bonus-time"].attributes['type']
223
+ end
224
+ end
225
+
226
+ def test_except_option
227
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :except => [:title, :replies_count])
228
+ assert_equal "<topic>", xml.first(7)
229
+ assert !xml.include?(%(<title>The First Topic</title>))
230
+ assert xml.include?(%(<author-name>David</author-name>))
231
+
232
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :except => [:title, :author_name, :replies_count])
233
+ assert !xml.include?(%(<title>The First Topic</title>))
234
+ assert !xml.include?(%(<author-name>David</author-name>))
235
+ end
160
236
 
161
237
  # to_xml used to mess with the hash the user provided which
162
238
  # caused the builder to be reused. This meant the document kept
@@ -192,6 +268,39 @@ class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase
192
268
  assert_match %r{<hello-post>}, xml
193
269
  end
194
270
 
271
+ def test_including_has_many_association
272
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :include => :replies, :except => :replies_count)
273
+ assert_equal "<topic>", xml.first(7)
274
+ assert xml.include?(%(<replies type="array"><reply>))
275
+ assert xml.include?(%(<title>The Second Topic of the day</title>))
276
+ end
277
+
278
+ def test_including_belongs_to_association
279
+ xml = companies(:first_client).to_xml(:indent => 0, :skip_instruct => true, :include => :firm)
280
+ assert !xml.include?("<firm>")
281
+
282
+ xml = companies(:second_client).to_xml(:indent => 0, :skip_instruct => true, :include => :firm)
283
+ assert xml.include?("<firm>")
284
+ end
285
+
286
+ def test_including_multiple_associations
287
+ xml = companies(:first_firm).to_xml(:indent => 0, :skip_instruct => true, :include => [ :clients, :account ])
288
+ assert_equal "<firm>", xml.first(6)
289
+ assert xml.include?(%(<account>))
290
+ assert xml.include?(%(<clients type="array"><client>))
291
+ end
292
+
293
+ def test_including_association_with_options
294
+ xml = companies(:first_firm).to_xml(
295
+ :indent => 0, :skip_instruct => true,
296
+ :include => { :clients => { :only => :name } }
297
+ )
298
+
299
+ assert_equal "<firm>", xml.first(6)
300
+ assert xml.include?(%(<client><name>Summit</name></client>))
301
+ assert xml.include?(%(<clients type="array"><client>))
302
+ end
303
+
195
304
  def test_methods_are_called_on_object
196
305
  xml = authors(:david).to_xml :methods => :label, :indent => 0
197
306
  assert_match %r{<label>.*</label>}, xml
@@ -273,4 +382,27 @@ class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase
273
382
  assert_equal array.size, array.select { |author| author.has_key? 'firstname' }.size
274
383
  end
275
384
 
385
+ def test_array_to_xml_including_has_many_association
386
+ xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :include => :replies)
387
+ assert xml.include?(%(<replies type="array"><reply>))
388
+ end
389
+
390
+ def test_array_to_xml_including_methods
391
+ xml = [ topics(:first), topics(:second) ].to_xml(:indent => 0, :skip_instruct => true, :methods => [ :topic_id ])
392
+ assert xml.include?(%(<topic-id type="integer">#{topics(:first).topic_id}</topic-id>)), xml
393
+ assert xml.include?(%(<topic-id type="integer">#{topics(:second).topic_id}</topic-id>)), xml
394
+ end
395
+
396
+ def test_array_to_xml_including_has_one_association
397
+ xml = [ companies(:first_firm), companies(:rails_core) ].to_xml(:indent => 0, :skip_instruct => true, :include => :account)
398
+ assert xml.include?(companies(:first_firm).account.to_xml(:indent => 0, :skip_instruct => true))
399
+ assert xml.include?(companies(:rails_core).account.to_xml(:indent => 0, :skip_instruct => true))
400
+ end
401
+
402
+ def test_array_to_xml_including_belongs_to_association
403
+ xml = [ companies(:first_client), companies(:second_client), companies(:another_client) ].to_xml(:indent => 0, :skip_instruct => true, :include => :firm)
404
+ assert xml.include?(companies(:first_client).to_xml(:indent => 0, :skip_instruct => true))
405
+ assert xml.include?(companies(:second_client).firm.to_xml(:indent => 0, :skip_instruct => true))
406
+ assert xml.include?(companies(:another_client).firm.to_xml(:indent => 0, :skip_instruct => true))
407
+ end
276
408
  end