padrino-helpers 0.12.9 → 0.13.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/padrino-helpers.rb +2 -2
- data/lib/padrino-helpers/asset_tag_helpers.rb +18 -26
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +3 -56
- data/lib/padrino-helpers/form_builder/standard_form_builder.rb +1 -1
- data/lib/padrino-helpers/form_helpers.rb +11 -227
- data/lib/padrino-helpers/form_helpers/options.rb +5 -7
- data/lib/padrino-helpers/output_helpers.rb +1 -1
- data/lib/padrino-helpers/output_helpers/abstract_handler.rb +1 -1
- data/lib/padrino-helpers/output_helpers/erb_handler.rb +1 -2
- data/lib/padrino-helpers/render_helpers.rb +2 -23
- data/lib/padrino-helpers/tag_helpers.rb +1 -14
- data/lib/padrino/rendering.rb +4 -56
- data/lib/padrino/rendering/erb_template.rb +0 -12
- data/lib/padrino/rendering/erubis_template.rb +1 -1
- data/padrino-helpers.gemspec +1 -1
- data/test/fixtures/markup_app/views/form_for.erb +0 -28
- data/test/fixtures/markup_app/views/form_for.haml +0 -22
- data/test/fixtures/markup_app/views/form_for.slim +0 -21
- data/test/fixtures/markup_app/views/form_tag.erb +0 -21
- data/test/fixtures/markup_app/views/form_tag.haml +0 -14
- data/test/fixtures/markup_app/views/form_tag.slim +0 -14
- data/test/helper.rb +17 -6
- data/test/test_asset_tag_helpers.rb +92 -110
- data/test/test_form_builder.rb +450 -691
- data/test/test_form_helpers.rb +457 -770
- data/test/test_format_helpers.rb +37 -17
- data/test/test_helpers.rb +0 -8
- data/test/test_output_helpers.rb +72 -72
- data/test/test_render_helpers.rb +100 -142
- data/test/test_rendering.rb +1 -58
- data/test/test_tag_helpers.rb +39 -41
- metadata +118 -34
- data/lib/padrino-helpers/form_builder/deprecated_builder_methods.rb +0 -79
data/test/test_format_helpers.rb
CHANGED
@@ -57,6 +57,25 @@ describe "FormatHelpers" do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
describe 'for #pluralize method' do
|
61
|
+
it 'should return singular count for 1 item collections' do
|
62
|
+
actual_text = pluralize(1, 'person')
|
63
|
+
assert_equal '1 person', actual_text
|
64
|
+
end
|
65
|
+
it 'should return plural count for empty collections' do
|
66
|
+
actual_text = pluralize(0, 'person')
|
67
|
+
assert_equal '0 people', actual_text
|
68
|
+
end
|
69
|
+
it 'should return plural count for many collections' do
|
70
|
+
actual_text = pluralize(2, 'person')
|
71
|
+
assert_equal '2 people', actual_text
|
72
|
+
end
|
73
|
+
it 'should return pluralized word specified as argument' do
|
74
|
+
actual_text = pluralize(3, 'person', 'users')
|
75
|
+
assert_equal '3 users', actual_text
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
60
79
|
describe 'for #word_wrap method' do
|
61
80
|
it 'should return proper formatting for 8 max width' do
|
62
81
|
actual_text = word_wrap('Once upon a time', :line_width => 8)
|
@@ -139,8 +158,6 @@ describe "FormatHelpers" do
|
|
139
158
|
end
|
140
159
|
|
141
160
|
describe 'for #time_ago_in_words method' do
|
142
|
-
_DAY = 24*60*60
|
143
|
-
|
144
161
|
it 'should less than 5 seconds' do
|
145
162
|
assert_equal 'less than 5 seconds', time_ago_in_words(Time.now, true)
|
146
163
|
end
|
@@ -160,49 +177,52 @@ describe "FormatHelpers" do
|
|
160
177
|
assert_equal 'less than a minute', time_ago_in_words(Time.now)
|
161
178
|
end
|
162
179
|
it 'should display yesterday' do
|
163
|
-
assert_equal '1 day', time_ago_in_words(
|
180
|
+
assert_equal '1 day', time_ago_in_words(1.day.ago)
|
164
181
|
end
|
165
182
|
it 'should display tomorrow' do
|
166
|
-
assert_equal '1 day', time_ago_in_words(
|
183
|
+
assert_equal '1 day', time_ago_in_words(1.day.from_now)
|
167
184
|
end
|
168
185
|
it 'should return future number of days' do
|
169
|
-
assert_equal '4 days', time_ago_in_words(
|
186
|
+
assert_equal '4 days', time_ago_in_words(4.days.from_now)
|
170
187
|
end
|
171
188
|
it 'should return past days ago' do
|
172
|
-
assert_equal '4 days', time_ago_in_words(
|
189
|
+
assert_equal '4 days', time_ago_in_words(4.days.ago)
|
173
190
|
end
|
174
191
|
it 'should return formatted archived date' do
|
175
|
-
assert_equal '3 months', time_ago_in_words(
|
192
|
+
assert_equal '3 months', time_ago_in_words(100.days.ago)
|
176
193
|
end
|
177
194
|
it 'should return formatted archived year date' do
|
178
|
-
assert_equal 'over 1 year', time_ago_in_words(
|
195
|
+
assert_equal 'over 1 year', time_ago_in_words(500.days.ago)
|
179
196
|
end
|
180
197
|
it 'should display now as a minute ago' do
|
181
|
-
assert_equal '1 minute', time_ago_in_words(
|
198
|
+
assert_equal '1 minute', time_ago_in_words(1.minute.ago)
|
182
199
|
end
|
183
200
|
it 'should display a few minutes ago' do
|
184
|
-
assert_equal '4 minutes', time_ago_in_words(
|
201
|
+
assert_equal '4 minutes', time_ago_in_words(4.minute.ago)
|
185
202
|
end
|
186
203
|
it 'should display an hour ago' do
|
187
|
-
assert_equal 'about 1 hour', time_ago_in_words(
|
204
|
+
assert_equal 'about 1 hour', time_ago_in_words(1.hour.ago + 5.minutes.ago.sec)
|
188
205
|
end
|
189
206
|
it 'should display a few hours ago' do
|
190
|
-
assert_equal 'about 3 hours', time_ago_in_words(
|
207
|
+
assert_equal 'about 3 hours', time_ago_in_words(3.hour.ago + 5.minutes.ago.sec)
|
208
|
+
end
|
209
|
+
it 'should display a day ago' do
|
210
|
+
assert_equal '1 day', time_ago_in_words(1.day.ago)
|
191
211
|
end
|
192
212
|
it 'should display a few days ago' do
|
193
|
-
assert_equal '5 days', time_ago_in_words(
|
213
|
+
assert_equal '5 days', time_ago_in_words(5.days.ago - 5.minutes.ago.sec)
|
194
214
|
end
|
195
215
|
it 'should display a month ago' do
|
196
|
-
assert_equal 'about 1 month', time_ago_in_words(
|
216
|
+
assert_equal 'about 1 month', time_ago_in_words(32.days.ago + 5.minutes.ago.sec)
|
197
217
|
end
|
198
218
|
it 'should display a few months ago' do
|
199
|
-
assert_equal '6 months', time_ago_in_words(
|
219
|
+
assert_equal '6 months', time_ago_in_words(180.days.ago - 5.minutes.ago.sec)
|
200
220
|
end
|
201
221
|
it 'should display a year ago' do
|
202
|
-
assert_equal 'about 1 year', time_ago_in_words(
|
222
|
+
assert_equal 'about 1 year', time_ago_in_words(365.days.ago - 5.minutes.ago.sec)
|
203
223
|
end
|
204
224
|
it 'should display a few years ago' do
|
205
|
-
assert_equal 'over 7 years', time_ago_in_words(
|
225
|
+
assert_equal 'over 7 years', time_ago_in_words(2800.days.ago - 5.minutes.ago.sec)
|
206
226
|
end
|
207
227
|
end
|
208
228
|
|
data/test/test_helpers.rb
CHANGED
@@ -7,12 +7,4 @@ describe "Padrino::Helpers" do
|
|
7
7
|
end
|
8
8
|
assert_equal '<div>bar</div>', Foo.new.content_tag(:div, 'bar')
|
9
9
|
end
|
10
|
-
|
11
|
-
it 'should not overwrite default_builder setting' do
|
12
|
-
mock_app do
|
13
|
-
set :default_builder, 'FancyBuilder'
|
14
|
-
register Padrino::Helpers
|
15
|
-
end
|
16
|
-
assert_equal 'FancyBuilder', @app.default_builder
|
17
|
-
end
|
18
10
|
end
|
data/test/test_output_helpers.rb
CHANGED
@@ -8,150 +8,150 @@ describe "OutputHelpers" do
|
|
8
8
|
|
9
9
|
describe 'for #content_for method' do
|
10
10
|
it 'should work for erb templates' do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
visit '/erb/content_for'
|
12
|
+
assert_have_selector '.demo h1', :content => "This is content yielded from a content_for", :count => 1
|
13
|
+
assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith", :count => 1
|
14
|
+
assert_have_no_selector '.demo3 p', :content => "One", :class => "duplication"
|
15
|
+
assert_have_selector '.demo3 p', :content => "Two", :class => "duplication"
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should work for haml templates' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
visit '/haml/content_for'
|
20
|
+
assert_have_selector '.demo h1', :content => "This is content yielded from a content_for", :count => 1
|
21
|
+
assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith", :count => 1
|
22
|
+
assert_have_no_selector '.demo3 p', :content => "One", :class => "duplication"
|
23
|
+
assert_have_selector '.demo3 p', :content => "Two", :class => "duplication"
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should work for slim templates' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
visit '/slim/content_for'
|
28
|
+
assert_have_selector '.demo h1', :content => "This is content yielded from a content_for", :count => 1
|
29
|
+
assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith", :count => 1
|
30
|
+
assert_have_no_selector '.demo3 p', :content => "One", :class => "duplication"
|
31
|
+
assert_have_selector '.demo3 p', :content => "Two", :class => "duplication"
|
32
32
|
end
|
33
33
|
end # content_for
|
34
34
|
|
35
35
|
describe "for #content_for? method" do
|
36
36
|
it 'should work for erb templates' do
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
visit '/erb/content_for'
|
38
|
+
assert_have_selector '.demo_has_content', :content => "true"
|
39
|
+
assert_have_selector '.fake_has_content', :content => "false"
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should work for haml templates' do
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
visit '/haml/content_for'
|
44
|
+
assert_have_selector '.demo_has_content', :content => "true"
|
45
|
+
assert_have_selector '.fake_has_content', :content => "false"
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should work for slim templates' do
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
visit '/slim/content_for'
|
50
|
+
assert_have_selector '.demo_has_content', :content => "true"
|
51
|
+
assert_have_selector '.fake_has_content', :content => "false"
|
52
52
|
end
|
53
53
|
end # content_for?
|
54
54
|
|
55
55
|
describe 'for #capture_html method' do
|
56
56
|
it 'should work for erb templates' do
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
visit '/erb/capture_concat'
|
58
|
+
assert_have_selector 'p span', :content => "Captured Line 1", :count => 1
|
59
|
+
assert_have_selector 'p span', :content => "Captured Line 2", :count => 1
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should work for haml templates' do
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
visit '/haml/capture_concat'
|
64
|
+
assert_have_selector 'p span', :content => "Captured Line 1", :count => 1
|
65
|
+
assert_have_selector 'p span', :content => "Captured Line 2", :count => 1
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'should work for slim templates' do
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
visit '/slim/capture_concat'
|
70
|
+
assert_have_selector 'p span', :content => "Captured Line 1", :count => 1
|
71
|
+
assert_have_selector 'p span', :content => "Captured Line 2", :count => 1
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe 'for #concat_content method' do
|
76
76
|
it 'should work for erb templates' do
|
77
|
-
|
78
|
-
|
77
|
+
visit '/erb/capture_concat'
|
78
|
+
assert_have_selector 'p', :content => "Concat Line 3", :count => 1
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should work for haml templates' do
|
82
|
-
|
83
|
-
|
82
|
+
visit '/haml/capture_concat'
|
83
|
+
assert_have_selector 'p', :content => "Concat Line 3", :count => 1
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should work for slim templates' do
|
87
|
-
|
88
|
-
|
87
|
+
visit '/slim/capture_concat'
|
88
|
+
assert_have_selector 'p', :content => "Concat Line 3", :count => 1
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
describe 'for #block_is_template?' do
|
93
93
|
it 'should work for erb templates' do
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
visit '/erb/capture_concat'
|
95
|
+
assert_have_selector 'p', :content => "The erb block passed in is a template", :class => 'is_template', :count => 1
|
96
|
+
assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template', :count => 1
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should work for haml templates' do
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
visit '/haml/capture_concat'
|
101
|
+
assert_have_selector 'p', :content => "The haml block passed in is a template", :class => 'is_template', :count => 1
|
102
|
+
assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template', :count => 1
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should work for slim templates' do
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
visit '/slim/capture_concat'
|
107
|
+
assert_have_selector 'p', :content => "The slim block passed in is a template", :class => 'is_template', :count => 1
|
108
|
+
assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template', :count => 1
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
describe 'for #current_engine method' do
|
113
113
|
it 'should detect correctly current engine for erb' do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
visit '/erb/current_engine'
|
115
|
+
assert_have_selector 'p.start', :content => "erb"
|
116
|
+
assert_have_selector 'p.haml', :content => "haml"
|
117
|
+
assert_have_selector 'p.erb', :content => "erb"
|
118
|
+
assert_have_selector 'p.slim', :content => "slim"
|
119
|
+
assert_have_selector 'p.end', :content => "erb"
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should detect correctly current engine for haml' do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
123
|
+
visit '/haml/current_engine'
|
124
|
+
assert_have_selector 'p.start', :content => "haml"
|
125
|
+
assert_have_selector 'p.haml', :content => "haml"
|
126
|
+
assert_have_selector 'p.erb', :content => "erb"
|
127
|
+
assert_have_selector 'p.slim', :content => "slim"
|
128
|
+
assert_have_selector 'p.end', :content => "haml"
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should detect correctly current engine for slim' do
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
132
|
+
visit '/slim/current_engine'
|
133
|
+
assert_have_selector 'p.start', :content => "slim"
|
134
|
+
assert_have_selector 'p.haml', :content => "haml"
|
135
|
+
assert_have_selector 'p.erb', :content => "erb"
|
136
|
+
assert_have_selector 'p.slim', :content => "slim"
|
137
|
+
assert_have_selector 'p.end', :content => "slim"
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
141
|
describe 'for #partial method in simple sinatra application' do
|
142
142
|
it 'should properly output in erb' do
|
143
|
-
|
144
|
-
|
143
|
+
visit '/erb/simple_partial'
|
144
|
+
assert_have_selector 'p.erb', :content => "erb"
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should properly output in haml' do
|
148
|
-
|
149
|
-
|
148
|
+
visit '/haml/simple_partial'
|
149
|
+
assert_have_selector 'p.haml', :content => "haml"
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should properly output in slim' do
|
153
|
-
|
154
|
-
|
153
|
+
visit '/slim/simple_partial'
|
154
|
+
assert_have_selector 'p.slim', :content => "slim"
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
data/test/test_render_helpers.rb
CHANGED
@@ -7,261 +7,219 @@ describe "RenderHelpers" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'for #partial method and object' do
|
10
|
-
before {
|
10
|
+
before { visit '/partial/object' }
|
11
11
|
it 'should render partial html with object' do
|
12
|
-
|
12
|
+
assert_have_selector "h1", :content => "User name is John"
|
13
13
|
end
|
14
14
|
it 'should have no counter index for single item' do
|
15
|
-
|
15
|
+
assert_have_no_selector "p", :content => "My counter is 1", :count => 1
|
16
16
|
end
|
17
17
|
it 'should include extra locals information' do
|
18
|
-
|
18
|
+
assert_have_selector 'p', :content => "Extra is bar"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'for #partial method and collection' do
|
23
|
-
before {
|
23
|
+
before { visit '/partial/collection' }
|
24
24
|
it 'should render partial html with collection' do
|
25
|
-
|
26
|
-
|
25
|
+
assert_have_selector "h1", :content => "User name is John"
|
26
|
+
assert_have_selector "h1", :content => "User name is Billy"
|
27
27
|
end
|
28
28
|
it 'should include counter which contains item index' do
|
29
|
-
|
30
|
-
|
29
|
+
assert_have_selector "p", :content => "My counter is 1"
|
30
|
+
assert_have_selector "p", :content => "My counter is 2"
|
31
31
|
end
|
32
32
|
it 'should include extra locals information' do
|
33
|
-
|
33
|
+
assert_have_selector 'p', :content => "Extra is bar"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'for #partial with ext and collection' do
|
38
|
-
before {
|
38
|
+
before { visit '/partial/collection.ext' }
|
39
39
|
it 'should not fail horribly with `invalid locals key` RuntimeError' do
|
40
|
-
|
40
|
+
assert_have_selector "h1", :content => "User name is John"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'for #partial method and locals' do
|
45
|
-
before {
|
45
|
+
before { visit '/partial/locals' }
|
46
46
|
it 'should render partial html with locals' do
|
47
|
-
|
47
|
+
assert_have_selector "h1", :content => "User name is John"
|
48
48
|
end
|
49
49
|
it 'should have no counter index for single item' do
|
50
|
-
|
50
|
+
assert_have_no_selector "p", :content => "My counter is 1", :count => 1
|
51
51
|
end
|
52
52
|
it 'should include extra locals information' do
|
53
|
-
|
53
|
+
assert_have_selector 'p', :content => "Extra is bar"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe 'for #partial method taking a path starting with forward slash' do
|
58
|
-
before {
|
58
|
+
before { visit '/partial/foward_slash' }
|
59
59
|
it 'should render partial without throwing an error' do
|
60
|
-
|
60
|
+
assert_have_selector "h1", :content => "User name is John"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe 'for #partial method with unsafe engine' do
|
65
65
|
it 'should render partial without escaping it' do
|
66
|
-
|
67
|
-
|
66
|
+
visit '/partial/unsafe'
|
67
|
+
assert_have_selector "h1", :content => "User name is John"
|
68
68
|
end
|
69
69
|
it 'should render partial object without escaping it' do
|
70
|
-
|
71
|
-
|
70
|
+
visit '/partial/unsafe_one'
|
71
|
+
assert_have_selector "h1", :content => "User name is Mary"
|
72
72
|
end
|
73
73
|
it 'should render partial collection without escaping it' do
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
visit '/partial/unsafe_many'
|
75
|
+
assert_have_selector "h1", :content => "User name is John"
|
76
|
+
assert_have_selector "h1", :content => "User name is Mary"
|
77
77
|
end
|
78
78
|
it 'should render unsafe partial without escaping it' do
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
visit '/partial/unsafe?block=%3Cevil%3E'
|
80
|
+
assert_have_selector "h1", :content => "User name is John"
|
81
|
+
assert_have_selector "evil"
|
82
82
|
end
|
83
83
|
it 'should render unsafe partial object without escaping it' do
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
visit '/partial/unsafe_one?block=%3Cevil%3E'
|
85
|
+
assert_have_selector "h1", :content => "User name is Mary"
|
86
|
+
assert_have_selector "evil"
|
87
87
|
end
|
88
88
|
it 'should render unsafe partial collection without escaping it' do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
visit '/partial/unsafe_many?block=%3Cevil%3E'
|
90
|
+
assert_have_selector "h1", :content => "User name is John"
|
91
|
+
assert_have_selector "h1", :content => "User name is Mary"
|
92
|
+
assert_have_selector "evil"
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
describe 'render with block' do
|
97
97
|
it 'should render slim with block' do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
visit '/render_block_slim'
|
99
|
+
assert_have_selector 'h1', :content => 'prefix'
|
100
|
+
assert_have_selector 'h3', :content => 'postfix'
|
101
|
+
assert_have_selector '.slim-block'
|
102
|
+
assert_have_selector 'div', :content => 'go block!'
|
103
103
|
end
|
104
104
|
it 'should render erb with block' do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
visit '/render_block_erb'
|
106
|
+
assert_have_selector 'h1', :content => 'prefix'
|
107
|
+
assert_have_selector 'h3', :content => 'postfix'
|
108
|
+
assert_have_selector '.erb-block'
|
109
|
+
assert_have_selector 'div', :content => 'go block!'
|
110
110
|
end
|
111
111
|
it 'should render haml with block' do
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
112
|
+
visit '/render_block_haml'
|
113
|
+
assert_have_selector 'h1', :content => 'prefix'
|
114
|
+
assert_have_selector 'h3', :content => 'postfix'
|
115
|
+
assert_have_selector '.haml-block'
|
116
|
+
assert_have_selector 'div', :content => 'go block!'
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe 'partial with block' do
|
121
121
|
it 'should show partial slim with block' do
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
visit '/partial_block_slim'
|
123
|
+
assert_have_selector 'h1', :content => 'prefix'
|
124
|
+
assert_have_selector 'h3', :content => 'postfix'
|
125
|
+
assert_have_selector '.slim-block'
|
126
|
+
assert_have_selector 'div', :content => 'go block!'
|
127
|
+
assert_have_selector 'div.deep', :content => 'Done'
|
128
128
|
end
|
129
129
|
it 'should show partial erb with block' do
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
visit '/partial_block_erb'
|
131
|
+
assert_have_selector 'h1', :content => 'prefix'
|
132
|
+
assert_have_selector 'h3', :content => 'postfix'
|
133
|
+
assert_have_selector '.erb-block'
|
134
|
+
assert_have_selector 'div', :content => 'go block!'
|
135
|
+
assert_have_selector 'div.deep', :content => 'Done'
|
136
136
|
end
|
137
137
|
it 'should show partial haml with block' do
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
138
|
+
visit '/partial_block_haml'
|
139
|
+
assert_have_selector 'h1', :content => 'prefix'
|
140
|
+
assert_have_selector 'h3', :content => 'postfix'
|
141
|
+
assert_have_selector '.haml-block'
|
142
|
+
assert_have_selector 'div', :content => 'go block!'
|
143
|
+
assert_have_selector 'div.deep', :content => 'Done'
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
147
|
describe 'for #current_engine method' do
|
148
148
|
it 'should detect correctly current engine for a padrino application' do
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
visit '/current_engine'
|
150
|
+
assert_have_selector 'p.start', :content => "haml"
|
151
|
+
assert_have_selector 'p.haml span', :content => "haml"
|
152
|
+
assert_have_selector 'p.erb span', :content => "erb"
|
153
|
+
assert_have_selector 'p.slim span', :content => "slim"
|
154
|
+
assert_have_selector 'p.end', :content => "haml"
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'should detect correctly current engine for explicit engine on partials' do
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
158
|
+
visit '/explicit_engine'
|
159
|
+
assert_have_selector 'p.start', :content => "haml"
|
160
|
+
assert_have_selector 'p.haml span', :content => "haml"
|
161
|
+
assert_have_selector 'p.erb span', :content => "erb"
|
162
|
+
assert_have_selector 'p.slim span', :content => "slim"
|
163
|
+
assert_have_selector 'p.end', :content => "haml"
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should capture slim template once and only once' do
|
167
167
|
$number_of_captures = 0
|
168
|
-
|
168
|
+
visit '/double_capture_slim'
|
169
169
|
assert_equal 1,$number_of_captures
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'should capture haml template once and only once' do
|
173
173
|
$number_of_captures = 0
|
174
|
-
|
174
|
+
visit '/double_capture_haml'
|
175
175
|
assert_equal 1,$number_of_captures
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should capture erb template once and only once' do
|
179
179
|
$number_of_captures = 0
|
180
|
-
|
180
|
+
visit '/double_capture_erb'
|
181
181
|
assert_equal 1,$number_of_captures
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should fail on wrong erb usage' do
|
185
185
|
assert_raises(SyntaxError) do
|
186
|
-
|
186
|
+
visit '/wrong_capture_erb'
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'should ignore wrong haml usage' do
|
191
|
-
|
192
|
-
|
191
|
+
visit '/wrong_capture_haml'
|
192
|
+
assert_have_no_selector 'p', :content => 'this is wrong'
|
193
193
|
end
|
194
194
|
|
195
195
|
it 'should ignore wrong slim usage' do
|
196
|
-
|
197
|
-
|
196
|
+
visit '/wrong_capture_slim'
|
197
|
+
assert_have_no_selector 'p', :content => 'this is wrong'
|
198
198
|
end
|
199
199
|
|
200
200
|
it 'should support weird ruby blocks in erb' do
|
201
|
-
|
202
|
-
|
201
|
+
visit '/ruby_block_capture_erb'
|
202
|
+
assert_have_selector 'b', :content => 'c'
|
203
203
|
end
|
204
204
|
|
205
205
|
it 'should support weird ruby blocks in haml' do
|
206
|
-
|
207
|
-
|
206
|
+
visit '/ruby_block_capture_haml'
|
207
|
+
assert_have_selector 'b', :content => 'c'
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'should support weird ruby blocks in slim' do
|
211
|
-
|
212
|
-
|
211
|
+
visit '/ruby_block_capture_slim'
|
212
|
+
assert_have_selector 'b', :content => 'c'
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
describe '
|
217
|
-
|
218
|
-
|
219
|
-
|
216
|
+
describe 'rendering with helpers that use render' do
|
217
|
+
%W{erb haml slim}.each do |engine|
|
218
|
+
it "should work with #{engine}" do
|
219
|
+
skip
|
220
|
+
visit "/double_dive_#{engine}"
|
221
|
+
assert_have_selector '.outer .wrapper form .inner .core'
|
220
222
|
end
|
221
|
-
locals = { :user => OpenStruct.new(:name => 'Joe') }
|
222
|
-
result = Standalone.new.partial(File.join(File.dirname(__FILE__), 'fixtures/render_app/views/template/user'), :engine => :haml, :locals => locals)
|
223
|
-
assert_equal '<h1>User name is Joe</h1>', result.chomp
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'should pass class context to renderer' do
|
227
|
-
class Standalone1
|
228
|
-
include Padrino::Helpers::RenderHelpers
|
229
|
-
def user
|
230
|
-
OpenStruct.new(:name => 'Jane')
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
result = Standalone1.new.partial(File.join(File.dirname(__FILE__), 'fixtures/render_app/views/template/user.haml'))
|
235
|
-
assert_equal '<h1>User name is Jane</h1>', result.chomp
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'should fail on missing template' do
|
239
|
-
class Standalone2
|
240
|
-
include Padrino::Helpers::RenderHelpers
|
241
|
-
end
|
242
|
-
assert_raises RuntimeError do
|
243
|
-
result = Standalone2.new.partial('none')
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'should not override existing render methods' do
|
248
|
-
class Standalone3
|
249
|
-
def render(*)
|
250
|
-
'existing'
|
251
|
-
end
|
252
|
-
include Padrino::Helpers::RenderHelpers
|
253
|
-
end
|
254
|
-
assert_equal 'existing', Standalone3.new.partial('none')
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'should not add "./" to partial template name' do
|
258
|
-
class Standalone4
|
259
|
-
def render(_, file, *)
|
260
|
-
file.to_s
|
261
|
-
end
|
262
|
-
include Padrino::Helpers::RenderHelpers
|
263
|
-
end
|
264
|
-
assert_equal '_none', Standalone4.new.partial('none')
|
265
223
|
end
|
266
224
|
end
|
267
225
|
end
|