Skip to content
This repository
Browse code

- 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
  • Loading branch information...
commit a71e07d61e8bb69788b7120a5cf0d3620c6094be 1 parent e3d6434
Gastón Ramos authored September 13, 2010
6  activeresource/lib/active_resource/base.rb
@@ -621,6 +621,12 @@ def prefix(options={}) "#{prefix_call}" end
621 621
       #   # => /posts/5/comments/1.xml?active=1
622 622
       #
623 623
       def element_path(id, prefix_options = {}, query_options = nil)
  624
+
  625
+        p_options = HashWithIndifferentAccess.new(prefix_options)
  626
+        prefix_parameters.each do |p|
  627
+          raise MissingPrefixParam if p_options[p].blank?
  628
+        end
  629
+
624 630
         prefix_options, query_options = split_options(prefix_options) if query_options.nil?
625 631
         "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
626 632
       end
3  activeresource/lib/active_resource/exceptions.rb
@@ -36,6 +36,9 @@ class Redirection < ConnectionError # :nodoc:
36 36
     def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
37 37
   end
38 38
 
  39
+  # Raised when ...
  40
+  class MissingPrefixParam < ArgumentError; end # :nodoc:
  41
+
39 42
   # 4xx Client Error
40 43
   class ClientError < ConnectionError; end # :nodoc:
41 44
 
8  activeresource/test/cases/base_test.rb
@@ -475,6 +475,12 @@ def test_custom_element_path
475 475
     assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary')
476 476
   end
477 477
 
  478
+  def test_custom_element_path_without_parent_id
  479
+    assert_raise ActiveResource::MissingPrefixParam do
  480
+      assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1)
  481
+    end
  482
+  end
  483
+
478 484
   def test_module_element_path
479 485
     assert_equal '/sounds/1.xml', Asset::Sound.element_path(1)
480 486
   end
@@ -560,6 +566,8 @@ def test_set_prefix_twice_should_clear_params
560 566
       assert_equal Set.new([:the_param1]), person_class.prefix_parameters
561 567
       person_class.prefix = "the_prefix/:the_param2"
562 568
       assert_equal Set.new([:the_param2]), person_class.prefix_parameters
  569
+      person_class.prefix = "the_prefix/:the_param1/other_prefix/:the_param2"
  570
+      assert_equal Set.new([:the_param2, :the_param1]), person_class.prefix_parameters
563 571
     end
564 572
   end
565 573
 
2  activeresource/test/cases/finder_test.rb
@@ -84,7 +84,7 @@ def test_last_with_params
84 84
 
85 85
   def test_find_by_id_not_found
86 86
     assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) }
87  
-    assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) }
  87
+    assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(99, :params => {:person_id => 1}) }
88 88
   end
89 89
 
90 90
   def test_find_all_sub_objects

0 notes on commit a71e07d

Please sign in to comment.
Something went wrong with that request. Please try again.