Permalink
Browse files

fix tests

fix visit_globbing
add tests for objects
  • Loading branch information...
1 parent 0b85e0f commit 076e051cfeffade829daea87bd14ee5a91bd357b @le0pard le0pard committed Apr 1, 2013
Showing with 33 additions and 30 deletions.
  1. +1 −9 lib/routes.js
  2. +0 −6 lib/routes.js.coffee
  3. +30 −14 spec/js_routes/rails_routes_compatibility_spec.rb
  4. +2 −1 spec/spec_helper.rb
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -129,12 +129,6 @@ Utils =
parameters[left] = switch @getObjectType(value)
when "array"
value.join("/")
- when "object"
- v = if value[left] then value[left] else value
- if @getObjectType(v) is "string"
- v
- else
- @serialize(v)
else
value
@visit route, parameters, optional
@@ -73,35 +73,31 @@
context "routes globbing" do
it "should be supported as parameters" do
- evaljs("Routes.book_path(1, 'thrillers')").should == routes.book_path(1, 'thrillers')
+ evaljs("Routes.book_path('thrillers', 1)").should == routes.book_path('thrillers', 1)
end
it "should support routes globbing as array" do
- evaljs("Routes.book_path(1, ['thrillers'])").should == routes.book_path(1, 'thrillers')
+ evaljs("Routes.book_path(['thrillers'], 1)").should == routes.book_path(['thrillers'], 1)
end
it "should bee support routes globbing as array" do
- evaljs("Routes.book_path(1, [1, 2, 3])").should == routes.book_path(1, [1, 2, 3])
- end
-
- it "should support routes globbing as hash" do
- evaljs("Routes.book_path(1, {section: 'a_test'})").should == routes.book_path(1, {:section => 'a_test'})
+ evaljs("Routes.book_path([1, 2, 3], 1)").should == routes.book_path([1, 2, 3], 1)
end
it "should bee support routes globbing as hash" do
- evaljs("Routes.book_path(1, {section: 'a_test/b_test/c_test'})").should == routes.book_path(1, {:section => 'a_test/b_test/c_test'})
+ evaljs("Routes.book_path('a_test/b_test/c_test', 1)").should == routes.book_path('a_test/b_test/c_test', 1)
end
- it "should bee support routes globbing as hash in hash" do
- evaljs("Routes.book_path(1, {section: {a: '1', b: '2'}})").should == routes.book_path(1, {:section => { :a => "1", :b => "2"}})
+ it "should support routes globbing as array with optional params" do
+ evaljs("Routes.book_path([1, 2, 3, 5], 1, {c: '1'})").should == routes.book_path([1, 2, 3, 5], 1, { :c => "1" })
end
- it "should bee support routes globbing as hash in hash with array" do
- evaljs("Routes.book_path(1, {section: {a: '1', b: ['t', 'c']}})").should == routes.book_path(1, {:section => { :a => "1", :b => ["t", "c"]}})
+ it "should support routes globbing in book_title route as array" do
+ evaljs("Routes.book_title_path('john', ['thrillers', 'comedian'])").should == routes.book_title_path('john', ['thrillers', 'comedian'])
end
- it "should support routes globbing as hash in hash even without named key" do
- evaljs("Routes.book_path(1, {a: '1', b: ['t', 'c']}, {c: '1'})").should == routes.book_path(1, {:section => { :a => "1", :b => ["t", "c"]}, :c => "1"})
+ it "should support routes globbing in book_title route as array with optional params" do
+ evaljs("Routes.book_title_path('john', ['thrillers', 'comedian'], {some_key: 'some_value'})").should == routes.book_title_path('john', ['thrillers', 'comedian'], {:some_key => 'some_value'})
end
end
@@ -221,5 +217,25 @@
"Routes.inbox_message_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})"
).should == routes.inbox_message_path(inbox, 2, :custom => true, :format => "json")
end
+
+ context "when globbing" do
+ it "should prefer to_param property over id property" do
+ evaljs("Routes.book_path({id: 1, to_param: 'my'}, 1)").should == routes.book_path(inbox, 1)
+ end
+
+ it "should call to_param if it is a function" do
+ evaljs("Routes.book_path({id: 1, to_param: function(){ return 'my';}}, 1)").should == routes.book_path(inbox, 1)
+ end
+
+ it "should call id if it is a function" do
+ evaljs("Routes.book_path({id: function() { return 'technical';}}, 1)").should == routes.book_path('technical', 1)
+ end
+
+ it "should support options argument" do
+ evaljs(
+ "Routes.book_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})"
+ ).should == routes.book_path(inbox, 2, :custom => true, :format => "json")
+ end
+ end
end
end
View
@@ -67,7 +67,8 @@ def draw_routes
match "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
- match 'books/:title/*section' => 'books#show', :as => :book
+ match 'books/*section/:title' => 'books#show', :as => :book
+ match 'books/:title/*section' => 'books#show', :as => :book_title
mount BlogEngine::Engine => "/blog", :as => :blog_app

0 comments on commit 076e051

Please sign in to comment.