Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec_on_rails / spec / rails / dsl / view_spec_spec.rb
blob8c4e42f6cc1f031622eec05077b76b4d15015233
1 require File.dirname(__FILE__) + '/../../spec_helper'
3 describe "A view with an implicit helper", :behaviour_type => :view do
4   before(:each) do
5     render "view_spec/show"
6   end
8   it "should include the helper" do
9     response.should have_tag('div', :content => "This is text from a method in the ViewSpecHelper")
10   end
12   it "should include the application helper" do
13     response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
14   end
15 end
17 describe "A view requiring an explicit helper", :behaviour_type => :view do
18   before(:each) do
19     render "view_spec/explicit_helper", :helper => 'explicit'
20   end
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")
24   end
26   it "should include the application helper" do
27     response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
28   end
29 end
31 describe "A view requiring multiple explicit helpers", :behaviour_type => :view do
32   before(:each) do
33     render "view_spec/multiple_helpers", :helpers => ['explicit', 'more_explicit']
34   end
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")
39   end
41   it "should include the application helper" do
42     response.should have_tag('div', :content => "This is text from a method in the ApplicationHelper")
43   end
44 end
46 describe "A view that includes a partial", :behaviour_type => :view do
47   def render!
48     render "view_spec/partial_including_template"
49   end
51   it "should render the enclosing template" do
52     render!
53     response.should have_tag('div', "method_in_included_partial in ViewSpecHelper")
54   end
56   it "should render the partial" do
57     render!
58     response.should have_tag('div', "method_in_partial_including_template in ViewSpecHelper")
59   end
61   it "should include the application helper" do
62     render!
63     response.should have_tag('div', "This is text from a method in the ApplicationHelper")
64   end
65   
66   it "should support mocking the render call" do
67     template.should_receive(:render).with(:partial => 'included_partial')
68     render!
69   end
70 end
72 describe "A view that includes a partial using :collection and :spacer_template", :behaviour_type => :view  do
73   before(:each) do
74     render "view_spec/partial_collection_including_template"
75   end
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')
81   end
83 end
85 describe "A view that includes a partial using an array as partial_path", :behaviour_type => :view do
86   before(:each) 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)
90           "Array Partial"
91         else
92           render_partial_without_array_support(partial_path, local_assigns, deprecated_local_assigns)
93         end
94       end
96       alias :render_partial_without_array_support :render_partial
97       alias :render_partial :render_partial_with_array_support
98     end
100     @array = ['Alice', 'Bob']
101     assigns[:array] = @array
102   end
104   after(:each) do
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
109     end
110   end
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$/)
115   end
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")
122   end
125 describe "A view", :behaviour_type => :view do
126   before(:each) do
127     session[:key] = "session"
128     params[:key] = "params"
129     flash[:key] = "flash"
130     render "view_spec/accessor"
131   end
133   it "should have access to session data" do
134     response.should have_tag("div#session", "session")
135   end
137   specify "should have access to params data" do
138     puts response.body
139     response.should have_tag("div#params", "params")
140   end
142   it "should have access to flash data" do
143     response.should have_tag("div#flash", "flash")
144   end
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")
151   end
154 module Spec
155   module Rails
156     module DSL
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
161         end
162       end
163     end
164   end