spec/js_routes_spec.rb in js-routes-0.3.1 vs spec/js_routes_spec.rb in js-routes-0.4.0

- old
+ new

@@ -19,10 +19,14 @@ it "should generate member routing" do evaljs("Routes.inbox_path(1)").should == "/inboxes/1" end + it "should generate nested routing with one parameter" do + evaljs("Routes.inbox_message_path(1)").should == "/inboxes/1/messages" + end + it "should generate nested routing" do evaljs("Routes.inbox_message_path(1,2)").should == "/inboxes/1/messages/2" end it "should generate routing with format" do @@ -31,10 +35,17 @@ it "should support get parameters" do evaljs("Routes.inbox_path(1, {format: 'json', q: 'hello', lang: 'ua'})").should == "/inboxes/1.json?q=hello&lang=ua" end + it "should support routes with reserved javascript words as parameters" do + #TODO: this doesn't actually test what it should test + #because the parameter name is return_id + #need to find the real way to test + evaljs("Routes.return_path(1)").should == "/returns/1" + end + context "when exclude is specified" do let(:_options) { {:exclude => /^admin_/} } it "should exclude specified routes from file" do @@ -43,11 +54,23 @@ it "should not exclude routes not under specified pattern" do evaljs("Routes.inboxes_path()").should_not be_nil end end + context "when include is specified" do + + let(:_options) { {:include => /^admin_/} } + it "should exclude specified routes from file" do + evaljs("Routes.admin_users_path()").should_not be_nil + end + + it "should not exclude routes not under specified pattern" do + evaljs("Routes.inboxes_path").should be_nil + end + end + context "when default_format is specified" do let(:_options) { {:default_format => "json"} } it "should render routing with default_format" do evaljs("Routes.inbox_path(1)").should == "/inboxes/1.json" @@ -76,9 +99,16 @@ let(:_options) { {:namespace => "PHM.Routes"} } it "should use this name space for routing" do evaljs("PHM.Routes.inbox_path").should_not be_nil end + end + + describe "generated js" do + subject { JsRoutes.generate } + it "should have correct function signature" do + subject.should include("inbox_message_path: function(_inbox_id, _id, options)") + end end describe ".generate!" do let(:name) { "#{File.dirname(__FILE__)}/../routes.js" } it "should generate routes file" do