wycats / merb

master merb branch

This URL has Read+Write access

merb / merb-core / spec / public / test / route_helper_spec.rb
f57cc0ce » michaelklishin 2008-09-28 Add missing pieces of forki... 1 require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
541c7492 » benburkert 2008-02-28 imported the /lib/merb-core... 2
3 class TestController < Merb::Controller
4 def get(id = nil); end
5 def post; end
6 end
7
8 describe Merb::Test::RouteHelper do
80b01f99 » carllerche 2008-09-20 Significant router refactor... 9 include Merb::Test::RouteHelper
10
541c7492 » benburkert 2008-02-28 imported the /lib/merb-core... 11 before(:each) do
8e722c60 » carllerche 2008-10-03 Cleaned up the specs. Remov... 12 Merb::Router.prepare do
13 match("/").defer_to do |request, params|
79f233a2 » mlangenberg 2008-09-12 You can now use request_to ... 14 { :controller => 'test_controller', :action => request.raw_post } unless request.raw_post.blank?
15 end
8e722c60 » carllerche 2008-10-03 Cleaned up the specs. Remov... 16 match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
17 match("/", :method => :post).to(:controller => "test_controller", :action => "post")
18 match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
19 default_routes
541c7492 » benburkert 2008-02-28 imported the /lib/merb-core... 20 end
21 end
22
23 describe "#url" do
24 it "should use Merb::Router" do
25 url(:getter).should == "/"
26 end
27
28 it "should work with a parameters hash" do
29 url(:with_id, :id => 123).should == "/123"
30 end
af5b14a3 » Michael Sheakoski 2008-05-06 Remove nil items from param... 31
32 it "should turn extra hash items into query params" do
33 generated_url = url(:getter, :id => 123, :color => 'red', :size => 'large')
34 lambda {
35 generated_url.match(/\bid=123\b/) &&
36 generated_url.match(/\bsize=large\b/) &&
37 generated_url.match(/\bcolor=red\b/)
38 }.call.should_not be_nil
39 end
40
41 it "should remove items with nil values from query params" do
42 url(:getter, :color => nil, :size => 'large').should == "/?size=large"
43 end
44
45 it "should remove items with nil values from query params when named route isn't specified" do
46 url(:controller => 'cont', :action => 'act', :color => nil, :size => 'large').should == "/cont/act?size=large"
47 end
541c7492 » benburkert 2008-02-28 imported the /lib/merb-core... 48 end
49
50 describe "#request_to" do
51 it "should GET if no method is given" do
52 request_to("/")[:action].should == "get"
53 end
54
55 it "should return a hash" do
56 Hash.should === request_to("/")
57 end
58
59 it "should contain the controller in the result" do
60 request_to("/")[:controller].should == "test_controller"
61 end
62
63 it "should contain the action in the result" do
64 request_to("/")[:action].should == "get"
65 end
66
67 it "should contain any parameters in the result" do
68 request_to("/123")[:id].should == "123"
69 end
79f233a2 » mlangenberg 2008-09-12 You can now use request_to ... 70
71 it "should play nice with raw_post in deferred routing" do
72 request_to("/", :post, {:post_body => 'deferred'})[:action].should == 'deferred'
73 end
541c7492 » benburkert 2008-02-28 imported the /lib/merb-core... 74 end
af5b14a3 » Michael Sheakoski 2008-05-06 Remove nil items from param... 75 end