From b8b19368dff6ac8908e3fec3d5616951d81c0fa8 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 10 Oct 2014 16:54:38 +1100 Subject: [PATCH 01/12] WIP: Making enterprise emails confirmable --- app/models/enterprise.rb | 2 ++ ...141010043405_add_confirmable_to_enterprise.rb | 16 ++++++++++++++++ db/schema.rb | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20141010043405_add_confirmable_to_enterprise.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index dfb7945878..e5b92b0382 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -2,6 +2,8 @@ class Enterprise < ActiveRecord::Base TYPES = %w(full single profile) ENTERPRISE_SEARCH_RADIUS = 100 + devise :confirmable, reconfirmable: true + self.inheritance_column = nil acts_as_gmappable :process_geocoding => false diff --git a/db/migrate/20141010043405_add_confirmable_to_enterprise.rb b/db/migrate/20141010043405_add_confirmable_to_enterprise.rb new file mode 100644 index 0000000000..22203fe419 --- /dev/null +++ b/db/migrate/20141010043405_add_confirmable_to_enterprise.rb @@ -0,0 +1,16 @@ +class AddConfirmableToEnterprise < ActiveRecord::Migration + def up + add_column :enterprises, :confirmation_token, :string + add_column :enterprises, :confirmed_at, :datetime + add_column :enterprises, :confirmation_sent_at, :datetime + add_column :enterprises, :unconfirmed_email, :string + add_index :enterprises, :confirmation_token, :unique => true + + # Existing enterprises are assumed to be confirmed + Enterprise.update_all(:confirmed_at => Time.now) + end + + def down + remove_columns :enterprises, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email + end +end diff --git a/db/schema.rb b/db/schema.rb index 73f10210a7..ee364758d7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140904003026) do +ActiveRecord::Schema.define(:version => 20141010043405) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -266,9 +266,14 @@ ActiveRecord::Schema.define(:version => 20140904003026) do t.string "linkedin" t.string "type", :default => "profile", :null => false t.integer "owner_id", :null => false + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" end add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id" + add_index "enterprises", ["confirmation_token"], :name => "index_enterprises_on_confirmation_token", :unique => true add_index "enterprises", ["owner_id"], :name => "index_enterprises_on_owner_id" create_table "exchange_fees", :force => true do |t| From 908c242d36b01c29350671f74e40f72df6b8b42f Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 10:48:05 +1100 Subject: [PATCH 02/12] Confirmation email when creating enterprise --- app/mailers/enterprise_mailer.rb | 8 ++++++++ app/mailers/spree/user_mailer_decorator.rb | 2 +- app/models/enterprise.rb | 6 ++++++ .../enterprise_mailer/confirmation_instructions.html.haml | 5 +++++ config/routes.rb | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/views/enterprise_mailer/confirmation_instructions.html.haml diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index 73c09e1e56..f5f92aed3f 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -1,10 +1,18 @@ +require 'devise/mailers/helpers' class EnterpriseMailer < Spree::BaseMailer + include Devise::Mailers::Helpers + def creation_confirmation(enterprise) find_enterprise(enterprise) subject = "#{@enterprise.name} is now on #{Spree::Config[:site_name]}" mail(:to => @enterprise.owner.email, :from => from_address, :subject => subject) end + def confirmation_instructions(record, token, opts={}) + @token = token + devise_mail(record, :confirmation_instructions, opts) + end + private def find_enterprise(enterprise) @enterprise = enterprise.is_a?(Enterprise) ? enterprise : Enterprise.find(enterprise) diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb index ff8bdc4691..dd21a3d0d7 100644 --- a/app/mailers/spree/user_mailer_decorator.rb +++ b/app/mailers/spree/user_mailer_decorator.rb @@ -1,5 +1,5 @@ Spree::UserMailer.class_eval do - + def signup_confirmation(user) @user = user mail(:to => user.email, :from => from_address, diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e5b92b0382..411f144f13 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -262,6 +262,12 @@ class Enterprise < ActiveRecord::Base select('DISTINCT spree_taxons.*') end + protected + + def devise_mailer + EnterpriseMailer + end + private def send_creation_email diff --git a/app/views/enterprise_mailer/confirmation_instructions.html.haml b/app/views/enterprise_mailer/confirmation_instructions.html.haml new file mode 100644 index 0000000000..277e27aae5 --- /dev/null +++ b/app/views/enterprise_mailer/confirmation_instructions.html.haml @@ -0,0 +1,5 @@ +%p= "Welcome #{@resource.contact}!" + +%p= "You can confirm this email address for #{@resource.name} using the link below:" + +%p= link_to 'Confirm this email address', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3e063641dd..9cdac4142d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,8 @@ Openfoodnetwork::Application.routes.draw do end end + devise_for :enterprise + namespace :admin do resources :order_cycles do post :bulk_update, on: :collection, as: :bulk_update From 6e699b2e8bb86c8ceddc78a3da332bbfd683f035 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 11:52:04 +1100 Subject: [PATCH 03/12] Mailer tests --- spec/mailers/enterprise_mailer_spec.rb | 5 ++++ spec/models/enterprise_spec.rb | 35 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb index 412870bad7..6b53d7d561 100644 --- a/spec/mailers/enterprise_mailer_spec.rb +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -10,4 +10,9 @@ describe EnterpriseMailer do EnterpriseMailer.creation_confirmation(@enterprise).deliver ActionMailer::Base.deliveries.count.should == 1 end + + it "should send an email confirmation when given an enterprise" do + EnterpriseMailer.confirmation_instructions(@enterprise, 'token').deliver + ActionMailer::Base.deliveries.count.should == 1 + end end \ No newline at end of file diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 241d1fafc7..4861157d87 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -3,6 +3,15 @@ require 'spec_helper' describe Enterprise do include AuthenticationWorkflow + describe "creation" do + it "should send a confirmation email" do + mail_message = double "Mail::Message" + EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message + mail_message.should_receive :deliver + create(:enterprise) + end + end + describe "associations" do it { should belong_to(:owner) } it { should have_many(:supplied_products) } @@ -507,40 +516,40 @@ describe Enterprise do # Swap type values full > sell_all, single > sell_own profile > sell_none # swap is_distributor for new can_supply flag. - let(:producer_sell_all_can_supply) { + let(:producer_sell_all_can_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: true) } - let(:producer_sell_all_cant_supply) { + let(:producer_sell_all_cant_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: false) } - let(:producer_sell_own_can_supply) { + let(:producer_sell_own_can_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: true) } - let(:producer_sell_own_cant_supply) { + let(:producer_sell_own_cant_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: false) } - let(:producer_sell_none_can_supply) { + let(:producer_sell_none_can_supply) { create(:enterprise, is_primary_producer: true, type: "profile", is_distributor: true) } - let(:producer_sell_none_cant_supply) { + let(:producer_sell_none_cant_supply) { create(:enterprise, is_primary_producer: true, type: "profile", is_distributor: false) } let(:non_producer_sell_all_can_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: true) } - let(:non_producer_sell_all_cant_supply) { + let(:non_producer_sell_all_cant_supply) { create(:enterprise, is_primary_producer: true, type: "full", is_distributor: false) } - let(:non_producer_sell_own_can_supply) { + let(:non_producer_sell_own_can_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: true) } - let(:non_producer_sell_own_cant_supply) { + let(:non_producer_sell_own_cant_supply) { create(:enterprise, is_primary_producer: true, type: "single", is_distributor: false) } - let(:non_producer_sell_none_can_supply) { + let(:non_producer_sell_none_can_supply) { create(:enterprise, is_primary_producer: false, type: "profile", is_distributor: true) } - let(:non_producer_sell_none_cant_supply) { + let(:non_producer_sell_none_cant_supply) { create(:enterprise, is_primary_producer: false, type: "profile", is_distributor: false) } @@ -555,8 +564,8 @@ describe Enterprise do producer_sell_own_cant_supply.enterprise_category.should == "producer_shop" producer_sell_none_can_supply.enterprise_category.should == "producer" producer_sell_none_cant_supply.enterprise_category.should == "producer_profile" - non_producer_sell_all_can_supply.enterprise_category.should == "hub" - non_producer_sell_all_cant_supply.enterprise_category.should == "hub" + non_producer_sell_all_can_supply.enterprise_category.should == "hub" + non_producer_sell_all_cant_supply.enterprise_category.should == "hub" non_producer_sell_own_can_supply.enterprise_category.should == "hub" non_producer_sell_own_cant_supply.enterprise_category.should == "hub" non_producer_sell_none_can_supply.enterprise_category.should == "hub_profile" From 56f4d5af0fb8550170fd7f7925096c7228556767 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 12:27:55 +1100 Subject: [PATCH 04/12] Visibility in the front end is contingent upon enterprise being confirmed --- app/serializers/api/enterprise_serializer.rb | 5 +++++ .../serializers/enterprise_serializer_spec.rb | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 6841337024..ce3412ab10 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -102,6 +102,11 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer has_one :address, serializer: Api::AddressSerializer + def visible + binding.pry + object.visible && object.confirmed? + end + def pickup object.shipping_methods.where(:require_ship_address => false).present? end diff --git a/spec/serializers/enterprise_serializer_spec.rb b/spec/serializers/enterprise_serializer_spec.rb index 5fe57a99e2..f3409f2d57 100644 --- a/spec/serializers/enterprise_serializer_spec.rb +++ b/spec/serializers/enterprise_serializer_spec.rb @@ -13,9 +13,27 @@ describe Api::EnterpriseSerializer do serializer = Api::EnterpriseSerializer.new enterprise serializer.to_json.should match taxon.id.to_s end - + it "will render urls" do serializer = Api::EnterpriseSerializer.new enterprise serializer.to_json.should match "map_005-hub.svg" end + + describe "visibility" do + before do + enterprise.stub(:visible).and_return true + end + + it "is visible when confirmed" do + enterprise.stub(:confirmed?).and_return true + serializer = Api::EnterpriseSerializer.new enterprise + expect(serializer.to_json).to match "\"visible\":true" + end + + it "is not visible when unconfirmed" do + enterprise.stub(:confirmed?).and_return false + serializer = Api::EnterpriseSerializer.new enterprise + expect(serializer.to_json).to match "\"visible\":false" + end + end end From 1bdc55cb3356d946a564b5a1b49b6a31c43a18b6 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 13:03:39 +1100 Subject: [PATCH 05/12] Adding confirmed scope to enterprises --- app/models/enterprise.rb | 1 + spec/models/enterprise_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 411f144f13..977b35390b 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -61,6 +61,7 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :visible, where(:visible => true) + scope :confirmed, where('confirmed_at IS NOT NULL') scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') } diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 4861157d87..692509890d 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -111,6 +111,7 @@ describe Enterprise do it { should delegate(:city).to(:address) } it { should delegate(:state_name).to(:address) } end + describe "scopes" do describe 'active' do it 'find active enterprises' do @@ -120,6 +121,17 @@ describe Enterprise do end end + describe "confirmed" do + it "find enterprises with a confirmed date" do + s1 = create(:supplier_enterprise, confirmed_at: Time.now) + d1 = create(:distributor_enterprise, confirmed_at: Time.now) + s2 = create(:supplier_enterprise, confirmed_at: nil) + d2 = create(:distributor_enterprise, confirmed_at: nil) + expect(Enterprise.confirmed).to include s1, d1 + expect(Enterprise.confirmed).to_not include s2, d2 + end + end + describe "distributors_with_active_order_cycles" do it "finds active distributors by order cycles" do s = create(:supplier_enterprise) From c76a3815c03eac35f02f611beda7aeb2038c8290 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 15:45:47 +1100 Subject: [PATCH 06/12] Add unconfirmed scope --- app/models/enterprise.rb | 1 + spec/models/enterprise_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 977b35390b..954667f3e1 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -62,6 +62,7 @@ class Enterprise < ActiveRecord::Base scope :by_name, order('name') scope :visible, where(:visible => true) scope :confirmed, where('confirmed_at IS NOT NULL') + scope :unconfirmed, where('confirmed_at IS NULL') scope :is_primary_producer, where(:is_primary_producer => true) scope :is_distributor, where(:is_distributor => true) scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') } diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 692509890d..7dc1d986a1 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -132,6 +132,17 @@ describe Enterprise do end end + describe "unconfirmed" do + it "find enterprises without a confirmed date" do + s1 = create(:supplier_enterprise, confirmed_at: Time.now) + d1 = create(:distributor_enterprise, confirmed_at: Time.now) + s2 = create(:supplier_enterprise, confirmed_at: nil) + d2 = create(:distributor_enterprise, confirmed_at: nil) + expect(Enterprise.unconfirmed).to_not include s1, d1 + expect(Enterprise.unconfirmed).to include s2, d2 + end + end + describe "distributors_with_active_order_cycles" do it "finds active distributors by order cycles" do s = create(:supplier_enterprise) From c59662758caaf9f60a3899bedf06fc6c0975a4a1 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 15:46:21 +1100 Subject: [PATCH 07/12] Add alerts for unconfirmed enterprises to overview page --- app/assets/stylesheets/admin/alert.css.sass | 10 +++++++++ .../admin/overview/_unconfirmed.html.haml | 4 ++++ .../spree/admin/overview/index.html.haml | 21 ++++++++++--------- 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 app/assets/stylesheets/admin/alert.css.sass create mode 100644 app/views/spree/admin/overview/_unconfirmed.html.haml diff --git a/app/assets/stylesheets/admin/alert.css.sass b/app/assets/stylesheets/admin/alert.css.sass new file mode 100644 index 0000000000..5404e1a0e2 --- /dev/null +++ b/app/assets/stylesheets/admin/alert.css.sass @@ -0,0 +1,10 @@ +.alert + border: 3px solid #DA5354 + border-radius: 6px + margin-bottom: 20px + color: #DA5354 + padding: 5px 10px + h6 + color: #DA5354 + .message + font-weight: bold diff --git a/app/views/spree/admin/overview/_unconfirmed.html.haml b/app/views/spree/admin/overview/_unconfirmed.html.haml new file mode 100644 index 0000000000..05c4df2a0d --- /dev/null +++ b/app/views/spree/admin/overview/_unconfirmed.html.haml @@ -0,0 +1,4 @@ +- @enterprises.unconfirmed.each do |enterprise| + .alert + %h6= "Action Required: Please confirm the email address for #{enterprise.name}." + %span.message= "We've sent a confirmation email to #{enterprise.email}, so please check there for further instructions. Thanks!" \ No newline at end of file diff --git a/app/views/spree/admin/overview/index.html.haml b/app/views/spree/admin/overview/index.html.haml index a46a31b404..0709ceb54f 100644 --- a/app/views/spree/admin/overview/index.html.haml +++ b/app/views/spree/admin/overview/index.html.haml @@ -1,17 +1,18 @@ %h1{ :style => 'margin-bottom: 30px'} Dashboard -- if @enterprises.empty? +- if @enterprises.unconfirmed.any? - = render partial: "spree/admin/overview/enterprises" + = render partial: "spree/admin/overview/unconfirmed" -- else - - if can? :admin, Spree::Product - = render partial: "spree/admin/overview/products" + %hr - %div.two.columns -   +- if can? :admin, Spree::Product + = render partial: "spree/admin/overview/products" - - if can? :admin, OrderCycle - = render partial: "spree/admin/overview/order_cycles" + %div.two.columns +   - = render partial: "spree/admin/overview/enterprises" +- if can? :admin, OrderCycle + = render partial: "spree/admin/overview/order_cycles" + += render partial: "spree/admin/overview/enterprises" From e0e8ba814f1f1122716a663c8b9c294ff572f273 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 16:20:45 +1100 Subject: [PATCH 08/12] Show explanation of confirm process on final page of registration --- .../templates/registration/finished.html.haml | 16 +++++++++------- .../templates/registration/social.html.haml | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/templates/registration/finished.html.haml b/app/assets/javascripts/templates/registration/finished.html.haml index 75489c607a..3d0daf5633 100644 --- a/app/assets/javascripts/templates/registration/finished.html.haml +++ b/app/assets/javascripts/templates/registration/finished.html.haml @@ -2,17 +2,19 @@ .header %h2 Well done! %h5 - You have successfully completed the profile for + That's all of the details we need for %span.brick{"ng-show" => "enterprise.is_distributor"} {{ enterprise.name }} %span.turquoise{"ng-show" => "!enterprise.is_distributor" } {{ enterprise.name }} .content{ style: 'text-align: center'} - %h3 Why not check it out on the Open Food Network? - %a.button.primary{ type: "button", href: "/map" } Go to Map Page > - %br - %br + %h3 There's just one last thing we need you to do: + %h5 We've sent a confirmation email to {{ enterprise.email }}, so please follow the instructions there to finalise the creation of your enterprise. - %h3 Next step - add some products: - %a.button.primary{ type: "button", href: "/admin/products/new" } Add a Product > + -# perhaps a pretty picture here? + + %br/ + %br/ + + %a.button.primary{ type: "button", href: "/" } Take me home > diff --git a/app/assets/javascripts/templates/registration/social.html.haml b/app/assets/javascripts/templates/registration/social.html.haml index 1b3490ffa0..f9d958e7e8 100644 --- a/app/assets/javascripts/templates/registration/social.html.haml +++ b/app/assets/javascripts/templates/registration/social.html.haml @@ -1,6 +1,6 @@ .container#registration-social .header - %h2 Last step! + %h2 Almost there! %h5 How can people find {{ enterprise.name }} online? %ng-include{ src: "'registration/steps.html'" } %form{ name: 'social', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('finished',social)" } } From 0940af6b660e3d1673b3539e343176009be7ada5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 16:21:11 +1100 Subject: [PATCH 09/12] Remove bad pry --- app/serializers/api/enterprise_serializer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index ce3412ab10..d750704657 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -103,7 +103,6 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer has_one :address, serializer: Api::AddressSerializer def visible - binding.pry object.visible && object.confirmed? end From 20cb11a298ecd357fa18823e145f17481e131b62 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 16:28:52 +1100 Subject: [PATCH 10/12] Update registration spec --- spec/features/consumer/registration_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index 7ac46a8970..e8a7e4aa09 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -75,7 +75,7 @@ feature "Registration", js: true do click_button 'Continue' # Filling in social - expect(page).to have_content 'Last step!' + expect(page).to have_content 'Almost there!' fill_in 'enterprise_website', with: 'www.shop.com' fill_in 'enterprise_facebook', with: 'FaCeBoOk' fill_in 'enterprise_linkedin', with: 'LiNkEdIn' @@ -84,7 +84,7 @@ feature "Registration", js: true do click_button 'Continue' # Done - expect(page).to have_content "You have successfully completed the profile for My Awesome Enterprise" + expect(page).to have_content "That's all of the details we need for My Awesome Enterprise" e.reload expect(e.website).to eq "www.shop.com" expect(e.facebook).to eq "FaCeBoOk" From 96878f5dcb373a9a900086525cbd5953e67c6cf7 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 17:22:56 +1100 Subject: [PATCH 11/12] Don't require confirmation for enterprises where the email address has already been confirmed for another enterprise --- app/models/enterprise.rb | 6 ++++++ spec/models/enterprise_spec.rb | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 954667f3e1..1bcd989f2a 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -8,6 +8,8 @@ class Enterprise < ActiveRecord::Base acts_as_gmappable :process_geocoding => false + before_create :check_email + after_create :send_creation_email has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup' @@ -272,6 +274,10 @@ class Enterprise < ActiveRecord::Base private + def check_email + skip_confirmation! if owner.enterprises.confirmed.map(&:email).include?(email) + end + def send_creation_email EnterpriseMailer.creation_confirmation(self).deliver end diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 7dc1d986a1..6f828b2f10 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -3,12 +3,22 @@ require 'spec_helper' describe Enterprise do include AuthenticationWorkflow - describe "creation" do - it "should send a confirmation email" do - mail_message = double "Mail::Message" - EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message - mail_message.should_receive :deliver - create(:enterprise) + describe "sending emails" do + describe "on creation" do + let!(:user) { create_enterprise_user( enterprise_limit: 2 ) } + let!(:enterprise) { create(:enterprise, owner: user, confirmed_at: Time.now) } + + it "when the email address has not already been confirmed" do + mail_message = double "Mail::Message" + EnterpriseMailer.should_receive(:confirmation_instructions).and_return mail_message + mail_message.should_receive :deliver + create(:enterprise, owner: user, email: "unknown@email.com" ) + end + + it "when the email address has already been confirmed" do + EnterpriseMailer.should_not_receive(:confirmation_instructions) + e = create(:enterprise, owner: user, email: enterprise.email) + end end end From 63e50dc88cc8b49539395b0bb8d5fda8db16c721 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 16 Oct 2014 11:34:06 +1100 Subject: [PATCH 12/12] Fiddle with alert styling --- app/assets/stylesheets/admin/alert.css.sass | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/admin/alert.css.sass b/app/assets/stylesheets/admin/alert.css.sass index 5404e1a0e2..d86cb38f55 100644 --- a/app/assets/stylesheets/admin/alert.css.sass +++ b/app/assets/stylesheets/admin/alert.css.sass @@ -1,10 +1,15 @@ .alert - border: 3px solid #DA5354 + border: 3px solid #919191 border-radius: 6px margin-bottom: 20px - color: #DA5354 + color: #919191 padding: 5px 10px h6 - color: #DA5354 + color: #919191 .message font-weight: bold + &:hover + border-color: #DA5354 + color: #DA5354 + h6 + color: #DA5354