diff --git a/app/assets/javascripts/admin/welcome/controllers/welcome_controller.js.coffee b/app/assets/javascripts/admin/welcome/controllers/welcome_controller.js.coffee index 9883e90937..8db38181c4 100644 --- a/app/assets/javascripts/admin/welcome/controllers/welcome_controller.js.coffee +++ b/app/assets/javascripts/admin/welcome/controllers/welcome_controller.js.coffee @@ -1,6 +1,7 @@ angular.module("admin.welcome") .controller "welcomeCtrl", ($scope) -> $scope.sells = "unspecified" + $scope.producer_profile_only = true $scope.submitted = false $scope.valid = (form) -> diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 8eacba5a53..8db4101075 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -19,6 +19,7 @@ module Admin def set_sells enterprise = Enterprise.find(params[:id]) attributes = { sells: params[:sells] } + attributes[:producer_profile_only] = !!params[:producer_profile_only] if params[:sells] == 'none' attributes[:shop_trial_start_date] = Time.now if params[:sells] == "own" if %w(none own).include?(params[:sells]) diff --git a/app/views/spree/admin/overview/welcome.html.haml b/app/views/spree/admin/overview/welcome.html.haml index 68cd58a748..b5b031eefb 100644 --- a/app/views/spree/admin/overview/welcome.html.haml +++ b/app/views/spree/admin/overview/welcome.html.haml @@ -12,11 +12,12 @@ = form_for @enterprise, url: main_app.set_sells_admin_enterprise_path(@enterprise), html: { name: "enterprise", novalidate: true } do |enterprise_form| -# Have to use hidden:'true' on this input rather than type:'hidden' as the latter seems to break ngPattern and therefore validation - %input{ hidden: "true", id: "sells", name: "sells", ng: { required: true, pattern: "/^(none|own)$/", model: 'sells', value: "sells"} } + %input{ hidden: "true", name: "sells", ng: { required: true, pattern: "/^(none|own)$/", model: 'sells', value: "sells"} } .options.sixteen.columns.alpha - if @enterprise.is_primary_producer + %input{ type: 'checkbox', hidden: true, name: "producer_profile_only", ng: { required: true, model: 'producer_profile_only', value: "producer_profile_only"} } .basic_producer.option.one-third.column.alpha - %a.full-width.button.selector{ ng: { click: "sells='none'", class: "{selected: sells=='none'}" } } + %a.full-width.button.selector{ ng: { click: "sells='none';producer_profile_only=true;", class: "{selected: sells=='none' && producer_profile_only==true}" } } .top %h3 Producer Profile %p Connect through OFN @@ -25,7 +26,7 @@ You want to use Open Food Network as a place for people to find and contact you. .producer_shop.option.one-third.column - %a.full-width.button.selector{ ng: { click: "sells='own'", class: "{selected: sells=='own'}" } } + %a.full-width.button.selector{ ng: { click: "sells='none';producer_profile_only=false;", class: "{selected: sells=='none' && producer_profile_only==false}" } } .top %h3 Sell products %p As a supplier @@ -34,7 +35,7 @@ Add your products to Open Food Network, allowing customers to see your product range, and allowing you to act as a supplier to other shopfronts. .full_hub.option.one-third.column.omega.disabled - %a.full-width.button.selector + %a.full-width.button.selector{ ng: { click: "sells='own';producer_profile_only=false;", class: "{selected: sells=='own' && producer_profile_only==false}" } } .top %h3 Sell products %p Through an OFN shopfront @@ -49,7 +50,7 @@ %h3 Shop Profile %p Get a listing .bottom ALWAYS FREE - .description + %p.description You want to use OFN as a place for people to find and contact you. .sixteen.columns.alpha diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index cecb700840..60f0d9f736 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -110,7 +110,7 @@ module Admin end end - describe "setting 'sells' on an enterprise" do + describe "set_sells" do let(:enterprise) { create(:enterprise, sells: 'none') } before do @@ -131,9 +131,18 @@ module Admin context "allows setting 'sells' to 'none'" do it "is allowed" do - spree_post :set_sells, { id: enterprise.id, sells: 'own' } + spree_post :set_sells, { id: enterprise.id, sells: 'none' } expect(response).to redirect_to spree.admin_path expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!" + expect(enterprise.reload.sells).to eq 'none' + end + + context "setting producer_profile_only to true" do + it "is allowed" do + spree_post :set_sells, { id: enterprise.id, sells: 'none', producer_profile_only: true } + expect(response).to redirect_to spree.admin_path + expect(enterprise.reload.producer_profile_only).to eq true + end end end @@ -158,6 +167,14 @@ module Admin expect(enterprise.reload.shop_trial_start_date).to be > Time.now-(1.minute) end end + + context "setting producer_profile_only to true" do + it "is ignored" do + spree_post :set_sells, { id: enterprise.id, sells: 'own', producer_profile_only: true } + expect(response).to redirect_to spree.admin_path + expect(enterprise.reload.producer_profile_only).to be false + end + end end context "setting 'sells' to any" do