diff --git a/app/assets/javascripts/templates/registration/introduction.html.haml b/app/assets/javascripts/templates/registration/introduction.html.haml index f0bb71924e..2db4e9e652 100644 --- a/app/assets/javascripts/templates/registration/introduction.html.haml +++ b/app/assets/javascripts/templates/registration/introduction.html.haml @@ -31,14 +31,13 @@ %p {{'registration_outcome2' | t}} %p {{'registration_outcome3' | t}} -.row +.row{'ng-init' => "tos_required=#{Spree::Config.enterprises_require_tos}" } %hr - .small-12.columns{'ng-init' => "tos_required=false", 'ng-hide' => '!tos_required' } - %p{'ng-hide' => '!tos_required'} - #{t(:enterprise_tos_message)} - %a{'href' => "#{Spree::Config[:enterprise_tos_link]}"} #{t(:enterprise_tos_link_text)} - %p - %input{ type: 'checkbox', name: 'accept_terms', ng: { model: "tos_accepted" } } + .small-12.columns{'ng-hide' => '!tos_required' } + %p.tos-message + %a{'href' => "#{Spree::Config.enterprise_tos_link}"} #{t(:enterprise_tos_link_text)} + %p.tos-checkbox + %input{ type: 'checkbox', name: 'accept_terms', id: 'accept_terms', ng: { model: "tos_accepted" } } %label{for: "accept_terms"} #{t(:enterprise_tos_agree)} .small-12.columns diff --git a/app/controllers/spree/admin/general_settings_controller_decorator.rb b/app/controllers/spree/admin/general_settings_controller_decorator.rb index 603f74bf63..0a44da39e3 100644 --- a/app/controllers/spree/admin/general_settings_controller_decorator.rb +++ b/app/controllers/spree/admin/general_settings_controller_decorator.rb @@ -8,6 +8,7 @@ module Spree def edit super @preferences_general << :bugherd_api_key + @preferences_terms_of_service = [:enterprises_require_tos] end end GeneralSettingsController.send(:prepend, GeneralSettingsEditPreferences) diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 5cd34206a5..f770194669 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -1,14 +1,19 @@ require 'spec_helper' feature "Registration", js: true do + include AuthenticationWorkflow include WebHelper describe "Registering a Profile" do let(:user) { create(:user, password: "password", password_confirmation: "password") } + before { Spree::Config.enterprises_require_tos = false } it "Allows a logged in user to register a profile" do visit registration_path + expect(Spree::Config.enterprises_require_tos).to eq false + Spree::Config[:enterprises_require_tos].should be false + expect(URI.parse(current_url).path).to eq registration_auth_path page.has_selector? "dd", text: "Login" @@ -94,6 +99,43 @@ feature "Registration", js: true do expect(e.twitter).to eq "@TwItTeR" expect(e.instagram).to eq "@InStAgRaM" end + + end + + describe "Terms of Service agreement" do + let!(:user2) { create(:user) } + + before do + quick_login_as user2 + end + + context "if accepting Terms of Service is not required" do + before { Spree::Config.enterprises_require_tos = false } + + it "allows registration as normal" do + visit registration_path + + click_button "Let's get started!" + find("div#progress-bar").visible?.should be_true + end + end + + context "if accepting Terms of Service is required" do + before { Spree::Config.enterprises_require_tos = true } + + it "does not allow registration unless checkbox is checked" do + visit registration_path + + page.should have_content('Terms of Service') + page.should have_selector("input.button.primary[disabled]") + + check 'accept_terms' + page.should_not have_selector("input.button.primary[disabled]") + + click_button "Let's get started!" + find("div#progress-bar").visible?.should be_true + end + end end def switch_to_login_tab @@ -117,6 +159,14 @@ feature "Registration", js: true do expect(page).to have_content content end + def wait_for(element) + using_wait_time 0.5 do + 10.times do + break if page.has_selector? element + end + end + end + def click_and_ensure(type, text, check) # Buttons appear to be unresponsive for a while, so keep clicking them until content appears using_wait_time 0.5 do