Specced the new terms of service functionality

This commit is contained in:
Matt-Yorkley
2016-12-02 19:41:47 +00:00
committed by Rob Harrington
parent a62998e5f1
commit 6a361f2d7b
3 changed files with 57 additions and 7 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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