diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 152ab5ab05..da50617189 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -135,7 +135,7 @@ module Admin return end - available_coordinators = permitted_coordinating_enterprises_for(@order_cycle).select(&:confirmed?) + available_coordinators = permitted_coordinating_enterprises_for(@order_cycle) case available_coordinators.count when 0 flash[:error] = I18n.t(:order_cycles_no_permission_to_coordinate_error) diff --git a/app/controllers/enterprise_confirmations_controller.rb b/app/controllers/enterprise_confirmations_controller.rb deleted file mode 100644 index 0375a04d49..0000000000 --- a/app/controllers/enterprise_confirmations_controller.rb +++ /dev/null @@ -1,55 +0,0 @@ -class EnterpriseConfirmationsController < DeviseController - include Spree::Core::ControllerHelpers::Auth # Needed for access to current_ability, so we can authorize! actions - - # GET /resource/confirmation/new - def new - build_resource({}) - end - - # POST /resource/confirmation - def create - self.resource = resource_class.find_by_unconfirmed_email_with_errors(resource_params) - authorize! :resend_confirmation, resource - - self.resource = resource_class.send_confirmation_instructions(resource_params) - - if successfully_sent?(resource) - set_flash_message(:success, :confirmation_sent) if is_navigational_format? - else - set_flash_message(:error, :confirmation_not_sent) if is_navigational_format? - end - - respond_with_navigational(resource){ redirect_to spree.admin_path } - end - - # GET /resource/confirmation?confirmation_token=abcdef - def show - self.resource = resource_class.confirm_by_token(params[:confirmation_token]) - - if resource.errors.empty? - set_flash_message(:success, :confirmed) if is_navigational_format? - else - set_flash_message(:error, :not_confirmed) if is_navigational_format? - end - - respond_with_navigational(resource){ redirect_to redirect_path(resource) } - end - - private - - def new_user_reset_path(resource) - password = Devise.friendly_token.first(8) - user = Spree::User.create(email: resource.email, password: password, password_confirmation: password) - user.send_reset_password_instructions_without_delay - resource.users << user - spree.edit_spree_user_password_path(user, :reset_password_token => user.reset_password_token, return_to: spree.admin_path) - end - - def redirect_path(resource) - if resource.persisted? && !Spree::User.exists?(email: resource.email) - new_user_reset_path(resource) - else - spree.admin_path - end - end -end diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index e8271cd68f..3f32830fbb 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -12,7 +12,7 @@ module OrderCyclesHelper end def permitted_producer_enterprise_options_for(order_cycle) - validated_enterprise_options permitted_producer_enterprises_for(order_cycle), confirmed: true + validated_enterprise_options permitted_producer_enterprises_for(order_cycle) end def permitted_coordinating_enterprises_for(order_cycle) @@ -20,7 +20,7 @@ module OrderCyclesHelper end def permitted_coordinating_enterprise_options_for(order_cycle) - validated_enterprise_options permitted_coordinating_enterprises_for(order_cycle), confirmed: true + validated_enterprise_options permitted_coordinating_enterprises_for(order_cycle) end def permitted_hub_enterprises_for(order_cycle) @@ -28,7 +28,7 @@ module OrderCyclesHelper end def permitted_hub_enterprise_options_for(order_cycle) - validated_enterprise_options permitted_hub_enterprises_for(order_cycle), confirmed: true, shipping_and_payment_methods: true + validated_enterprise_options permitted_hub_enterprises_for(order_cycle), shipping_and_payment_methods: true end def order_cycle_status_class(order_cycle) @@ -91,8 +91,6 @@ module OrderCyclesHelper elsif e.payment_methods.available.empty? disabled_message = I18n.t(:no_payment) end - elsif options[:confirmed] && !e.confirmed? - disabled_message = I18n.t(:unconfirmed) end if disabled_message diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index dfd3f21636..6ce24e320e 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -12,16 +12,6 @@ class EnterpriseMailer < Spree::BaseMailer :subject => subject) end - def confirmation_instructions(record, token) - @token = token - find_enterprise(record) - subject = t('enterprise_mailer.confirmation_instructions.subject', - enterprise: @enterprise.name) - mail(to: (@enterprise.unconfirmed_email || @enterprise.email), - from: from_address, - subject: subject) - end - private def find_enterprise(enterprise) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a8111d963f..3d0f674666 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -13,9 +13,6 @@ class Enterprise < ActiveRecord::Base # TODO: delegate this to a separate model instead of abusing Preferences. preference :product_selection_from_inventory_only, :boolean, default: false - devise :confirmable, reconfirmable: true, confirmation_keys: [ :id, :email ] - handle_asynchronously :send_confirmation_instructions - handle_asynchronously :send_on_create_confirmation_instructions has_paper_trail only: [:owner_id, :sells], on: [:update] self.inheritance_column = nil @@ -79,8 +76,6 @@ class Enterprise < ActiveRecord::Base validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? } validates_length_of :description, :maximum => 255 - before_save :confirmation_check, if: lambda { email_changed? } - before_validation :initialize_permalink, if: lambda { permalink.nil? } before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? } before_validation :ensure_email_set @@ -89,17 +84,13 @@ class Enterprise < ActiveRecord::Base after_touch :touch_distributors after_create :relate_to_owners_enterprises - # TODO: Later versions of devise have a dedicated after_confirmation callback, so use that - after_update :welcome_after_confirm, if: lambda { confirmation_token_changed? && confirmation_token.nil? } - after_create :send_welcome_email, if: lambda { email_is_known? } + after_create :send_welcome_email after_rollback :restore_permalink 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 :activated, where("confirmed_at IS NOT NULL AND sells != 'unspecified'") + scope :activated, where("sells != 'unspecified'") scope :ready_for_checkout, lambda { joins(:shipping_methods). joins(:payment_methods). @@ -188,7 +179,7 @@ class Enterprise < ActiveRecord::Base end def activated? - confirmed_at.present? && sells != 'unspecified' + owner.confirmed? && sells != 'unspecified' end def set_producer_property(property_name, property_value) @@ -341,11 +332,6 @@ class Enterprise < ActiveRecord::Base end end - # Based on a devise method, but without adding errors - def pending_any_confirmation? - !confirmed? || pending_reconfirmation? - end - def shop_trial_expiry shop_trial_start_date.andand + Spree::Config[:shop_trial_length_days].days end @@ -371,25 +357,6 @@ class Enterprise < ActiveRecord::Base end end - def email_is_known? - owner.enterprises.confirmed.map(&:email).include?(email) - end - - def confirmation_check - # Skip confirmation/reconfirmation if the new email has already been confirmed - if email_is_known? - new_record? ? skip_confirmation! : skip_reconfirmation! - end - end - - def welcome_after_confirm - # Send welcome email if we are confirming a newly created enterprise - # Note: this callback only runs on email confirmation - if confirmed? && unconfirmed_email.nil? && !unconfirmed_email_changed? - send_welcome_email - end - end - def send_welcome_email Delayed::Job.enqueue WelcomeEnterpriseJob.new(self.id) end diff --git a/app/views/admin/enterprises/form/_users.html.haml b/app/views/admin/enterprises/form/_users.html.haml index a0b5b7e662..eb0081a923 100644 --- a/app/views/admin/enterprises/form/_users.html.haml +++ b/app/views/admin/enterprises/form/_users.html.haml @@ -1,13 +1,6 @@ - owner_email = @enterprise.andand.owner.andand.email || "" - full_permissions = (spree_current_user.admin? || spree_current_user == @enterprise.andand.owner) --if @enterprise.pending_any_confirmation? - .alert-box - - email = @enterprise.confirmed? ? @enterprise.unconfirmed_email : @enterprise.email - = t('.email_confirmation_notice_html', {email: "#{email}".html_safe}) - = link_to(t('.resend'), main_app.enterprise_confirmation_path(enterprise: { id: @enterprise.id, email: email } ), method: :post) - %a.close{ href: "#" } × - .row .three.columns.alpha =f.label :owner_id, t('.owner') diff --git a/app/views/enterprise_mailer/confirmation_instructions.html.haml b/app/views/enterprise_mailer/confirmation_instructions.html.haml deleted file mode 100644 index c1b288f6ef..0000000000 --- a/app/views/enterprise_mailer/confirmation_instructions.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -%h3 - = t :email_confirmation_greeting, contact: @enterprise.contact -%p.lead - = t :email_confirmation_profile_created, name: @enterprise.name -%p   - -%p.callout - = t :email_confirmation_click_link - %br - %strong - = link_to t(:email_confirmation_link_label), confirmation_url(@enterprise, :confirmation_token => @enterprise.confirmation_token) - -%p   -%p - = t :email_confirmation_help_html, link: link_to(t(:email_confirmation_userguide), 'http://www.openfoodnetwork.org/platform/user-guide/'), sitename: Spree::Config[:site_name] - -= render 'shared/mailers/signoff' - -= render 'shared/mailers/social_and_contact' diff --git a/app/views/spree/admin/overview/_unconfirmed.html.haml b/app/views/spree/admin/overview/_unconfirmed.html.haml deleted file mode 100644 index 5ff0e17a84..0000000000 --- a/app/views/spree/admin/overview/_unconfirmed.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -- @enterprises.unconfirmed.each do |enterprise| - .alert - %h6= "#{t :spree_admin_overview_action_required}: #{t :spree_admin_single_enterprise_alert_mail_confirmation} #{enterprise.name}." - %span.message= "#{t :spree_admin_single_enterprise_alert_mail_sent} #{enterprise.email}. #{t :spree_admin_overview_check_your_inbox}" diff --git a/app/views/spree/admin/overview/multi_enterprise_dashboard.html.haml b/app/views/spree/admin/overview/multi_enterprise_dashboard.html.haml index f65f045e6d..0840358a14 100644 --- a/app/views/spree/admin/overview/multi_enterprise_dashboard.html.haml +++ b/app/views/spree/admin/overview/multi_enterprise_dashboard.html.haml @@ -6,12 +6,6 @@ %h1{ :style => 'margin-bottom: 30px' } = t 'dashboard' - - if @enterprises.unconfirmed.any? - - = render partial: "unconfirmed" - - %hr - - if @enterprises.empty? = render partial: "enterprises" diff --git a/app/views/spree/admin/overview/single_enterprise_dashboard.html.haml b/app/views/spree/admin/overview/single_enterprise_dashboard.html.haml index 76377f32e2..dd7322b5b9 100644 --- a/app/views/spree/admin/overview/single_enterprise_dashboard.html.haml +++ b/app/views/spree/admin/overview/single_enterprise_dashboard.html.haml @@ -26,15 +26,6 @@ #package_selection{ hidden: true } = render partial: "/admin/enterprises/change_type_form" - -- if @enterprise.confirmed_at.nil? - .alert-box - = t "spree_admin_single_enterprise_alert_mail_confirmation" - %strong= "#{@enterprise.name}." - = t "spree_admin_single_enterprise_alert_mail_sent" - %strong= "#{@enterprise.email}." - = link_to(t('resend'), main_app.enterprise_confirmation_path(enterprise: { id: @enterprise.id, email: @enterprise.email } ), method: :post) - %a.close{ href: "#" } × - if !@enterprise.visible .alert-box %strong diff --git a/config/locales/en.yml b/config/locales/en.yml index 85af4ed997..a829c7bb0e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1818,7 +1818,7 @@ Please follow the instructions there to make your enterprise visible on the Open report_header_special_instructions: Special Instructions report_header_order_number: Order number report_header_date: Date - report_header_confirmation_date: Confirmation Date + report_header_creation_date: Creation Date report_header_tags: Tags report_header_items: Items report_header_items_total: "Items total %{currency_symbol}" diff --git a/config/routes.rb b/config/routes.rb index 4237f251ec..e6b8153eb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,8 +84,6 @@ Openfoodnetwork::Application.routes.draw do get '/:id/shop', to: 'enterprises#shop', as: 'enterprise_shop' get "/enterprises/:permalink", to: redirect("/") # Legacy enterprise URL - devise_for :enterprise, controllers: { confirmations: 'enterprise_confirmations' } - namespace :admin do resources :order_cycles do post :bulk_update, on: :collection, as: :bulk_update diff --git a/db/migrate/20170719125120_remove_confirmable_from_enterprises.rb b/db/migrate/20170719125120_remove_confirmable_from_enterprises.rb new file mode 100644 index 0000000000..a4aad51dd4 --- /dev/null +++ b/db/migrate/20170719125120_remove_confirmable_from_enterprises.rb @@ -0,0 +1,16 @@ +class RemoveConfirmableFromEnterprises < ActiveRecord::Migration + def up + remove_columns :enterprises, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email + end + + def down + 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.zone.now) + end +end diff --git a/db/schema.rb b/db/schema.rb index 16b54e9ae5..3feb83674e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -238,10 +238,6 @@ ActiveRecord::Schema.define(:version => 20170921065259) do t.string "linkedin" t.integer "owner_id", :null => false t.string "sells", :default => "none", :null => false - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" t.datetime "shop_trial_start_date" t.boolean "producer_profile_only", :default => false t.string "permalink", :null => false @@ -255,7 +251,6 @@ ActiveRecord::Schema.define(:version => 20170921065259) do 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", ["is_primary_producer", "sells"], :name => "index_enterprises_on_is_primary_producer_and_sells" add_index "enterprises", ["name"], :name => "index_enterprises_on_name", :unique => true add_index "enterprises", ["owner_id"], :name => "index_enterprises_on_owner_id" diff --git a/lib/open_food_network/enterprise_issue_validator.rb b/lib/open_food_network/enterprise_issue_validator.rb index eccc5a4a68..252d03f836 100644 --- a/lib/open_food_network/enterprise_issue_validator.rb +++ b/lib/open_food_network/enterprise_issue_validator.rb @@ -20,11 +20,6 @@ module OpenFoodNetwork link: "#{I18n.t('admin.enterprise_issues.create_new')}" } unless payment_methods_ok? - issues << { - description: I18n.t('admin.enterprise_issues.email_confirmation', email: @enterprise.email), - link: "#{I18n.t('admin.enterprise_issues.resend_email')}" - } unless confirmed? - issues end @@ -35,8 +30,6 @@ module OpenFoodNetwork I18n.t(:no_shipping) elsif !opts[:confirmation_only] && !payment_methods_ok? I18n.t(:no_payment) - elsif !confirmed? - I18n.t(:unconfirmed) end end @@ -64,9 +57,5 @@ module OpenFoodNetwork return true unless @enterprise.is_distributor @enterprise.payment_methods.available.any? end - - def confirmed? - @enterprise.confirmed? - end end end diff --git a/lib/open_food_network/users_and_enterprises_report.rb b/lib/open_food_network/users_and_enterprises_report.rb index 58cb9688c8..4f816af8bd 100644 --- a/lib/open_food_network/users_and_enterprises_report.rb +++ b/lib/open_food_network/users_and_enterprises_report.rb @@ -22,32 +22,33 @@ module OpenFoodNetwork end def table - users_and_enterprises.map do |uae| [ - uae["user_email"], - uae["relationship_type"], - uae["name"], - to_bool(uae["is_primary_producer"]), - uae["sells"], - uae["visible"], - to_local_datetime(uae["confirmed_at"]) - ] + users_and_enterprises.map do |uae| + [ + uae["user_email"], + uae["relationship_type"], + uae["name"], + to_bool(uae["is_primary_producer"]), + uae["sells"], + uae["visible"], + to_local_datetime(uae["created_at"]) + ] end end def owners_and_enterprises - query = "SELECT enterprises.name, enterprises.sells, enterprises.visible, enterprises.is_primary_producer, enterprises.confirmed_at, + query = "SELECT enterprises.name, enterprises.sells, enterprises.visible, enterprises.is_primary_producer, enterprises.created_at AS created_at, 'owns' AS relationship_type, owners.email as user_email FROM enterprises LEFT JOIN spree_users AS owners ON owners.id=enterprises.owner_id WHERE enterprises.id IS NOT NULL #{ params[:enterprise_id_in].present? ? "AND enterprises.id IN (#{ params[:enterprise_id_in] })" : "" } #{ params[:user_id_in].present? ? "AND owners.id IN (#{ params[:user_id_in] })" : "" } - ORDER BY confirmed_at DESC" + ORDER BY enterprises.created_at DESC" ActiveRecord::Base.connection.execute(query).to_a end def managers_and_enterprises - query = "SELECT enterprises.name, enterprises.sells, enterprises.visible, enterprises.is_primary_producer, enterprises.confirmed_at, + query = "SELECT enterprises.name, enterprises.sells, enterprises.visible, enterprises.is_primary_producer, enterprises.created_at AS created_at, 'manages' AS relationship_type, managers.email as user_email FROM enterprises LEFT JOIN enterprise_roles ON enterprises.id=enterprise_roles.enterprise_id LEFT JOIN spree_users AS managers ON enterprise_roles.user_id=managers.id @@ -55,7 +56,7 @@ module OpenFoodNetwork #{ params[:enterprise_id_in].present? ? "AND enterprise_id IN (#{ params[:enterprise_id_in] })" : "" } AND user_id IS NOT NULL #{ params[:user_id_in].present? ? "AND user_id IN (#{ params[:user_id_in] })" : "" } - ORDER BY confirmed_at DESC" + ORDER BY enterprises.created_at DESC" ActiveRecord::Base.connection.execute(query).to_a end @@ -66,12 +67,12 @@ module OpenFoodNetwork def sort(results) results.sort do |a,b| - if a["confirmed_at"].nil? || b["confirmed_at"].nil? - [ (a["confirmed_at"].nil? ? 0 : 1), a["name"], b["relationship_type"], a["user_email"] ] <=> - [ (b["confirmed_at"].nil? ? 0 : 1), b["name"], a["relationship_type"], b["user_email"] ] + if a["created_at"].nil? || b["created_at"].nil? + [ (a["created_at"].nil? ? 0 : 1), a["name"], b["relationship_type"], a["user_email"] ] <=> + [ (b["created_at"].nil? ? 0 : 1), b["name"], a["relationship_type"], b["user_email"] ] else - [ DateTime.parse(b["confirmed_at"]), a["name"], b["relationship_type"], a["user_email"] ] <=> - [ DateTime.parse(a["confirmed_at"]), b["name"], a["relationship_type"], b["user_email"] ] + [ DateTime.parse(b["created_at"]), a["name"], b["relationship_type"], a["user_email"] ] <=> + [ DateTime.parse(a["created_at"]), b["name"], a["relationship_type"], b["user_email"] ] end end end @@ -80,9 +81,9 @@ module OpenFoodNetwork ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value) end - def to_local_datetime(string) - return I18n.t(:report_header_not_confirmed) if string.nil? - string.to_datetime.in_time_zone.strftime "%Y-%m-%d %H:%M" + def to_local_datetime(date) + return "" if date.nil? + date.to_datetime.in_time_zone.strftime "%Y-%m-%d %H:%M" end end end diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb index 7dfa1deb31..e91a48694c 100644 --- a/spec/controllers/admin/order_cycles_controller_spec.rb +++ b/spec/controllers/admin/order_cycles_controller_spec.rb @@ -45,15 +45,6 @@ module Admin end describe "new" do - describe "when the user manages no distributor enterprises suitable for coordinator" do - let!(:distributor) { create(:distributor_enterprise, owner: distributor_owner, confirmed_at: nil) } - - it "redirects to order cycles index" do - spree_get :new - expect(response).to redirect_to admin_order_cycles_path - end - end - describe "when the user manages a single distributor enterprise suitable for coordinator" do let!(:distributor) { create(:distributor_enterprise, owner: distributor_owner) } diff --git a/spec/controllers/enterprise_confirmations_controller_spec.rb b/spec/controllers/enterprise_confirmations_controller_spec.rb deleted file mode 100644 index 995df8276c..0000000000 --- a/spec/controllers/enterprise_confirmations_controller_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'spec_helper' - -describe EnterpriseConfirmationsController, type: :controller do - include AuthenticationWorkflow - let!(:user) { create_enterprise_user( enterprise_limit: 10 ) } - let!(:unconfirmed_enterprise) { create(:distributor_enterprise, confirmed_at: nil, owner: user) } - let!(:confirmed_enterprise) { create(:distributor_enterprise, confirmed_at: nil, owner: user) } - let!(:confirmed_token) { confirmed_enterprise.confirmation_token } - let!(:unowned_enterprise) { create(:distributor_enterprise) } - - before do - controller.stub spree_current_user: user - @request.env["devise.mapping"] = Devise.mappings[:enterprise] - confirmed_enterprise.confirm! - end - - context "confirming an enterprise" do - context "that has already been confirmed" do - - before do - spree_get :show, confirmation_token: confirmed_token - end - - it "redirects the user to admin" do - expect(response).to redirect_to spree.admin_path - expect(flash[:error]).to eq I18n.t('devise.enterprise_confirmations.enterprise.not_confirmed') - end - end - - context "that has not been confirmed" do - context "where the enterprise contact email maps to an existing user account" do - before do - unconfirmed_enterprise.update_attribute(:email, user.email) - end - - it "redirects the user to admin" do - spree_get :show, confirmation_token: unconfirmed_enterprise.confirmation_token - expect(response).to redirect_to spree.admin_path - expect(flash[:success]).to eq I18n.t('devise.enterprise_confirmations.enterprise.confirmed') - end - end - - context "where the enterprise contact email doesn't map to an existing user account" do - let(:new_user) { create_enterprise_user } - - before do - unconfirmed_enterprise.update_attribute(:email, 'random@email.com') - allow(Spree::User).to receive(:create) { new_user } - allow(new_user).to receive(:reset_password_token) { "token" } - end - - it "redirects to the user to reset their password" do - expect(new_user).to receive(:send_reset_password_instructions_without_delay).and_call_original - spree_get :show, confirmation_token: unconfirmed_enterprise.confirmation_token - expect(response).to redirect_to spree.edit_spree_user_password_path(new_user, :reset_password_token => "token", return_to: spree.admin_path) - expect(flash[:success]).to eq I18n.t('devise.enterprise_confirmations.enterprise.confirmed') - expect(unconfirmed_enterprise.users(:reload)).to include new_user - end - end - end - end - - context "requesting confirmation instructions to be resent" do - it "when the user owns the enterprise" do - spree_post :create, { enterprise: { id: unconfirmed_enterprise.id, email: unconfirmed_enterprise.email } } - expect(response).to redirect_to spree.admin_path - expect(flash[:success]).to eq I18n.t('devise.enterprise_confirmations.enterprise.confirmation_sent') - end - - it "when the user does not own the enterprise" do - spree_post :create, { enterprise: { id: unowned_enterprise.id, email: unowned_enterprise.email } } - expect(response).to redirect_to spree.unauthorized_path - expect(flash[:error]).to eq "Authorization Failure" - end - end -end diff --git a/spec/factories.rb b/spec/factories.rb index 44ebc50de8..603e48d351 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -154,7 +154,6 @@ FactoryGirl.define do long_description '

