diff options
Diffstat (limited to 'activeresource/test/cases/base_test.rb')
-rw-r--r-- | activeresource/test/cases/base_test.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index b5914683e9..abf4259a54 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -5,6 +5,8 @@ require "fixtures/street_address" require "fixtures/sound" require "fixtures/beast" require "fixtures/proxy" +require "fixtures/address" +require "fixtures/subscription_plan" require 'active_support/json' require 'active_support/ordered_hash' require 'active_support/core_ext/hash/conversions' @@ -473,6 +475,12 @@ class BaseTest < Test::Unit::TestCase assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary') end + def test_custom_element_path_without_required_prefix_param + assert_raise ActiveResource::MissingPrefixParam do + StreetAddress.element_path(1) + end + end + def test_module_element_path assert_equal '/sounds/1.xml', Asset::Sound.element_path(1) end @@ -511,6 +519,12 @@ class BaseTest < Test::Unit::TestCase assert_equal '/people/1/addresses/1.xml?type=work', StreetAddress.element_path(1, {:person_id => 1}, {:type => 'work'}) end + def test_custom_collection_path_without_required_prefix_param + assert_raise ActiveResource::MissingPrefixParam do + StreetAddress.collection_path + end + end + def test_custom_collection_path assert_equal '/people/1/addresses.xml', StreetAddress.collection_path(:person_id => 1) assert_equal '/people/1/addresses.xml', StreetAddress.collection_path('person_id' => 1) @@ -558,6 +572,8 @@ class BaseTest < Test::Unit::TestCase assert_equal Set.new([:the_param1]), person_class.prefix_parameters person_class.prefix = "the_prefix/:the_param2" assert_equal Set.new([:the_param2]), person_class.prefix_parameters + person_class.prefix = "the_prefix/:the_param1/other_prefix/:the_param2" + assert_equal Set.new([:the_param2, :the_param1]), person_class.prefix_parameters end end @@ -1034,4 +1050,56 @@ class BaseTest < Test::Unit::TestCase end end end + + def test_with_custom_formatter + @addresses = [{:id => "1", :street => "1 Infinite Loop", :city => "Cupertino", :state => "CA"}].to_xml(:root => 'addresses') + + ActiveResource::HttpMock.respond_to do |mock| + mock.get "/addresses.xml", {}, @addresses, 200 + end + + # late bind the site + AddressResource.site = "http://localhost" + addresses = AddressResource.find(:all) + + assert_equal "Cupertino, CA", addresses.first.city_state + end + + def test_create_with_custom_primary_key + silver_plan = {:code => "silver", :price => 5.00}.to_xml(:root => "plan") + + ActiveResource::HttpMock.respond_to do |mock| + mock.post "/plans.xml", {}, silver_plan, 201, 'Location' => '/plans/silver.xml' + end + + plan = SubscriptionPlan.new(:code => "silver", :price => 5.00) + assert plan.new? + + plan.save! + assert !plan.new? + end + + def test_update_with_custom_primary_key + silver_plan = {:code => "silver", :price => 5.00}.to_xml(:root => "plan") + silver_plan_updated = {:code => "silver", :price => 10.00}.to_xml(:root => "plan") + + ActiveResource::HttpMock.respond_to do |mock| + mock.get "/plans/silver.xml", {}, silver_plan + mock.put "/plans/silver.xml", {}, silver_plan_updated, 201, 'Location' => '/plans/silver.xml' + end + + plan = SubscriptionPlan.find("silver") + assert !plan.new? + assert_equal 5.00, plan.price + + # update price + plan.price = 10.00 + plan.save! + assert_equal 10.00, plan.price + end + + def test_namespacing + sound = Asset::Sound.find(1) + assert_equal "Asset::Sound::Author", sound.author.class.to_s + end end |