spec/path_helper_spec.rb in nyara-0.0.1.pre.5 vs spec/path_helper_spec.rb in nyara-0.0.1.pre.6

- old
+ new

@@ -21,57 +21,65 @@ end module Nyara describe [Controller, Route] do before :all do - Route.clear Config.configure do + reset set 'host', 'yavaeye.com' map '/', 'foo' map '/bar-prefix', 'foo_controller::bar' map '/baz-prefix', 'foo_controller::baz' end - Route.compile + Nyara.setup end - context '#path_for' do + context '#path_to' do it "local query" do c = FooController.new :stub_request - assert_equal '/12', c.path_for('#index', 12) + assert_equal '/12', c.path_to('#index', 12) assert_raise ArgumentError do - c.path_for '#index' + c.path_to '#index' end assert_raise ArgumentError do - c.path_for('#index', 'a') + c.path_to('#index', 'a') end end it "global query" do c = FooController::BarController.new :stub_request - assert_equal '/bar-prefix/', c.path_for('foo_controller::bar#index') - assert_equal '/baz-prefix/1', c.path_for('baz#index', 1) + assert_equal '/bar-prefix/', c.path_to('foo_controller::bar#index') + assert_equal '/baz-prefix/1', c.path_to('baz#index', 1) end it "generates for nested query" do - pending + c = FooController.new :stub_request + path = c.path_to('#index', 1, post: {array: [1, 2]}) + items = URI.parse(path).query.split('&').map{|q| CGI.unescape q } + assert_equal ["post[array][]=1", "post[array][]=2"], items end it "perserves _method query" do pending end it "appends format and query" do c = FooController.new :stub_request - generated = c.path_for '#index', 1, format: 'js', 'utm_source' => 'a spam' + generated = c.path_to '#index', 1, format: 'js', 'utm_source' => 'a spam' assert_equal "/1.js?utm_source=a+spam", generated end end - context '#url_for' do + context '#url_to' do it "works" do - c = FooController::BazController.new :stub_request - assert_equal '//yavaeye.com/baz-prefix/1', c.url_for('#index', 1) - assert_equal 'https://localhost:4567/1', c.url_for('foo#index', 1, scheme: 'https', host: 'localhost:4567') + request = Object.new + class << request + attr_accessor :host_with_port + end + request.host_with_port = 'yavaeye.com' + c = FooController::BazController.new request + assert_equal '//yavaeye.com/baz-prefix/1', c.url_to('#index', 1) + assert_equal 'https://localhost:4567/1', c.url_to('foo#index', 1, scheme: 'https', host: 'localhost:4567') end end end end