Hello, world!

This is a paragraph.

' email 'enterprise@example.com' address { FactoryGirl.create(:address) } - confirmed_at { Time.zone.now } end factory :supplier_enterprise, :parent => :enterprise do diff --git a/spec/features/admin/overview_spec.rb b/spec/features/admin/overview_spec.rb index 31591349c7..26a7afd046 100644 --- a/spec/features/admin/overview_spec.rb +++ b/spec/features/admin/overview_spec.rb @@ -28,18 +28,6 @@ feature %q{ page.should have_selector ".dashboard_item .button.bottom", text: "SEE #{d1.name.upcase} LIVE" end - context "when enterprise has not been confirmed" do - before do - d1.confirmed_at = nil - d1.save! - end - - it "displays a message telling to user to confirm" do - visit '/admin' - page.should have_selector ".alert-box", text: "Please confirm the email address for #{d1.name}. We've sent an email to #{d1.email}." - end - end - context "when visibilty is set to false" do before do d1.visible = false diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb index 4804be6941..1b4398e8d7 100644 --- a/spec/helpers/order_cycles_helper_spec.rb +++ b/spec/helpers/order_cycles_helper_spec.rb @@ -9,7 +9,7 @@ describe OrderCyclesHelper, type: :helper do end it "asks for a validation option list" do - expect(helper).to receive(:validated_enterprise_options).with("enterprise list", {confirmed: true}) + expect(helper).to receive(:validated_enterprise_options).with("enterprise list") helper.permitted_producer_enterprise_options_for(oc) end end @@ -20,7 +20,7 @@ describe OrderCyclesHelper, type: :helper do end it "asks for a validation option list" do - expect(helper).to receive(:validated_enterprise_options).with("enterprise list", {confirmed: true}) + expect(helper).to receive(:validated_enterprise_options).with("enterprise list") helper.permitted_coordinating_enterprise_options_for(oc) end end @@ -31,7 +31,7 @@ describe OrderCyclesHelper, type: :helper do end it "asks for a validation option list" do - expect(helper).to receive(:validated_enterprise_options).with("enterprise list", {confirmed: true, shipping_and_payment_methods: true}) + expect(helper).to receive(:validated_enterprise_options).with("enterprise list", {shipping_and_payment_methods: true}) helper.permitted_hub_enterprise_options_for(oc) end end @@ -58,14 +58,6 @@ describe OrderCyclesHelper, type: :helper do .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]] end - it "returns unconfirmed enterprises as disabled" do - create(:shipping_method, distributors: [e]) - create(:payment_method, distributors: [e]) - e.stub(:confirmed_at) { nil } - expect(helper.send(:validated_enterprise_options, [e], confirmed: true)) - .to eq [['enterprise (unconfirmed)', e.id, {disabled: true}]] - end - it "returns enterprises with neither shipping nor payment methods as disabled" do expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true)) .to eq [['enterprise (no shipping or payment methods)', e.id, {disabled: true}]] diff --git a/spec/lib/open_food_network/enterprise_injection_data_spec.rb b/spec/lib/open_food_network/enterprise_injection_data_spec.rb index ded13c9a6b..d1e76221be 100644 --- a/spec/lib/open_food_network/enterprise_injection_data_spec.rb +++ b/spec/lib/open_food_network/enterprise_injection_data_spec.rb @@ -5,7 +5,7 @@ module OpenFoodNetwork describe "relatives" do let!(:enterprise) { create(:distributor_enterprise) } let!(:producer) { create(:supplier_enterprise) } - let!(:producer_inactive) { create(:supplier_enterprise, confirmed_at: nil) } + let!(:producer_inactive) { create(:supplier_enterprise, sells: 'unspecified') } let!(:er_p) { create(:enterprise_relationship, parent: producer, child: enterprise) } let!(:er_pi) { create(:enterprise_relationship, parent: producer_inactive, child: enterprise) } diff --git a/spec/lib/open_food_network/enterprise_issue_validator_spec.rb b/spec/lib/open_food_network/enterprise_issue_validator_spec.rb index 1d0b065ee4..ddae3e0b53 100644 --- a/spec/lib/open_food_network/enterprise_issue_validator_spec.rb +++ b/spec/lib/open_food_network/enterprise_issue_validator_spec.rb @@ -2,21 +2,6 @@ require 'open_food_network/enterprise_issue_validator' module OpenFoodNetwork describe EnterpriseIssueValidator do - describe "issues" do - let(:enterprise) { create(:enterprise) } - let(:eiv) { EnterpriseIssueValidator.new(enterprise) } - let(:issues) { eiv.issues } - - it "reports enterprises requiring email confirmation" do - eiv.stub(:shipping_methods_ok?) { true } - eiv.stub(:payment_methods_ok?) { true } - eiv.stub(:confirmed?) { false } - - issues.count.should == 1 - issues.first[:description].should include "Email confirmation is pending" - end - end - describe "warnings" do let(:enterprise_invisible) { create(:enterprise, visible: false) } let(:warnings) { EnterpriseIssueValidator.new(enterprise_invisible).warnings } diff --git a/spec/lib/open_food_network/users_and_enterprises_report_spec.rb b/spec/lib/open_food_network/users_and_enterprises_report_spec.rb index 7119d16239..906bef1eef 100644 --- a/spec/lib/open_food_network/users_and_enterprises_report_spec.rb +++ b/spec/lib/open_food_network/users_and_enterprises_report_spec.rb @@ -26,18 +26,10 @@ module OpenFoodNetwork describe "sorting results" do let!(:subject) { OpenFoodNetwork::UsersAndEnterprisesReport.new {} } - it "sorts unconfirmed enterprises to the top" do + it "sorts by creation date" do uae_mock = [ - { "confirmed_at" => "2015-01-01", "name" => "aaa" }, - { "confirmed_at" => nil, "name" => "bbb" } - ] - expect(subject.sort uae_mock).to eq [ uae_mock[1], uae_mock[0] ] - end - - it "then sorts by confirmation date" do - uae_mock = [ - { "confirmed_at" => "2015-01-01", "name" => "bbb" }, - { "confirmed_at" => "2015-01-02", "name" => "aaa" } + { "created_at" => "2015-01-01", "name" => "bbb" }, + { "created_at" => "2015-01-02", "name" => "aaa" } ] expect(subject.sort uae_mock).to eq [ uae_mock[1], uae_mock[0] ] end diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb index 2399d4146a..7eda5ff505 100644 --- a/spec/mailers/enterprise_mailer_spec.rb +++ b/spec/mailers/enterprise_mailer_spec.rb @@ -7,32 +7,6 @@ describe EnterpriseMailer do ActionMailer::Base.deliveries = [] end - context "when given an enterprise without an unconfirmed_email" do - it "should send an email confirmation to email" do - EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver - ActionMailer::Base.deliveries.count.should == 1 - mail = ActionMailer::Base.deliveries.first - expect(mail.subject).to eq "Please confirm the email address for #{enterprise.name}" - expect(mail.to).to include enterprise.email - expect(mail.reply_to).to be_nil - end - end - - context "when given an enterprise with an unconfirmed_email" do - before do - enterprise.unconfirmed_email = "unconfirmed@email.com" - enterprise.save! - end - - it "should send an email confirmation to unconfirmed_email" do - EnterpriseMailer.confirmation_instructions(enterprise, 'token').deliver - ActionMailer::Base.deliveries.count.should == 1 - mail = ActionMailer::Base.deliveries.first - expect(mail.subject).to eq "Please confirm the email address for #{enterprise.name}" - expect(mail.to).to include enterprise.unconfirmed_email - end - end - it "should send a welcome email when given an enterprise" do EnterpriseMailer.welcome(enterprise).deliver ActionMailer::Base.deliveries.count.should == 1 diff --git a/spec/models/enterprise_relationship_spec.rb b/spec/models/enterprise_relationship_spec.rb index ca21cc7dfc..5dbdf1f3be 100644 --- a/spec/models/enterprise_relationship_spec.rb +++ b/spec/models/enterprise_relationship_spec.rb @@ -124,12 +124,12 @@ describe EnterpriseRelationship do end it "finds inactive enterprises by default" do - e1.update_attribute :confirmed_at, nil + e1.update_attribute :sells, 'unspecified' EnterpriseRelationship.relatives[e2.id][:producers].should == Set.new([e1.id]) end it "does not find inactive enterprises when requested" do - e1.update_attribute :confirmed_at, nil + e1.update_attribute :sells, 'unspecified' EnterpriseRelationship.relatives(true)[e2.id][:producers].should be_empty end diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 12fc3bd744..e122fadf7b 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -8,77 +8,10 @@ describe Enterprise do let!(:user) { create_enterprise_user( enterprise_limit: 2 ) } let!(:enterprise) { create(:enterprise, owner: user) } - context "when the email address has not already been confirmed" do - it "sends a confirmation email" do - expect do - create(:enterprise, owner: user, email: "unknown@email.com", confirmed_at: nil ) - end.to enqueue_job Delayed::PerformableMethod - Delayed::Job.last.payload_object.method_name.should == :send_on_create_confirmation_instructions_without_delay - end - - it "does not send a welcome email" do - expect(EnterpriseMailer).to_not receive(:welcome) - create(:enterprise, owner: user, email: "unknown@email.com", confirmed_at: nil ) - end - end - - context "when the email address has already been confirmed" do - it "does not send a confirmation email" do - expect(EnterpriseMailer).to_not receive(:confirmation_instructions) - create(:enterprise, owner: user, email: enterprise.email, confirmed_at: nil) - end - - it "sends a welcome email" do - expect do - create(:enterprise, owner: user, email: enterprise.email, confirmed_at: nil) - end.to enqueue_job WelcomeEnterpriseJob - end - end - end - - describe "on update of email" do - let!(:user) { create_enterprise_user( enterprise_limit: 2 ) } - let!(:enterprise) { create(:enterprise, owner: user) } - - it "when the email address has not already been confirmed" do + it "sends a welcome email" do expect do - enterprise.update_attributes(email: "unknown@email.com") - end.to enqueue_job Delayed::PerformableMethod - Delayed::Job.last.payload_object.method_name.should == :send_confirmation_instructions_without_delay - end - - it "when the email address has already been confirmed" do - create(:enterprise, owner: user, email: "second.known.email@email.com") # Another enterpise with same owner but different email - expect(EnterpriseMailer).to_not receive(:confirmation_instructions) - enterprise.update_attributes!(email: "second.known.email@email.com") - end - end - - describe "on email confirmation" do - let!(:user) { create_enterprise_user( enterprise_limit: 2 ) } - let!(:unconfirmed_enterprise) { create(:enterprise, owner: user, confirmed_at: nil) } - - context "when we are confirming an email address for the first time for the enterprise" do - it "sends a welcome email" do - # unconfirmed_email is blank if we are not reconfirming an email - unconfirmed_enterprise.unconfirmed_email = nil - unconfirmed_enterprise.save! - - expect do - unconfirmed_enterprise.confirm! - end.to enqueue_job WelcomeEnterpriseJob, enterprise_id: unconfirmed_enterprise.id - end - end - - context "when we are reconfirming the email address for the enterprise" do - it "does not send a welcome email" do - # unconfirmed_email is present if we are reconfirming an email - unconfirmed_enterprise.unconfirmed_email = "unconfirmed@email.com" - unconfirmed_enterprise.save! - - expect(EnterpriseMailer).to_not receive(:welcome) - unconfirmed_enterprise.confirm! - end + create(:enterprise, owner: user, email: enterprise.email) + end.to enqueue_job WelcomeEnterpriseJob end end end @@ -284,38 +217,14 @@ describe Enterprise do end end - describe "confirmed" do - it "find enterprises with a confirmed date" do - s1 = create(:supplier_enterprise) - d1 = create(:distributor_enterprise) - 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 "unconfirmed" do - it "find enterprises without a confirmed date" do - s1 = create(:supplier_enterprise) - d1 = create(:distributor_enterprise) - 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 "activated" do - let!(:inactive_enterprise1) { create(:enterprise, sells: "unspecified", confirmed_at: Time.zone.now) ;} - let!(:inactive_enterprise2) { create(:enterprise, sells: "none", confirmed_at: nil) } - let!(:active_enterprise) { create(:enterprise, sells: "none", confirmed_at: Time.zone.now) } + let!(:inactive_enterprise) { create(:enterprise, sells: "unspecified") ;} + let!(:active_enterprise) { create(:enterprise, sells: "none") } - it "finds enterprises that have a sells property other than 'unspecified' and that are confirmed" do + it "finds enterprises that have a sells property other than 'unspecified'" do activated_enterprises = Enterprise.activated expect(activated_enterprises).to include active_enterprise - expect(activated_enterprises).to_not include inactive_enterprise1 - expect(activated_enterprises).to_not include inactive_enterprise2 + expect(activated_enterprises).to_not include inactive_enterprise end end