aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-10 00:25:29 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-10 00:25:29 +0000
commitdb37c0c95fea1ddb3a34665f82d3cba9bced49f8 (patch)
treeebc836f012aa248adfe9a9b7d8dd794bf777d92b /activerecord/test
parent0c6d1785529ab2f9c86908f03a10c871512311e5 (diff)
downloadrails-db37c0c95fea1ddb3a34665f82d3cba9bced49f8.tar.gz
rails-db37c0c95fea1ddb3a34665f82d3cba9bced49f8.tar.bz2
rails-db37c0c95fea1ddb3a34665f82d3cba9bced49f8.zip
Added association inclusion in to_xml [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3831 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/base_test.rb48
1 files changed, 43 insertions, 5 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index d82bde433d..3ad2d6e960 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1155,12 +1155,12 @@ class BasicsTest < Test::Unit::TestCase
end
def test_to_xml
- xml = Topic.find(:first).to_xml(:indent => 0, :skip_instruct => true)
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true)
assert_equal "<topic>", xml.first(7)
assert xml.include?(%(<title>The First Topic</title>))
assert xml.include?(%(<author-name>David</author-name>))
assert xml.include?(%(<id type="integer">1</id>))
- assert xml.include?(%(<approved type="boolean">false</approved>))
+ assert xml.include?(%(<approved type="boolean">false</approved>)), "Approved should be a boolean"
assert xml.include?(%(<replies-count type="integer">0</replies-count>))
assert xml.include?(%(<bonus-time type="datetime">2000-01-01 08:28:00</bonus-time>))
assert xml.include?(%(<written-on type="datetime">2003-07-16 09:28:00</written-on>))
@@ -1171,16 +1171,54 @@ class BasicsTest < Test::Unit::TestCase
end
def test_to_xml_skipping_attributes
- xml = Topic.find(:first).to_xml(:indent => 0, :skip_instruct => true, :skip_attributes => :title)
- breakpoint
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :except => :title)
assert_equal "<topic>", xml.first(7)
assert !xml.include?(%(<title>The First Topic</title>))
assert xml.include?(%(<author-name>David</author-name>))
- xml = Topic.find(:first).to_xml(:indent => 0, :skip_instruct => true, :skip_attributes => [ :title, :author_name ])
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :except => [ :title, :author_name ])
assert !xml.include?(%(<title>The First Topic</title>))
assert !xml.include?(%(<author-name>David</author-name>))
end
+
+ def test_to_xml_including_has_many_association
+ xml = topics(:first).to_xml(:indent => 0, :skip_instruct => true, :include => :replies)
+ assert_equal "<topic>", xml.first(7)
+ assert xml.include?(%(<replies><reply>))
+ assert xml.include?(%(<title>The Second Topic's of the day</title>))
+ end
+
+ def test_to_xml_including_belongs_to_association
+ xml = companies(:first_client).to_xml(:indent => 0, :skip_instruct => true, :include => :firm)
+ assert !xml.include?("<firm>")
+
+ xml = companies(:second_client).to_xml(:indent => 0, :skip_instruct => true, :include => :firm)
+ assert xml.include?("<firm>")
+ end
+
+ def test_to_xml_including_multiple_associations
+ xml = companies(:first_firm).to_xml(:indent => 0, :skip_instruct => true, :include => [ :clients, :account ])
+ assert_equal "<firm>", xml.first(6)
+ assert xml.include?(%(<account>))
+ assert xml.include?(%(<clients><client>))
+ end
+
+ def test_except_attributes
+ assert_equal(
+ %w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read),
+ topics(:first).attributes(:except => :title).keys
+ )
+
+ assert_equal(
+ %w( replies_count bonus_time written_on content author_email_address parent_id last_read),
+ topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys
+ )
+ end
+
+ def test_include_attributes
+ assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
+ assert_equal(%w( title author_name type id approved ), topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)
+ end
# FIXME: this test ought to run, but it needs to run sandboxed so that it
# doesn't b0rk the current test environment by undefing everything.