forked from mbleigh/subdomain-fu
/
url_rewriter_spec.rb
74 lines (59 loc) · 2.96 KB
/
url_rewriter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require File.dirname(__FILE__) + '/spec_helper'
describe "SubdomainFu URL Writing" do
before do
SubdomainFu.tld_size = 1
default_url_options[:host] = "testapp.com"
end
describe "#url_for" do
it "should be able to add a subdomain" do
url_for(:controller => "something", :action => "other", :subdomain => "awesome").should == "http://awesome.testapp.com/something/other"
end
it "should be able to remove a subdomain" do
url_for(:controller => "something", :action => "other", :subdomain => false, :host => "awesome.testapp.com").should == "http://testapp.com/something/other"
end
it "should not change a mirrored subdomain" do
url_for(:controller => "something", :action => "other", :subdomain => false, :host => "www.testapp.com").should == "http://www.testapp.com/something/other"
end
it "should should force the full url, even with :only_path" do
url_for(:controller => "something", :action => "other", :subdomain => "awesome", :only_path => true).should == "http://awesome.testapp.com/something/other"
end
end
describe "Standard Routes" do
it "should be able to add a subdomain" do
needs_subdomain_url(:subdomain => "awesome").should == "http://awesome.testapp.com/needs_subdomain"
end
it "should be able to remove a subdomain" do
default_url_options[:host] = "awesome.testapp.com"
needs_subdomain_url(:subdomain => false).should == "http://testapp.com/needs_subdomain"
end
it "should not change a mirrored subdomain" do
default_url_options[:host] = "www.testapp.com"
needs_subdomain_url(:subdomain => false).should == "http://www.testapp.com/needs_subdomain"
end
it "should should force the full url, even with _path" do
needs_subdomain_path(:subdomain => "awesome").should == needs_subdomain_url(:subdomain => "awesome")
end
end
describe "Resourced Routes" do
it "should be able to add a subdomain" do
foo_path(:id => "something", :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something"
end
it "should be able to remove a subdomain" do
default_url_options[:host] = "awesome.testapp.com"
foo_path(:id => "something", :subdomain => false).should == "http://testapp.com/foos/something"
end
it "should work when passed in a paramable object" do
foo_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something"
end
it "should work on nested resource collections" do
foo_bars_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something/bars"
end
it "should work on nested resource members" do
foo_bar_path(Paramed.new("something"),Paramed.new("else"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something/bars/else"
end
end
after do
SubdomainFu.tld_size = 0
default_url_options[:host] = "localhost"
end
end