Skip to content

Commit

Permalink
Extracted template_exists? stuff into BC module for Rails < 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Feb 3, 2009
1 parent 4bdecf2 commit 7e50de0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 5 additions & 1 deletion init.rb
@@ -1,3 +1,7 @@
require 'ardes/response_for'
ActionController::Base.send :include, Ardes::ResponseFor
ActionController::MimeResponds::Responder.send :include, Ardes::ResponseFor::Responder

if Rails.version < "2.3.0"
require 'ardes/response_for/bc'
ActionController::Base.send :include, Ardes::ResponseFor::Bc
end
14 changes: 5 additions & 9 deletions lib/ardes/response_for.rb
Expand Up @@ -5,7 +5,7 @@ def self.included(base)
base.class_eval do
extend ClassMethods
alias_method_chain :default_render, :response_for
alias_method_chain :template_exists?, :response_for
::ActionController::MimeResponds::Responder.send :include, Responder
end
end

Expand Down Expand Up @@ -129,12 +129,6 @@ def respond_to_performed?
(response && response.content_type) ? true : false
end

# we extend template_exists? to return true if a template OR a response exists corresponding to the current action.
# This is so that a default render will be triggered when no action, but a repsonse does exist.
def template_exists_with_response_for?
action_responses.any? || template_exists_without_response_for?
end

# if the response.content_type has not been set (if it has, then responthere are responses for the current action, then respond_to them
#
# we rescue the case where there were no responses, so that the default_render
Expand All @@ -152,6 +146,8 @@ def respond_to_action_responses
def default_render_with_response_for
respond_to_action_responses
default_render_without_response_for unless performed?
rescue ActionView::MissingTemplate => e
respond_to_action_responses
end

# included into ActionController::MimeResponds::Responder
Expand All @@ -172,8 +168,8 @@ def respond_with_response_for

module VERSION #:nodoc:
MAJOR = 0
MINOR = 2
TINY = 2
MINOR = 3
TINY = 0

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/version_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))

describe Ardes::ResponseFor::VERSION do
it "STRING should be 0.2.2" do
Ardes::ResponseFor::VERSION::STRING.should == '0.2.2'
it "STRING should be 0.3.0" do
Ardes::ResponseFor::VERSION::STRING.should == '0.3.0'
end
end

0 comments on commit 7e50de0

Please sign in to comment.