rocketio 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rocketio.rb +6 -3
- data/lib/rocketio/application.rb +3 -7
- data/lib/rocketio/controller.rb +62 -90
- data/lib/rocketio/controller/authentication.rb +38 -44
- data/lib/rocketio/controller/authorization.rb +8 -4
- data/lib/rocketio/controller/error_handlers.rb +12 -8
- data/lib/rocketio/controller/filters.rb +14 -19
- data/lib/rocketio/controller/helpers.rb +1 -1
- data/lib/rocketio/controller/middleware.rb +1 -1
- data/lib/rocketio/controller/render/engine.rb +3 -3
- data/lib/rocketio/controller/render/layout.rb +1 -1
- data/lib/rocketio/controller/render/layouts.rb +6 -6
- data/lib/rocketio/controller/render/template_vars.rb +3 -3
- data/lib/rocketio/controller/render/templates.rb +6 -6
- data/lib/rocketio/controller/sessions.rb +1 -1
- data/lib/rocketio/error_templates/409.html +11 -7
- data/lib/rocketio/error_templates/501.html +4 -4
- data/lib/rocketio/router.rb +35 -21
- data/lib/rocketio/version.rb +1 -1
- data/rocketio.gemspec +2 -0
- data/test/aliases_test.rb +2 -2
- data/test/api_test.rb +24 -117
- data/test/authentication_test.rb +96 -60
- data/test/authorization_test.rb +28 -17
- data/test/cache_control_test.rb +12 -12
- data/test/content_type_test.rb +7 -7
- data/test/cookies_test.rb +4 -4
- data/test/error_handlers_test.rb +14 -12
- data/test/etag_test.rb +32 -32
- data/test/filters_test.rb +96 -79
- data/test/halt_test.rb +1 -1
- data/test/helpers_test.rb +6 -6
- data/test/middleware_test.rb +4 -4
- data/test/redirect_test.rb +6 -7
- data/test/render/{post.erb → b.erb} +0 -0
- data/test/render/{put.erb → c.erb} +0 -0
- data/test/render/engine_test.rb +5 -5
- data/test/render/{get.erb → index.erb} +0 -0
- data/test/render/layout_test.rb +21 -17
- data/test/render/layouts_test.rb +14 -14
- data/test/render/render_test.rb +17 -14
- data/test/render/template_vars_test.rb +9 -9
- data/test/render/templates_test.rb +16 -16
- data/test/response_test.rb +4 -4
- data/test/routes_test.rb +21 -42
- data/test/sendfile_test.rb +8 -8
- data/test/sessions_test.rb +27 -27
- data/test/setup.rb +2 -0
- metadata +34 -6
File without changes
|
data/test/render/layout_test.rb
CHANGED
@@ -8,7 +8,7 @@ spec :Views do
|
|
8
8
|
}
|
9
9
|
b = mock_controller(a) {
|
10
10
|
}
|
11
|
-
assert(b.
|
11
|
+
assert(b.new.layout) == :master
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'overrides layout inherited from superclass' do
|
@@ -18,7 +18,7 @@ spec :Views do
|
|
18
18
|
b = mock_controller(a) {
|
19
19
|
layout :baster
|
20
20
|
}
|
21
|
-
assert(b.
|
21
|
+
assert(b.new.layout) == :baster
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'can use `inherit` to override layout inherited from superclass' do
|
@@ -31,12 +31,12 @@ spec :Views do
|
|
31
31
|
c = mock_controller(a) {
|
32
32
|
import :layout, from: b
|
33
33
|
}
|
34
|
-
assert(c.
|
34
|
+
assert(c.new.layout) == :baster
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'renders without layout if no default layout set' do
|
38
38
|
app mock_controller {
|
39
|
-
def
|
39
|
+
def index; render; end
|
40
40
|
}
|
41
41
|
get
|
42
42
|
assert(last_response).is_ok_with_body('/')
|
@@ -45,7 +45,7 @@ spec :Views do
|
|
45
45
|
it 'renders without layout if default layout set to false' do
|
46
46
|
app mock_controller {
|
47
47
|
layout false
|
48
|
-
def
|
48
|
+
def index; render; end
|
49
49
|
}
|
50
50
|
get
|
51
51
|
assert(last_response).is_ok_with_body('/')
|
@@ -55,15 +55,17 @@ spec :Views do
|
|
55
55
|
app mock_controller {
|
56
56
|
layout :layout
|
57
57
|
def var; @var end
|
58
|
-
def
|
59
|
-
def
|
60
|
-
def
|
58
|
+
def index; render(layout: nil); end
|
59
|
+
def b; @var = 'x'; render(layout: false); end
|
60
|
+
def c; @var = 'y'; render; end
|
61
61
|
}
|
62
62
|
get
|
63
63
|
assert(last_response).is_ok_with_body('/')
|
64
|
-
|
64
|
+
|
65
|
+
get :b
|
65
66
|
assert(last_response).is_ok_with_body('x')
|
66
|
-
|
67
|
+
|
68
|
+
get :c
|
67
69
|
assert(last_response).is_ok_with_body("=y=\n")
|
68
70
|
end
|
69
71
|
|
@@ -71,7 +73,7 @@ spec :Views do
|
|
71
73
|
app mock_controller {
|
72
74
|
define_layout(:master) {'=<%= yield %>='}
|
73
75
|
layout :master
|
74
|
-
def
|
76
|
+
def index; render; end
|
75
77
|
}
|
76
78
|
get
|
77
79
|
assert(last_response).is_ok_with_body('=/=')
|
@@ -81,7 +83,7 @@ spec :Views do
|
|
81
83
|
app mock_controller {
|
82
84
|
define_layout(:layout) {'-<%= yield %>-'}
|
83
85
|
layout :layout
|
84
|
-
def
|
86
|
+
def index; render; end
|
85
87
|
}
|
86
88
|
get
|
87
89
|
assert(last_response).is_ok_with_body('-/-')
|
@@ -92,18 +94,20 @@ spec :Views do
|
|
92
94
|
define_layout(:x) {'x<%= yield %>'}
|
93
95
|
define_layout(:y) {'y<%= yield %>'}
|
94
96
|
layout :x
|
95
|
-
def
|
96
|
-
def
|
97
|
+
def index; render {''}; end
|
98
|
+
def b; render(layout: :y) {''}; end
|
97
99
|
}
|
100
|
+
|
98
101
|
get
|
99
102
|
assert(last_response).is_ok_with_body('x')
|
100
|
-
|
103
|
+
|
104
|
+
get :b
|
101
105
|
assert(last_response).is_ok_with_body('y')
|
102
106
|
end
|
103
107
|
|
104
108
|
it 'accepts layout as :template option' do
|
105
109
|
app mock_controller {
|
106
|
-
def
|
110
|
+
def index; render_layout(template: '+<%= yield %>+') {'='}; end
|
107
111
|
}
|
108
112
|
get
|
109
113
|
assert(last_response).is_ok_with_body('+=+')
|
@@ -111,7 +115,7 @@ spec :Views do
|
|
111
115
|
|
112
116
|
it 'raises ArgumentError if both layout name and :template option given' do
|
113
117
|
app mock_controller {
|
114
|
-
def
|
118
|
+
def index; render_layout(:x, template: '+<%= yield %>+') {'='}; end
|
115
119
|
}
|
116
120
|
assert {get}.raise ArgumentError, /both/i
|
117
121
|
end
|
data/test/render/layouts_test.rb
CHANGED
@@ -7,7 +7,7 @@ spec :layouts do
|
|
7
7
|
define_layout(:a) {'a'}
|
8
8
|
}
|
9
9
|
b = mock_controller(a) {
|
10
|
-
}.
|
10
|
+
}.new
|
11
11
|
assert(b.__send__ b.layouts[:a]) == 'a'
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ spec :layouts do
|
|
17
17
|
}
|
18
18
|
b = mock_controller(a) {
|
19
19
|
define_layout(:b) {'b'}
|
20
|
-
}.
|
20
|
+
}.new
|
21
21
|
assert(b.__send__ b.layouts[:a]) == 'a'
|
22
22
|
assert(b.__send__ b.layouts[:b]) == 'b'
|
23
23
|
end
|
@@ -28,7 +28,7 @@ spec :layouts do
|
|
28
28
|
}
|
29
29
|
b = mock_controller(a) {
|
30
30
|
define_layout(:x) {'b'}
|
31
|
-
}.
|
31
|
+
}.new
|
32
32
|
assert(b.__send__ b.layouts[:x]) == 'b'
|
33
33
|
end
|
34
34
|
|
@@ -41,7 +41,7 @@ spec :layouts do
|
|
41
41
|
}
|
42
42
|
c = mock_controller(a) {
|
43
43
|
import :layouts, from: b
|
44
|
-
}.
|
44
|
+
}.new
|
45
45
|
assert(c.__send__ c.layouts[:x]) == 'b'
|
46
46
|
end
|
47
47
|
|
@@ -54,7 +54,7 @@ spec :layouts do
|
|
54
54
|
}
|
55
55
|
c = mock_controller(a) {
|
56
56
|
import :layouts, from: b
|
57
|
-
}.
|
57
|
+
}.new
|
58
58
|
assert(c.__send__ c.layouts[:a]) == 'a'
|
59
59
|
assert(c.__send__ c.layouts[:b]) == 'b'
|
60
60
|
end
|
@@ -66,7 +66,7 @@ spec :layouts do
|
|
66
66
|
b = mock_controller {
|
67
67
|
define_layout(:x) {'b'}
|
68
68
|
import :layouts, from: a
|
69
|
-
}.
|
69
|
+
}.new
|
70
70
|
assert(b.__send__ b.layouts[:x]) == 'a'
|
71
71
|
end
|
72
72
|
|
@@ -77,7 +77,7 @@ spec :layouts do
|
|
77
77
|
b = mock_controller {
|
78
78
|
define_layout(:b) {'b'}
|
79
79
|
import :layouts, from: a
|
80
|
-
}.
|
80
|
+
}.new
|
81
81
|
assert(b.__send__ b.layouts[:a]) == 'a'
|
82
82
|
assert(b.__send__ b.layouts[:b]) == 'b'
|
83
83
|
end
|
@@ -89,7 +89,7 @@ spec :layouts do
|
|
89
89
|
b = mock_controller {
|
90
90
|
import :layouts, from: a
|
91
91
|
define_layout(:x) {'b'}
|
92
|
-
}.
|
92
|
+
}.new
|
93
93
|
assert(b.__send__ b.layouts[:x]) == 'b'
|
94
94
|
end
|
95
95
|
end
|
@@ -98,7 +98,7 @@ spec :layouts do
|
|
98
98
|
it 'uses a file with same name if only name given' do
|
99
99
|
c = mock_controller {
|
100
100
|
define_layout :master
|
101
|
-
}.
|
101
|
+
}.new
|
102
102
|
assert(c.render_layout(:master) {'yo'}) == "master yo layout\n"
|
103
103
|
end
|
104
104
|
|
@@ -106,28 +106,28 @@ spec :layouts do
|
|
106
106
|
layout = rand.to_s
|
107
107
|
c = mock_controller {
|
108
108
|
define_layout layout
|
109
|
-
}.
|
109
|
+
}.new
|
110
110
|
assert {c.render_layout(layout) {}}.raise RocketIO::TemplateError
|
111
111
|
end
|
112
112
|
|
113
113
|
it 'uses given file - file resides in controller dirname' do
|
114
114
|
c = mock_controller {
|
115
115
|
define_layout :master, file: :layout
|
116
|
-
}.
|
116
|
+
}.new
|
117
117
|
assert(c.render_layout(:master) {'yo'}) == "=yo=\n"
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'uses given file - file resides outside controller dirname' do
|
121
121
|
c = mock_controller {
|
122
122
|
define_layout :master, file: './layouts/master'
|
123
|
-
}.
|
123
|
+
}.new
|
124
124
|
assert(c.render_layout(:master) {'yo'}) == "outside yo layout\n"
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'accepts a block for given file' do
|
128
128
|
c = mock_controller {
|
129
129
|
define_layout :master, file: -> {@outside ? './layouts/master' : :master}
|
130
|
-
}.
|
130
|
+
}.new
|
131
131
|
assert(c.render_layout(:master) {'yo'}) == "master yo layout\n"
|
132
132
|
c.instance_variable_set(:@outside, true)
|
133
133
|
assert(c.render_layout(:master) {'yo'}) == "outside yo layout\n"
|
@@ -136,7 +136,7 @@ spec :layouts do
|
|
136
136
|
it 'accepts a block and uses returned value as layout without searching for file' do
|
137
137
|
c = mock_controller {
|
138
138
|
define_layout(:master) {@admin ? ':<%= yield %>:' : '|<%= yield %>|'}
|
139
|
-
}.
|
139
|
+
}.new
|
140
140
|
assert(c.render_layout(:master) {'yo'}) == "|yo|"
|
141
141
|
c.instance_variable_set(:@admin, true)
|
142
142
|
assert(c.render_layout(:master) {'yo'}) == ":yo:"
|
data/test/render/render_test.rb
CHANGED
@@ -2,11 +2,12 @@ require 'setup'
|
|
2
2
|
|
3
3
|
spec :Views do
|
4
4
|
context :cache do
|
5
|
+
|
5
6
|
engine = Tilt::ERBTemplate
|
6
7
|
path = File.expand_path('../templates/a', __FILE__)
|
7
|
-
define_method(:file) {mock_controller(:a).
|
8
|
-
define_method(:read) {mock_controller(:a).
|
9
|
-
define_method(:compile) {|tpl| mock_controller(:a).
|
8
|
+
define_method(:file) {mock_controller(:a).new.send(:find_template, path, 'get', engine)}
|
9
|
+
define_method(:read) {mock_controller(:a).new.send(:read_template, file).__id__}
|
10
|
+
define_method(:compile) {|tpl| mock_controller(:a).new.send(:compile_template, tpl, engine).__id__}
|
10
11
|
|
11
12
|
it 'resolves template path only once' do
|
12
13
|
cache_id = file.__id__
|
@@ -28,23 +29,25 @@ spec :Views do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
context :scope do
|
32
|
+
|
31
33
|
it 'uses controller instance for scope' do
|
32
34
|
app mock_controller {
|
33
35
|
before {@var = :val}
|
34
|
-
def
|
36
|
+
def b; render; end
|
35
37
|
}
|
36
|
-
|
38
|
+
get :b
|
37
39
|
assert(last_response).is_ok_with_body('val')
|
38
40
|
end
|
41
|
+
|
39
42
|
it 'uses custom scope' do
|
40
43
|
app mock_controller {
|
41
44
|
before {@var = :val}
|
42
|
-
def
|
45
|
+
def b
|
43
46
|
scope = Class.new {def initialize; @var = :vax; end}.new
|
44
47
|
render(scope: scope)
|
45
48
|
end
|
46
49
|
}
|
47
|
-
|
50
|
+
get :b
|
48
51
|
assert(last_response).is_ok_with_body('vax')
|
49
52
|
end
|
50
53
|
end
|
@@ -52,9 +55,9 @@ spec :Views do
|
|
52
55
|
context :locals do
|
53
56
|
it 'makes :locals accessible via attributes' do
|
54
57
|
app mock_controller {
|
55
|
-
def
|
58
|
+
def c; render(locals: {var: :val}); end
|
56
59
|
}
|
57
|
-
|
60
|
+
get :c
|
58
61
|
assert(last_response).is_ok_with_body('val')
|
59
62
|
end
|
60
63
|
end
|
@@ -62,7 +65,7 @@ spec :Views do
|
|
62
65
|
context 'implicit templates' do
|
63
66
|
it 'uses the folder controller resides in as default path' do
|
64
67
|
app controller = mock_controller(:a) {
|
65
|
-
def
|
68
|
+
def index; render end
|
66
69
|
}
|
67
70
|
get
|
68
71
|
assert(last_response).is_ok_with_body '/a'
|
@@ -72,8 +75,8 @@ spec :Views do
|
|
72
75
|
context 'defined templates' do
|
73
76
|
it 'prefers defined templates over files' do
|
74
77
|
app mock_controller {
|
75
|
-
define_template(:
|
76
|
-
def
|
78
|
+
define_template(:index) {'x'}
|
79
|
+
def index; render end
|
77
80
|
}
|
78
81
|
get
|
79
82
|
assert(last_response).is_ok_with_body 'x'
|
@@ -84,7 +87,7 @@ spec :Views do
|
|
84
87
|
define_template(:t) {'t'}
|
85
88
|
define_layout(:x) {'x<%= yield %>x'}
|
86
89
|
layout(:x)
|
87
|
-
def
|
90
|
+
def index; render(:t) end
|
88
91
|
}
|
89
92
|
get
|
90
93
|
assert(last_response).is_ok_with_body 'xtx'
|
@@ -93,7 +96,7 @@ spec :Views do
|
|
93
96
|
|
94
97
|
it 'uses given block for template' do
|
95
98
|
app mock_controller {
|
96
|
-
def
|
99
|
+
def index; render {'x'} end
|
97
100
|
}
|
98
101
|
get
|
99
102
|
assert(last_response).is_ok_with_body 'x'
|
@@ -6,7 +6,7 @@ spec :template_vars do
|
|
6
6
|
a = mock_controller {
|
7
7
|
define_template_var(:a, 'a')
|
8
8
|
}
|
9
|
-
b = mock_controller(a) {}.
|
9
|
+
b = mock_controller(a) {}.new
|
10
10
|
assert(b.template_vars[:a]) == 'a'
|
11
11
|
end
|
12
12
|
|
@@ -16,7 +16,7 @@ spec :template_vars do
|
|
16
16
|
}
|
17
17
|
b = mock_controller(a) {
|
18
18
|
define_template_var(:b, 'b')
|
19
|
-
}.
|
19
|
+
}.new
|
20
20
|
assert(b.template_vars[:a]) == 'a'
|
21
21
|
assert(b.template_vars[:b]) == 'b'
|
22
22
|
end
|
@@ -27,7 +27,7 @@ spec :template_vars do
|
|
27
27
|
}
|
28
28
|
b = mock_controller(a) {
|
29
29
|
define_template_var(:a, 'b')
|
30
|
-
}.
|
30
|
+
}.new
|
31
31
|
assert(b.template_vars[:a]) == 'b'
|
32
32
|
end
|
33
33
|
|
@@ -40,7 +40,7 @@ spec :template_vars do
|
|
40
40
|
}
|
41
41
|
c = mock_controller(a) {
|
42
42
|
import :template_vars, from: b
|
43
|
-
}.
|
43
|
+
}.new
|
44
44
|
assert(c.template_vars[:a]) == 'b'
|
45
45
|
end
|
46
46
|
|
@@ -53,7 +53,7 @@ spec :template_vars do
|
|
53
53
|
}
|
54
54
|
c = mock_controller(a) {
|
55
55
|
import :template_vars, from: b
|
56
|
-
}.
|
56
|
+
}.new
|
57
57
|
assert(c.template_vars[:a]) == 'a'
|
58
58
|
assert(c.template_vars[:b]) == 'b'
|
59
59
|
end
|
@@ -65,7 +65,7 @@ spec :template_vars do
|
|
65
65
|
b = mock_controller {
|
66
66
|
define_template_var(:a, 'b')
|
67
67
|
import :template_vars, from: a
|
68
|
-
}.
|
68
|
+
}.new
|
69
69
|
assert(b.template_vars[:a]) == 'a'
|
70
70
|
end
|
71
71
|
end
|
@@ -76,7 +76,7 @@ spec :template_vars do
|
|
76
76
|
c = mock_controller {
|
77
77
|
define_template(:get) {'<%= x %>'}
|
78
78
|
define_template_var(:x, 'y')
|
79
|
-
}.
|
79
|
+
}.new
|
80
80
|
assert(c.render(:get)) == 'y'
|
81
81
|
end
|
82
82
|
|
@@ -84,7 +84,7 @@ spec :template_vars do
|
|
84
84
|
c = mock_controller {
|
85
85
|
define_template(:get) {'<%= x %>'}
|
86
86
|
define_template_var(:x, -> {'y'})
|
87
|
-
}.
|
87
|
+
}.new
|
88
88
|
assert(c.render(:get)) == 'y'
|
89
89
|
end
|
90
90
|
|
@@ -92,7 +92,7 @@ spec :template_vars do
|
|
92
92
|
c = mock_controller {
|
93
93
|
define_template(:get) {'<%= x %>'}
|
94
94
|
define_template_var(:x) {'y'}
|
95
|
-
}.
|
95
|
+
}.new
|
96
96
|
assert(c.render(:get)) == 'y'
|
97
97
|
end
|
98
98
|
|
@@ -7,7 +7,7 @@ spec :templates do
|
|
7
7
|
define_template(:a) {'a'}
|
8
8
|
}
|
9
9
|
b = mock_controller(a) {
|
10
|
-
}.
|
10
|
+
}.new
|
11
11
|
assert(b.__send__ b.templates[:a]) == 'a'
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ spec :templates do
|
|
17
17
|
}
|
18
18
|
b = mock_controller(a) {
|
19
19
|
define_template(:b) {'b'}
|
20
|
-
}.
|
20
|
+
}.new
|
21
21
|
assert(b.__send__ b.templates[:a]) == 'a'
|
22
22
|
assert(b.__send__ b.templates[:b]) == 'b'
|
23
23
|
end
|
@@ -28,7 +28,7 @@ spec :templates do
|
|
28
28
|
}
|
29
29
|
b = mock_controller(a) {
|
30
30
|
define_template(:x) {'b'}
|
31
|
-
}.
|
31
|
+
}.new
|
32
32
|
assert(b.__send__ b.templates[:x]) == 'b'
|
33
33
|
end
|
34
34
|
|
@@ -41,7 +41,7 @@ spec :templates do
|
|
41
41
|
}
|
42
42
|
c = mock_controller(a) {
|
43
43
|
import :templates, from: b
|
44
|
-
}.
|
44
|
+
}.new
|
45
45
|
assert(c.__send__ c.templates[:x]) == 'b'
|
46
46
|
end
|
47
47
|
|
@@ -54,7 +54,7 @@ spec :templates do
|
|
54
54
|
}
|
55
55
|
c = mock_controller(a) {
|
56
56
|
import :templates, from: b
|
57
|
-
}.
|
57
|
+
}.new
|
58
58
|
assert(c.__send__ c.templates[:a]) == 'a'
|
59
59
|
assert(c.__send__ c.templates[:b]) == 'b'
|
60
60
|
end
|
@@ -66,7 +66,7 @@ spec :templates do
|
|
66
66
|
b = mock_controller {
|
67
67
|
define_template(:x) {'b'}
|
68
68
|
import :templates, from: a
|
69
|
-
}.
|
69
|
+
}.new
|
70
70
|
assert(b.__send__ b.templates[:x]) == 'a'
|
71
71
|
end
|
72
72
|
|
@@ -77,7 +77,7 @@ spec :templates do
|
|
77
77
|
b = mock_controller {
|
78
78
|
define_template(:b) {'b'}
|
79
79
|
import :templates, from: a
|
80
|
-
}.
|
80
|
+
}.new
|
81
81
|
assert(b.__send__ b.templates[:a]) == 'a'
|
82
82
|
assert(b.__send__ b.templates[:b]) == 'b'
|
83
83
|
end
|
@@ -89,7 +89,7 @@ spec :templates do
|
|
89
89
|
b = mock_controller {
|
90
90
|
import :templates, from: a
|
91
91
|
define_template(:x) {'b'}
|
92
|
-
}.
|
92
|
+
}.new
|
93
93
|
assert(b.__send__ b.templates[:x]) == 'b'
|
94
94
|
end
|
95
95
|
end
|
@@ -98,37 +98,37 @@ spec :templates do
|
|
98
98
|
|
99
99
|
it 'uses a file with same name if only name given' do
|
100
100
|
c = mock_controller {
|
101
|
-
define_template :
|
102
|
-
}.
|
103
|
-
assert(c.render(:
|
101
|
+
define_template :index
|
102
|
+
}.new
|
103
|
+
assert(c.render(:index)) == "/"
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'raises a TemplateError if there is no file with same name' do
|
107
107
|
template = rand.to_s
|
108
108
|
c = mock_controller {
|
109
109
|
define_template template
|
110
|
-
}.
|
110
|
+
}.new
|
111
111
|
assert {c.render(template)}.raise RocketIO::TemplateError
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'uses given file - file resides in controller dirname' do
|
115
115
|
c = mock_controller {
|
116
116
|
define_template :get, file: :items
|
117
|
-
}.
|
117
|
+
}.new
|
118
118
|
assert(c.render(:get)) == "items\n"
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'uses given file - file resides outside controller dirname' do
|
122
122
|
c = mock_controller {
|
123
123
|
define_template :get, file: './templates/a/get'
|
124
|
-
}.
|
124
|
+
}.new
|
125
125
|
assert(c.render(:get)) == "hi\n"
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'accepts a block for given file' do
|
129
129
|
c = mock_controller {
|
130
130
|
define_template :master, file: -> {@outside ? './templates/a/get' : :items}
|
131
|
-
}.
|
131
|
+
}.new
|
132
132
|
assert(c.render(:master)) == "items\n"
|
133
133
|
c.instance_variable_set(:@outside, true)
|
134
134
|
assert(c.render(:master)) == "hi\n"
|
@@ -137,7 +137,7 @@ spec :templates do
|
|
137
137
|
it 'accepts a block and uses returned value as template without searching for file' do
|
138
138
|
c = mock_controller {
|
139
139
|
define_template(:master) {@admin ? 'admin' : 'user'}
|
140
|
-
}.
|
140
|
+
}.new
|
141
141
|
assert(c.render(:master)) == "user"
|
142
142
|
c.instance_variable_set(:@admin, true)
|
143
143
|
assert(c.render(:master)) == "admin"
|