为devise 增加单元测试 (devise for spec)
建立一个 Admin模型。 如果你是默认的Devise, 那就把下面的Admin都替换成 User.
1. rails_helper中:
RSpec.configure do |config|
# 增加这一行:
config.include Devise::TestHelpers, :type => :controller
end
def admin_login
sign_in Admin.create(email: 'admin@this.com', password: '88888888')
end
spec/rails_help
spec :
# -*- encoding : utf-8 -*-
require 'rails_helper'
describe SystemSettingsController do
before do
admin_login
end
it 'should get index' do
get :index
response.should be_success
end
end