ghazel-erubis_rails_helper 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +66 -0
- data/lib/erubis_rails_helper/erubis/generator.rb +100 -0
- data/lib/erubis_rails_helper/template_handlers/erubis.rb +260 -0
- data/lib/erubis_rails_helper.rb +20 -0
- data/test/abstract_unit.rb +51 -0
- data/test/controller/action_pack_assertions_test.rb +516 -0
- data/test/controller/addresses_render_test.rb +37 -0
- data/test/controller/assert_select_test.rb +734 -0
- data/test/controller/base_test.rb +217 -0
- data/test/controller/benchmark_test.rb +32 -0
- data/test/controller/caching_test.rb +690 -0
- data/test/controller/capture_test.rb +66 -0
- data/test/controller/content_type_test.rb +168 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +111 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +32 -0
- data/test/controller/dispatcher_test.rb +103 -0
- data/test/controller/fake_controllers.rb +33 -0
- data/test/controller/fake_models.rb +19 -0
- data/test/controller/filter_params_test.rb +49 -0
- data/test/controller/filters_test.rb +885 -0
- data/test/controller/flash_test.rb +142 -0
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +224 -0
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/document_test.rb +148 -0
- data/test/controller/html-scanner/node_test.rb +89 -0
- data/test/controller/html-scanner/sanitizer_test.rb +273 -0
- data/test/controller/html-scanner/tag_node_test.rb +238 -0
- data/test/controller/html-scanner/text_node_test.rb +50 -0
- data/test/controller/html-scanner/tokenizer_test.rb +131 -0
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +417 -0
- data/test/controller/layout_test.rb +204 -0
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +536 -0
- data/test/controller/mime_type_test.rb +93 -0
- data/test/controller/polymorphic_routes_test.rb +293 -0
- data/test/controller/rack_test.rb +294 -0
- data/test/controller/record_identifier_test.rb +139 -0
- data/test/controller/redirect_test.rb +282 -0
- data/test/controller/render_test.rb +1752 -0
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +246 -0
- data/test/controller/request_test.rb +407 -0
- data/test/controller/rescue_test.rb +536 -0
- data/test/controller/resources_test.rb +1341 -0
- data/test/controller/routing_test.rb +2557 -0
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +161 -0
- data/test/controller/session/cookie_store_test.rb +239 -0
- data/test/controller/session/mem_cache_store_test.rb +127 -0
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +692 -0
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +359 -0
- data/test/controller/verification_test.rb +270 -0
- data/test/controller/view_paths_test.rb +141 -0
- data/test/controller/webservice_test.rb +260 -0
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/company.rb +10 -0
- data/test/fixtures/developer.rb +9 -0
- data/test/fixtures/helpers/abc_helper.rb +5 -0
- data/test/fixtures/helpers/fun/games_helper.rb +3 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/template/asset_tag_helper_test.rb +713 -0
- data/test/template/atom_feed_helper_test.rb +286 -0
- data/test/template/benchmark_helper_test.rb +86 -0
- data/test/template/compiled_templates_test.rb +203 -0
- data/test/template/date_helper_i18n_test.rb +120 -0
- data/test/template/date_helper_test.rb +2469 -0
- data/test/template/erb_util_test.rb +24 -0
- data/test/template/form_helper_test.rb +1176 -0
- data/test/template/form_options_helper_test.rb +751 -0
- data/test/template/form_tag_helper_test.rb +327 -0
- data/test/template/javascript_helper_test.rb +106 -0
- data/test/template/number_helper_i18n_test.rb +69 -0
- data/test/template/number_helper_test.rb +128 -0
- data/test/template/prototype_helper_test.rb +639 -0
- data/test/template/record_tag_helper_test.rb +58 -0
- data/test/template/render_test.rb +291 -0
- data/test/template/sanitize_helper_test.rb +48 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/tag_helper_test.rb +97 -0
- data/test/template/test_test.rb +54 -0
- data/test/template/text_helper_test.rb +520 -0
- data/test/template/translation_helper_test.rb +32 -0
- data/test/template/url_helper_test.rb +614 -0
- data/test/test_erubis_rails_helper.rb +4 -0
- data/test/testing_sandbox.rb +15 -0
- data/test/view/test_case_test.rb +8 -0
- metadata +174 -0
@@ -0,0 +1,286 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
Scroll = Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
|
4
|
+
|
5
|
+
class ScrollsController < ActionController::Base
|
6
|
+
FEEDS = {}
|
7
|
+
FEEDS["defaults"] = <<-EOT
|
8
|
+
atom_feed(:schema_date => '2008') do |feed|
|
9
|
+
feed.title("My great blog!")
|
10
|
+
feed.updated((@scrolls.first.created_at))
|
11
|
+
|
12
|
+
for scroll in @scrolls
|
13
|
+
feed.entry(scroll) do |entry|
|
14
|
+
entry.title(scroll.title)
|
15
|
+
entry.content(scroll.body, :type => 'html')
|
16
|
+
|
17
|
+
entry.author do |author|
|
18
|
+
author.name("DHH")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
EOT
|
24
|
+
FEEDS["entry_options"] = <<-EOT
|
25
|
+
atom_feed do |feed|
|
26
|
+
feed.title("My great blog!")
|
27
|
+
feed.updated((@scrolls.first.created_at))
|
28
|
+
|
29
|
+
for scroll in @scrolls
|
30
|
+
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
|
31
|
+
entry.title(scroll.title)
|
32
|
+
entry.content(scroll.body, :type => 'html')
|
33
|
+
|
34
|
+
entry.author do |author|
|
35
|
+
author.name("DHH")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
EOT
|
41
|
+
FEEDS["xml_block"] = <<-EOT
|
42
|
+
atom_feed do |feed|
|
43
|
+
feed.title("My great blog!")
|
44
|
+
feed.updated((@scrolls.first.created_at))
|
45
|
+
|
46
|
+
feed.author do |author|
|
47
|
+
author.name("DHH")
|
48
|
+
end
|
49
|
+
|
50
|
+
for scroll in @scrolls
|
51
|
+
feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param, :updated => Time.utc(2007, 1, scroll.id)) do |entry|
|
52
|
+
entry.title(scroll.title)
|
53
|
+
entry.content(scroll.body, :type => 'html')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
EOT
|
58
|
+
FEEDS["feed_with_atomPub_namespace"] = <<-EOT
|
59
|
+
atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
|
60
|
+
'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
|
61
|
+
feed.title("My great blog!")
|
62
|
+
feed.updated((@scrolls.first.created_at))
|
63
|
+
|
64
|
+
for scroll in @scrolls
|
65
|
+
feed.entry(scroll) do |entry|
|
66
|
+
entry.title(scroll.title)
|
67
|
+
entry.content(scroll.body, :type => 'html')
|
68
|
+
entry.tag!('app:edited', Time.now)
|
69
|
+
|
70
|
+
entry.author do |author|
|
71
|
+
author.name("DHH")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
EOT
|
77
|
+
FEEDS["feed_with_overridden_ids"] = <<-EOT
|
78
|
+
atom_feed({:id => 'tag:test.rubyonrails.org,2008:test/'}) do |feed|
|
79
|
+
feed.title("My great blog!")
|
80
|
+
feed.updated((@scrolls.first.created_at))
|
81
|
+
|
82
|
+
for scroll in @scrolls
|
83
|
+
feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry|
|
84
|
+
entry.title(scroll.title)
|
85
|
+
entry.content(scroll.body, :type => 'html')
|
86
|
+
entry.tag!('app:edited', Time.now)
|
87
|
+
|
88
|
+
entry.author do |author|
|
89
|
+
author.name("DHH")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
EOT
|
95
|
+
FEEDS["feed_with_xml_processing_instructions"] = <<-EOT
|
96
|
+
atom_feed(:schema_date => '2008',
|
97
|
+
:instruct => {'xml-stylesheet' => { :href=> 't.css', :type => 'text/css' }}) do |feed|
|
98
|
+
feed.title("My great blog!")
|
99
|
+
feed.updated((@scrolls.first.created_at))
|
100
|
+
|
101
|
+
for scroll in @scrolls
|
102
|
+
feed.entry(scroll) do |entry|
|
103
|
+
entry.title(scroll.title)
|
104
|
+
entry.content(scroll.body, :type => 'html')
|
105
|
+
|
106
|
+
entry.author do |author|
|
107
|
+
author.name("DHH")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
EOT
|
113
|
+
FEEDS["feed_with_xml_processing_instructions_duplicate_targets"] = <<-EOT
|
114
|
+
atom_feed(:schema_date => '2008',
|
115
|
+
:instruct => {'target1' => [{ :a => '1', :b => '2' }, { :c => '3', :d => '4' }]}) do |feed|
|
116
|
+
feed.title("My great blog!")
|
117
|
+
feed.updated((@scrolls.first.created_at))
|
118
|
+
|
119
|
+
for scroll in @scrolls
|
120
|
+
feed.entry(scroll) do |entry|
|
121
|
+
entry.title(scroll.title)
|
122
|
+
entry.content(scroll.body, :type => 'html')
|
123
|
+
|
124
|
+
entry.author do |author|
|
125
|
+
author.name("DHH")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
EOT
|
131
|
+
FEEDS["feed_with_xhtml_content"] = <<-'EOT'
|
132
|
+
atom_feed do |feed|
|
133
|
+
feed.title("My great blog!")
|
134
|
+
feed.updated((@scrolls.first.created_at))
|
135
|
+
|
136
|
+
for scroll in @scrolls
|
137
|
+
feed.entry(scroll) do |entry|
|
138
|
+
entry.title(scroll.title)
|
139
|
+
entry.summary(:type => 'xhtml') do |xhtml|
|
140
|
+
xhtml.p "before #{scroll.id}"
|
141
|
+
xhtml.p {xhtml << scroll.body}
|
142
|
+
xhtml.p "after #{scroll.id}"
|
143
|
+
end
|
144
|
+
entry.tag!('app:edited', Time.now)
|
145
|
+
|
146
|
+
entry.author do |author|
|
147
|
+
author.name("DHH")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
EOT
|
153
|
+
def index
|
154
|
+
@scrolls = [
|
155
|
+
Scroll.new(1, "1", "Hello One", "Something <i>COOL!</i>", Time.utc(2007, 12, 12, 15), Time.utc(2007, 12, 12, 15)),
|
156
|
+
Scroll.new(2, "2", "Hello Two", "Something Boring", Time.utc(2007, 12, 12, 15)),
|
157
|
+
]
|
158
|
+
|
159
|
+
render :inline => FEEDS[params[:id]], :type => :builder
|
160
|
+
end
|
161
|
+
|
162
|
+
protected
|
163
|
+
|
164
|
+
def rescue_action(e)
|
165
|
+
raise(e)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
class AtomFeedTest < ActionController::TestCase
|
170
|
+
tests ScrollsController
|
171
|
+
|
172
|
+
def setup
|
173
|
+
@request.host = "www.nextangle.com"
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_feed_should_use_default_language_if_none_is_given
|
177
|
+
with_restful_routing(:scrolls) do
|
178
|
+
get :index, :id => "defaults"
|
179
|
+
assert_match %r{xml:lang="en-US"}, @response.body
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_feed_should_include_two_entries
|
184
|
+
with_restful_routing(:scrolls) do
|
185
|
+
get :index, :id => "defaults"
|
186
|
+
assert_select "entry", 2
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_entry_should_only_use_published_if_created_at_is_present
|
191
|
+
with_restful_routing(:scrolls) do
|
192
|
+
get :index, :id => "defaults"
|
193
|
+
assert_select "published", 1
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_entry_with_prefilled_options_should_use_those_instead_of_querying_the_record
|
198
|
+
with_restful_routing(:scrolls) do
|
199
|
+
get :index, :id => "entry_options"
|
200
|
+
|
201
|
+
assert_select "updated", Time.utc(2007, 1, 1).xmlschema
|
202
|
+
assert_select "updated", Time.utc(2007, 1, 2).xmlschema
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_self_url_should_default_to_current_request_url
|
207
|
+
with_restful_routing(:scrolls) do
|
208
|
+
get :index, :id => "defaults"
|
209
|
+
assert_select "link[rel=self][href=http://www.nextangle.com/scrolls?id=defaults]"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_feed_id_should_be_a_valid_tag
|
214
|
+
with_restful_routing(:scrolls) do
|
215
|
+
get :index, :id => "defaults"
|
216
|
+
assert_select "id", :text => "tag:www.nextangle.com,2008:/scrolls?id=defaults"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_entry_id_should_be_a_valid_tag
|
221
|
+
with_restful_routing(:scrolls) do
|
222
|
+
get :index, :id => "defaults"
|
223
|
+
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/1"
|
224
|
+
assert_select "entry id", :text => "tag:www.nextangle.com,2008:Scroll/2"
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_feed_should_allow_nested_xml_blocks
|
229
|
+
with_restful_routing(:scrolls) do
|
230
|
+
get :index, :id => "xml_block"
|
231
|
+
assert_select "author name", :text => "DHH"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_feed_should_include_atomPub_namespace
|
236
|
+
with_restful_routing(:scrolls) do
|
237
|
+
get :index, :id => "feed_with_atomPub_namespace"
|
238
|
+
assert_match %r{xml:lang="en-US"}, @response.body
|
239
|
+
assert_match %r{xmlns="http://www.w3.org/2005/Atom"}, @response.body
|
240
|
+
assert_match %r{xmlns:app="http://www.w3.org/2007/app"}, @response.body
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_feed_should_allow_overriding_ids
|
245
|
+
with_restful_routing(:scrolls) do
|
246
|
+
get :index, :id => "feed_with_overridden_ids"
|
247
|
+
assert_select "id", :text => "tag:test.rubyonrails.org,2008:test/"
|
248
|
+
assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:1"
|
249
|
+
assert_select "entry id", :text => "tag:test.rubyonrails.org,2008:2"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_feed_xml_processing_instructions
|
254
|
+
with_restful_routing(:scrolls) do
|
255
|
+
get :index, :id => 'feed_with_xml_processing_instructions'
|
256
|
+
assert_match %r{<\?xml-stylesheet [^\?]*type="text/css"}, @response.body
|
257
|
+
assert_match %r{<\?xml-stylesheet [^\?]*href="t.css"}, @response.body
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_feed_xml_processing_instructions_duplicate_targets
|
262
|
+
with_restful_routing(:scrolls) do
|
263
|
+
get :index, :id => 'feed_with_xml_processing_instructions_duplicate_targets'
|
264
|
+
assert_match %r{<\?target1 (a="1" b="2"|b="2" a="1")\?>}, @response.body
|
265
|
+
assert_match %r{<\?target1 (c="3" d="4"|d="4" c="3")\?>}, @response.body
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_feed_xhtml
|
270
|
+
with_restful_routing(:scrolls) do
|
271
|
+
get :index, :id => "feed_with_xhtml_content"
|
272
|
+
assert_match %r{xmlns="http://www.w3.org/1999/xhtml"}, @response.body
|
273
|
+
assert_select "summary div p", :text => "Something Boring"
|
274
|
+
assert_select "summary div p", :text => "after 2"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
private
|
278
|
+
def with_restful_routing(resources)
|
279
|
+
with_routing do |set|
|
280
|
+
set.draw do |map|
|
281
|
+
map.resources(resources)
|
282
|
+
end
|
283
|
+
yield
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'action_view/helpers/benchmark_helper'
|
3
|
+
|
4
|
+
class BenchmarkHelperTest < ActionView::TestCase
|
5
|
+
tests ActionView::Helpers::BenchmarkHelper
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
controller.logger.send(:clear_buffer)
|
9
|
+
end
|
10
|
+
|
11
|
+
def controller
|
12
|
+
logger = ActiveSupport::BufferedLogger.new(StringIO.new)
|
13
|
+
logger.auto_flushing = false
|
14
|
+
@controller ||= Struct.new(:logger).new(logger)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_without_block
|
18
|
+
assert_raise(LocalJumpError) { benchmark }
|
19
|
+
assert buffer.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_defaults
|
23
|
+
i_was_run = false
|
24
|
+
benchmark { i_was_run = true }
|
25
|
+
assert i_was_run
|
26
|
+
assert_last_logged
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_with_message
|
30
|
+
i_was_run = false
|
31
|
+
benchmark('test_run') { i_was_run = true }
|
32
|
+
assert i_was_run
|
33
|
+
assert_last_logged 'test_run'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_with_message_and_deprecated_level
|
37
|
+
i_was_run = false
|
38
|
+
|
39
|
+
assert_deprecated do
|
40
|
+
benchmark('debug_run', :debug) { i_was_run = true }
|
41
|
+
end
|
42
|
+
|
43
|
+
assert i_was_run
|
44
|
+
assert_last_logged 'debug_run'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_within_level
|
48
|
+
controller.logger.level = ActiveSupport::BufferedLogger::DEBUG
|
49
|
+
benchmark('included_debug_run', :level => :debug) { }
|
50
|
+
assert_last_logged 'included_debug_run'
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_outside_level
|
54
|
+
controller.logger.level = ActiveSupport::BufferedLogger::ERROR
|
55
|
+
benchmark('skipped_debug_run', :level => :debug) { }
|
56
|
+
assert_no_match(/skipped_debug_run/, buffer.last)
|
57
|
+
ensure
|
58
|
+
controller.logger.level = ActiveSupport::BufferedLogger::DEBUG
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_without_silencing
|
62
|
+
benchmark('debug_run', :silence => false) do
|
63
|
+
controller.logger.info "not silenced!"
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_equal 2, buffer.size
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_with_silencing
|
70
|
+
benchmark('debug_run', :silence => true) do
|
71
|
+
controller.logger.info "silenced!"
|
72
|
+
end
|
73
|
+
|
74
|
+
assert_equal 1, buffer.size
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
private
|
79
|
+
def buffer
|
80
|
+
controller.logger.send(:buffer)
|
81
|
+
end
|
82
|
+
|
83
|
+
def assert_last_logged(message = 'Benchmarking')
|
84
|
+
assert_match(/^#{message} \(.*\)$/, buffer.last)
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'controller/fake_models'
|
3
|
+
|
4
|
+
class CompiledTemplatesTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@compiled_templates = ActionView::Base::CompiledTemplates
|
8
|
+
@compiled_templates.instance_methods.each do |m|
|
9
|
+
@compiled_templates.send(:remove_method, m) if m =~ /^_run_/
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_template_gets_compiled
|
14
|
+
with_caching(true) do
|
15
|
+
assert_equal 0, @compiled_templates.instance_methods.size
|
16
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
17
|
+
assert_equal 1, @compiled_templates.instance_methods.size
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
|
22
|
+
with_caching(true) do
|
23
|
+
assert_equal 0, @compiled_templates.instance_methods.size
|
24
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
25
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"})
|
26
|
+
assert_equal 2, @compiled_templates.instance_methods.size
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns
|
31
|
+
with_caching(true) do
|
32
|
+
assert_equal 0, @compiled_templates.instance_methods.size
|
33
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
34
|
+
ActionView::Template.any_instance.expects(:compile!).never
|
35
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_template_changes_are_not_reflected_with_cached_template_loading
|
40
|
+
with_caching(true) do
|
41
|
+
with_reloading(false) do
|
42
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
43
|
+
modify_template "test/hello_world.erb", "Goodbye world!" do
|
44
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
45
|
+
end
|
46
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_template_changes_are_reflected_without_cached_template_loading
|
52
|
+
with_caching(true) do
|
53
|
+
with_reloading(true) do
|
54
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
55
|
+
modify_template "test/hello_world.erb", "Goodbye world!" do
|
56
|
+
assert_equal "Goodbye world!", render(:file => "test/hello_world.erb")
|
57
|
+
end
|
58
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_template_becomes_missing_if_deleted_without_cached_template_loading
|
64
|
+
with_reloading(true) do
|
65
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world.erb')
|
66
|
+
delete_template 'test/hello_world.erb' do
|
67
|
+
assert_raise(ActionView::MissingTemplate) { render(:file => 'test/hello_world.erb') }
|
68
|
+
end
|
69
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world.erb')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_swapping_template_handler_is_working_without_cached_template_loading
|
74
|
+
with_reloading(true) do
|
75
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
76
|
+
delete_template 'test/hello_world.erb' do
|
77
|
+
rename_template 'test/hello_world_from_rxml.builder', 'test/hello_world.builder' do
|
78
|
+
assert_equal "<html>\n <p>Hello</p>\n</html>\n", render(:file => 'test/hello_world')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_adding_localized_template_will_take_precedence_without_cached_template_loading
|
86
|
+
with_reloading(true) do
|
87
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
88
|
+
rename_template 'test/hello_world.da.html.erb', 'test/hello_world.en.html.erb' do
|
89
|
+
assert_equal 'Hey verden', render(:file => 'test/hello_world')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_deleting_localized_template_will_fall_back_to_non_localized_template_without_cached_template_loading
|
95
|
+
with_reloading(true) do
|
96
|
+
rename_template 'test/hello_world.da.html.erb', 'test/hello_world.en.html.erb' do
|
97
|
+
assert_equal 'Hey verden', render(:file => 'test/hello_world')
|
98
|
+
delete_template 'test/hello_world.en.html.erb' do
|
99
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
100
|
+
end
|
101
|
+
assert_equal 'Hey verden', render(:file => 'test/hello_world')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_parallel_reloadable_view_paths_are_working
|
107
|
+
with_reloading(true) do
|
108
|
+
view_paths_copy = new_reloadable_view_paths
|
109
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
110
|
+
with_view_paths(view_paths_copy, new_reloadable_view_paths) do
|
111
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
112
|
+
end
|
113
|
+
modify_template 'test/hello_world.erb', 'Goodbye world!' do
|
114
|
+
assert_equal 'Goodbye world!', render(:file => 'test/hello_world')
|
115
|
+
modify_template 'test/hello_world.erb', 'So long, world!' do
|
116
|
+
with_view_paths(view_paths_copy, new_reloadable_view_paths) do
|
117
|
+
assert_equal 'So long, world!', render(:file => 'test/hello_world')
|
118
|
+
end
|
119
|
+
assert_equal 'So long, world!', render(:file => 'test/hello_world')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
def render(*args)
|
127
|
+
view_paths = @explicit_view_paths || ActionController::Base.view_paths
|
128
|
+
ActionView::Base.new(view_paths, {}).render(*args)
|
129
|
+
end
|
130
|
+
|
131
|
+
def with_view_paths(*args)
|
132
|
+
args.each do |view_paths|
|
133
|
+
begin
|
134
|
+
@explicit_view_paths = view_paths
|
135
|
+
yield
|
136
|
+
ensure
|
137
|
+
@explicit_view_paths = nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def reset_mtime_of(template_name, view_paths_to_use)
|
143
|
+
view_paths_to_use.find_template(template_name).previously_last_modified = 10.seconds.ago unless ActionView::Base.cache_template_loading?
|
144
|
+
end
|
145
|
+
|
146
|
+
def modify_template(template, content, view_paths_to_use = ActionController::Base.view_paths)
|
147
|
+
filename = filename_for(template)
|
148
|
+
old_content = File.read(filename)
|
149
|
+
begin
|
150
|
+
File.open(filename, "wb+") { |f| f.write(content) }
|
151
|
+
reset_mtime_of(template, view_paths_to_use)
|
152
|
+
yield
|
153
|
+
ensure
|
154
|
+
File.open(filename, "wb+") { |f| f.write(old_content) }
|
155
|
+
reset_mtime_of(template, view_paths_to_use)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def filename_for(template)
|
160
|
+
File.join(FIXTURE_LOAD_PATH, template)
|
161
|
+
end
|
162
|
+
|
163
|
+
def rename_template(old_name, new_name)
|
164
|
+
File.rename(filename_for(old_name), filename_for(new_name))
|
165
|
+
yield
|
166
|
+
ensure
|
167
|
+
File.rename(filename_for(new_name), filename_for(old_name))
|
168
|
+
end
|
169
|
+
|
170
|
+
def delete_template(template, &block)
|
171
|
+
rename_template(template, File.join(File.dirname(template), "__#{File.basename(template)}"), &block)
|
172
|
+
end
|
173
|
+
|
174
|
+
def with_caching(perform_caching)
|
175
|
+
old_perform_caching = ActionController::Base.perform_caching
|
176
|
+
begin
|
177
|
+
ActionController::Base.perform_caching = perform_caching
|
178
|
+
yield
|
179
|
+
ensure
|
180
|
+
ActionController::Base.perform_caching = old_perform_caching
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def with_reloading(reload_templates, view_paths_owner = ActionController::Base)
|
185
|
+
old_view_paths, old_cache_templates = view_paths_owner.view_paths, ActionView::Base.cache_template_loading
|
186
|
+
begin
|
187
|
+
ActionView::Base.cache_template_loading = !reload_templates
|
188
|
+
view_paths_owner.view_paths = view_paths_for(reload_templates)
|
189
|
+
yield
|
190
|
+
ensure
|
191
|
+
view_paths_owner.view_paths, ActionView::Base.cache_template_loading = old_view_paths, old_cache_templates
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def new_reloadable_view_paths
|
196
|
+
ActionView::PathSet.new(CACHED_VIEW_PATHS.map(&:to_s))
|
197
|
+
end
|
198
|
+
|
199
|
+
def view_paths_for(reload_templates)
|
200
|
+
# reloadable paths are cheap to create
|
201
|
+
reload_templates ? new_reloadable_view_paths : CACHED_VIEW_PATHS
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase
|
4
|
+
include ActionView::Helpers::DateHelper
|
5
|
+
attr_reader :request
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@from = Time.mktime(2004, 6, 6, 21, 45, 0)
|
9
|
+
end
|
10
|
+
|
11
|
+
# distance_of_time_in_words
|
12
|
+
|
13
|
+
def test_distance_of_time_in_words_calls_i18n
|
14
|
+
{ # with include_seconds
|
15
|
+
[2.seconds, true] => [:'less_than_x_seconds', 5],
|
16
|
+
[9.seconds, true] => [:'less_than_x_seconds', 10],
|
17
|
+
[19.seconds, true] => [:'less_than_x_seconds', 20],
|
18
|
+
[30.seconds, true] => [:'half_a_minute', nil],
|
19
|
+
[59.seconds, true] => [:'less_than_x_minutes', 1],
|
20
|
+
[60.seconds, true] => [:'x_minutes', 1],
|
21
|
+
|
22
|
+
# without include_seconds
|
23
|
+
[29.seconds, false] => [:'less_than_x_minutes', 1],
|
24
|
+
[60.seconds, false] => [:'x_minutes', 1],
|
25
|
+
[44.minutes, false] => [:'x_minutes', 44],
|
26
|
+
[61.minutes, false] => [:'about_x_hours', 1],
|
27
|
+
[24.hours, false] => [:'x_days', 1],
|
28
|
+
[30.days, false] => [:'about_x_months', 1],
|
29
|
+
[60.days, false] => [:'x_months', 2],
|
30
|
+
[1.year, false] => [:'about_x_years', 1],
|
31
|
+
[3.years, false] => [:'over_x_years', 3]
|
32
|
+
|
33
|
+
}.each do |passed, expected|
|
34
|
+
assert_distance_of_time_in_words_translates_key passed, expected
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_distance_of_time_in_words_translates_key(passed, expected)
|
39
|
+
diff, include_seconds = *passed
|
40
|
+
key, count = *expected
|
41
|
+
to = @from + diff
|
42
|
+
|
43
|
+
options = {:locale => 'en', :scope => :'datetime.distance_in_words'}
|
44
|
+
options[:count] = count if count
|
45
|
+
|
46
|
+
I18n.expects(:t).with(key, options)
|
47
|
+
distance_of_time_in_words(@from, to, include_seconds, :locale => 'en')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_distance_of_time_pluralizations
|
51
|
+
{ [:'less_than_x_seconds', 1] => 'less than 1 second',
|
52
|
+
[:'less_than_x_seconds', 2] => 'less than 2 seconds',
|
53
|
+
[:'less_than_x_minutes', 1] => 'less than a minute',
|
54
|
+
[:'less_than_x_minutes', 2] => 'less than 2 minutes',
|
55
|
+
[:'x_minutes', 1] => '1 minute',
|
56
|
+
[:'x_minutes', 2] => '2 minutes',
|
57
|
+
[:'about_x_hours', 1] => 'about 1 hour',
|
58
|
+
[:'about_x_hours', 2] => 'about 2 hours',
|
59
|
+
[:'x_days', 1] => '1 day',
|
60
|
+
[:'x_days', 2] => '2 days',
|
61
|
+
[:'about_x_years', 1] => 'about 1 year',
|
62
|
+
[:'about_x_years', 2] => 'about 2 years',
|
63
|
+
[:'over_x_years', 1] => 'over 1 year',
|
64
|
+
[:'over_x_years', 2] => 'over 2 years'
|
65
|
+
|
66
|
+
}.each do |args, expected|
|
67
|
+
key, count = *args
|
68
|
+
assert_equal expected, I18n.t(key, :count => count, :scope => 'datetime.distance_in_words')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class DateHelperSelectTagsI18nTests < Test::Unit::TestCase
|
74
|
+
include ActionView::Helpers::DateHelper
|
75
|
+
attr_reader :request
|
76
|
+
|
77
|
+
def setup
|
78
|
+
@prompt_defaults = {:year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds'}
|
79
|
+
|
80
|
+
I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES
|
81
|
+
end
|
82
|
+
|
83
|
+
# select_month
|
84
|
+
|
85
|
+
def test_select_month_given_use_month_names_option_does_not_translate_monthnames
|
86
|
+
I18n.expects(:translate).never
|
87
|
+
select_month(8, :locale => 'en', :use_month_names => Date::MONTHNAMES)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_select_month_translates_monthnames
|
91
|
+
I18n.expects(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES
|
92
|
+
select_month(8, :locale => 'en')
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_select_month_given_use_short_month_option_translates_abbr_monthnames
|
96
|
+
I18n.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date::ABBR_MONTHNAMES
|
97
|
+
select_month(8, :locale => 'en', :use_short_month => true)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_date_or_time_select_translates_prompts
|
101
|
+
@prompt_defaults.each do |key, prompt|
|
102
|
+
I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt
|
103
|
+
end
|
104
|
+
|
105
|
+
I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day]
|
106
|
+
datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true)
|
107
|
+
end
|
108
|
+
|
109
|
+
# date_or_time_select
|
110
|
+
|
111
|
+
def test_date_or_time_select_given_an_order_options_does_not_translate_order
|
112
|
+
I18n.expects(:translate).never
|
113
|
+
datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en')
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_date_or_time_select_given_no_order_options_translates_order
|
117
|
+
I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day]
|
118
|
+
datetime_select('post', 'updated_at', :locale => 'en')
|
119
|
+
end
|
120
|
+
end
|