spec/model/paths_spec.rb in her-0.2.1 vs spec/model/paths_spec.rb in her-0.2.2

- old
+ new

@@ -1,41 +1,56 @@ # encoding: utf-8 require File.join(File.dirname(__FILE__), "../spec_helper.rb") describe Her::Model::Paths do context "building request paths" do - before do # {{{ - spawn_model :User - end # }}} - - describe "#build_request_path" do - it "builds paths with defaults" do # {{{ - User.build_request_path(id: "foo").should == "/users/foo" - User.build_request_path.should == "/users" + context "simple model" do + before do # {{{ + spawn_model :User end # }}} - it "builds paths with custom collection path" do # {{{ - User.collection_path "/utilisateurs" - User.build_request_path(id: "foo").should == "/utilisateurs/foo" - User.build_request_path.should == "/utilisateurs" - end # }}} + describe "#build_request_path" do + it "builds paths with defaults" do # {{{ + User.build_request_path(id: "foo").should == "/users/foo" + User.build_request_path.should == "/users" + end # }}} - it "builds paths with custom collection path with multiple variables" do # {{{ - User.collection_path "/organizations/:organization_id/utilisateurs" - User.build_request_path(:id => "foo", :_organization_id => "acme").should == "/organizations/acme/utilisateurs/foo" - User.build_request_path(:_organization_id => "acme").should == "/organizations/acme/utilisateurs" - end # }}} + it "builds paths with custom collection path" do # {{{ + User.collection_path "/utilisateurs" + User.build_request_path(id: "foo").should == "/utilisateurs/foo" + User.build_request_path.should == "/utilisateurs" + end # }}} - it "builds paths with custom item path" do # {{{ - User.resource_path "/utilisateurs/:id" - User.build_request_path(id: "foo").should == "/utilisateurs/foo" - User.build_request_path.should == "/users" - end # }}} + it "builds paths with custom collection path with multiple variables" do # {{{ + User.collection_path "/organizations/:organization_id/utilisateurs" + User.build_request_path(:id => "foo", :_organization_id => "acme").should == "/organizations/acme/utilisateurs/foo" + User.build_request_path(:_organization_id => "acme").should == "/organizations/acme/utilisateurs" + end # }}} - it "raises exceptions when building a path without required custom variables" do # {{{ - User.collection_path "/organizations/:organization_id/utilisateurs" - expect { User.build_request_path(:id => "foo") }.should raise_error(Her::Errors::PathError) + it "builds paths with custom item path" do # {{{ + User.resource_path "/utilisateurs/:id" + User.build_request_path(id: "foo").should == "/utilisateurs/foo" + User.build_request_path.should == "/users" + end # }}} + + it "raises exceptions when building a path without required custom variables" do # {{{ + User.collection_path "/organizations/:organization_id/utilisateurs" + expect { User.build_request_path(:id => "foo") }.should raise_error(Her::Errors::PathError) + end # }}} + end + end + + context "nested model" do + before do # {{{ + spawn_submodel :Base, :User end # }}} + + describe "#build_request_path" do + it "builds paths with defaults" do # {{{ + Base::User.build_request_path(id: "foo").should == "/users/foo" + Base::User.build_request_path.should == "/users" + end # }}} + end end end context "making HTTP requests" do before do # {{{