@@ -773,6 +773,10 @@ def test_collection_path
773
773
assert_equal "/people.json" , Person . collection_path
774
774
end
775
775
776
+ def test_collection_url
777
+ assert_equal "http://37s.sunrise.i:3000/people.json" , Person . collection_url
778
+ end
779
+
776
780
def test_collection_path_with_parameters
777
781
assert_equal "/people.json?gender=male" , Person . collection_path ( gender : "male" )
778
782
assert_equal "/people.json?gender=false" , Person . collection_path ( gender : false )
@@ -789,6 +793,22 @@ def test_collection_path_with_parameters
789
793
assert_equal "/people.json?struct%5Ba%5D%5B%5D=2&struct%5Ba%5D%5B%5D=1&struct%5Bb%5D=fred" , Person . collection_path ( struct : { :a => [ 2 , 1 ] , "b" => "fred" } )
790
794
end
791
795
796
+ def test_collection_url_with_parameters
797
+ assert_equal "http://37s.sunrise.i:3000/people.json?gender=male" , Person . collection_url ( gender : "male" )
798
+ assert_equal "http://37s.sunrise.i:3000/people.json?gender=false" , Person . collection_url ( gender : false )
799
+ assert_equal "http://37s.sunrise.i:3000/people.json?gender=" , Person . collection_url ( gender : nil )
800
+
801
+ assert_equal "http://37s.sunrise.i:3000/people.json?gender=male" , Person . collection_url ( "gender" => "male" )
802
+
803
+ # Use includes? because ordering of param hash is not guaranteed
804
+ assert Person . collection_url ( gender : "male" , student : true ) . include? ( "/people.json?" )
805
+ assert Person . collection_url ( gender : "male" , student : true ) . include? ( "gender=male" )
806
+ assert Person . collection_url ( gender : "male" , student : true ) . include? ( "student=true" )
807
+
808
+ assert_equal "http://37s.sunrise.i:3000/people.json?name%5B%5D=bob&name%5B%5D=your+uncle%2Bme&name%5B%5D=&name%5B%5D=false" , Person . collection_url ( name : [ "bob" , "your uncle+me" , nil , false ] )
809
+ assert_equal "http://37s.sunrise.i:3000/people.json?struct%5Ba%5D%5B%5D=2&struct%5Ba%5D%5B%5D=1&struct%5Bb%5D=fred" , Person . collection_url ( struct : { :a => [ 2 , 1 ] , "b" => "fred" } )
810
+ end
811
+
792
812
def test_custom_element_path
793
813
assert_equal "/people/1/addresses/1.json" , StreetAddress . element_path ( 1 , person_id : 1 )
794
814
assert_equal "/people/1/addresses/1.json" , StreetAddress . element_path ( 1 , "person_id" => 1 )
0 commit comments