1 require File.dirname(__FILE__) + '/../../spec_helper'
3 describe "A view with an implicit helper", :behaviour_type => :view do
5 render "view_spec/show"
8 it "should include the helper" do
9 response.should have_tag('div', :content => "This is text from a method in the ViewSpecHelper")
12 it "should include the application helper" do
13 response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
17 describe "A view requiring an explicit helper", :behaviour_type => :view do
19 render "view_spec/explicit_helper", :helper => 'explicit'
22 it "should include the helper if specified" do
23 response.should have_tag('div', :content => "This is text from a method in the ExplicitHelper")
26 it "should include the application helper" do
27 response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
31 describe "A view requiring multiple explicit helpers", :behaviour_type => :view do
33 render "view_spec/multiple_helpers", :helpers => ['explicit', 'more_explicit']
36 it "should included all specified helpers" do
37 response.should have_tag('div', :content => "This is text from a method in the ExplicitHelper")
38 response.should have_tag('div', :content => "This is text from a method in the MoreExplicitHelper")
41 it "should include the application helper" do
42 response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
46 describe "A view that includes a partial", :behaviour_type => :view do
48 render "view_spec/partial_including_template"
51 it "should render the enclosing template" do
53 response.should have_tag('div', "method_in_included_partial in ViewSpecHelper")
56 it "should render the partial" do
58 response.should have_tag('div', "method_in_partial_including_template in ViewSpecHelper")
61 it "should include the application helper" do
63 response.should have_tag('div', "This is text from a method in the ApplicationHelper")
66 it "should support mocking the render call" do
67 template.should_receive(:render).with(:partial => 'included_partial')
72 describe "A view that includes a partial using :collection and :spacer_template", :behaviour_type => :view do
74 render "view_spec/partial_collection_including_template"
77 it "should render the partial w/ spacer_tamplate" do
78 response.should have_tag('div', :content => 'Alice')
79 response.should have_tag('hr', :attributes =>{:id => "spacer"})
80 response.should have_tag('div', :content => 'Bob')
85 describe "A view that includes a partial using an array as partial_path", :behaviour_type => :view do
87 module ActionView::Partials
88 def render_partial_with_array_support(partial_path, local_assigns = nil, deprecated_local_assigns = nil)
89 if partial_path.is_a?(Array)
92 render_partial_without_array_support(partial_path, local_assigns, deprecated_local_assigns)
96 alias :render_partial_without_array_support :render_partial
97 alias :render_partial :render_partial_with_array_support
100 @array = ['Alice', 'Bob']
101 assigns[:array] = @array
105 module ActionView::Partials
106 alias :render_partial_with_array_support :render_partial
107 alias :render_partial :render_partial_without_array_support
108 undef render_partial_with_array_support
112 it "should render have the array passed through to render_partial without modification" do
113 render "view_spec/partial_with_array"
114 response.body.should match(/^Array Partial$/)
118 describe "Different types of renders (not :template)", :behaviour_type => :view do
119 it "should render partial with local" do
120 render :partial => "view_spec/partial_with_local_variable", :locals => {:x => "Ender"}
121 response.should have_tag('div', :content => "Ender")
125 describe "A view", :behaviour_type => :view do
127 session[:key] = "session"
128 params[:key] = "params"
129 flash[:key] = "flash"
130 render "view_spec/accessor"
133 it "should have access to session data" do
134 response.should have_tag("div#session", "session")
137 specify "should have access to params data" do
139 response.should have_tag("div#params", "params")
142 it "should have access to flash data" do
143 response.should have_tag("div#flash", "flash")
147 describe "A view with a form_tag", :behaviour_type => :view do
148 it "should render the right action" do
149 render "view_spec/entry_form"
150 response.should have_tag("form[action=?]","/view_spec/entry_form")
157 describe ViewBehaviour do
158 it "should tell you its behaviour_type is :view" do
159 behaviour = ViewBehaviour.new("") {}
160 behaviour.behaviour_type.should == :view