Keep ENV['LOCAL_HTTPS'] with ApplicationControllerSpec (fix random fail) (#3479)

* Keep ENV['LOCAL_HTTPS'] with ApplicationControllerSpec (fix random fail)

* use climate_control
This commit is contained in:
Yamagishi Kazutoshi 2017-06-01 00:09:17 +09:00 committed by Eugen Rochko
parent c00ead8a72
commit 41fa53253c
4 changed files with 19 additions and 12 deletions

View file

@ -70,6 +70,7 @@ end
group :test do group :test do
gem 'capybara', '~> 2.14' gem 'capybara', '~> 2.14'
gem 'climate_control', '~> 0.2'
gem 'faker', '~> 1.7' gem 'faker', '~> 1.7'
gem 'microformats2', '~> 3.0' gem 'microformats2', '~> 3.0'
gem 'rails-controller-testing', '~> 1.0' gem 'rails-controller-testing', '~> 1.0'

View file

@ -487,6 +487,7 @@ DEPENDENCIES
capistrano-yarn (~> 2.0) capistrano-yarn (~> 2.0)
capybara (~> 2.14) capybara (~> 2.14)
cld3 (~> 3.1) cld3 (~> 3.1)
climate_control (~> 0.2)
devise (~> 4.2) devise (~> 4.2)
devise-two-factor (~> 3.0) devise-two-factor (~> 3.0)
doorkeeper (~> 4.2) doorkeeper (~> 4.2)

View file

@ -39,19 +39,21 @@ describe ApplicationController, type: :controller do
it "does not force ssl if LOCAL_HTTPS is not 'true'" do it "does not force ssl if LOCAL_HTTPS is not 'true'" do
routes.draw { get 'success' => 'anonymous#success' } routes.draw { get 'success' => 'anonymous#success' }
ENV['LOCAL_HTTPS'] = '' ClimateControl.modify LOCAL_HTTPS: '' do
allow(Rails.env).to receive(:production?).and_return(true) allow(Rails.env).to receive(:production?).and_return(true)
get 'success' get 'success'
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
end
it "forces ssl if LOCAL_HTTPS is 'true'" do it "forces ssl if LOCAL_HTTPS is 'true'" do
routes.draw { get 'success' => 'anonymous#success' } routes.draw { get 'success' => 'anonymous#success' }
ENV['LOCAL_HTTPS'] = 'true' ClimateControl.modify LOCAL_HTTPS: 'true' do
allow(Rails.env).to receive(:production?).and_return(true) allow(Rails.env).to receive(:production?).and_return(true)
get 'success' get 'success'
expect(response).to redirect_to('https://test.host/success') expect(response).to redirect_to('https://test.host/success')
end end
end
describe 'helper_method :current_account' do describe 'helper_method :current_account' do
it 'returns nil if not signed in' do it 'returns nil if not signed in' do

View file

@ -1,11 +1,14 @@
require "rails_helper" require "rails_helper"
feature "Log in" do feature "Log in" do
scenario "A valid email and password user is able to log in" do given(:email) { "test@examle.com" }
email = "test@example.com" given(:password) { "password" }
password = "password"
Fabricate(:user, email: email, password: password)
background do
Fabricate(:user, email: email, password: password)
end
scenario "A valid email and password user is able to log in" do
visit new_user_session_path visit new_user_session_path
fill_in "user_email", with: email fill_in "user_email", with: email
fill_in "user_password", with: password fill_in "user_password", with: password