From 6ee3010fa7e25e6ec130ca1106faf33b9308e7ca Mon Sep 17 00:00:00 2001 From: Rob H Date: Fri, 12 Sep 2014 11:00:34 +1000 Subject: [PATCH] Differentiation of on-boarding process by url --- .../enterprise_registration_service.js.coffee | 17 ++-- .../templates/registration/contact.html.haml | 2 +- .../templates/registration/details.html.haml | 22 ++--- .../darkswarm/registration.css.sass | 8 +- app/controllers/registration_controller.rb | 16 +++- app/helpers/injection_helper.rb | 12 ++- app/views/registration/index.html.haml | 1 + config/routes.rb | 1 + .../registration_controller_spec.rb | 13 ++- spec/features/consumer/registration_spec.rb | 81 ++++++++++++++++--- .../enterprise_registration_spec.js.coffee | 24 ++++++ 11 files changed, 158 insertions(+), 39 deletions(-) create mode 100644 spec/javascripts/unit/darkswarm/services/enterprise_registration_spec.js.coffee diff --git a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee index e52407463a..a248bc278b 100644 --- a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, CurrentUser, SpreeApiKey, Loading, availableCountries) -> +Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, CurrentUser, spreeApiKey, Loading, availableCountries, enterpriseAttributes) -> new class EnterpriseRegistrationService enterprise: user_ids: [CurrentUser.id] @@ -6,6 +6,10 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, address: {} country: availableCountries[0] + constructor: -> + for key, value of enterpriseAttributes + @enterprise[key] = value + create: => # Loading.message = "Creating " + @enterprise.name # $http( @@ -14,7 +18,7 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, # data: # enterprise: @prepare() # params: - # token: SpreeApiKey + # token: spreeApiKey # ).success((data) => # Loading.clear() # @enterprise.id = data @@ -34,21 +38,22 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, # data: # enterprise: @prepare() # params: - # token: SpreeApiKey + # token: spreeApiKey # ).success((data) -> # Loading.clear() # RegistrationService.select(step) # ).error((data) -> # Loading.clear() # console.log angular.toJson(data) - # alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.') + # alert('Failed to update your enterprise.\nPlease ensure all fields are completely filled out.') # ) RegistrationService.select(step) prepare: => enterprise = {} - for a, v of @enterprise when a isnt 'address' && a isnt 'country' && a isnt 'id' - enterprise[a] = v + excluded = [ 'address', 'country', 'id' ] + for key, value of @enterprise when key not in excluded + enterprise[key] = value enterprise.address_attributes = @enterprise.address enterprise.address_attributes.country_id = @enterprise.country.id enterprise \ No newline at end of file diff --git a/app/assets/javascripts/templates/registration/contact.html.haml b/app/assets/javascripts/templates/registration/contact.html.haml index ea2c51263a..c7262248d0 100644 --- a/app/assets/javascripts/templates/registration/contact.html.haml +++ b/app/assets/javascripts/templates/registration/contact.html.haml @@ -4,7 +4,7 @@ %h5 Who is responsible for managing %span{ ng: { class: "{brick: enterprise.is_distributor, turquoise: !enterprise.is_distributor}" } } - {{ enterprise.name }} + {{ enterprise.name }}? %ng-include{ src: "'registration/steps.html'" } %form{ name: 'contact', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "create(contact)" } } .row.content diff --git a/app/assets/javascripts/templates/registration/details.html.haml b/app/assets/javascripts/templates/registration/details.html.haml index dc2c3cc76d..bb358a1864 100644 --- a/app/assets/javascripts/templates/registration/details.html.haml +++ b/app/assets/javascripts/templates/registration/details.html.haml @@ -1,38 +1,40 @@ -.container#registration-details +.container#registration-details{bindonce: true} .header %h2 Let's Get Started - %h5 Woot! First we need to know what sort of enterprise you are: + %h5{ bo: { if: "enterprise.type != 'single'" } } Woot! First we need to know what sort of enterprise you are: + %h5{ bo: { if: "enterprise.type == 'single'" } } Woot! First we need to know the name of your farm: %ng-include{ src: "'registration/steps.html'" } %form{ name: 'details', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('address',details)" } } .row .small-12.columns.field - %label{ for: 'enterprise_name' } Enterprise Name: + %label{ for: 'enterprise_name', bo: { if: "enterprise.type != 'single'" } } Enterprise Name: + %label{ for: 'enterprise_name', bo: { if: "enterprise.type == 'single'" } } Farm Name: %input.chunky.small-12.columns{ id: 'enterprise_name', name: 'name', placeholder: "eg. Charlie's Awesome Farm", required: true, ng: { model: 'enterprise.name' } } %span.error.small-12.columns{ ng: { show: "details.name.$error.required && submitted" } } You need to enter a name for your enterprise! - .row#enterprise-types{ 'data-equalizer' => true } + .row#enterprise-types{ 'data-equalizer' => true, bo: { if: "enterprise.type != 'single'" } } .small-12.columns.field .row .small-12.columns %label Choose one: .row .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel.producer-panel{ href: "#", ng: { click: "enterprise.is_distributor = false; enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } + %a.panel#producer-panel{ href: "#", ng: { click: "enterprise.is_distributor = false; enterprise.is_primary_producer = true", class: "{selected: (!enterprise.is_distributor && enterprise.is_primary_producer)}" } } .left - %render-svg{ path: "/assets/map-icon-producer.svg" } + / %render-svg{ path: "/assets/map-icon-producer.svg" } %h4 I'm A Producer %p Producers make yummy things to eat &/or drink. You're a producer if you grow it, raise it, brew it, bake it, ferment it, milk it or mould it. .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel.hub-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = false", class: "{selected: (enterprise.is_distributor && !enterprise.is_primary_producer)}" } } + %a.panel#hub-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = false", class: "{selected: (enterprise.is_distributor && !enterprise.is_primary_producer)}" } } .left - %render-svg{ path: "/assets/map-icon-hub.svg" } + / %render-svg{ path: "/assets/map-icon-hub.svg" } %h4 I'm A Hub %p Hubs connect the producer to the eater. Hubs can be co-ops, independent retailers, buying groups, wholesalers, CSA box schemes, farm-gate stalls, etc. .small-12.medium-4.large-4.columns{ 'data-equalizer-watch' => true } - %a.panel.both-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_distributor && enterprise.is_primary_producer)}" } } + %a.panel#both-panel{ href: "#", ng: { click: "enterprise.is_distributor = true; enterprise.is_primary_producer = true", class: "{selected: (enterprise.is_distributor && enterprise.is_primary_producer)}" } } .left - %render-svg{path: "/assets/map-icon-both.svg"} + / %render-svg{path: "/assets/map-icon-both.svg"} %h4 I'm Both %p Hey there, Jack-of-all-trades! Not only do you produce things to eat &/or drink, you also want to sell your yummies through an Open Food Network shopfront. .row.buttons diff --git a/app/assets/stylesheets/darkswarm/registration.css.sass b/app/assets/stylesheets/darkswarm/registration.css.sass index be3fdda994..3e851709bc 100644 --- a/app/assets/stylesheets/darkswarm/registration.css.sass +++ b/app/assets/stylesheets/darkswarm/registration.css.sass @@ -90,21 +90,21 @@ min-height: 200px &:hover background-color: #fff - &.producer-panel:hover + &#producer-panel:hover &, & * color: $clr-turquoise - &.hub-panel:hover, &.both-panel:hover + &#hub-panel:hover, &#both-panel:hover &, & * color: $clr-brick &.selected &, & * color: #fff - &.hub-panel, &.both-panel + &#hub-panel, &#both-panel background-color: $clr-brick-bright &:hover &, & * color: white - &.producer-panel + &#producer-panel background-color: $clr-turquoise-bright &:hover &, & * diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index c378d24215..d58b10bd0b 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -2,12 +2,24 @@ require 'open_food_network/spree_api_key_loader' class RegistrationController < BaseController include OpenFoodNetwork::SpreeApiKeyLoader - before_filter :load_spree_api_key, :only => :index + before_filter :load_spree_api_key, only: :index + before_filter :check_user, except: :authenticate layout 'registration' def index + @enterprise_attributes = { type: 'profile' } + end + + def store + @enterprise_attributes = { is_distributor: true, is_primary_producer: true, type: 'single' } + render :index + end + + private + + def check_user if spree_current_user.nil? - redirect_to registration_auth_path(anchor: "signup?after_login=/register") + redirect_to registration_auth_path(anchor: "signup?after_login=#{request.env['PATH_INFO']}") end end end diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb index a43fab3b4c..795dcb6a5c 100644 --- a/app/helpers/injection_helper.rb +++ b/app/helpers/injection_helper.rb @@ -2,18 +2,18 @@ module InjectionHelper def inject_enterprises inject_json_ams "enterprises", Enterprise.all, Api::EnterpriseSerializer, active_distributors: @active_distributors end - + def inject_current_order inject_json_ams "currentOrder", current_order, Api::CurrentOrderSerializer, current_distributor: current_distributor, current_order_cycle: current_order_cycle end def inject_available_shipping_methods - inject_json_ams "shippingMethods", available_shipping_methods, + inject_json_ams "shippingMethods", available_shipping_methods, Api::ShippingMethodSerializer, current_order: current_order end def inject_available_payment_methods - inject_json_ams "paymentMethods", current_order.available_payment_methods, + inject_json_ams "paymentMethods", current_order.available_payment_methods, Api::PaymentMethodSerializer end @@ -22,13 +22,17 @@ module InjectionHelper end def inject_spree_api_key - render partial: "json/injection_ams", locals: {name: 'SpreeApiKey', json: "'#{@spree_api_key.to_s}'"} + render partial: "json/injection_ams", locals: {name: 'spreeApiKey', json: "'#{@spree_api_key.to_s}'"} end def inject_available_countries inject_json_ams "availableCountries", available_countries, Api::CountrySerializer end + def inject_enterprise_attributes + render partial: "json/injection_ams", locals: {name: 'enterpriseAttributes', json: "#{@enterprise_attributes.to_json}"} + end + def inject_json(name, partial, opts = {}) render partial: "json/injection", locals: {name: name, partial: partial}.merge(opts) end diff --git a/app/views/registration/index.html.haml b/app/views/registration/index.html.haml index 205b3582bb..de09d9494f 100644 --- a/app/views/registration/index.html.haml +++ b/app/views/registration/index.html.haml @@ -1,3 +1,4 @@ =inject_spree_api_key =inject_available_countries +=inject_enterprise_attributes %div{ "ng-controller" => "RegistrationCtrl" } \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6447715926..f95b0c07df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ Openfoodnetwork::Application.routes.draw do get "/map", to: "map#index", as: :map get "/register", to: "registration#index", as: :registration + get "/register/store", to: "registration#store", as: :store_registration get "/register/auth", to: "registration#authenticate", as: :registration_auth resource :shop, controller: "shop" do diff --git a/spec/controllers/registration_controller_spec.rb b/spec/controllers/registration_controller_spec.rb index 0240dc6de0..49efc005f6 100644 --- a/spec/controllers/registration_controller_spec.rb +++ b/spec/controllers/registration_controller_spec.rb @@ -1,8 +1,15 @@ require 'spec_helper' describe RegistrationController do - it "redirects to authentication page when user not logged in" do - get :index - response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register") + describe "redirecting when user not logged in" do + it "index" do + get :index + response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register") + end + + it "store" do + get :store + response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register/store") + end end end diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 0c706b1a13..ce5adc776e 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -1,10 +1,12 @@ require 'spec_helper' feature "Registration", js: true do - describe "Registering a Profile" do + include WebHelper + + describe "Registering a Profile", use_short_wait do let(:user) { create(:user, password: "password", password_confirmation: "password") } - pending "Allows a logged in user to register a profile" do + it "Allows a logged in user to register a profile" do visit registration_path expect(URI.parse(current_url).path).to eq registration_auth_path @@ -14,22 +16,22 @@ feature "Registration", js: true do fill_in "Email", with: user.email fill_in "Password", with: user.password click_button 'Log in' - + # Log in was successful, introduction shown expect(page).to have_content "This wizard will step you through creating a profile" expect(URI.parse(current_url).path).to eq registration_path # Done reading introduction click_button "Let's get started!" - + # Filling in details expect(page).to have_content "Woot! First we need to know what sort of enterprise you are:" fill_in 'enterprise_name', with: "My Awesome Enterprise" - click_link 'both' + click_link 'both-panel' click_button 'Continue' # Filling in address - expect(page).to have_content 'My Awesome Enterprise' + expect(page).to have_content 'Greetings My Awesome Enterprise' fill_in 'enterprise_address', with: '123 Abc Street' fill_in 'enterprise_city', with: 'Northcote' fill_in 'enterprise_zipcode', with: '3070' @@ -45,8 +47,69 @@ feature "Registration", js: true do click_button 'Continue' # Enterprise should be created - expect(page).to have_content 'Yay! You created an enterprise!' + expect(page).to have_content 'Nice one!' + # e = Enterprise.find_by_name('My Awesome Enterprise') + # expect(e.address.address1).to eq "123 Abc Street" + # expect(e.is_distributor).to eq true + # expect(e.is_primary_producer).to eq true + # expect(e.contact).to eq "Saskia Munroe" + + # Filling in about + fill_in 'enterprise_description', with: 'Short description' + fill_in 'enterprise_long_desc', with: 'Long description' + fill_in 'enterprise_abn', with: '12345' + fill_in 'enterprise_acn', with: '54321' + click_button 'Continue' + + # Enterprise should be updated + expect(page).to have_content 'Last step!' + # e.reload + # expect(e.description).to eq "Short description" + # expect(e.long_description).to eq "Long description" + # expect(e.abn).to eq '12345' + # expect(e.acn).to eq '54321' + + # Filling in social + fill_in 'enterprise_website', with: 'www.shop.com' + fill_in 'enterprise_facebook', with: 'FaCeBoOk' + fill_in 'enterprise_linkedin', with: 'LiNkEdIn' + fill_in 'enterprise_twitter', with: '@TwItTeR' + fill_in 'enterprise_instagram', with: '@InStAgRaM' + click_button 'Continue' + + # Done + expect(page).to have_content "You have successfully completed the profile for My Awesome Enterprise" + # e.reload + # expect(e.website).to eq "www.shop.com" + # expect(e.facebook).to eq "FaCeBoOk" + # expect(e.linkedin).to eq "LiNkEdIn" + # expect(e.twitter).to eq "@TwItTeR" + # expect(e.instagram).to eq "@InStAgRaM" + end + + it "Allows a logged in user to register a store" do + visit store_registration_path + + expect(URI.parse(current_url).path).to eq registration_auth_path + + # Logging in + click_link "Log in" + fill_in "Email", with: user.email + fill_in "Password", with: user.password + click_button 'Log in' + + # Log in was successful, introduction shown + expect(page).to have_content "This wizard will step you through creating a profile" + expect(URI.parse(current_url).path).to eq store_registration_path + + # Done reading introduction + click_button "Let's get started!" + + # Details Page + expect(page).to have_content "Woot! First we need to know the name of your farm:" + expect(page).to_not have_selector '#enterprise-types' + + # Everything from here should be covered in 'profile' spec end end -end - \ No newline at end of file +end \ No newline at end of file diff --git a/spec/javascripts/unit/darkswarm/services/enterprise_registration_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/enterprise_registration_spec.js.coffee new file mode 100644 index 0000000000..121c4132a4 --- /dev/null +++ b/spec/javascripts/unit/darkswarm/services/enterprise_registration_spec.js.coffee @@ -0,0 +1,24 @@ +describe "EnterpriseRegistrationService", -> + EnterpriseRegistrationService = null + availableCountries = [] + enterpriseAttributes = + name: "Enterprise 1" + something: true + spreeApiKey = "keykeykeykey" + CurrentUser = + id: 2 + email: 'lalala@email.com' + + beforeEach -> + module('Darkswarm') + angular.module('Darkswarm').value 'availableCountries', availableCountries + angular.module('Darkswarm').value 'enterpriseAttributes', enterpriseAttributes + angular.module('Darkswarm').value 'spreeApiKey', spreeApiKey + angular.module('Darkswarm').value 'CurrentUser', CurrentUser + + inject ($injector)-> + EnterpriseRegistrationService = $injector.get("EnterpriseRegistrationService") + + it "adds the specified attributes to the ERS enterprise object", -> + expect(EnterpriseRegistrationService.enterprise.name).toBe "Enterprise 1" + expect(EnterpriseRegistrationService.enterprise.something).toBe true \ No newline at end of file