From a71e07d61e8bb69788b7120a5cf0d3620c6094be Mon Sep 17 00:00:00 2001 From: Gaston Ramos Date: Mon, 13 Sep 2010 17:05:52 -0300 Subject: - elmenth_path raise an ActiveResource::MissingPrefixParam exception when prefix_options does not has all required prefix_options ex: class StreetAddress < ActiveResource::Base self.site = "http://37s.sunrise.i:3000/people/:person_id/" end StreetAddress.element_path(1) # => ActiveResource::MissingPrefixParam --- activeresource/test/cases/base_test.rb | 8 ++++++++ activeresource/test/cases/finder_test.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 6fabeeebcd..eb1a747c0a 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_parent_id + assert_raise ActiveResource::MissingPrefixParam do + assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1) + end + end + def test_module_element_path assert_equal '/sounds/1.xml', Asset::Sound.element_path(1) end @@ -560,6 +566,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 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 -- cgit v1.2.3 From 9363931f349d783058688c2c14a31856116125e0 Mon Sep 17 00:00:00 2001 From: Gaston Ramos Date: Mon, 13 Sep 2010 17:21:49 -0300 Subject: - better name for prefix param test case --- activeresource/test/cases/base_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index eb1a747c0a..f813ce2181 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -475,7 +475,7 @@ 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_parent_id + def test_custom_element_path_without_required_prefix_param assert_raise ActiveResource::MissingPrefixParam do assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1) end -- cgit v1.2.3 From 823a8e6e66b6e63583f569fdbc2e9cffa9430bf8 Mon Sep 17 00:00:00 2001 From: Gaston Ramos Date: Mon, 13 Sep 2010 17:33:58 -0300 Subject: - check prefix options in collection_path --- activeresource/test/cases/base_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index f813ce2181..18c732b2ab 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -477,7 +477,7 @@ class BaseTest < Test::Unit::TestCase def test_custom_element_path_without_required_prefix_param assert_raise ActiveResource::MissingPrefixParam do - assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1) + StreetAddress.element_path(1) end end @@ -519,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) -- cgit v1.2.3 From 67a838574be000f329c0f340474bc9cec1aeca16 Mon Sep 17 00:00:00 2001 From: Matthijs Langenberg Date: Fri, 24 Sep 2010 22:37:26 +0200 Subject: Fix broken module namespacing in ActiveResource with Ruby 1.9 [#5699 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following namespace use case was broken with Ruby 1.9: class Author < ActiveRecord::Base ... end module Api class Book < ActiveResouce::Base end end Let's say XML contains John.... Api::Book.first.author.class.to_s #=> Ruby 1.8.7: "Api::Book::Author" (namespaced, correct), Ruby 1.9: "Author" (toplevel, broken) Signed-off-by: José Valim --- activeresource/test/cases/base_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activeresource/test/cases') diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 18c732b2ab..abf4259a54 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -1097,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 -- cgit v1.2.3 From 0495736339df48a625fd58f4304b7b497b02d859 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 30 Sep 2010 22:38:04 +0800 Subject: assert on empty array is always true. fixing test. --- activeresource/test/cases/format_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activeresource/test/cases') 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 -- cgit v1.2.3