我们在 Rails 4 应用程序中使用Sorcery gem 进行身份验证。我们想为我们的应用程序编写控制器规范(我们正在使用 Rspec 进行测试),但是我们在规范中的所有方法调用都被重定向,因为在运行测试时我们还没有登录到我们的应用程序。
我们需要进行哪些额外的配置更改才能允许控制器规格?
rails_helper.rb
Spec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.include FactoryGirl::Syntax::Methods
config.include Sorcery::TestHelpers::Rails
end
customers_vehicles_spec.rb
require 'rails_helper'
RSpec.describe CustomersVehiclesController, type: :controller do
describe 'POST update_customer' do
before(:each) do
@job = create(:job)
@vehicle = @job.vehicle
@customer = @vehicle.customers.last
@user = create(:user_schade)
@now = DateTime.now
login_user
end
context 'user has unassinged time' do
it 'gets the vehicle information page' do
get :show_customer, id: @customer.id
expect(response).to be_success
expect(action).to render_template(partial:'customer_form')
end
end
end
该测试在获取时失败;我们收到 302(重定向),因为我们没有登录。
我们缺少哪些配置选项来测试我们的控制器?
注意:我们使用的是 Sorcery 0.8.4