diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-09-30 23:29:23 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2010-09-30 23:29:23 +0100 |
commit | 704961ce688f5bc1942529f44ea6b00014ef8378 (patch) | |
tree | b951112aed4914cdc4203bca6e810a7b71d37e82 /activeresource/test | |
parent | b689834bcf2730353d066277f43047f10abb8d30 (diff) | |
parent | 91deff08c940f16ed149e7628694faff0393fe0a (diff) | |
download | rails-704961ce688f5bc1942529f44ea6b00014ef8378.tar.gz rails-704961ce688f5bc1942529f44ea6b00014ef8378.tar.bz2 rails-704961ce688f5bc1942529f44ea6b00014ef8378.zip |
Merge branch 'master' into nested_has_many_through_2
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/abstract_unit.rb | 7 | ||||
-rw-r--r-- | activeresource/test/cases/base_test.rb | 19 | ||||
-rw-r--r-- | activeresource/test/cases/finder_test.rb | 2 | ||||
-rw-r--r-- | activeresource/test/cases/format_test.rb | 2 | ||||
-rw-r--r-- | activeresource/test/fixtures/sound.rb | 6 |
5 files changed, 33 insertions, 3 deletions
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb index 129efeb879..195f93f2a6 100644 --- a/activeresource/test/abstract_unit.rb +++ b/activeresource/test/abstract_unit.rb @@ -75,6 +75,10 @@ def setup_response </person> eof + @startup_sound = { + :name => "Mac Startup Sound", :author => { :name => "Jim Reekes" } + }.to_xml(:root => 'sound') + ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1.xml", {}, @matz mock.get "/people/2.xml", {}, @david @@ -97,6 +101,7 @@ def setup_response mock.put "/people/1/addresses/1.xml", {}, nil, 204 mock.delete "/people/1/addresses/1.xml", {}, nil, 200 mock.post "/people/1/addresses.xml", {}, nil, 201, 'Location' => '/people/1/addresses/5' + mock.get "/people/1/addresses/99.xml", {}, nil, 404 mock.get "/people//addresses.xml", {}, nil, 404 mock.get "/people//addresses/1.xml", {}, nil, 404 mock.put "/people//addresses/1.xml", {}, nil, 404 @@ -111,6 +116,8 @@ def setup_response mock.head "/people/Greg/addresses/1.xml", {}, nil, 200 # customer mock.get "/customers/1.xml", {}, @luis + # sound + mock.get "/sounds/1.xml", {}, @startup_sound end Person.user = nil diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 6fabeeebcd..abf4259a54 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -475,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 @@ -513,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) @@ -560,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 @@ -1083,4 +1097,9 @@ class BaseTest < Test::Unit::TestCase 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 diff --git a/activeresource/test/cases/finder_test.rb b/activeresource/test/cases/finder_test.rb index fd09ef46d7..ebb783996d 100644 --- a/activeresource/test/cases/finder_test.rb +++ b/activeresource/test/cases/finder_test.rb @@ -84,7 +84,7 @@ class FinderTest < Test::Unit::TestCase def test_find_by_id_not_found assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) } - assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) } + assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(99, :params => {:person_id => 1}) } end def test_find_all_sub_objects diff --git a/activeresource/test/cases/format_test.rb b/activeresource/test/cases/format_test.rb index c3733e13d8..bed95ef524 100644 --- a/activeresource/test/cases/format_test.rb +++ b/activeresource/test/cases/format_test.rb @@ -33,7 +33,7 @@ class FormatTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to.get "/people.#{format}", {'Accept' => ActiveResource::Formats[format].mime_type}, ActiveResource::Formats[format].encode(@programmers) remote_programmers = Person.find(:all) assert_equal 2, remote_programmers.size - assert remote_programmers.select { |p| p.name == 'David' } + assert remote_programmers.map { |p| p.name }.include? 'David' end end end diff --git a/activeresource/test/fixtures/sound.rb b/activeresource/test/fixtures/sound.rb index 5c0ef5d55c..d9d2b99fcd 100644 --- a/activeresource/test/fixtures/sound.rb +++ b/activeresource/test/fixtures/sound.rb @@ -1,5 +1,9 @@ -module Asset +module Asset class Sound < ActiveResource::Base self.site = "http://37s.sunrise.i:3000" end end + +# to test namespacing in a module +class Author +end
\ No newline at end of file |