From e35eff95bb6ebe1b60f41960c63bac97b9558dec Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 15:53:16 +0100 Subject: [PATCH 01/18] Add mail_methods controller from spree_backend related to config --- .../spree/admin/mail_methods_controller.rb | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/controllers/spree/admin/mail_methods_controller.rb diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb new file mode 100644 index 0000000000..2cf2527592 --- /dev/null +++ b/app/controllers/spree/admin/mail_methods_controller.rb @@ -0,0 +1,38 @@ +module Spree + module Admin + class MailMethodsController < Spree::Admin::BaseController + after_filter :initialize_mail_settings + + def update + if params[:smtp_password].blank? + params.delete(:smtp_password) + end + + params.each do |name, value| + next unless Spree::Config.has_preference? name + Spree::Config[name] = value + end + + flash[:success] = Spree.t(:successfully_updated, :resource => Spree.t(:mail_methods)) + render :edit + end + + def testmail + if TestMailer.test_email(try_spree_current_user).deliver + flash[:success] = Spree.t('admin.mail_methods.testmail.delivery_success') + else + flash[:error] = Spree.t('admin.mail_methods.testmail.delivery_error') + end + rescue Exception => e + flash[:error] = Spree.t('admin.mail_methods.testmail.error') % {:e => e} + ensure + redirect_to edit_admin_mail_method_url + end + + private + def initialize_mail_settings + Spree::Core::MailSettings.init + end + end + end +end From 3f3c33bce6322fe3f1518a9f36573386419fa650 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 15:56:53 +0100 Subject: [PATCH 02/18] Fix basic rubocop issues in newly added controller --- .../spree/admin/mail_methods_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb index 2cf2527592..867829c0bd 100644 --- a/app/controllers/spree/admin/mail_methods_controller.rb +++ b/app/controllers/spree/admin/mail_methods_controller.rb @@ -13,7 +13,7 @@ module Spree Spree::Config[name] = value end - flash[:success] = Spree.t(:successfully_updated, :resource => Spree.t(:mail_methods)) + flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:mail_methods)) render :edit end @@ -23,16 +23,17 @@ module Spree else flash[:error] = Spree.t('admin.mail_methods.testmail.delivery_error') end - rescue Exception => e - flash[:error] = Spree.t('admin.mail_methods.testmail.error') % {:e => e} + rescue StandardError => e + flash[:error] = Spree.t('admin.mail_methods.testmail.error') % { e: e } ensure redirect_to edit_admin_mail_method_url end private - def initialize_mail_settings - Spree::Core::MailSettings.init - end + + def initialize_mail_settings + Spree::Core::MailSettings.init + end end end end From 2377b833ee29218f97f89c470d439cef1c79f52d Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:02:37 +0100 Subject: [PATCH 03/18] Bring general settings and image settings controllers that are overrides in ofn to ofn so we can merge them with their decorators in a second step --- .../admin/general_settings_controller.rb | 34 ++++++++++ .../spree/admin/image_settings_controller.rb | 64 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 app/controllers/spree/admin/general_settings_controller.rb create mode 100644 app/controllers/spree/admin/image_settings_controller.rb diff --git a/app/controllers/spree/admin/general_settings_controller.rb b/app/controllers/spree/admin/general_settings_controller.rb new file mode 100644 index 0000000000..0498839ee0 --- /dev/null +++ b/app/controllers/spree/admin/general_settings_controller.rb @@ -0,0 +1,34 @@ +module Spree + module Admin + class GeneralSettingsController < Spree::Admin::BaseController + + def edit + @preferences_general = [:site_name, :default_seo_title, :default_meta_keywords, + :default_meta_description, :site_url] + @preferences_security = [:allow_ssl_in_production, + :allow_ssl_in_staging, :allow_ssl_in_development_and_test, + :check_for_spree_alerts] + @preferences_currency = [:display_currency, :hide_cents] + end + + def update + params.each do |name, value| + next unless Spree::Config.has_preference? name + Spree::Config[name] = value + end + flash[:success] = Spree.t(:successfully_updated, :resource => Spree.t(:general_settings)) + + redirect_to edit_admin_general_settings_path + end + + def dismiss_alert + if request.xhr? and params[:alert_id] + dismissed = Spree::Config[:dismissed_spree_alerts] || '' + Spree::Config.set :dismissed_spree_alerts => dismissed.split(',').push(params[:alert_id]).join(',') + filter_dismissed_alerts + render :nothing => true + end + end + end + end +end diff --git a/app/controllers/spree/admin/image_settings_controller.rb b/app/controllers/spree/admin/image_settings_controller.rb new file mode 100644 index 0000000000..d65350eace --- /dev/null +++ b/app/controllers/spree/admin/image_settings_controller.rb @@ -0,0 +1,64 @@ +module Spree + module Admin + class ImageSettingsController < Spree::Admin::BaseController + def edit + @styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) + @headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) + end + + def update + update_styles(params) + update_headers(params) if Spree::Config[:use_s3] + + Spree::Config.set(params[:preferences]) + update_paperclip_settings + + respond_to do |format| + format.html { + flash[:success] = Spree.t(:image_settings_updated) + redirect_to spree.edit_admin_image_settings_path + } + end + end + + private + + def update_styles(params) + params[:new_attachment_styles].each do |index, style| + params[:attachment_styles][style[:name]] = style[:value] unless style[:value].empty? + end if params[:new_attachment_styles].present? + + styles = params[:attachment_styles] + + Spree::Config[:attachment_styles] = ActiveSupport::JSON.encode(styles) unless styles.nil? + end + + def update_headers(params) + params[:new_s3_headers].each do |index, header| + params[:s3_headers][header[:name]] = header[:value] unless header[:value].empty? + end if params[:new_s3_headers].present? + + headers = params[:s3_headers] + + Spree::Config[:s3_headers] = ActiveSupport::JSON.encode(headers) unless headers.nil? + end + + def update_paperclip_settings + if Spree::Config[:use_s3] + s3_creds = { :access_key_id => Spree::Config[:s3_access_key], :secret_access_key => Spree::Config[:s3_secret], :bucket => Spree::Config[:s3_bucket] } + Spree::Image.attachment_definitions[:attachment][:storage] = :s3 + Spree::Image.attachment_definitions[:attachment][:s3_credentials] = s3_creds + Spree::Image.attachment_definitions[:attachment][:s3_headers] = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) + Spree::Image.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket] + else + Spree::Image.attachment_definitions[:attachment].delete :storage + end + + Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]).symbolize_keys! + Spree::Image.attachment_definitions[:attachment][:path] = Spree::Config[:attachment_path] + Spree::Image.attachment_definitions[:attachment][:default_url] = Spree::Config[:attachment_default_url] + Spree::Image.attachment_definitions[:attachment][:default_style] = Spree::Config[:attachment_default_style] + end + end + end +end From 686840e2627cc712ef817bae4d3d4e9796d15d46 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:12:25 +0100 Subject: [PATCH 04/18] Fix basic rubocop issues in recently added controllers from spree_backend --- .../admin/general_settings_controller.rb | 23 ++++++------- .../spree/admin/image_settings_controller.rb | 32 ++++++++++++------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/app/controllers/spree/admin/general_settings_controller.rb b/app/controllers/spree/admin/general_settings_controller.rb index 0498839ee0..6d2475c8cf 100644 --- a/app/controllers/spree/admin/general_settings_controller.rb +++ b/app/controllers/spree/admin/general_settings_controller.rb @@ -1,13 +1,12 @@ module Spree module Admin class GeneralSettingsController < Spree::Admin::BaseController - def edit @preferences_general = [:site_name, :default_seo_title, :default_meta_keywords, - :default_meta_description, :site_url] + :default_meta_description, :site_url] @preferences_security = [:allow_ssl_in_production, - :allow_ssl_in_staging, :allow_ssl_in_development_and_test, - :check_for_spree_alerts] + :allow_ssl_in_staging, :allow_ssl_in_development_and_test, + :check_for_spree_alerts] @preferences_currency = [:display_currency, :hide_cents] end @@ -16,18 +15,20 @@ module Spree next unless Spree::Config.has_preference? name Spree::Config[name] = value end - flash[:success] = Spree.t(:successfully_updated, :resource => Spree.t(:general_settings)) + flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings)) redirect_to edit_admin_general_settings_path end def dismiss_alert - if request.xhr? and params[:alert_id] - dismissed = Spree::Config[:dismissed_spree_alerts] || '' - Spree::Config.set :dismissed_spree_alerts => dismissed.split(',').push(params[:alert_id]).join(',') - filter_dismissed_alerts - render :nothing => true - end + return unless request.xhr? && params[:alert_id] + dismissed = Spree::Config[:dismissed_spree_alerts] || '' + Spree::Config.set(dismissed_spree_alerts: dismissed. + split(','). + push(params[:alert_id]). + join(',')) + filter_dismissed_alerts + render nothing: true end end end diff --git a/app/controllers/spree/admin/image_settings_controller.rb b/app/controllers/spree/admin/image_settings_controller.rb index d65350eace..da7b8ce4f9 100644 --- a/app/controllers/spree/admin/image_settings_controller.rb +++ b/app/controllers/spree/admin/image_settings_controller.rb @@ -24,9 +24,11 @@ module Spree private def update_styles(params) - params[:new_attachment_styles].each do |index, style| - params[:attachment_styles][style[:name]] = style[:value] unless style[:value].empty? - end if params[:new_attachment_styles].present? + if params[:new_attachment_styles].present? + params[:new_attachment_styles].each do |_index, style| + params[:attachment_styles][style[:name]] = style[:value] unless style[:value].empty? + end + end styles = params[:attachment_styles] @@ -34,9 +36,11 @@ module Spree end def update_headers(params) - params[:new_s3_headers].each do |index, header| - params[:s3_headers][header[:name]] = header[:value] unless header[:value].empty? - end if params[:new_s3_headers].present? + if params[:new_s3_headers].present? + params[:new_s3_headers].each do |_index, header| + params[:s3_headers][header[:name]] = header[:value] unless header[:value].empty? + end + end headers = params[:s3_headers] @@ -45,19 +49,25 @@ module Spree def update_paperclip_settings if Spree::Config[:use_s3] - s3_creds = { :access_key_id => Spree::Config[:s3_access_key], :secret_access_key => Spree::Config[:s3_secret], :bucket => Spree::Config[:s3_bucket] } + s3_creds = { access_key_id: Spree::Config[:s3_access_key], + secret_access_key: Spree::Config[:s3_secret], + bucket: Spree::Config[:s3_bucket] } Spree::Image.attachment_definitions[:attachment][:storage] = :s3 Spree::Image.attachment_definitions[:attachment][:s3_credentials] = s3_creds - Spree::Image.attachment_definitions[:attachment][:s3_headers] = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) + Spree::Image.attachment_definitions[:attachment][:s3_headers] = + ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) Spree::Image.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket] else Spree::Image.attachment_definitions[:attachment].delete :storage end - Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]).symbolize_keys! + Spree::Image.attachment_definitions[:attachment][:styles] = + ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]).symbolize_keys! Spree::Image.attachment_definitions[:attachment][:path] = Spree::Config[:attachment_path] - Spree::Image.attachment_definitions[:attachment][:default_url] = Spree::Config[:attachment_default_url] - Spree::Image.attachment_definitions[:attachment][:default_style] = Spree::Config[:attachment_default_style] + Spree::Image.attachment_definitions[:attachment][:default_url] = + Spree::Config[:attachment_default_url] + Spree::Image.attachment_definitions[:attachment][:default_style] = + Spree::Config[:attachment_default_style] end end end From 7f9f0d840c2fb4063c63da8c06ab11b9b447d69c Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 20 Sep 2019 14:36:40 +0100 Subject: [PATCH 05/18] Merge decorators into controllers and remove decorators --- .../spree/admin/general_settings_controller.rb | 2 +- .../admin/general_settings_controller_decorator.rb | 14 -------------- .../spree/admin/image_settings_controller.rb | 5 +++++ .../admin/image_settings_controller_decorator.rb | 11 ----------- 4 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 app/controllers/spree/admin/general_settings_controller_decorator.rb delete mode 100644 app/controllers/spree/admin/image_settings_controller_decorator.rb diff --git a/app/controllers/spree/admin/general_settings_controller.rb b/app/controllers/spree/admin/general_settings_controller.rb index 6d2475c8cf..7389ee0890 100644 --- a/app/controllers/spree/admin/general_settings_controller.rb +++ b/app/controllers/spree/admin/general_settings_controller.rb @@ -3,7 +3,7 @@ module Spree class GeneralSettingsController < Spree::Admin::BaseController def edit @preferences_general = [:site_name, :default_seo_title, :default_meta_keywords, - :default_meta_description, :site_url] + :default_meta_description, :site_url, :bugherd_api_key] @preferences_security = [:allow_ssl_in_production, :allow_ssl_in_staging, :allow_ssl_in_development_and_test, :check_for_spree_alerts] diff --git a/app/controllers/spree/admin/general_settings_controller_decorator.rb b/app/controllers/spree/admin/general_settings_controller_decorator.rb deleted file mode 100644 index 7e6c1fc71a..0000000000 --- a/app/controllers/spree/admin/general_settings_controller_decorator.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Spree - module Admin - GeneralSettingsController.class_eval do - end - - module GeneralSettingsEditPreferences - def edit - super - @preferences_general << :bugherd_api_key - end - end - GeneralSettingsController.prepend(GeneralSettingsEditPreferences) - end -end diff --git a/app/controllers/spree/admin/image_settings_controller.rb b/app/controllers/spree/admin/image_settings_controller.rb index da7b8ce4f9..32aae5c783 100644 --- a/app/controllers/spree/admin/image_settings_controller.rb +++ b/app/controllers/spree/admin/image_settings_controller.rb @@ -68,6 +68,11 @@ module Spree Spree::Config[:attachment_default_url] Spree::Image.attachment_definitions[:attachment][:default_style] = Spree::Config[:attachment_default_style] + + # Spree stores attachent definitions in JSON. This converts the style name and format to + # strings. However, when paperclip encounters these, it doesn't recognise the format. + # Here we solve that problem by converting format and style name to symbols. + Spree::Image.reformat_styles end end end diff --git a/app/controllers/spree/admin/image_settings_controller_decorator.rb b/app/controllers/spree/admin/image_settings_controller_decorator.rb deleted file mode 100644 index 5fe7dae551..0000000000 --- a/app/controllers/spree/admin/image_settings_controller_decorator.rb +++ /dev/null @@ -1,11 +0,0 @@ -Spree::Admin::ImageSettingsController.class_eval do - # Spree stores attachent definitions in JSON. This converts the style name and format to - # strings. However, when paperclip encounters these, it doesn't recognise the format. - # Here we solve that problem by converting format and style name to symbols. - def update_paperclip_settings_with_format_styles - update_paperclip_settings_without_format_styles - Spree::Image.reformat_styles - end - - alias_method_chain :update_paperclip_settings, :format_styles -end From 96737da1287f6809498f1dbd420b04e38f147202 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:23:39 +0100 Subject: [PATCH 06/18] Add spree_backend mail methods views that are missing in ofn --- .../spree/admin/mail_methods/_form.html.erb | 76 +++++++++++++++++++ .../spree/admin/mail_methods/edit.html.erb | 21 +++++ 2 files changed, 97 insertions(+) create mode 100644 app/views/spree/admin/mail_methods/_form.html.erb create mode 100644 app/views/spree/admin/mail_methods/edit.html.erb diff --git a/app/views/spree/admin/mail_methods/_form.html.erb b/app/views/spree/admin/mail_methods/_form.html.erb new file mode 100644 index 0000000000..f9062582df --- /dev/null +++ b/app/views/spree/admin/mail_methods/_form.html.erb @@ -0,0 +1,76 @@ +
+
+ +
+
+ <%= Spree.t(:general) %> + +
+ <%= preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], :type => :boolean) %> + <%= label_tag :enable_mail_delivery, Spree.t(:enable_mail_delivery) %> +
+ +
+ <%= label_tag :mails_from, Spree.t(:send_mails_as) %>
+ <%= text_field_tag :mails_from, Spree::Config[:mails_from], :maxlength => 256, :class => 'fullwidth' %> +
+ + <%= Spree.t(:smtp_send_all_emails_as_from_following_address) %> + +
+ +
+ <%= label_tag :mail_bcc, Spree.t(:send_copy_of_all_mails_to) %>
+ <%= text_field_tag :mail_bcc, Spree::Config[:mail_bcc], :maxlength => 256, :class => 'fullwidth' %> +
+ + <%= Spree.t(:smtp_send_copy_to_this_addresses) %> + +
+ +
+ <%= label_tag :intercept_email, Spree.t(:intercept_email_address) %>
+ <%= text_field_tag :intercept_email, Spree::Config[:intercept_email], :maxlength => 256, :class => 'fullwidth' %> +
+ + <%= Spree.t(:intercept_email_instructions) %> + +
+
+
+ +
+
+ <%= Spree.t(:smtp) %> +
+ <%= label_tag :mail_domain, Spree.t(:smtp_domain) %>
+ <%= text_field_tag :mail_domain, Spree::Config[:mail_domain], :class => 'fullwidth' %> +
+
+ <%= label_tag :mail_host, Spree.t(:smtp_mail_host) %>
+ <%= text_field_tag :mail_host, Spree::Config[:mail_host], :class => 'fullwidth' %> +
+
+ <%= label_tag :mail_port, Spree.t(:smtp_port) %>
+ <%= text_field_tag :mail_port, Spree::Config[:mail_port], :class => 'fullwidth' %> +
+
+ <%= label_tag :secure_connection_type, Spree.t(:secure_connection_type) %>
+ <%= select_tag(:secure_connection_type, options_from_collection_for_select(Spree::Core::MailSettings::SECURE_CONNECTION_TYPES.map{|w| Spree.t(w.downcase.to_sym, :default => w)}, :to_s, :to_s, Spree::Config[:secure_connection_type]), :class => 'select2 fullwidth') %> +
+
+ <%= label_tag :mail_auth_type, Spree.t(:smtp_authentication_type) %>
+ <%= select_tag(:mail_auth_type, options_from_collection_for_select(Spree::Core::MailSettings::MAIL_AUTH.map{|w| Spree.t(w.downcase.to_sym, :default => w)}, :to_s, :to_s, Spree::Config[:mail_auth_type]), :class => 'select2 fullwidth') %> +
+
+ <%= label_tag :smtp_username, Spree.t(:smtp_username) %>
+ <%= text_field_tag :smtp_username, Spree::Config[:smtp_username], :class => 'fullwidth' %> +
+
+ <%= label_tag :preferred_smtp_password, Spree.t(:smtp_password) %>
+ <%= password_field_tag :smtp_password, Spree::Config[:smtp_password], :class => 'fullwidth' %> +
+
+
+
+
diff --git a/app/views/spree/admin/mail_methods/edit.html.erb b/app/views/spree/admin/mail_methods/edit.html.erb new file mode 100644 index 0000000000..9519360d9f --- /dev/null +++ b/app/views/spree/admin/mail_methods/edit.html.erb @@ -0,0 +1,21 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:mail_method_settings) %> +<% end %> + +<% content_for :page_actions do %> +
  • + <%= link_to_with_icon 'icon-envelope-alt', Spree.t('admin.mail_methods.send_testmail'), testmail_admin_mail_method_path, + :method => :post, :title => Spree.t('admin.mail_methods.send_testmail'), :class => 'send_mail button no-text' %> +
  • +<% end %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @mail_method } %> + +<%= form_tag admin_mail_method_path, :method => :put do |f| %> +
    + <%= render :partial => 'form', :locals => { :f => f } %> +
    <%= button Spree.t('actions.update'), 'icon-refresh' %>
    +
    +<% end %> From 42e3f2f2f41df348ffb4b94ee3ea4be73f2d967f Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:42:54 +0100 Subject: [PATCH 07/18] Convert spree/admin/mail_methods from erb to haml --- .../spree/admin/mail_methods/_form.html.erb | 76 ------------------- .../spree/admin/mail_methods/_form.html.haml | 60 +++++++++++++++ .../spree/admin/mail_methods/edit.html.erb | 21 ----- .../spree/admin/mail_methods/edit.html.haml | 15 ++++ 4 files changed, 75 insertions(+), 97 deletions(-) delete mode 100644 app/views/spree/admin/mail_methods/_form.html.erb create mode 100644 app/views/spree/admin/mail_methods/_form.html.haml delete mode 100644 app/views/spree/admin/mail_methods/edit.html.erb create mode 100644 app/views/spree/admin/mail_methods/edit.html.haml diff --git a/app/views/spree/admin/mail_methods/_form.html.erb b/app/views/spree/admin/mail_methods/_form.html.erb deleted file mode 100644 index f9062582df..0000000000 --- a/app/views/spree/admin/mail_methods/_form.html.erb +++ /dev/null @@ -1,76 +0,0 @@ -
    -
    - -
    -
    - <%= Spree.t(:general) %> - -
    - <%= preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], :type => :boolean) %> - <%= label_tag :enable_mail_delivery, Spree.t(:enable_mail_delivery) %> -
    - -
    - <%= label_tag :mails_from, Spree.t(:send_mails_as) %>
    - <%= text_field_tag :mails_from, Spree::Config[:mails_from], :maxlength => 256, :class => 'fullwidth' %> -
    - - <%= Spree.t(:smtp_send_all_emails_as_from_following_address) %> - -
    - -
    - <%= label_tag :mail_bcc, Spree.t(:send_copy_of_all_mails_to) %>
    - <%= text_field_tag :mail_bcc, Spree::Config[:mail_bcc], :maxlength => 256, :class => 'fullwidth' %> -
    - - <%= Spree.t(:smtp_send_copy_to_this_addresses) %> - -
    - -
    - <%= label_tag :intercept_email, Spree.t(:intercept_email_address) %>
    - <%= text_field_tag :intercept_email, Spree::Config[:intercept_email], :maxlength => 256, :class => 'fullwidth' %> -
    - - <%= Spree.t(:intercept_email_instructions) %> - -
    -
    -
    - -
    -
    - <%= Spree.t(:smtp) %> -
    - <%= label_tag :mail_domain, Spree.t(:smtp_domain) %>
    - <%= text_field_tag :mail_domain, Spree::Config[:mail_domain], :class => 'fullwidth' %> -
    -
    - <%= label_tag :mail_host, Spree.t(:smtp_mail_host) %>
    - <%= text_field_tag :mail_host, Spree::Config[:mail_host], :class => 'fullwidth' %> -
    -
    - <%= label_tag :mail_port, Spree.t(:smtp_port) %>
    - <%= text_field_tag :mail_port, Spree::Config[:mail_port], :class => 'fullwidth' %> -
    -
    - <%= label_tag :secure_connection_type, Spree.t(:secure_connection_type) %>
    - <%= select_tag(:secure_connection_type, options_from_collection_for_select(Spree::Core::MailSettings::SECURE_CONNECTION_TYPES.map{|w| Spree.t(w.downcase.to_sym, :default => w)}, :to_s, :to_s, Spree::Config[:secure_connection_type]), :class => 'select2 fullwidth') %> -
    -
    - <%= label_tag :mail_auth_type, Spree.t(:smtp_authentication_type) %>
    - <%= select_tag(:mail_auth_type, options_from_collection_for_select(Spree::Core::MailSettings::MAIL_AUTH.map{|w| Spree.t(w.downcase.to_sym, :default => w)}, :to_s, :to_s, Spree::Config[:mail_auth_type]), :class => 'select2 fullwidth') %> -
    -
    - <%= label_tag :smtp_username, Spree.t(:smtp_username) %>
    - <%= text_field_tag :smtp_username, Spree::Config[:smtp_username], :class => 'fullwidth' %> -
    -
    - <%= label_tag :preferred_smtp_password, Spree.t(:smtp_password) %>
    - <%= password_field_tag :smtp_password, Spree::Config[:smtp_password], :class => 'fullwidth' %> -
    -
    -
    -
    -
    diff --git a/app/views/spree/admin/mail_methods/_form.html.haml b/app/views/spree/admin/mail_methods/_form.html.haml new file mode 100644 index 0000000000..670e37140e --- /dev/null +++ b/app/views/spree/admin/mail_methods/_form.html.haml @@ -0,0 +1,60 @@ +%div + .row + .alpha.six.columns + %fieldset.no-border-bottom + %legend{align: "center"}= t("spree.general") + .field + = preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], type: :boolean) + = label_tag :enable_mail_delivery, t("spree.enable_mail_delivery") + .field + = label_tag :mails_from, t("spree.send_mails_as") + %br/ + = text_field_tag :mails_from, Spree::Config[:mails_from], maxlength: 256, class: 'fullwidth' + %br/ + %span.info + = t("spree.smtp_send_all_emails_as_from_following_address") + .field + = label_tag :mail_bcc, t("spree.send_copy_of_all_mails_to") + %br/ + = text_field_tag :mail_bcc, Spree::Config[:mail_bcc], maxlength: 256, class: 'fullwidth' + %br/ + %span.info + = t("spree.smtp_send_copy_to_this_addresses") + .field + = label_tag :intercept_email, t("spree.intercept_email_address") + %br/ + = text_field_tag :intercept_email, Spree::Config[:intercept_email], maxlength: 256, class: 'fullwidth' + %br/ + %span.info + = t("spree.intercept_email_instructions") + .six.columns.omega + %fieldset.no-border-bottom + %legend{align: "center"}= t("spree.smtp") + .field + = label_tag :mail_domain, t("spree.smtp_domain") + %br/ + = text_field_tag :mail_domain, Spree::Config[:mail_domain], class: 'fullwidth' + .field + = label_tag :mail_host, t("spree.smtp_mail_host") + %br/ + = text_field_tag :mail_host, Spree::Config[:mail_host], class: 'fullwidth' + .field + = label_tag :mail_port, t("spree.smtp_port") + %br/ + = text_field_tag :mail_port, Spree::Config[:mail_port], class: 'fullwidth' + .field + = label_tag :secure_connection_type, t("spree.secure_connection_type") + %br/ + = select_tag(:secure_connection_type, options_from_collection_for_select(Spree::Core::MailSettings::SECURE_CONNECTION_TYPES.map{|w| Spree.t(w.downcase.to_sym, default: w)}, :to_s, :to_s, Spree::Config[:secure_connection_type]), class: 'select2 fullwidth') + .field + = label_tag :mail_auth_type, t("spree.smtp_authentication_type") + %br/ + = select_tag(:mail_auth_type, options_from_collection_for_select(Spree::Core::MailSettings::MAIL_AUTH.map{|w| Spree.t(w.downcase.to_sym, default: w)}, :to_s, :to_s, Spree::Config[:mail_auth_type]), class: 'select2 fullwidth') + .field + = label_tag :smtp_username, t("spree.smtp_username") + %br/ + = text_field_tag :smtp_username, Spree::Config[:smtp_username], class: 'fullwidth' + .field + = label_tag :preferred_smtp_password, t("spree.smtp_password") + %br/ + = password_field_tag :smtp_password, Spree::Config[:smtp_password], class: 'fullwidth' diff --git a/app/views/spree/admin/mail_methods/edit.html.erb b/app/views/spree/admin/mail_methods/edit.html.erb deleted file mode 100644 index 9519360d9f..0000000000 --- a/app/views/spree/admin/mail_methods/edit.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:mail_method_settings) %> -<% end %> - -<% content_for :page_actions do %> -
  • - <%= link_to_with_icon 'icon-envelope-alt', Spree.t('admin.mail_methods.send_testmail'), testmail_admin_mail_method_path, - :method => :post, :title => Spree.t('admin.mail_methods.send_testmail'), :class => 'send_mail button no-text' %> -
  • -<% end %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @mail_method } %> - -<%= form_tag admin_mail_method_path, :method => :put do |f| %> -
    - <%= render :partial => 'form', :locals => { :f => f } %> -
    <%= button Spree.t('actions.update'), 'icon-refresh' %>
    -
    -<% end %> diff --git a/app/views/spree/admin/mail_methods/edit.html.haml b/app/views/spree/admin/mail_methods/edit.html.haml new file mode 100644 index 0000000000..90938e4542 --- /dev/null +++ b/app/views/spree/admin/mail_methods/edit.html.haml @@ -0,0 +1,15 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.mail_method_settings") + +- content_for :page_actions do + %li + = link_to_with_icon 'icon-envelope-alt', t("spree.admin.mail_methods.send_testmail"), testmail_admin_mail_method_path, method: :post, title: t("spree.admin.mail_methods.send_testmail"), class: 'send_mail button no-text' + += render partial: 'spree/shared/error_messages', locals: { target: @mail_method } + += form_tag admin_mail_method_path, method: :put do |f| + %fieldset.no-border-top + = render partial: 'form', locals: { f: f } + .form-buttons.filter-actions.actions= button t("spree.actions.update"), 'icon-refresh' From d31b50be3d056327d31115e64db0901ca2b9f7c5 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 17:45:30 +0100 Subject: [PATCH 08/18] Bring spree/admin configuration routes to ofn --- config/routes/spree.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/config/routes/spree.rb b/config/routes/spree.rb index 68a1dd9dda..77a954081e 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -90,6 +90,23 @@ Spree::Core::Engine.routes.prepend do end # Configuration section + resource :general_settings do + collection do + post :dismiss_alert + end + end + resource :mail_method, :only => [:edit, :update] do + post :testmail, :on => :collection + end + + resource :image_settings + + resources :zones + resources :countries do + resources :states + end + resources :states + resources :taxonomies do collection do post :update_positions @@ -109,12 +126,6 @@ Spree::Core::Engine.routes.prepend do resources :tax_rates resource :tax_settings resources :tax_categories - - resources :zones - resources :countries do - resources :states - end - resources :states end resources :orders do From b83d74a609c41f42196765104259ef8e4fea997f Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 20 Sep 2019 14:28:59 +0100 Subject: [PATCH 09/18] Bring general_settings_helper from spree_backend --- app/helpers/spree/admin/general_settings_helper.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/helpers/spree/admin/general_settings_helper.rb diff --git a/app/helpers/spree/admin/general_settings_helper.rb b/app/helpers/spree/admin/general_settings_helper.rb new file mode 100644 index 0000000000..733c5be254 --- /dev/null +++ b/app/helpers/spree/admin/general_settings_helper.rb @@ -0,0 +1,13 @@ +module Spree + module Admin + module GeneralSettingsHelper + def currency_options + currencies = ::Money::Currency.table.map do |code, details| + iso = details[:iso_code] + [iso, "#{details[:name]} (#{iso})"] + end + options_from_collection_for_select(currencies, :first, :last, Spree::Config[:currency]) + end + end + end +end From 30aa31252b54063f30d336a16c1609ee96571914 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 17:54:29 +0100 Subject: [PATCH 10/18] Fix simple rubocop issues in helpers --- app/helpers/spree/admin/general_settings_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/spree/admin/general_settings_helper.rb b/app/helpers/spree/admin/general_settings_helper.rb index 733c5be254..c1c39ea58a 100644 --- a/app/helpers/spree/admin/general_settings_helper.rb +++ b/app/helpers/spree/admin/general_settings_helper.rb @@ -2,7 +2,7 @@ module Spree module Admin module GeneralSettingsHelper def currency_options - currencies = ::Money::Currency.table.map do |code, details| + currencies = ::Money::Currency.table.map do |_code, details| iso = details[:iso_code] [iso, "#{details[:name]} (#{iso})"] end From 6677543de0dba2aca0a8b435867af604e96efd68 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 17:55:00 +0100 Subject: [PATCH 11/18] bring 2 specs from spree_backend to cover image_settings page and mail_methods page --- .../admin/image_settings_controller_spec.rb | 68 +++++++++++++++++++ .../admin/mail_methods_controller_spec.rb | 24 +++++++ 2 files changed, 92 insertions(+) create mode 100644 spec/controllers/spree/admin/image_settings_controller_spec.rb create mode 100644 spec/controllers/spree/admin/mail_methods_controller_spec.rb diff --git a/spec/controllers/spree/admin/image_settings_controller_spec.rb b/spec/controllers/spree/admin/image_settings_controller_spec.rb new file mode 100644 index 0000000000..ab8d6a77df --- /dev/null +++ b/spec/controllers/spree/admin/image_settings_controller_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Spree::Admin::ImageSettingsController do + stub_authorization! + + context "updating image settings" do + it "should be able to update paperclip settings" do + spree_put :update, { :preferences => { + "attachment_path" => "foo/bar", + "attachment_default_url" => "baz/bar" + } + } + Spree::Config[:attachment_path].should == "foo/bar" + Spree::Config[:attachment_default_url].should == "baz/bar" + end + + context "paperclip styles" do + it "should be able to update the paperclip styles" do + spree_put :update, { "attachment_styles" => { "thumb" => "25x25>" } } + updated_styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) + updated_styles["thumb"].should == "25x25>" + end + + it "should be able to add a new style" do + spree_put :update, { "attachment_styles" => { }, "new_attachment_styles" => { "1" => { "name" => "jumbo", "value" => "2000x2000>" } } } + styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) + styles["jumbo"].should == "2000x2000>" + end + end + + context "amazon s3" do + after(:all) do + Spree::Image.attachment_definitions[:attachment].delete :storage + end + + it "should be able to update s3 settings" do + spree_put :update, { :preferences => { + "use_s3" => "1", + "s3_access_key" => "a_valid_key", + "s3_secret" => "a_secret", + "s3_bucket" => "some_bucket" + } + } + Spree::Config[:use_s3].should be_true + Spree::Config[:s3_access_key].should == "a_valid_key" + Spree::Config[:s3_secret].should == "a_secret" + Spree::Config[:s3_bucket].should == "some_bucket" + end + + context "headers" do + before(:each) { Spree::Config[:use_s3] = true } + + it "should be able to update the s3 headers" do + spree_put :update, { :preferences => { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } } + headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) + headers["Cache-Control"].should == "max-age=1111" + end + + it "should be able to add a new header" do + spree_put :update, { "s3_headers" => { }, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } } + headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) + headers["Charset"].should == "utf-8" + end + end + end + end +end + diff --git a/spec/controllers/spree/admin/mail_methods_controller_spec.rb b/spec/controllers/spree/admin/mail_methods_controller_spec.rb new file mode 100644 index 0000000000..ce01e75864 --- /dev/null +++ b/spec/controllers/spree/admin/mail_methods_controller_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe Spree::Admin::MailMethodsController do + stub_authorization! + + context "#update" do + it "should reinitialize the mail settings" do + Spree::Core::MailSettings.should_receive(:init) + spree_put :update, { :enable_mail_delivery => "1", :mails_from => "spree@example.com" } + end + end + + it "can trigger testmail" do + request.env["HTTP_REFERER"] = "/" + user = double('User', email: 'user@spree.com', spree_api_key: 'fake') + controller.stub(:try_spree_current_user => user) + Spree::Config[:enable_mail_delivery] = "1" + ActionMailer::Base.perform_deliveries = true + + expect { + spree_post :testmail + }.to change { ActionMailer::Base.deliveries.size }.by(1) + end +end From edd84530af4f3728b9d546055f0b307e20b013f4 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:00:51 +0100 Subject: [PATCH 12/18] Fix simle rubocopo issues in image_settings ctrl spec --- .../admin/image_settings_controller_spec.rb | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/controllers/spree/admin/image_settings_controller_spec.rb b/spec/controllers/spree/admin/image_settings_controller_spec.rb index ab8d6a77df..b673e28be6 100644 --- a/spec/controllers/spree/admin/image_settings_controller_spec.rb +++ b/spec/controllers/spree/admin/image_settings_controller_spec.rb @@ -1,28 +1,27 @@ require 'spec_helper' describe Spree::Admin::ImageSettingsController do - stub_authorization! + include AuthenticationWorkflow + + before { login_as_admin } context "updating image settings" do it "should be able to update paperclip settings" do - spree_put :update, { :preferences => { - "attachment_path" => "foo/bar", - "attachment_default_url" => "baz/bar" - } - } + spree_put :update, preferences: { "attachment_path" => "foo/bar", "attachment_default_url" => "baz/bar" } + Spree::Config[:attachment_path].should == "foo/bar" Spree::Config[:attachment_default_url].should == "baz/bar" end context "paperclip styles" do it "should be able to update the paperclip styles" do - spree_put :update, { "attachment_styles" => { "thumb" => "25x25>" } } + spree_put :update, "attachment_styles" => { "thumb" => "25x25>" } updated_styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) updated_styles["thumb"].should == "25x25>" end it "should be able to add a new style" do - spree_put :update, { "attachment_styles" => { }, "new_attachment_styles" => { "1" => { "name" => "jumbo", "value" => "2000x2000>" } } } + spree_put :update, "attachment_styles" => {}, "new_attachment_styles" => { "1" => { "name" => "jumbo", "value" => "2000x2000>" } } styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) styles["jumbo"].should == "2000x2000>" end @@ -34,14 +33,14 @@ describe Spree::Admin::ImageSettingsController do end it "should be able to update s3 settings" do - spree_put :update, { :preferences => { + spree_put :update, preferences: + { "use_s3" => "1", "s3_access_key" => "a_valid_key", "s3_secret" => "a_secret", "s3_bucket" => "some_bucket" - } } - Spree::Config[:use_s3].should be_true + Spree::Config[:use_s3].should be_truthy Spree::Config[:s3_access_key].should == "a_valid_key" Spree::Config[:s3_secret].should == "a_secret" Spree::Config[:s3_bucket].should == "some_bucket" @@ -51,13 +50,13 @@ describe Spree::Admin::ImageSettingsController do before(:each) { Spree::Config[:use_s3] = true } it "should be able to update the s3 headers" do - spree_put :update, { :preferences => { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } } + spree_put :update, preferences: { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) headers["Cache-Control"].should == "max-age=1111" end it "should be able to add a new header" do - spree_put :update, { "s3_headers" => { }, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } } + spree_put :update, "s3_headers" => {}, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) headers["Charset"].should == "utf-8" end @@ -65,4 +64,3 @@ describe Spree::Admin::ImageSettingsController do end end end - From 05d24cf11a1c72f95ea4e347280e9afa968aeb5d Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:02:03 +0100 Subject: [PATCH 13/18] Transpec image_setting_controller_spec --- .../admin/image_settings_controller_spec.rb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/controllers/spree/admin/image_settings_controller_spec.rb b/spec/controllers/spree/admin/image_settings_controller_spec.rb index b673e28be6..d808743ac7 100644 --- a/spec/controllers/spree/admin/image_settings_controller_spec.rb +++ b/spec/controllers/spree/admin/image_settings_controller_spec.rb @@ -9,21 +9,21 @@ describe Spree::Admin::ImageSettingsController do it "should be able to update paperclip settings" do spree_put :update, preferences: { "attachment_path" => "foo/bar", "attachment_default_url" => "baz/bar" } - Spree::Config[:attachment_path].should == "foo/bar" - Spree::Config[:attachment_default_url].should == "baz/bar" + expect(Spree::Config[:attachment_path]).to eq("foo/bar") + expect(Spree::Config[:attachment_default_url]).to eq("baz/bar") end context "paperclip styles" do it "should be able to update the paperclip styles" do spree_put :update, "attachment_styles" => { "thumb" => "25x25>" } updated_styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) - updated_styles["thumb"].should == "25x25>" + expect(updated_styles["thumb"]).to eq("25x25>") end it "should be able to add a new style" do spree_put :update, "attachment_styles" => {}, "new_attachment_styles" => { "1" => { "name" => "jumbo", "value" => "2000x2000>" } } styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) - styles["jumbo"].should == "2000x2000>" + expect(styles["jumbo"]).to eq("2000x2000>") end end @@ -40,10 +40,10 @@ describe Spree::Admin::ImageSettingsController do "s3_secret" => "a_secret", "s3_bucket" => "some_bucket" } - Spree::Config[:use_s3].should be_truthy - Spree::Config[:s3_access_key].should == "a_valid_key" - Spree::Config[:s3_secret].should == "a_secret" - Spree::Config[:s3_bucket].should == "some_bucket" + expect(Spree::Config[:use_s3]).to be_truthy + expect(Spree::Config[:s3_access_key]).to eq("a_valid_key") + expect(Spree::Config[:s3_secret]).to eq("a_secret") + expect(Spree::Config[:s3_bucket]).to eq("some_bucket") end context "headers" do @@ -52,13 +52,13 @@ describe Spree::Admin::ImageSettingsController do it "should be able to update the s3 headers" do spree_put :update, preferences: { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) - headers["Cache-Control"].should == "max-age=1111" + expect(headers["Cache-Control"]).to eq("max-age=1111") end it "should be able to add a new header" do spree_put :update, "s3_headers" => {}, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) - headers["Charset"].should == "utf-8" + expect(headers["Charset"]).to eq("utf-8") end end end From 495de376201ca8ae67eeae93834e7ecebd751516 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:03:47 +0100 Subject: [PATCH 14/18] Fix more rubocop issues in image_settings_controller_spec --- .../spree/admin/image_settings_controller_spec.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/controllers/spree/admin/image_settings_controller_spec.rb b/spec/controllers/spree/admin/image_settings_controller_spec.rb index d808743ac7..8582b19eeb 100644 --- a/spec/controllers/spree/admin/image_settings_controller_spec.rb +++ b/spec/controllers/spree/admin/image_settings_controller_spec.rb @@ -7,7 +7,8 @@ describe Spree::Admin::ImageSettingsController do context "updating image settings" do it "should be able to update paperclip settings" do - spree_put :update, preferences: { "attachment_path" => "foo/bar", "attachment_default_url" => "baz/bar" } + spree_put :update, preferences: { "attachment_path" => "foo/bar", + "attachment_default_url" => "baz/bar" } expect(Spree::Config[:attachment_path]).to eq("foo/bar") expect(Spree::Config[:attachment_default_url]).to eq("baz/bar") @@ -21,7 +22,9 @@ describe Spree::Admin::ImageSettingsController do end it "should be able to add a new style" do - spree_put :update, "attachment_styles" => {}, "new_attachment_styles" => { "1" => { "name" => "jumbo", "value" => "2000x2000>" } } + spree_put :update, "attachment_styles" => {}, + "new_attachment_styles" => { "1" => { "name" => "jumbo", + "value" => "2000x2000>" } } styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles]) expect(styles["jumbo"]).to eq("2000x2000>") end @@ -50,13 +53,16 @@ describe Spree::Admin::ImageSettingsController do before(:each) { Spree::Config[:use_s3] = true } it "should be able to update the s3 headers" do - spree_put :update, preferences: { "use_s3" => "1" }, "s3_headers" => { "Cache-Control" => "max-age=1111" } + spree_put :update, "preferences" => { "use_s3" => "1" }, + "s3_headers" => { "Cache-Control" => "max-age=1111" } headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) expect(headers["Cache-Control"]).to eq("max-age=1111") end it "should be able to add a new header" do - spree_put :update, "s3_headers" => {}, "new_s3_headers" => { "1" => { "name" => "Charset", "value" => "utf-8" } } + spree_put :update, "s3_headers" => {}, + "new_s3_headers" => { "1" => { "name" => "Charset", + "value" => "utf-8" } } headers = ActiveSupport::JSON.decode(Spree::Config[:s3_headers]) expect(headers["Charset"]).to eq("utf-8") end From 713769b4975023705a17951f236091c85e06848b Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:18:26 +0100 Subject: [PATCH 15/18] Fix rubocop issues in mail_methods_controller_spec --- .../spree/admin/mail_methods_controller_spec.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/controllers/spree/admin/mail_methods_controller_spec.rb b/spec/controllers/spree/admin/mail_methods_controller_spec.rb index ce01e75864..b58fc75da5 100644 --- a/spec/controllers/spree/admin/mail_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/mail_methods_controller_spec.rb @@ -1,19 +1,25 @@ require 'spec_helper' describe Spree::Admin::MailMethodsController do - stub_authorization! + include AuthenticationWorkflow + + before { login_as_admin } context "#update" do it "should reinitialize the mail settings" do - Spree::Core::MailSettings.should_receive(:init) - spree_put :update, { :enable_mail_delivery => "1", :mails_from => "spree@example.com" } + expect(Spree::Core::MailSettings).to receive(:init) + spree_put :update, enable_mail_delivery: "1", mails_from: "spree@example.com" end end it "can trigger testmail" do request.env["HTTP_REFERER"] = "/" - user = double('User', email: 'user@spree.com', spree_api_key: 'fake') - controller.stub(:try_spree_current_user => user) + user = double('User', email: 'user@spree.com', + spree_api_key: 'fake', + id: nil, + owned_groups: nil) + allow(user).to receive_messages(enterprises: [create(:enterprise)], has_spree_role?: true) + allow(controller).to receive_messages(try_spree_current_user: user) Spree::Config[:enable_mail_delivery] = "1" ActionMailer::Base.perform_deliveries = true From 32a7f13dd2e9402b25be59763d4464a2274c9717 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:21:14 +0100 Subject: [PATCH 16/18] Bring feature specs for configuration pages from spree_backend --- .../configuration/general_settings_spec.rb | 38 ++++++++++++++++++ .../configuration/image_settings_spec.rb | 40 +++++++++++++++++++ .../admin/configuration/mail_methods_spec.rb | 32 +++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 spec/features/admin/configuration/general_settings_spec.rb create mode 100644 spec/features/admin/configuration/image_settings_spec.rb create mode 100644 spec/features/admin/configuration/mail_methods_spec.rb diff --git a/spec/features/admin/configuration/general_settings_spec.rb b/spec/features/admin/configuration/general_settings_spec.rb new file mode 100644 index 0000000000..60c8be824e --- /dev/null +++ b/spec/features/admin/configuration/general_settings_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe "General Settings" do + include AuthenticationWorkflow + + before(:each) do + quick_login_as_admin + visit spree.admin_path + click_link "Configuration" + click_link "General Settings" + end + + context "visiting general settings (admin)" do + it "should have the right content" do + page.should have_content("General Settings") + find("#site_name").value.should == "Spree Demo Site" + find("#site_url").value.should == "demo.spreecommerce.com" + end + end + + context "editing general settings (admin)" do + it "should be able to update the site name" do + fill_in "site_name", :with => "Spree Demo Site99" + click_button "Update" + + assert_successful_update_message(:general_settings) + + find("#site_name").value.should == "Spree Demo Site99" + end + + def assert_successful_update_message(resource) + flash = Spree.t(:successfully_updated, resource: Spree.t(resource)) + within("[class='flash success']") do + page.should have_content(flash) + end + end + end +end diff --git a/spec/features/admin/configuration/image_settings_spec.rb b/spec/features/admin/configuration/image_settings_spec.rb new file mode 100644 index 0000000000..5f0ded6f9b --- /dev/null +++ b/spec/features/admin/configuration/image_settings_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe "image settings" do + include AuthenticationWorkflow + + before do + quick_login_as_admin + visit spree.admin_path + click_link "Configuration" + click_link "Image Settings" + end + + # Regression test for #2344 + it "can update attachment_url" do + fill_in "Attachments URL", :with => "foobar" + fill_in "Attachments Default URL", :with => "barfoo" + fill_in "Attachments Path", :with => "spec/dummy/tmp/bfaoro" + click_button "Update" + + Spree::Config[:attachment_url].should == "foobar" + Spree::Config[:attachment_default_url].should == "barfoo" + Spree::Config[:attachment_path].should == "spec/dummy/tmp/bfaoro" + end + + # Regression test for #3069 + context "updates style configs and uploads products" do + let!(:product) { create(:product) } + let(:file_path) { Rails.root + "spec/support/fixtures/thinking-cat.jpg" } + + it "still uploads image gracefully" do + click_button "Update" + + visit spree.new_admin_product_image_path(product) + attach_file('image_attachment', file_path) + expect { + click_on "Update" + }.to_not raise_error + end + end +end diff --git a/spec/features/admin/configuration/mail_methods_spec.rb b/spec/features/admin/configuration/mail_methods_spec.rb new file mode 100644 index 0000000000..7ffd66f135 --- /dev/null +++ b/spec/features/admin/configuration/mail_methods_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe "Mail Methods" do + include AuthenticationWorkflow + + before(:each) do + quick_login_as_admin + visit spree.admin_path + click_link "Configuration" + end + + context "edit" do + before(:each) do + click_link "Mail Method Settings" + end + + it "should be able to edit mail method settings" do + fill_in "mail_bcc", :with => "spree@example.com99" + click_button "Update" + page.should have_content("successfully updated!") + end + + # Regression test for #2094 + it "does not clear password if not provided" do + Spree::Config[:smtp_password] = "haxme" + click_button "Update" + page.should have_content("successfully updated!") + + Spree::Config[:smtp_password].should_not be_blank + end + end +end From b712ec7f130ffe2c33b86c579819851eee27f7f5 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:52:45 +0100 Subject: [PATCH 17/18] Transpec feature specs brought from spre_backend --- .../admin/configuration/general_settings_spec.rb | 10 +++++----- .../admin/configuration/image_settings_spec.rb | 6 +++--- spec/features/admin/configuration/mail_methods_spec.rb | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/features/admin/configuration/general_settings_spec.rb b/spec/features/admin/configuration/general_settings_spec.rb index 60c8be824e..f066c26340 100644 --- a/spec/features/admin/configuration/general_settings_spec.rb +++ b/spec/features/admin/configuration/general_settings_spec.rb @@ -12,9 +12,9 @@ describe "General Settings" do context "visiting general settings (admin)" do it "should have the right content" do - page.should have_content("General Settings") - find("#site_name").value.should == "Spree Demo Site" - find("#site_url").value.should == "demo.spreecommerce.com" + expect(page).to have_content("General Settings") + expect(find("#site_name").value).to eq("Spree Demo Site") + expect(find("#site_url").value).to eq("demo.spreecommerce.com") end end @@ -25,13 +25,13 @@ describe "General Settings" do assert_successful_update_message(:general_settings) - find("#site_name").value.should == "Spree Demo Site99" + expect(find("#site_name").value).to eq("Spree Demo Site99") end def assert_successful_update_message(resource) flash = Spree.t(:successfully_updated, resource: Spree.t(resource)) within("[class='flash success']") do - page.should have_content(flash) + expect(page).to have_content(flash) end end end diff --git a/spec/features/admin/configuration/image_settings_spec.rb b/spec/features/admin/configuration/image_settings_spec.rb index 5f0ded6f9b..c9e1455376 100644 --- a/spec/features/admin/configuration/image_settings_spec.rb +++ b/spec/features/admin/configuration/image_settings_spec.rb @@ -17,9 +17,9 @@ describe "image settings" do fill_in "Attachments Path", :with => "spec/dummy/tmp/bfaoro" click_button "Update" - Spree::Config[:attachment_url].should == "foobar" - Spree::Config[:attachment_default_url].should == "barfoo" - Spree::Config[:attachment_path].should == "spec/dummy/tmp/bfaoro" + expect(Spree::Config[:attachment_url]).to eq("foobar") + expect(Spree::Config[:attachment_default_url]).to eq("barfoo") + expect(Spree::Config[:attachment_path]).to eq("spec/dummy/tmp/bfaoro") end # Regression test for #3069 diff --git a/spec/features/admin/configuration/mail_methods_spec.rb b/spec/features/admin/configuration/mail_methods_spec.rb index 7ffd66f135..acdb60d527 100644 --- a/spec/features/admin/configuration/mail_methods_spec.rb +++ b/spec/features/admin/configuration/mail_methods_spec.rb @@ -17,16 +17,16 @@ describe "Mail Methods" do it "should be able to edit mail method settings" do fill_in "mail_bcc", :with => "spree@example.com99" click_button "Update" - page.should have_content("successfully updated!") + expect(page).to have_content("successfully updated!") end # Regression test for #2094 it "does not clear password if not provided" do Spree::Config[:smtp_password] = "haxme" click_button "Update" - page.should have_content("successfully updated!") + expect(page).to have_content("successfully updated!") - Spree::Config[:smtp_password].should_not be_blank + expect(Spree::Config[:smtp_password]).not_to be_blank end end end From c5a17bcde0c41982d53256dbe6c12cf410f868f4 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:56:55 +0100 Subject: [PATCH 18/18] Fix rubocop issues in feature specs related to configuration --- spec/features/admin/configuration/general_settings_spec.rb | 2 +- spec/features/admin/configuration/image_settings_spec.rb | 6 +++--- spec/features/admin/configuration/mail_methods_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/admin/configuration/general_settings_spec.rb b/spec/features/admin/configuration/general_settings_spec.rb index f066c26340..0577d44cd6 100644 --- a/spec/features/admin/configuration/general_settings_spec.rb +++ b/spec/features/admin/configuration/general_settings_spec.rb @@ -20,7 +20,7 @@ describe "General Settings" do context "editing general settings (admin)" do it "should be able to update the site name" do - fill_in "site_name", :with => "Spree Demo Site99" + fill_in "site_name", with: "Spree Demo Site99" click_button "Update" assert_successful_update_message(:general_settings) diff --git a/spec/features/admin/configuration/image_settings_spec.rb b/spec/features/admin/configuration/image_settings_spec.rb index c9e1455376..ff22c6a7c6 100644 --- a/spec/features/admin/configuration/image_settings_spec.rb +++ b/spec/features/admin/configuration/image_settings_spec.rb @@ -12,9 +12,9 @@ describe "image settings" do # Regression test for #2344 it "can update attachment_url" do - fill_in "Attachments URL", :with => "foobar" - fill_in "Attachments Default URL", :with => "barfoo" - fill_in "Attachments Path", :with => "spec/dummy/tmp/bfaoro" + fill_in "Attachments URL", with: "foobar" + fill_in "Attachments Default URL", with: "barfoo" + fill_in "Attachments Path", with: "spec/dummy/tmp/bfaoro" click_button "Update" expect(Spree::Config[:attachment_url]).to eq("foobar") diff --git a/spec/features/admin/configuration/mail_methods_spec.rb b/spec/features/admin/configuration/mail_methods_spec.rb index acdb60d527..834b3dabe7 100644 --- a/spec/features/admin/configuration/mail_methods_spec.rb +++ b/spec/features/admin/configuration/mail_methods_spec.rb @@ -15,7 +15,7 @@ describe "Mail Methods" do end it "should be able to edit mail method settings" do - fill_in "mail_bcc", :with => "spree@example.com99" + fill_in "mail_bcc", with: "spree@example.com99" click_button "Update" expect(page).to have_content("successfully updated!") end