Skip to content

Commit

Permalink
Merge pull request Sutto#53 from keithpitt/fix-testcase-for-rails-4
Browse files Browse the repository at this point in the history
Fixed TestHelper for Rails 4
  • Loading branch information
Sutto committed Mar 5, 2013
2 parents 19fffa2 + eea67c4 commit 97ae3a8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Gemfile
@@ -1,4 +1,4 @@
source :rubygems source 'https://rubygems.org'


# Allow testing multiple versions with Travis. # Allow testing multiple versions with Travis.
rails_version = ENV['RAILS_VERSION'] rails_version = ENV['RAILS_VERSION']
Expand All @@ -23,4 +23,4 @@ end


gem 'active_model_serializers' gem 'active_model_serializers'


gemspec gemspec
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -7,7 +7,7 @@ require 'bundler/gem_tasks'
desc "Run all specs in spec directory (excluding plugin specs)" desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(:spec) RSpec::Core::RakeTask.new(:spec)


INTEGRATION_LIBS = %w(will_paginate kaminari active_record active_model_serializers) INTEGRATION_LIBS = %w(will_paginate kaminari active_record active_model_serializers rspec)


namespace :spec do namespace :spec do


Expand All @@ -33,4 +33,4 @@ namespace :spec do
end end
end end


task :default => ([:spec] + INTEGRATION_LIBS.map { |l| "spec:integration:#{l}" }) task :default => ([:spec] + INTEGRATION_LIBS.map { |l| "spec:integration:#{l}" })
14 changes: 12 additions & 2 deletions lib/rocket_pants/test_helper.rb
Expand Up @@ -5,6 +5,8 @@ module TestHelper
extend ActiveSupport::Concern extend ActiveSupport::Concern


included do included do
require 'action_controller/test_case'

# Extend the response on first include. # Extend the response on first include.
class_attribute :_default_version class_attribute :_default_version
unless ActionController::TestResponse < ResponseHelper unless ActionController::TestResponse < ResponseHelper
Expand All @@ -13,7 +15,7 @@ module TestHelper
end end


module ResponseHelper module ResponseHelper

def recycle_cached_body! def recycle_cached_body!
@_parsed_body = @_decoded_body = nil @_parsed_body = @_decoded_body = nil
end end
Expand Down Expand Up @@ -73,7 +75,15 @@ def have_decoded_response(value)
protected protected


# Like process, but automatically adds the api version. # Like process, but automatically adds the api version.
def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') def process(action, http_method = 'GET', *args)
# Rails 4 changes the method signature. In rails 3, http_method is actually
# the paramters.
if http_method.kind_of?(String)
parameters, session, flash = args
else
parameters = http_method
end

response.recycle_cached_body! response.recycle_cached_body!
parameters ||= {} parameters ||= {}
if _default_version.present? && parameters[:version].blank? && parameters['version'].blank? if _default_version.present? && parameters[:version].blank? && parameters['version'].blank?
Expand Down
29 changes: 29 additions & 0 deletions spec/integration/rspec_spec.rb
@@ -0,0 +1,29 @@
require 'spec_helper'

describe TestController, 'rspec integration', :integration => true, :target => 'rspec' do
# Hack to allow us to include the ActionController::TestCase::Behaviour module
def self.setup(*args); end
def self.teardown(*args); end

# Important to include behaviour before the RocketPants::TestHelpers
include ActionController::TestCase::Behavior
include RocketPants::TestHelper
include RocketPants::RSpecMatchers

default_version 1

before do
@routes = TestRouter
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end

describe 'should have_exposed' do
it "allows you to asset what should have been exposed by an action" do
get :echo, :echo => "ping"

response.should have_exposed(:echo => "ping")
end
end
end

0 comments on commit 97ae3a8

Please sign in to comment.