diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-10-10 17:15:11 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-10-10 17:15:11 +0100 |
commit | 66ee2654ff243f03595a402fa15e1eea1b5b45be (patch) | |
tree | 3f1055e03082f0c767719e8cba5155e4207779e0 /activeresource/test/cases/base_test.rb | |
parent | dd2779e1b83b4d867d47dd286ec0c919f5df12a9 (diff) | |
parent | b9ce8216fa849a47ad0b0f99fa510e226a23c12e (diff) | |
download | rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.gz rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.bz2 rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'activeresource/test/cases/base_test.rb')
-rw-r--r-- | activeresource/test/cases/base_test.rb | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 8c0217aad6..1593e25595 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -11,12 +11,12 @@ class BaseTest < Test::Unit::TestCase @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person') @david = { :id => 2, :name => 'David' }.to_xml(:root => 'person') @greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person') - @addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address') + @addy = { :id => 1, :street => '12345 Street', :country => 'Australia' }.to_xml(:root => 'address') @default_request_headers = { 'Content-Type' => 'application/xml' } @rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person") @people = [{ :id => 1, :name => 'Matz' }, { :id => 2, :name => 'David' }].to_xml(:root => 'people') @people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people') - @addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses') + @addresses = [{ :id => 1, :street => '12345 Street', :country => 'Australia' }].to_xml(:root => 'addresses') # - deep nested resource - # - Luis (Customer) @@ -102,6 +102,9 @@ class BaseTest < Test::Unit::TestCase Person.password = nil end + ######################################################################## + # Tests relating to setting up the API-connection configuration + ######################################################################## def test_site_accessor_accepts_uri_or_string_argument site = URI.parse('http://localhost') @@ -509,6 +512,11 @@ class BaseTest < Test::Unit::TestCase assert_not_equal(first_connection, second_connection, 'Connection should be re-created') end + + ######################################################################## + # Tests for setting up remote URLs for a given model (including adding + # parameters appropriately) + ######################################################################## def test_collection_name assert_equal "people", Person.collection_name end @@ -637,6 +645,10 @@ class BaseTest < Test::Unit::TestCase assert_equal [:person_id].to_set, StreetAddress.__send__(:prefix_parameters) end + + ######################################################################## + # Tests basic CRUD functions (find/save/create etc) + ######################################################################## def test_respond_to matz = Person.find(1) assert matz.respond_to?(:name) @@ -813,6 +825,55 @@ class BaseTest < Test::Unit::TestCase assert_raise(ActiveResource::ResourceConflict) { Person.find(2).save } end + + ###### + # update_attribute(s)(!) + + def test_update_attribute_as_symbol + matz = Person.first + matz.expects(:save).returns(true) + + assert_equal "Matz", matz.name + assert matz.update_attribute(:name, "David") + assert_equal "David", matz.name + end + + def test_update_attribute_as_string + matz = Person.first + matz.expects(:save).returns(true) + + assert_equal "Matz", matz.name + assert matz.update_attribute('name', "David") + assert_equal "David", matz.name + end + + + def test_update_attributes_as_symbols + addy = StreetAddress.first(:params => {:person_id => 1}) + addy.expects(:save).returns(true) + + assert_equal "12345 Street", addy.street + assert_equal "Australia", addy.country + assert addy.update_attributes(:street => '54321 Street', :country => 'USA') + assert_equal "54321 Street", addy.street + assert_equal "USA", addy.country + end + + def test_update_attributes_as_strings + addy = StreetAddress.first(:params => {:person_id => 1}) + addy.expects(:save).returns(true) + + assert_equal "12345 Street", addy.street + assert_equal "Australia", addy.country + assert addy.update_attributes('street' => '54321 Street', 'country' => 'USA') + assert_equal "54321 Street", addy.street + assert_equal "USA", addy.country + end + + + ##### + # Mayhem and destruction + def test_destroy assert Person.find(1).destroy ActiveResource::HttpMock.respond_to do |mock| @@ -852,7 +913,7 @@ class BaseTest < Test::Unit::TestCase end assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) } end - + def test_delete_with_410_gone assert Person.delete(1) ActiveResource::HttpMock.respond_to do |mock| @@ -861,6 +922,9 @@ class BaseTest < Test::Unit::TestCase assert_raise(ActiveResource::ResourceGone) { Person.find(1) } end + ######################################################################## + # Tests the more miscelaneous helper methods + ######################################################################## def test_exists # Class method. assert !Person.exists?(nil) |