ruil 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,50 +0,0 @@
1
- require 'rubygems'
2
- require 'ruil/delegator'
3
- require 'ruil/resource'
4
- require 'ruil/tenjin_template'
5
-
6
- describe 'Delegator' do
7
-
8
- before(:all) do
9
- a_resource = Class.new(Ruil::Resource) do
10
- def path_pattern
11
- /^\/a/
12
- end
13
- def template_pattern
14
- 'a.*.html'
15
- end
16
- end
17
- b_resource = Class.new(Ruil::Resource) do
18
- def path_pattern
19
- /^\/b/
20
- end
21
- def template_pattern
22
- 'b.*.html'
23
- end
24
- end
25
- user_agent_parser = Proc.new do |env|
26
- /Mobile/ === env['HTTP_USER_AGENT'] ? :mobile : :desktop
27
- end
28
- template_dir = File.join(File.dirname(__FILE__), 'templates')
29
- @delegator = Ruil::Delegator.new(user_agent_parser, template_dir, Ruil::TenjinTemplate) do |d|
30
- d.add_resource a_resource
31
- d.add_resource b_resource
32
- end
33
- end
34
-
35
- it 'delegate a request' do
36
- env = { 'PATH_INFO' => '/a', 'HTTP_USER_AGENT' => 'Mobile' }
37
- exp = [200, {"Content-Type" => "text/html"}, ["a mobile\n"]]
38
- @delegator.call(env).should == exp
39
- env = { 'PATH_INFO' => '/a', 'HTTP_USER_AGENT' => 'Desktop' }
40
- exp = [200, {"Content-Type" => "text/html"}, ["a desktop\n"]]
41
- @delegator.call(env).should == exp
42
- env = { 'PATH_INFO' => '/b', 'HTTP_USER_AGENT' => 'Desktop' }
43
- exp = [200, {"Content-Type" => "text/html"}, ["b desktop\n"]]
44
- @delegator.call(env).should == exp
45
- env = { 'PATH_INFO' => '/c', 'HTTP_USER_AGENT' => 'Desktop' }
46
- exp =[ 302, {"Content-Type" => "text/html", 'Location'=> '/' }, [] ]
47
- @delegator.call(env).should == exp
48
- end
49
-
50
- end
@@ -1,23 +0,0 @@
1
- require 'rubygems'
2
- require 'ruil/resource'
3
-
4
- describe 'Resource' do
5
-
6
- before(:all) do
7
- user_agent_parser = Proc.new do |env|
8
- /Mobile/ === env['HTTP_USER_AGENT'] ? :mobile : :desktop
9
- end
10
- @resource = Ruil::Resource.new(user_agent_parser) do |r|
11
- r.add_template :mobile, Proc.new { |opt| opt[:template_key].to_s }
12
- r.add_template :desktop, Proc.new { |opt| opt[:template_key].to_s }
13
- end
14
- end
15
-
16
- it 'should display a content' do
17
- env = { 'HTTP_USER_AGENT' => 'Mobile' }
18
- @resource.call(env).should == [200, {"Content-Type" => "text/html"}, ['mobile']]
19
- env = { 'HTTP_USER_AGENT' => 'Desktop' }
20
- @resource.call(env).should == [200, {"Content-Type" => "text/html"}, ['desktop']]
21
- end
22
-
23
- end
@@ -1 +0,0 @@
1
- a #{@template_key}
@@ -1 +0,0 @@
1
- a #{@template_key}
@@ -1 +0,0 @@
1
- b #{@template_key}
@@ -1 +0,0 @@
1
- b #{@template_key}