I'm using bartt-ssl_requirement in a Rails 3.0.9 app.

The ssl_required and ssl_allowed statements at the top of my controllers are breaking my rspec with their redirects. How do I fix that?

From poking around, I can "stub" the ssl_required method in my spec_helper.rb (a new concept to me I don't thoroughly understand) to just return true and not do a redirect.

Gemfile (relevant):

gem 'rails', '3.0.9'
gem 'bartt-ssl_requirement', '~>1.4.0', :require => 'ssl_requirement'

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'spork', '0.9.0.rc8'
end

Controller:

class PagesController < ApplicationController
  ssl_required :about

  def about
    @title = "About Us"
  end

end

spec_helper.rb:

require 'rubygems'
require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  RSpec.configure do |config|
    config.mock_with :rspec
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true

    config.before(:each, :type => :controller) do
      controller.stub(:ssl_required).and_return(:true)
    end

  end
end

If I comment out ssl_required in my controller, my tests pass. Otherwise they're still redirecting and ruining my shoulds.

有帮助吗?

解决方案

Well, it doesn't answer my question about how to configure a stub in spec_helper.rb or whether that's even a good idea, but all I needed to do was add SslRequirement.disable_ssl_check = true to my test.rb environment.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top