aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/base_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-06-25 14:44:22 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-06-25 14:44:22 +0000
commit99d268c8534ad398c6c60a4978ef94699cbb8ada (patch)
tree70a65800284217eef66405826748c8588504e666 /activeresource/test/base_test.rb
parenta55265132b37c6fb8ac15a96b44e64a64bcd4c45 (diff)
downloadrails-99d268c8534ad398c6c60a4978ef94699cbb8ada.tar.gz
rails-99d268c8534ad398c6c60a4978ef94699cbb8ada.tar.bz2
rails-99d268c8534ad398c6c60a4978ef94699cbb8ada.zip
Initial check-in of Active Resourse
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4492 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/base_test.rb')
-rw-r--r--activeresource/test/base_test.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb
new file mode 100644
index 0000000000..3c87ca532c
--- /dev/null
+++ b/activeresource/test/base_test.rb
@@ -0,0 +1,60 @@
+require "#{File.dirname(__FILE__)}/abstract_unit"
+require "fixtures/person"
+
+class BaseTest < Test::Unit::TestCase
+ def setup
+ ActiveResource::HttpMock.respond_to(
+ ActiveResource::Request.new(:get, "/people/1.xml") => ActiveResource::Response.new("<person><name>Matz</name><id type='integer'>1</id></person>"),
+ ActiveResource::Request.new(:get, "/people/2.xml") => ActiveResource::Response.new("<person><name>David</name><id type='integer'>2</id></person>"),
+ ActiveResource::Request.new(:put, "/people/1.xml") => ActiveResource::Response.new({}, 200),
+ ActiveResource::Request.new(:delete, "/people/1.xml") => ActiveResource::Response.new({}, 200),
+ ActiveResource::Request.new(:delete, "/people/2.xml") => ActiveResource::Response.new({}, 400),
+ ActiveResource::Request.new(:post, "/people.xml") => ActiveResource::Response.new({}, 200),
+ ActiveResource::Request.new(:get, "/people/99.xml") => ActiveResource::Response.new({}, 404),
+ ActiveResource::Request.new(:get, "/people.xml") => ActiveResource::Response.new(
+ "<people><person><name>Matz</name><id type='integer'>1</id></person><person><name>David</name><id type='integer'>2</id></person></people>"
+ )
+ )
+ end
+
+ def test_collection_name
+ assert_equal "people", Person.collection_name
+ end
+
+ def test_find_by_id
+ matz = Person.find(1)
+ assert_kind_of Person, matz
+ assert_equal "Matz", matz.name
+ end
+
+ def test_find_all
+ all = Person.find(:all)
+ assert_equal 2, all.size
+ assert_kind_of Person, all.first
+ assert_equal "Matz", all.first.name
+ assert_equal "David", all.last.name
+ end
+
+ def test_find_first
+ matz = Person.find(:first)
+ assert_kind_of Person, matz
+ assert_equal "Matz", matz.name
+ end
+
+ def test_find_by_id_not_found
+ assert_raises(ActiveResource::ResourceNotFound) { Person.find(99) }
+ end
+
+ def test_update
+ matz = Person.find(:first)
+ matz.name = "David"
+ assert_kind_of Person, matz
+ assert_equal "David", matz.name
+ matz.save
+ end
+
+ def test_destroy
+ assert Person.find(1).destroy
+ assert_raises(ActiveResource::ClientError) { Person.find(2).destroy }
+ end
+end \ No newline at end of file