erector-rails4 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +143 -0
- data/README.md +4 -0
- data/Rakefile +24 -0
- data/erector-rails4.gemspec +36 -0
- data/erector-rails4.sublimeproject +20 -0
- data/lib/erector/abstract_widget.rb +231 -0
- data/lib/erector/after_initialize.rb +29 -0
- data/lib/erector/attributes.rb +29 -0
- data/lib/erector/cache.rb +37 -0
- data/lib/erector/caching.rb +65 -0
- data/lib/erector/convenience.rb +98 -0
- data/lib/erector/dependencies.rb +24 -0
- data/lib/erector/dependency.rb +31 -0
- data/lib/erector/element.rb +113 -0
- data/lib/erector/externals.rb +104 -0
- data/lib/erector/html.rb +12 -0
- data/lib/erector/html_widget.rb +220 -0
- data/lib/erector/inline.rb +37 -0
- data/lib/erector/jquery.rb +28 -0
- data/lib/erector/mixin.rb +12 -0
- data/lib/erector/needs.rb +95 -0
- data/lib/erector/output.rb +144 -0
- data/lib/erector/promise.rb +141 -0
- data/lib/erector/rails/form_builder.rb +44 -0
- data/lib/erector/rails/railtie.rb +13 -0
- data/lib/erector/rails/template_handler.rb +16 -0
- data/lib/erector/rails/widget_renderer.rb +6 -0
- data/lib/erector/rails.rb +221 -0
- data/lib/erector/raw_string.rb +12 -0
- data/lib/erector/sass.rb +32 -0
- data/lib/erector/tag.rb +66 -0
- data/lib/erector/text.rb +123 -0
- data/lib/erector/unicode.rb +18185 -0
- data/lib/erector/unicode_builder.rb +67 -0
- data/lib/erector/version.rb +5 -0
- data/lib/erector/widget.rb +94 -0
- data/lib/erector/widgets.rb +5 -0
- data/lib/erector/xml_widget.rb +131 -0
- data/lib/erector.rb +28 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/erb_as_layout.html.erb +2 -0
- data/spec/dummy/app/views/layouts/widget_as_layout.rb +8 -0
- data/spec/dummy/app/views/test/_erb.erb +1 -0
- data/spec/dummy/app/views/test/_erector.rb +5 -0
- data/spec/dummy/app/views/test/_partial_with_locals.rb +7 -0
- data/spec/dummy/app/views/test/bare.rb +5 -0
- data/spec/dummy/app/views/test/erb_from_erector.html.rb +5 -0
- data/spec/dummy/app/views/test/erector_from_erb.html.erb +1 -0
- data/spec/dummy/app/views/test/erector_with_locals_from_erb.html.erb +6 -0
- data/spec/dummy/app/views/test/implicit_assigns.html.rb +5 -0
- data/spec/dummy/app/views/test/needs.html.rb +7 -0
- data/spec/dummy/app/views/test/needs_subclass.html.rb +5 -0
- data/spec/dummy/app/views/test/protected_instance_variable.html.rb +5 -0
- data/spec/dummy/app/views/test/render_default.html.rb +5 -0
- data/spec/dummy/app/views/test/render_default_erb_with_layout.html.erb +1 -0
- data/spec/dummy/app/views/test/render_default_widget_with_layout.html.rb +5 -0
- data/spec/dummy/app/views/test/render_partial.html.rb +5 -0
- data/spec/dummy/app/views/test/render_with_widget_as_layout.rb +5 -0
- data/spec/dummy/app/views/test/render_with_widget_as_layout_using_content_for.rb +8 -0
- data/spec/dummy/config/application.rb +44 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +22 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/form_builder_spec.rb +21 -0
- data/spec/dummy/spec/rails_helpers_spec.rb +236 -0
- data/spec/dummy/spec/rails_spec_helper.rb +10 -0
- data/spec/dummy/spec/rails_widget_spec.rb +83 -0
- data/spec/dummy/spec/render_spec.rb +369 -0
- data/spec/erector/after_initialize_spec.rb +45 -0
- data/spec/erector/cache_spec.rb +133 -0
- data/spec/erector/caching_spec.rb +184 -0
- data/spec/erector/convenience_spec.rb +250 -0
- data/spec/erector/dependency_spec.rb +67 -0
- data/spec/erector/hello_from_readme.rb +18 -0
- data/spec/erector/hello_from_readme_spec.rb +11 -0
- data/spec/erector/html_spec.rb +585 -0
- data/spec/erector/indentation_spec.rb +211 -0
- data/spec/erector/inline_spec.rb +94 -0
- data/spec/erector/jquery_spec.rb +35 -0
- data/spec/erector/mixin_spec.rb +65 -0
- data/spec/erector/needs_spec.rb +141 -0
- data/spec/erector/output_spec.rb +293 -0
- data/spec/erector/promise_spec.rb +173 -0
- data/spec/erector/sample-file.txt +1 -0
- data/spec/erector/sass_spec.rb +57 -0
- data/spec/erector/tag_spec.rb +67 -0
- data/spec/erector/unicode_builder_spec.rb +75 -0
- data/spec/erector/widget_spec.rb +310 -0
- data/spec/erector/xml_widget_spec.rb +73 -0
- data/spec/spec_helper.rb +31 -0
- metadata +368 -0
@@ -0,0 +1,10 @@
|
|
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}/../../spec_helper", __FILE__)
|
6
|
+
require File.expand_path("#{here}/../config/environment", __FILE__)
|
7
|
+
|
8
|
+
Bundler.require(:test)
|
9
|
+
|
10
|
+
require "erector/rails"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/rails_spec_helper")
|
2
|
+
|
3
|
+
describe Erector::Rails 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
|
+
test_render { text "<>&" }.should == "<>&"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "does not escape safe strings" do
|
72
|
+
test_render { text "<>&".html_safe }.should == "<>&"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns safe strings from capture" do
|
76
|
+
captured = nil
|
77
|
+
test_render do
|
78
|
+
captured = capture {}
|
79
|
+
end
|
80
|
+
captured.should be_html_safe
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,369 @@
|
|
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
|
+
# replicate deprecated use for rails <3.2
|
13
|
+
if (Gem::Version.new(Rails.version) < Gem::Version.new('3.2.0') rescue false)
|
14
|
+
def render(*args, &block)
|
15
|
+
options = args.extract_options!
|
16
|
+
if options[:template]
|
17
|
+
handlers = options.delete(:handlers)
|
18
|
+
format = '.html' unless options.delete(:bare)
|
19
|
+
options[:template] += "#{format}.#{handlers.first}"
|
20
|
+
end
|
21
|
+
render(*(args << options), &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_widget_class
|
26
|
+
@foobar = "foobar"
|
27
|
+
render :widget => TestWidget
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_widget_with_ignored_controller_variables
|
31
|
+
@foo = "foo"
|
32
|
+
@baz = "baz"
|
33
|
+
render :widget => NeedsWidget
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_widget_with_extra_controller_variables
|
37
|
+
with_ignoring_extra_controller_assigns(NeedsWidget, false) do
|
38
|
+
@foo = "foo"
|
39
|
+
@baz = "baz"
|
40
|
+
render :widget => NeedsWidget
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def render_widget_instance
|
45
|
+
render :widget => TestWidget.new(:foobar => "foobar")
|
46
|
+
end
|
47
|
+
|
48
|
+
def render_with_content_method
|
49
|
+
render :widget => TestWidget, :content_method_name => :content_method
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_with_rails_options
|
53
|
+
render :widget => TestWidget, :status => 500, :content_type => "application/json"
|
54
|
+
end
|
55
|
+
|
56
|
+
def render_template_with_implicit_assigns
|
57
|
+
@foobar = "foobar"
|
58
|
+
render :template => "test/implicit_assigns", :handlers => [:rb]
|
59
|
+
end
|
60
|
+
|
61
|
+
def render_template_with_protected_instance_variable
|
62
|
+
render :template => "test/protected_instance_variable", :handlers => [:rb]
|
63
|
+
end
|
64
|
+
|
65
|
+
def render_template_with_excess_variables
|
66
|
+
with_ignoring_extra_controller_assigns(Views::Test::Needs, false) do
|
67
|
+
@foobar = "foobar"
|
68
|
+
@barfoo = "barfoo"
|
69
|
+
render :template => 'test/render_default', :handlers => [:rb]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def render_needs_template_with_excess_variables
|
74
|
+
with_ignoring_extra_controller_assigns(Views::Test::Needs, false) do
|
75
|
+
@foobar = "foobar"
|
76
|
+
@barfoo = "barfoo"
|
77
|
+
render :template => 'test/needs', :handlers => [:rb]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def with_ignoring_extra_controller_assigns(klass, value)
|
82
|
+
old_value = klass.ignore_extra_controller_assigns
|
83
|
+
begin
|
84
|
+
klass.ignore_extra_controller_assigns = value
|
85
|
+
yield
|
86
|
+
ensure
|
87
|
+
klass.ignore_extra_controller_assigns = old_value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def render_needs_template_with_excess_variables_and_ignoring_extras
|
92
|
+
@foobar = "foobar"
|
93
|
+
@barfoo = "barfoo"
|
94
|
+
render :template => 'test/needs', :handlers => [:rb]
|
95
|
+
end
|
96
|
+
|
97
|
+
def render_needs_subclass_template_with_excess_variables_and_ignoring_extras
|
98
|
+
@foobar = "foobar"
|
99
|
+
@barfoo = "barfoo"
|
100
|
+
render :template => 'test/needs_subclass', :handlers => [:rb]
|
101
|
+
end
|
102
|
+
|
103
|
+
def render_bare_rb
|
104
|
+
render :template => "test/bare", :handlers => [:rb], :bare => true
|
105
|
+
end
|
106
|
+
|
107
|
+
def render_default
|
108
|
+
@foobar = "foobar"
|
109
|
+
end
|
110
|
+
|
111
|
+
def render_template_with_partial
|
112
|
+
@foobar = "foobar"
|
113
|
+
render :template => "test/render_partial", :handlers => [:rb]
|
114
|
+
end
|
115
|
+
|
116
|
+
def render_erb_from_erector
|
117
|
+
@foobar = "foobar"
|
118
|
+
render :template => "test/erb_from_erector", :handlers => [:rb]
|
119
|
+
end
|
120
|
+
|
121
|
+
def render_erector_from_erb
|
122
|
+
@foobar = "foobar"
|
123
|
+
render :template => "test/erector_from_erb", :handlers => [:erb]
|
124
|
+
end
|
125
|
+
|
126
|
+
def render_erector_with_locals_from_erb
|
127
|
+
@local_foo = "hihi"
|
128
|
+
@local_bar = "byebye"
|
129
|
+
render :template => 'test/erector_with_locals_from_erb', :handlers => [:erb]
|
130
|
+
end
|
131
|
+
|
132
|
+
def render_erector_with_locals_from_erb_defaulted
|
133
|
+
@local_foo = "hihi"
|
134
|
+
render :template => 'test/erector_with_locals_from_erb', :handlers => [:erb]
|
135
|
+
end
|
136
|
+
|
137
|
+
def render_erector_with_locals_from_erb_override
|
138
|
+
@foo = "globalfoo"
|
139
|
+
@local_foo = "localfoo"
|
140
|
+
render :template => 'test/erector_with_locals_from_erb', :handlers => [:erb]
|
141
|
+
end
|
142
|
+
|
143
|
+
def render_erector_with_locals_from_erb_not_needed
|
144
|
+
@local_foo = "localfoo"
|
145
|
+
@local_baz = "unneeded"
|
146
|
+
render :template => 'test/erector_with_locals_from_erb', :handlers => [:erb]
|
147
|
+
end
|
148
|
+
|
149
|
+
def render_erector_partial_with_unneeded_controller_variables
|
150
|
+
@local_foo = "localfoo"
|
151
|
+
@baz = "unneeded"
|
152
|
+
render :template => 'test/erector_with_locals_from_erb', :handlers => [:erb]
|
153
|
+
end
|
154
|
+
|
155
|
+
def with_controller_assigns_propagate_to_partials(klass, value)
|
156
|
+
old_value = klass.controller_assigns_propagate_to_partials
|
157
|
+
begin
|
158
|
+
klass.controller_assigns_propagate_to_partials = value
|
159
|
+
yield
|
160
|
+
ensure
|
161
|
+
klass.controller_assigns_propagate_to_partials = old_value
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def render_erector_partial_without_controller_variables
|
166
|
+
with_controller_assigns_propagate_to_partials(Views::Test::PartialWithLocals, false) do
|
167
|
+
@local_foo = "localfoo"
|
168
|
+
@bar = "barbar"
|
169
|
+
render :template => 'test/erector_with_locals_from_erb', :handlers => [:erb]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def render_with_needs
|
174
|
+
@foo = "foo"
|
175
|
+
@bar = "bar"
|
176
|
+
render :widget => NeedsWidget
|
177
|
+
end
|
178
|
+
|
179
|
+
def render_with_widget_as_layout
|
180
|
+
render :layout => "layouts/widget_as_layout"
|
181
|
+
end
|
182
|
+
|
183
|
+
def render_default_widget_with_layout
|
184
|
+
@widget_content = "widget content"
|
185
|
+
@layout_content = "layout content"
|
186
|
+
end
|
187
|
+
|
188
|
+
def render_default_erb_with_layout
|
189
|
+
@erb_content = "erb content"
|
190
|
+
@layout_content = "layout content"
|
191
|
+
end
|
192
|
+
|
193
|
+
def render_with_widget_as_layout_and_vars
|
194
|
+
@before = "Breakfast"
|
195
|
+
@during = "Lunch"
|
196
|
+
@after = "Dinner"
|
197
|
+
render :template => "test/render_with_widget_as_layout", :layout => "layouts/widget_as_layout"
|
198
|
+
end
|
199
|
+
|
200
|
+
def render_with_widget_as_layout_using_content_for
|
201
|
+
render :template => "test/render_with_widget_as_layout_using_content_for", :layout => "layouts/widget_as_layout"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class TestWidget < Erector::Widget
|
206
|
+
def content
|
207
|
+
text @foobar
|
208
|
+
end
|
209
|
+
|
210
|
+
def content_method
|
211
|
+
text "content_method"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class TestFormWidget < Erector::Widget
|
216
|
+
def content
|
217
|
+
form_tag('/') do
|
218
|
+
h1 "Create a foo"
|
219
|
+
rawtext text_field_tag(:name)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
class NeedsWidget < Erector::Widget
|
225
|
+
needs :foo, :bar => true
|
226
|
+
|
227
|
+
def content
|
228
|
+
text "foo #{@foo} bar #{@bar}"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_action(action)
|
233
|
+
@response = TestController.action(action).call(Rack::MockRequest.env_for("/path"))[2]
|
234
|
+
@response.body
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "#render" do
|
238
|
+
it "should render a widget class with implicit assigns" do
|
239
|
+
test_action(:render_widget_class).should == "foobar"
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should render a widget instance with explicit assigns" do
|
243
|
+
test_action(:render_widget_instance).should == "foobar"
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should render a widget class with implicit assigns and ignoring extra variables" do
|
247
|
+
test_action(:render_widget_with_ignored_controller_variables).should == "foo foo bar true"
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should raise when rendering a widget class with implicit assigns and too many variables" do
|
251
|
+
proc { test_action(:render_widget_with_extra_controller_variables) }.should raise_error(ArgumentError, /Excess parameters?.*: .*baz/)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should render a specific content method" do
|
255
|
+
test_action(:render_with_content_method).should == "content_method"
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should pass rails options to base render method" do
|
259
|
+
test_action(:render_with_rails_options)
|
260
|
+
@response.response_code.should == 500
|
261
|
+
@response.content_type.should == "application/json"
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should render a template with implicit assigns" do
|
265
|
+
test_action(:render_template_with_implicit_assigns).should == "foobar"
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should not include protected instance variables in assigns" do
|
269
|
+
test_action(:render_template_with_protected_instance_variable).should == ""
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should render a template without a .html format included" do
|
273
|
+
test_action(:render_bare_rb).should == "Bare"
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should render a template with excess controller variables" do
|
277
|
+
test_action(:render_template_with_excess_variables).should == "Default foobar"
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should raise if rendering a #needs template with excess controller variables" do
|
281
|
+
proc { test_action(:render_needs_template_with_excess_variables) }.should raise_error(ActionView::TemplateError, /Excess parameters?.*: .*barfoo/)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should render a #needs template with excess controller variables and ignore_extra_controller_assigns" do
|
285
|
+
test_action(:render_needs_template_with_excess_variables_and_ignoring_extras).should == "Needs foobar"
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should respect ignore_extra_controller_assigns in subclasses" do
|
289
|
+
test_action(:render_needs_subclass_template_with_excess_variables_and_ignoring_extras).should == "NeedsSubclass foobar"
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should render a template which uses partials" do
|
293
|
+
test_action(:render_template_with_partial).should == "Partial foobar"
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should render an erector widget which uses an ERB partial'" do
|
297
|
+
test_action(:render_erb_from_erector).should == "Partial foobar"
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should render an ERB template which uses an erector widget partial" do
|
301
|
+
test_action(:render_erector_from_erb).should == "Partial foobar"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should render an ERB template which uses an erector widget partial with locals" do
|
305
|
+
test_action(:render_erector_with_locals_from_erb).should == "Partial, foo hihi, bar byebye"
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should render an ERB template which uses an erector widget partial with a defaulted local" do
|
309
|
+
test_action(:render_erector_with_locals_from_erb_defaulted).should == "Partial, foo hihi, bar 12345"
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should override instance variables with local variables when rendering partials" do
|
313
|
+
test_action(:render_erector_with_locals_from_erb_override).should == "Partial, foo localfoo, bar 12345"
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should raise if passing a local that's not needed" do
|
317
|
+
proc { test_action(:render_erector_with_locals_from_erb_not_needed) }.should raise_error(ActionView::TemplateError, /Excess parameters?.*: .*baz/)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should not pass unneeded controller variables to a partial" do
|
321
|
+
test_action(:render_erector_partial_with_unneeded_controller_variables).should == "Partial, foo localfoo, bar 12345"
|
322
|
+
end
|
323
|
+
|
324
|
+
it "should not pass controller variables to a partial at all, if requested" do
|
325
|
+
test_action(:render_erector_partial_without_controller_variables).should == "Partial, foo localfoo, bar 12345"
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should render a default template" do
|
329
|
+
test_action(:render_default).should == "Default foobar"
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should render a default erb template with default erb layout" do
|
333
|
+
TestController.layout 'erb_as_layout'
|
334
|
+
test_action(:render_default_erb_with_layout).should == "layout content\nerb content"
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should render a default widget with default erb layout" do
|
338
|
+
TestController.layout 'erb_as_layout'
|
339
|
+
test_action(:render_default_widget_with_layout).should == "layout content\nwidget content"
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should render a default erb template with default widget layout" do
|
343
|
+
TestController.layout 'widget_as_layout'
|
344
|
+
test_action(:render_default_erb_with_layout).should == "BEFOREerb contentAFTER"
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should render a default widget with default widget layout" do
|
348
|
+
TestController.layout 'widget_as_layout'
|
349
|
+
test_action(:render_default_widget_with_layout).should == "BEFOREwidget contentAFTER"
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should allow rendering widget with needs" do
|
353
|
+
proc { test_action(:render_with_needs) }.should_not raise_error
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should allow using a widget as a layout" do
|
357
|
+
test_action(:render_with_widget_as_layout).should == "BEFOREDURINGAFTER"
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should allow using a widget as a layout with instance vars" do
|
361
|
+
test_action(:render_with_widget_as_layout_and_vars).should == "BreakfastLunchDinner"
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should allow using a widget as a layout using content_for" do
|
365
|
+
test_action(:render_with_widget_as_layout_using_content_for).should == "TOPBEFOREDURINGAFTER"
|
366
|
+
end
|
367
|
+
|
368
|
+
end
|
369
|
+
end
|