erector 0.8.2 → 0.8.3
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.
- data/README.txt +0 -4
- data/VERSION.yml +1 -1
- data/lib/erector.rb +2 -4
- data/lib/erector/abstract_widget.rb +2 -1
- data/lib/erector/erect/erect.rb +17 -14
- data/lib/erector/erect/rhtml.treetop +18 -10
- data/lib/erector/externals.rb +7 -1
- data/lib/erector/html.rb +30 -39
- data/lib/erector/rails.rb +6 -26
- data/lib/erector/rails/form_builder.rb +36 -0
- data/lib/erector/rails/railtie.rb +11 -0
- data/lib/erector/rails/template_handler.rb +16 -0
- data/lib/erector/rails/widget_renderer.rb +6 -0
- data/lib/erector/rails2.rb +27 -0
- data/lib/erector/{rails → rails2}/extensions/action_controller.rb +1 -1
- data/lib/erector/{rails → rails2}/extensions/rails_helpers.rb +17 -4
- data/lib/erector/{rails → rails2}/extensions/rails_widget.rb +6 -3
- data/lib/erector/{rails → rails2}/rails_form_builder.rb +0 -0
- data/lib/erector/rails2/rails_version.rb +6 -0
- data/lib/erector/{rails → rails2}/template_handlers/ert_handler.rb +0 -0
- data/lib/erector/{rails → rails2}/template_handlers/rb_handler.rb +2 -2
- data/lib/erector/rails3.rb +208 -0
- data/lib/erector/raw_string.rb +4 -0
- data/lib/erector/widgets/external_renderer.rb +8 -0
- data/spec/erect/erect_rails_spec.rb +34 -49
- data/spec/erect/erected_spec.rb +11 -0
- data/spec/rails2/erect_rails_spec.rb +114 -0
- data/spec/rails2/rails_app/Gemfile +12 -0
- data/spec/rails2/rails_app/Gemfile.lock +89 -0
- data/spec/rails2/rails_app/README +243 -0
- data/spec/rails2/rails_app/Rakefile +19 -0
- data/spec/rails2/rails_app/app/controllers/application_controller.rb +10 -0
- data/spec/rails2/rails_app/app/helpers/application_helper.rb +3 -0
- data/spec/rails2/rails_app/app/views/test/_erb.erb +1 -0
- data/spec/rails2/rails_app/app/views/test/_erector.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/_partial_with_locals.rb +7 -0
- data/spec/rails2/rails_app/app/views/test/bare.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/erb_from_erector.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/erector_from_erb.html.erb +1 -0
- data/spec/rails2/rails_app/app/views/test/erector_with_locals_from_erb.html.erb +6 -0
- data/spec/rails2/rails_app/app/views/test/implicit_assigns.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/needs.html.rb +7 -0
- data/spec/rails2/rails_app/app/views/test/needs_subclass.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/protected_instance_variable.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/render_default.html.rb +5 -0
- data/spec/rails2/rails_app/app/views/test/render_partial.html.rb +5 -0
- data/spec/rails2/rails_app/config/boot.rb +114 -0
- data/spec/rails2/rails_app/config/database.yml +16 -0
- data/spec/rails2/rails_app/config/environment.rb +42 -0
- data/spec/rails2/rails_app/config/environments/development.rb +17 -0
- data/spec/rails2/rails_app/config/environments/production.rb +28 -0
- data/spec/rails2/rails_app/config/environments/test.rb +28 -0
- data/spec/rails2/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails2/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/rails2/rails_app/config/initializers/inflections.rb +10 -0
- data/spec/rails2/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails2/rails_app/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/rails2/rails_app/config/initializers/session_store.rb +15 -0
- data/spec/rails2/rails_app/config/locales/en.yml +5 -0
- data/spec/rails2/rails_app/config/routes.rb +43 -0
- data/spec/rails2/rails_app/db/development.sqlite3 +0 -0
- data/spec/rails2/rails_app/db/schema.rb +14 -0
- data/spec/rails2/rails_app/db/seeds.rb +7 -0
- data/spec/rails2/rails_app/doc/README_FOR_APP +2 -0
- data/spec/rails2/rails_app/log/development.log +76 -0
- data/spec/rails2/rails_app/log/production.log +0 -0
- data/spec/rails2/rails_app/log/server.log +0 -0
- data/spec/rails2/rails_app/log/test.log +4158 -0
- data/spec/rails2/rails_app/public/404.html +30 -0
- data/spec/rails2/rails_app/public/422.html +30 -0
- data/spec/rails2/rails_app/public/500.html +30 -0
- data/spec/rails2/rails_app/public/favicon.ico +0 -0
- data/spec/rails2/rails_app/public/images/rails.png +0 -0
- data/spec/rails2/rails_app/public/index.html +275 -0
- data/spec/rails2/rails_app/public/javascripts/application.js +2 -0
- data/spec/rails2/rails_app/public/javascripts/controls.js +963 -0
- data/spec/rails2/rails_app/public/javascripts/dragdrop.js +973 -0
- data/spec/rails2/rails_app/public/javascripts/effects.js +1128 -0
- data/spec/rails2/rails_app/public/javascripts/prototype.js +4320 -0
- data/spec/rails2/rails_app/public/robots.txt +5 -0
- data/spec/rails2/rails_app/script/about +4 -0
- data/spec/rails2/rails_app/script/console +3 -0
- data/spec/rails2/rails_app/script/dbconsole +3 -0
- data/spec/rails2/rails_app/script/destroy +3 -0
- data/spec/rails2/rails_app/script/generate +3 -0
- data/spec/rails2/rails_app/script/performance/benchmarker +3 -0
- data/spec/rails2/rails_app/script/performance/profiler +3 -0
- data/spec/rails2/rails_app/script/plugin +3 -0
- data/spec/rails2/rails_app/script/runner +3 -0
- data/spec/rails2/rails_app/script/server +3 -0
- data/spec/rails2/rails_app/spec/rails_helpers_spec.rb +255 -0
- data/spec/rails2/rails_app/spec/rails_spec_helper.rb +34 -0
- data/spec/rails2/rails_app/spec/rails_widget_spec.rb +83 -0
- data/spec/rails2/rails_app/spec/render_spec.rb +324 -0
- data/spec/rails2/rails_app/test/performance/browsing_test.rb +9 -0
- data/spec/rails2/rails_app/test/test_helper.rb +38 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/MIT-LICENSE +20 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/README.markdown +90 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/Rakefile +23 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/init.rb +7 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss.rb +3 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/action_view.rb +87 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/erubis.rb +33 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb +52 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/tasks/rails_xss_tasks.rake +4 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/active_record_helper_test.rb +74 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/asset_tag_helper_test.rb +49 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/caching_test.rb +43 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/date_helper_test.rb +29 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/deprecated_output_safety_test.rb +112 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/erb_util_test.rb +36 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_helper_test.rb +1447 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_tag_helper_test.rb +354 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/output_safety_test.rb +115 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/rails_xss_test.rb +23 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/test_helper.rb +5 -0
- data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/text_helper_test.rb +17 -0
- data/spec/spec_helper.rb +2 -6
- metadata +348 -23
- data/lib/erector/errors.rb +0 -12
- data/lib/erector/extensions/hash.rb +0 -21
- data/lib/erector/extensions/object.rb +0 -18
- data/lib/erector/rails/rails_version.rb +0 -6
- data/rails/init.rb +0 -4
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")
|
|
2
|
+
|
|
3
|
+
describe Erector::Rails::Helpers do
|
|
4
|
+
class RailsHelpersSpecController < ActionController::Base
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@controller = RailsHelpersSpecController.new
|
|
9
|
+
@request = ActionController::TestRequest.new
|
|
10
|
+
@response = ActionController::TestResponse.new
|
|
11
|
+
@controller.send(:initialize_template_class, @response)
|
|
12
|
+
@controller.send(:assign_shortcuts, @request, @response)
|
|
13
|
+
@controller.send(:initialize_current_url)
|
|
14
|
+
|
|
15
|
+
@view = ActionView::Base.new
|
|
16
|
+
@view.output_buffer = ""
|
|
17
|
+
@view.controller = @controller
|
|
18
|
+
|
|
19
|
+
def @view.protect_against_forgery?
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class << @controller
|
|
24
|
+
public :render
|
|
25
|
+
|
|
26
|
+
attr_accessor :user # dummy instance variable for assigns testing
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_render(&block)
|
|
31
|
+
Erector::Rails.render(Erector.inline(&block), @view)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#link_to" do
|
|
35
|
+
it "renders a link" do
|
|
36
|
+
test_render do
|
|
37
|
+
link_to 'Test', '/foo'
|
|
38
|
+
end.should == %{<a href="/foo">Test</a>}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "supports blocks" do
|
|
42
|
+
test_render do
|
|
43
|
+
link_to '/foo' do
|
|
44
|
+
strong "Test"
|
|
45
|
+
end
|
|
46
|
+
end.should == %{<a href="/foo"><strong>Test</strong></a>}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "escapes input" do
|
|
50
|
+
test_render do
|
|
51
|
+
link_to 'This&that', '/foo?this=1&that=1'
|
|
52
|
+
end.should == %{<a href="/foo?this=1&that=1">This&that</a>}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "isn't double rendered when 'text link_to' is used by mistake" do
|
|
56
|
+
test_render do
|
|
57
|
+
text link_to('Test', '/foo')
|
|
58
|
+
end.should == %{<a href="/foo">Test</a>}
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe "a regular helper" do
|
|
63
|
+
it "can be called directly" do
|
|
64
|
+
test_render do
|
|
65
|
+
text truncate("foo")
|
|
66
|
+
end.should == "foo"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "can be called via capture" do
|
|
70
|
+
test_render do
|
|
71
|
+
text capture { text truncate("foo") }
|
|
72
|
+
end.should == "foo"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "can be called via sub-widget" do
|
|
76
|
+
test_render do
|
|
77
|
+
widget Erector.inline { text truncate("foo") }
|
|
78
|
+
end.should == "foo"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "a named route helper" do
|
|
83
|
+
before do
|
|
84
|
+
ActionController::Routing::Routes.draw do |map|
|
|
85
|
+
map.root :controller => "rails_helpers_spec"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "can be called directly" do
|
|
90
|
+
test_render do
|
|
91
|
+
text root_path
|
|
92
|
+
end.should == "/"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "can be called via parent" do
|
|
96
|
+
test_render do
|
|
97
|
+
text parent.root_path
|
|
98
|
+
end.should == "/"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "respects default_url_options defined by the controller" do
|
|
102
|
+
def @controller.default_url_options(options = nil)
|
|
103
|
+
{ :host => "www.override.com" }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
test_render do
|
|
107
|
+
text root_url
|
|
108
|
+
end.should == "http://www.override.com/"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe "#auto_discovery_link_tag" do
|
|
113
|
+
it "renders tag" do
|
|
114
|
+
test_render do
|
|
115
|
+
auto_discovery_link_tag(:rss, "rails")
|
|
116
|
+
end.should == %{<link href="rails" rel="alternate" title="RSS" type="application/rss+xml" />}
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "#javascript_include_tag" do
|
|
121
|
+
it "renders tag" do
|
|
122
|
+
test_render do
|
|
123
|
+
javascript_include_tag("rails")
|
|
124
|
+
end.should == %{<script src="/javascripts/rails.js" type="text/javascript"></script>}
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
describe "#stylesheet_link_tag" do
|
|
129
|
+
it "renders tag" do
|
|
130
|
+
test_render do
|
|
131
|
+
stylesheet_link_tag("rails")
|
|
132
|
+
end.should == %{<link href="/stylesheets/rails.css" media="screen" rel="stylesheet" type="text/css" />}
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe "#image_tag" do
|
|
137
|
+
it "renders tag" do
|
|
138
|
+
test_render do
|
|
139
|
+
image_tag("/foo")
|
|
140
|
+
end.should == %{<img alt="Foo" src="/foo" />}
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
describe "#javascript_tag" do
|
|
145
|
+
it "renders tag" do
|
|
146
|
+
test_render do
|
|
147
|
+
javascript_tag "alert('All is good')"
|
|
148
|
+
end.should == %{<script type="text/javascript">\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "supports block syntax" do
|
|
152
|
+
test_render do
|
|
153
|
+
javascript_tag do
|
|
154
|
+
text! "alert('All is good')"
|
|
155
|
+
end
|
|
156
|
+
end.should == %{<script type="text/javascript">\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>}
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
[:sortable_element,
|
|
161
|
+
:draggable_element,
|
|
162
|
+
:drop_receiving_element].each do |helper|
|
|
163
|
+
describe "##{helper}" do
|
|
164
|
+
it "renders helper js" do
|
|
165
|
+
test_render do
|
|
166
|
+
send(helper, "rails", :url => "/foo")
|
|
167
|
+
end.should =~ %r{<script type="text/javascript">.*</script>}m
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe "#link_to_function" do
|
|
173
|
+
context "when passed a string for the js function" do
|
|
174
|
+
it "renders a link with the name as the content and the onclick handler" do
|
|
175
|
+
test_render do
|
|
176
|
+
link_to_function("hi", "alert('hi')")
|
|
177
|
+
end.should == "<a href=\"#\" onclick=\"alert('hi'); return false;\">hi</a>"
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
context "when passed a block for the js function" do
|
|
182
|
+
it "renders the name and the block rjs contents onto onclick" do
|
|
183
|
+
test_render do
|
|
184
|
+
link_to_function("Show me more", nil, :id => "more_link") do |page|
|
|
185
|
+
page[:details].visual_effect :toggle_blind
|
|
186
|
+
page[:more_link].replace_html "Show me less"
|
|
187
|
+
end
|
|
188
|
+
end.should == "<a href=\"#\" id=\"more_link\" onclick=\"$("details").visualEffect("toggle_blind");\n$("more_link").update("Show me less");; return false;\">Show me more</a>"
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
describe "#render" do
|
|
194
|
+
it "renders text" do
|
|
195
|
+
test_render do
|
|
196
|
+
render :text => "Test"
|
|
197
|
+
end.should == "Test"
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
describe "#error_messages_for" do
|
|
202
|
+
it "renders the error message" do
|
|
203
|
+
pending "RR problem with Ruby 1.9" if RUBY_VERSION >= "1.9.0"
|
|
204
|
+
|
|
205
|
+
user_class = BaseDummyModel
|
|
206
|
+
stub(user_class).human_attribute_name {'User'}
|
|
207
|
+
user = user_class.new
|
|
208
|
+
stub(user).name {'bob'}
|
|
209
|
+
errors = ActiveRecord::Errors.new(user)
|
|
210
|
+
errors.add("name", "must be unpronounceable")
|
|
211
|
+
stub(user).errors {errors}
|
|
212
|
+
|
|
213
|
+
@controller.user = user
|
|
214
|
+
|
|
215
|
+
test_render do
|
|
216
|
+
error_messages_for('user')
|
|
217
|
+
end.should == "<div class=\"errorExplanation\" id=\"errorExplanation\"><h2>1 error prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User must be unpronounceable</li></ul></div>"
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
describe "#form_tag" do
|
|
222
|
+
it "works without a block" do
|
|
223
|
+
test_render do
|
|
224
|
+
form_tag("/posts")
|
|
225
|
+
end.should == %{<form action="/posts" method="post">}
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "can be mixed with erector and rails helpers" do
|
|
229
|
+
test_render do
|
|
230
|
+
form_tag("/posts") do
|
|
231
|
+
div { submit_tag 'Save' }
|
|
232
|
+
end
|
|
233
|
+
end.should == %{<form action="/posts" method="post"><div><input name="commit" type="submit" value="Save" /></div></form>}
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
describe "#form_for" do
|
|
238
|
+
it "produces expected output" do
|
|
239
|
+
test_render do
|
|
240
|
+
form_for(:something, :url => "/test") do |form|
|
|
241
|
+
form.label :my_input, "My input"
|
|
242
|
+
form.text_field :my_input
|
|
243
|
+
end
|
|
244
|
+
end.should == %{<form action="/test" method="post"><label for="something_my_input">My input</label><input id="something_my_input" name="something[my_input]" size="30" type="text" /></form>}
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
it "doesn't double render if 'text form.label' is used by mistake" do
|
|
248
|
+
test_render do
|
|
249
|
+
form_for(:something, :url => "/test") do |form|
|
|
250
|
+
text form.label(:my_input, "My input")
|
|
251
|
+
end
|
|
252
|
+
end.should == %{<form action="/test" method="post"><label for="something_my_input">My input</label></form>}
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
|
2
|
+
ENV["BUNDLE_GEMFILE"] ||= "#{File.dirname(__FILE__)}/../Gemfile"
|
|
3
|
+
|
|
4
|
+
here = File.expand_path(File.dirname(__FILE__))
|
|
5
|
+
require File.expand_path("#{here}/../config/environment", __FILE__)
|
|
6
|
+
require File.expand_path("#{here}/../../../spec_helper", __FILE__)
|
|
7
|
+
|
|
8
|
+
Bundler.require(:test)
|
|
9
|
+
|
|
10
|
+
class BaseDummyModel
|
|
11
|
+
# see http://gist.github.com/191263
|
|
12
|
+
def self.self_and_descendants_from_active_record
|
|
13
|
+
[self]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.human_attribute_name(attribute_key_name, options = {})
|
|
17
|
+
defaults = self_and_descendants_from_active_record.map do |klass|
|
|
18
|
+
"#{klass.name.underscore}.#{attribute_key_name}""#{klass.name.underscore}.#{attribute_key_name}"
|
|
19
|
+
end
|
|
20
|
+
defaults << options[:default] if options[:default]
|
|
21
|
+
defaults.flatten!
|
|
22
|
+
defaults << attribute_key_name.humanize
|
|
23
|
+
options[:count] ||= 1
|
|
24
|
+
I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => [:activerecord, :attributes]))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.human_name(options = {})
|
|
28
|
+
defaults = self_and_descendants_from_active_record.map do |klass|
|
|
29
|
+
"#{klass.name.underscore}""#{klass.name.underscore}"
|
|
30
|
+
end
|
|
31
|
+
defaults << self.name.humanize
|
|
32
|
+
I18n.translate(defaults.shift, {:scope => [:activerecord, :models], :count => 1, :default => defaults}.merge(options))
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")
|
|
2
|
+
|
|
3
|
+
describe Erector::Rails::WidgetExtensions do
|
|
4
|
+
include Erector::Mixin
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@view = ActionView::Base.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_render(&block)
|
|
11
|
+
Erector::Rails.render(Erector.inline(&block), @view)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should be set up with the same output buffer as rails" do
|
|
15
|
+
test_render { output.buffer.should === parent.output_buffer }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should get a new output buffer every time" do
|
|
19
|
+
one = test_render { text "foo" }
|
|
20
|
+
two = test_render { text "foo" }
|
|
21
|
+
one.should == "foo"
|
|
22
|
+
two.should == "foo"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#capture" do
|
|
26
|
+
it "captures parent output" do
|
|
27
|
+
captured = nil
|
|
28
|
+
test_render do
|
|
29
|
+
captured = capture do
|
|
30
|
+
parent.concat "capture me!"
|
|
31
|
+
end
|
|
32
|
+
end.should == ""
|
|
33
|
+
captured.should == "capture me!"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "captures with an erector block" do
|
|
37
|
+
captured = nil
|
|
38
|
+
test_render do
|
|
39
|
+
captured = capture do
|
|
40
|
+
text 'capture me!'
|
|
41
|
+
end
|
|
42
|
+
end.should == ""
|
|
43
|
+
captured.should == "capture me!"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "captures erector output when called via parent" do
|
|
47
|
+
test_render do
|
|
48
|
+
text "A"
|
|
49
|
+
c = parent.capture do
|
|
50
|
+
text "C"
|
|
51
|
+
end
|
|
52
|
+
text "B"
|
|
53
|
+
text c
|
|
54
|
+
end.should == "ABC"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "returns a safe string" do
|
|
58
|
+
captured = nil
|
|
59
|
+
test_render do
|
|
60
|
+
captured = capture {}
|
|
61
|
+
end.should == ""
|
|
62
|
+
captured.should be_html_safe
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "escaping" do
|
|
67
|
+
it "escapes non-safe strings" do
|
|
68
|
+
erector { text "<>&" }.should == "<>&"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "does not escape safe strings" do
|
|
72
|
+
erector { text "<>&".html_safe }.should == "<>&"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "returns safe strings from capture" do
|
|
76
|
+
captured = nil
|
|
77
|
+
erector do
|
|
78
|
+
captured = capture {}
|
|
79
|
+
end
|
|
80
|
+
captured.should be_html_safe
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")
|
|
2
|
+
|
|
3
|
+
describe ActionController::Base do
|
|
4
|
+
class TestController < ActionController::Base
|
|
5
|
+
# Let exceptions propagate rather than generating the usual error page.
|
|
6
|
+
include ActionController::TestCase::RaiseActionExceptions
|
|
7
|
+
|
|
8
|
+
# We need this, because we reference Views::Test::Needs below, and it
|
|
9
|
+
# doesn't auto-load otherwise.
|
|
10
|
+
require 'views/test/needs.html.rb'
|
|
11
|
+
|
|
12
|
+
def render_widget_with_implicit_assigns
|
|
13
|
+
@foobar = "foobar"
|
|
14
|
+
render_widget TestWidget
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def render_widget_with_explicit_assigns
|
|
18
|
+
render_widget TestWidget, :foobar => "foobar"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def render_widget_class
|
|
22
|
+
@foobar = "foobar"
|
|
23
|
+
render :widget => TestWidget
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def render_widget_with_ignored_controller_variables
|
|
27
|
+
@foo = "foo"
|
|
28
|
+
@baz = "baz"
|
|
29
|
+
render :widget => NeedsWidget
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def render_widget_with_extra_controller_variables
|
|
33
|
+
with_ignoring_extra_controller_assigns(NeedsWidget, false) do
|
|
34
|
+
@foo = "foo"
|
|
35
|
+
@baz = "baz"
|
|
36
|
+
render :widget => NeedsWidget
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def render_widget_instance
|
|
41
|
+
render :widget => TestWidget.new(:foobar => "foobar")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def render_with_content_method
|
|
45
|
+
render :widget => TestWidget, :content_method_name => :content_method
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def render_with_rails_options
|
|
49
|
+
render :widget => TestWidget, :status => 500, :content_type => "application/json"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def render_template_with_implicit_assigns
|
|
53
|
+
@foobar = "foobar"
|
|
54
|
+
render :template => "test/implicit_assigns.html.rb"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def render_template_with_protected_instance_variable
|
|
58
|
+
render :template => "test/protected_instance_variable.html.rb"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def render_template_with_excess_variables
|
|
62
|
+
with_ignoring_extra_controller_assigns(Views::Test::Needs, false) do
|
|
63
|
+
@foobar = "foobar"
|
|
64
|
+
@barfoo = "barfoo"
|
|
65
|
+
render :template => 'test/render_default.html.rb'
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def render_needs_template_with_excess_variables
|
|
70
|
+
with_ignoring_extra_controller_assigns(Views::Test::Needs, false) do
|
|
71
|
+
@foobar = "foobar"
|
|
72
|
+
@barfoo = "barfoo"
|
|
73
|
+
render :template => 'test/needs.html.rb'
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def with_ignoring_extra_controller_assigns(klass, value)
|
|
78
|
+
old_value = klass.ignore_extra_controller_assigns
|
|
79
|
+
begin
|
|
80
|
+
klass.ignore_extra_controller_assigns = value
|
|
81
|
+
yield
|
|
82
|
+
ensure
|
|
83
|
+
klass.ignore_extra_controller_assigns = old_value
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def render_needs_template_with_excess_variables_and_ignoring_extras
|
|
88
|
+
@foobar = "foobar"
|
|
89
|
+
@barfoo = "barfoo"
|
|
90
|
+
render :template => 'test/needs.html.rb'
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def render_needs_subclass_template_with_excess_variables_and_ignoring_extras
|
|
94
|
+
@foobar = "foobar"
|
|
95
|
+
@barfoo = "barfoo"
|
|
96
|
+
render :template => 'test/needs_subclass.html.rb'
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def render_bare_rb
|
|
100
|
+
render :template => "test/bare.rb"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def render_default
|
|
104
|
+
@foobar = "foobar"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def render_template_with_partial
|
|
108
|
+
@foobar = "foobar"
|
|
109
|
+
render :template => "test/render_partial.html.rb"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def render_erb_from_erector
|
|
113
|
+
@foobar = "foobar"
|
|
114
|
+
render :template => "test/erb_from_erector.html.rb"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def render_erector_from_erb
|
|
118
|
+
@foobar = "foobar"
|
|
119
|
+
render :template => "test/erector_from_erb.html.erb"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def render_erector_with_locals_from_erb
|
|
123
|
+
@local_foo = "hihi"
|
|
124
|
+
@local_bar = "byebye"
|
|
125
|
+
render :template => 'test/erector_with_locals_from_erb.html.erb'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def render_erector_with_locals_from_erb_defaulted
|
|
129
|
+
@local_foo = "hihi"
|
|
130
|
+
render :template => 'test/erector_with_locals_from_erb.html.erb'
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def render_erector_with_locals_from_erb_override
|
|
134
|
+
@foo = "globalfoo"
|
|
135
|
+
@local_foo = "localfoo"
|
|
136
|
+
render :template => 'test/erector_with_locals_from_erb.html.erb'
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def render_erector_with_locals_from_erb_not_needed
|
|
140
|
+
@local_foo = "localfoo"
|
|
141
|
+
@local_baz = "unneeded"
|
|
142
|
+
render :template => 'test/erector_with_locals_from_erb.html.erb'
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def render_erector_partial_with_unneeded_controller_variables
|
|
146
|
+
@local_foo = "localfoo"
|
|
147
|
+
@baz = "unneeded"
|
|
148
|
+
render :template => 'test/erector_with_locals_from_erb.html.erb'
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def with_controller_assigns_propagate_to_partials(klass, value)
|
|
152
|
+
old_value = klass.controller_assigns_propagate_to_partials
|
|
153
|
+
begin
|
|
154
|
+
klass.controller_assigns_propagate_to_partials = value
|
|
155
|
+
yield
|
|
156
|
+
ensure
|
|
157
|
+
klass.controller_assigns_propagate_to_partials = old_value
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def render_erector_partial_without_controller_variables
|
|
162
|
+
with_controller_assigns_propagate_to_partials(Views::Test::PartialWithLocals, false) do
|
|
163
|
+
@local_foo = "localfoo"
|
|
164
|
+
@bar = "barbar"
|
|
165
|
+
render :template => 'test/erector_with_locals_from_erb.html.erb'
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def render_with_needs
|
|
170
|
+
@foo = "foo"
|
|
171
|
+
@bar = "bar"
|
|
172
|
+
render :widget => NeedsWidget
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
class TestWidget < Erector::Widget
|
|
177
|
+
def content
|
|
178
|
+
text @foobar
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def content_method
|
|
182
|
+
text "content_method"
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
class TestFormWidget < Erector::Widget
|
|
187
|
+
def content
|
|
188
|
+
form_tag('/') do
|
|
189
|
+
h1 "Create a foo"
|
|
190
|
+
rawtext text_field_tag(:name)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
class NeedsWidget < Erector::Widget
|
|
196
|
+
needs :foo, :bar => true
|
|
197
|
+
|
|
198
|
+
def content
|
|
199
|
+
text "foo #{@foo} bar #{@bar}"
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
before do
|
|
204
|
+
@controller = TestController.new
|
|
205
|
+
@request = ActionController::TestRequest.new
|
|
206
|
+
@response = ActionController::TestResponse.new
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def test_action(action)
|
|
210
|
+
@request.action = action.to_s
|
|
211
|
+
@controller.process(@request, @response)
|
|
212
|
+
@response.body
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
describe "#render_widget" do
|
|
216
|
+
it "should render a widget with implicit assigns" do
|
|
217
|
+
test_action(:render_widget_with_implicit_assigns).should == "foobar"
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
it "should render a widget with explicit assigns" do
|
|
221
|
+
test_action(:render_widget_with_explicit_assigns).should == "foobar"
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
describe "#render" do
|
|
226
|
+
it "should render a widget class with implicit assigns" do
|
|
227
|
+
test_action(:render_widget_class).should == "foobar"
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "should render a widget instance with explicit assigns" do
|
|
231
|
+
test_action(:render_widget_instance).should == "foobar"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it "should render a widget class with implicit assigns and ignoring extra variables" do
|
|
235
|
+
test_action(:render_widget_with_ignored_controller_variables).should == "foo foo bar true"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "should raise when rendering a widget class with implicit assigns and too many variables" do
|
|
239
|
+
proc { test_action(:render_widget_with_extra_controller_variables) }.should raise_error(RuntimeError, /Excess parameters?.*: .*baz/)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "should render a specific content method" do
|
|
243
|
+
test_action(:render_with_content_method).should == "content_method"
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "should pass rails options to base render method" do
|
|
247
|
+
test_action(:render_with_rails_options)
|
|
248
|
+
@response.response_code.should == 500
|
|
249
|
+
@response.content_type.should == "application/json"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "should render a template with implicit assigns" do
|
|
253
|
+
test_action(:render_template_with_implicit_assigns).should == "foobar"
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
it "should not include protected instance variables in assigns" do
|
|
257
|
+
test_action(:render_template_with_protected_instance_variable).should == ""
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
it "should render a template without a .html format included" do
|
|
261
|
+
test_action(:render_bare_rb).should == "Bare"
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
it "should render a template with excess controller variables" do
|
|
265
|
+
test_action(:render_template_with_excess_variables).should == "Default foobar"
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "should raise if rendering a #needs template with excess controller variables" do
|
|
269
|
+
proc { test_action(:render_needs_template_with_excess_variables) }.should raise_error(ActionView::TemplateError, /Excess parameters?.*: .*barfoo/)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it "should render a #needs template with excess controller variables and ignore_extra_controller_assigns" do
|
|
273
|
+
test_action(:render_needs_template_with_excess_variables_and_ignoring_extras).should == "Needs foobar"
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
it "should respect ignore_extra_controller_assigns in subclasses" do
|
|
277
|
+
test_action(:render_needs_subclass_template_with_excess_variables_and_ignoring_extras).should == "NeedsSubclass foobar"
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it "should render a template which uses partials" do
|
|
281
|
+
test_action(:render_template_with_partial).should == "Partial foobar"
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
it "should render an erector widget which uses an ERB partial'" do
|
|
285
|
+
test_action(:render_erb_from_erector).should == "Partial foobar"
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it "should render an ERB template which uses an erector widget partial" do
|
|
289
|
+
test_action(:render_erector_from_erb).should == "Partial foobar"
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it "should render an ERB template which uses an erector widget partial with locals" do
|
|
293
|
+
test_action(:render_erector_with_locals_from_erb).should == "Partial, foo hihi, bar byebye"
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it "should render an ERB template which uses an erector widget partial with a defaulted local" do
|
|
297
|
+
test_action(:render_erector_with_locals_from_erb_defaulted).should == "Partial, foo hihi, bar 12345"
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it "should override instance variables with local variables when rendering partials" do
|
|
301
|
+
test_action(:render_erector_with_locals_from_erb_override).should == "Partial, foo localfoo, bar 12345"
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it "should raise if passing a local that's not needed" do
|
|
305
|
+
proc { test_action(:render_erector_with_locals_from_erb_not_needed) }.should raise_error(ActionView::TemplateError, /Excess parameters?.*: .*baz/)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
it "should not pass unneeded controller variables to a partial" do
|
|
309
|
+
test_action(:render_erector_partial_with_unneeded_controller_variables).should == "Partial, foo localfoo, bar 12345"
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
it "should not pass controller variables to a partial at all, if requested" do
|
|
313
|
+
test_action(:render_erector_partial_without_controller_variables).should == "Partial, foo localfoo, bar 12345"
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
it "should render a default template" do
|
|
317
|
+
test_action(:render_default).should == "Default foobar"
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
it "should allow rendering widget with needs" do
|
|
321
|
+
proc { test_action(:render_with_needs) }.should_not raise_error
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|