diff options
author | Rémy Coutable <remy@rymai.me> | 2016-02-26 14:27:27 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-02-26 14:27:27 +0300 |
commit | bb3563b5cd063772fa16c934404e7912d9f3d726 (patch) | |
tree | 29494d63dabb5ff9d72cb32fc0229636b4bc7b46 | |
parent | 3f83d1dc3a6af8854747d695847c75ba41d25cb0 (diff) | |
parent | b95ef77e233eab3b3d37a4a7dce545d9da36f8a0 (diff) |
Merge branch 'rs-crowd-form-view-spec' into 'master'
Move "I should see Crowd login form" feature to a view spec
We were doing all kinds of code gymnastics to "enable" Crowd in the
feature spec and this would sometimes cause a transient failure.
Really what it's testing is if the Crowd login form shows when Crowd's
enabled, so this is much better suited to a view spec.
See merge request !2963
-rw-r--r-- | app/helpers/auth_helper.rb | 4 | ||||
-rw-r--r-- | app/views/devise/sessions/new.html.haml | 4 | ||||
-rw-r--r-- | features/login_form.feature | 11 | ||||
-rw-r--r-- | features/steps/login_form.rb | 25 | ||||
-rw-r--r-- | spec/views/devise/shared/_signin_box.html.haml_spec.rb | 37 |
5 files changed, 43 insertions, 38 deletions
diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb index de669e529a7..b4f80fd9b3e 100644 --- a/app/helpers/auth_helper.rb +++ b/app/helpers/auth_helper.rb @@ -6,6 +6,10 @@ module AuthHelper Gitlab.config.ldap.enabled end + def omniauth_enabled? + Gitlab.config.omniauth.enabled + end + def provider_has_icon?(name) PROVIDERS_WITH_ICONS.include?(name.to_s) end diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 1136afbf29c..d65fa60025c 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -4,7 +4,7 @@ = render 'devise/shared/signin_box' -# Omniauth fits between signin/ldap signin and signup and does not have a surrounding box - - if Gitlab.config.omniauth.enabled && devise_mapping.omniauthable? + - if omniauth_enabled? && devise_mapping.omniauthable? .clearfix.prepend-top-20 = render 'devise/shared/omniauth_box' @@ -14,6 +14,6 @@ = render 'devise/shared/signup_box' -# Show a message if none of the mechanisms above are enabled - - if !signin_enabled? && !ldap_enabled? && !(Gitlab.config.omniauth.enabled && devise_mapping.omniauthable?) + - if !signin_enabled? && !ldap_enabled? && !(omniauth_enabled? && devise_mapping.omniauthable?) %div No authentication methods configured. diff --git a/features/login_form.feature b/features/login_form.feature deleted file mode 100644 index 7965882f7fc..00000000000 --- a/features/login_form.feature +++ /dev/null @@ -1,11 +0,0 @@ -Feature: Login form - Scenario: I see Crowd form - Given Crowd integration enabled - When I visit sign in page - Then I should see Crowd login form - - Scenario: I see Crowd form when sign-in is disabled - Given Crowd integration enabled - And Sign-in is disabled - When I visit sign in page - Then I should see Crowd login form diff --git a/features/steps/login_form.rb b/features/steps/login_form.rb deleted file mode 100644 index 90ab10e6229..00000000000 --- a/features/steps/login_form.rb +++ /dev/null @@ -1,25 +0,0 @@ -class Spinach::Features::LoginForm < Spinach::FeatureSteps - include SharedAuthentication - include SharedPaths - include SharedSnippet - include SharedUser - include SharedSearch - - step 'Sign-in is disabled' do - allow_any_instance_of(ApplicationHelper).to receive(:signin_enabled?).and_return(false) - end - - step 'Crowd integration enabled' do - expect(Gitlab::OAuth::Provider).to receive(:providers).and_return([:crowd]) - expect(Gitlab.config.omniauth).to receive(:enabled).and_return(true) - allow_any_instance_of(ApplicationHelper).to receive(:user_omniauth_authorize_path).and_return(root_path) - end - - step 'I should see Crowd login form' do - expect(page).to have_selector '#tab-crowd form' - end - - step 'I visit sign in page' do - visit new_user_session_path - end -end diff --git a/spec/views/devise/shared/_signin_box.html.haml_spec.rb b/spec/views/devise/shared/_signin_box.html.haml_spec.rb new file mode 100644 index 00000000000..05a76ee4bdb --- /dev/null +++ b/spec/views/devise/shared/_signin_box.html.haml_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +describe 'devise/shared/_signin_box' do + describe 'Crowd form' do + before do + stub_devise + assign(:ldap_servers, []) + end + + it 'is shown when Crowd is enabled' do + enable_crowd + + render + + expect(rendered).to have_selector('#tab-crowd form') + end + + it 'is not shown when Crowd is disabled' do + render + + expect(rendered).not_to have_selector('#tab-crowd') + end + end + + def stub_devise + allow(view).to receive(:devise_mapping).and_return(Devise.mappings[:user]) + allow(view).to receive(:resource).and_return(spy) + allow(view).to receive(:resource_name).and_return(:user) + end + + def enable_crowd + allow(view).to receive(:form_based_providers).and_return([:crowd]) + allow(view).to receive(:crowd_enabled?).and_return(true) + allow(view).to receive(:user_omniauth_authorize_path).with('crowd'). + and_return('/crowd') + end +end |