Skip to content

Commit

Permalink
Merge branch 'master' of garlic/work/edge/vendor/plugins/response_for
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Apr 30, 2008
2 parents 69cfeab + 1b82c39 commit f67d6cc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
32 changes: 16 additions & 16 deletions SPECDOC
@@ -1,50 +1,50 @@

BackToFooController:
BackToFooController
- get :foo, :format => 'xml' should not render foo

DefaultRespondToController behaviour of #respond_to:
- get :foo should not call first
- get :foo should not call second
- get :foo should call third

FooBailOutController:
FooBailOutController
- get :foo, :bail_out => true should redirect

FooController:
FooController
- get :foo should render text/html: foo
- get :foo should assign @foo
- get :foo, :format => 'html' should render foo
- get :foo, :format => 'xml' should not render foo

InlineXmlFooController:
- get :foo should render text/html 'foo'
FooAController
- get :foo should call a
- get :baz should call bazza (inside the response_for block)

FooBController
- get :foo should call b

InlineXmlFooController
- get :foo should assign @foo
- get :foo, :format => 'html' should render 'foo'
- get :foo, :format => 'xml' should call xml_call with 'foo
- get :foo, :format => 'xml' should have response.body of 'XML'

XmlFooController:
XmlFooController
- get :foo should render foo
- get :foo should assign @foo
- get :foo, :format => 'html' should render foo
- get :foo, :format => 'xml' should render foo
- get :bar, :format => 'xml' should render bar
- get :just_a_template, :format => 'xml' should render just_a_template

XmlOnlyFooController:
XmlOnlyFooController
- get :foo should render xml: foo
- get :bar should render xml: bar
- get :foo should assign @foo
- get :foo, :format => 'html' should not render foo
- get :foo, :format => 'xml' should render foo

class method #action_responses:
class method #action_responses
- @child.action_responses[:action] should be copy of parent's action response for :action
- @grandchild.action_responses[:action] should be copy of @child.action_responses[:action]
- @child.action_responses[:action] not be same object as parent's action response for :action
- @grandchild.action_responses[:action] not be same object as @child.action_responses[:action]
- adding to @grandchild.action_responses[:action] should not change parents

Finished in 0.236473 seconds
Finished in 0.328216 seconds

30 examples, 0 failures
28 examples, 0 failures
2 changes: 1 addition & 1 deletion lib/ardes/response_for.rb
Expand Up @@ -162,7 +162,7 @@ def erase_render_results_with_response_for
# This allows actions without an explicit respond_to block to be decorated
# with response_for
def render_with_response_for(*args, &block)
if !instance_variable_get('@performed_respond_to') && !block_given? && args.reject(&:nil?) == [] && self.class.send(:action_responses)[action_name]
if !instance_variable_get('@performed_respond_to') && self.class.send(:action_responses)[action_name] && !block_given? && args.reject{|a| a.nil? || a.empty?}.empty?
respond_to
return if performed?
end
Expand Down
4 changes: 4 additions & 0 deletions spec/app.rb
Expand Up @@ -11,6 +11,10 @@ def bar
respond_to(:json)
erase_render_results
end

def baz
# no respond_to block in here, but we can still supplu one with response_for
end
end

class XmlFooController < FooController
Expand Down
14 changes: 12 additions & 2 deletions spec/controllers/inerited_controllers_spec.rb
Expand Up @@ -5,6 +5,10 @@ class FooAController < FooController
response_for :foo do |format|
format.html { a }
end

response_for :baz do |format|
format.html { bazza }
end
end

class FooBController < FooAController
Expand All @@ -16,20 +20,26 @@ class FooBController < FooAController
describe FooAController do
before do
@controller.stub!(:a)
@controller.stub!(:bazza)
end

it "get :foo should call :b" do
it "get :foo should call a" do
@controller.should_receive(:a)
get :foo
end

it "get :baz should call bazza (inside the response_for block)" do
@controller.should_receive(:bazza)
get :baz
end
end

describe FooBController do
before do
@controller.stub!(:b)
end

it "get :foo should call :b" do
it "get :foo should call b" do
@controller.should_receive(:b)
get :foo
end
Expand Down

0 comments on commit f67d6cc

Please sign in to comment.