Skip to content

Commit

Permalink
Bye bye hash rockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
futhr committed Jan 8, 2015
1 parent 912200d commit 750b772
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'spree/testing_support/extension_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]
task default: [:spec]

desc 'Generates a dummy app for testing'
task :test_app do
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/spree/admin/mail_methods_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Spree
module Admin
class MailMethodsController < Spree::Admin::BaseController
class MailMethodsController < BaseController
def update
if params[:smtp_password].blank?
params.delete(:smtp_password)
Expand All @@ -11,7 +11,7 @@ def update
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))
redirect_to edit_admin_mail_method_url
end

Expand All @@ -22,7 +22,7 @@ def testmail
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}
flash[:error] = Spree.t('admin.mail_methods.testmail.error') % { e: e }
ensure
redirect_to edit_admin_mail_method_url
end
Expand Down
16 changes: 8 additions & 8 deletions app/models/spree/app_configuration_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Spree
AppConfiguration.class_eval do
# Default mail headers settings
preference :enable_mail_delivery, :boolean, :default => false
preference :mail_bcc, :string, :default => '[email protected]'
preference :intercept_email, :string, :default => nil
preference :enable_mail_delivery, :boolean, default: false
preference :mail_bcc, :string, default: '[email protected]'
preference :intercept_email, :string, default: nil

# Default smtp settings
preference :mail_host, :string, :default => 'localhost'
preference :mail_domain, :string, :default => 'localhost'
preference :mail_port, :integer, :default => 25
preference :secure_connection_type, :string, :default => Core::MailSettings::SECURE_CONNECTION_TYPES[0]
preference :mail_auth_type, :string, :default => Core::MailSettings::MAIL_AUTH[0]
preference :mail_host, :string, default: 'localhost'
preference :mail_domain, :string, default: 'localhost'
preference :mail_port, :integer, default: 25
preference :secure_connection_type, :string, default: Core::MailSettings::SECURE_CONNECTION_TYPES[0]
preference :mail_auth_type, :string, default: Core::MailSettings::MAIL_AUTH[0]
preference :smtp_username, :string
preference :smtp_password, :string

Expand Down
11 changes: 6 additions & 5 deletions app/overrides/views_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Deface::Override.new(
:virtual_path => "spree/admin/shared/_configuration_menu",
:name => "mail_settings_admin_configurations_menu",
:insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
:text => "<%= configurations_sidebar_menu_item Spree.t(:mail_method_settings), edit_admin_mail_method_url %>",
:disabled => false)
virtual_path: "spree/admin/shared/_configuration_menu",
name: "mail_settings_admin_configurations_menu",
insert_bottom: "[data-hook='admin_configurations_sidebar_menu']",
text: "<%= configurations_sidebar_menu_item Spree.t(:mail_method_settings), edit_admin_mail_method_url %>",
disabled: false
)
24 changes: 12 additions & 12 deletions app/views/spree/admin/mail_methods/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<legend align="center"><%= Spree.t(:general) %></legend>

<div class="field">
<%= preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], :type => :boolean) %>
<%= preference_field_tag("enable_mail_delivery", Spree::Config[:enable_mail_delivery], type: :boolean) %>
<%= label_tag :enable_mail_delivery, Spree.t(:enable_mail_delivery) %>
</div>

<div class="field">
<%= label_tag :mails_from, Spree.t(:send_mails_as) %><br />
<%= text_field_tag :mails_from, Spree::Config[:mails_from], :maxlength => 256, :class => 'fullwidth' %>
<%= text_field_tag :mails_from, Spree::Config[:mails_from], maxlength: 256, class: 'fullwidth' %>
<br />
<span class="info">
<%= Spree.t(:smtp_send_all_emails_as_from_following_address) %>
Expand All @@ -21,7 +21,7 @@

<div class="field">
<%= label_tag :mail_bcc, Spree.t(:send_copy_of_all_mails_to) %><br />
<%= text_field_tag :mail_bcc, Spree::Config[:mail_bcc], :maxlength => 256, :class => 'fullwidth' %>
<%= text_field_tag :mail_bcc, Spree::Config[:mail_bcc], maxlength: 256, class: 'fullwidth' %>
<br />
<span class="info">
<%= Spree.t(:smtp_send_copy_to_this_addresses) %>
Expand All @@ -30,7 +30,7 @@

<div class="field">
<%= label_tag :intercept_email, Spree.t(:intercept_email_address) %><br />
<%= text_field_tag :intercept_email, Spree::Config[:intercept_email], :maxlength => 256, :class => 'fullwidth' %>
<%= text_field_tag :intercept_email, Spree::Config[:intercept_email], maxlength: 256, class: 'fullwidth' %>
<br />
<span class="info">
<%= Spree.t(:intercept_email_instructions) %>
Expand All @@ -44,35 +44,35 @@
<legend align="center"><%= Spree.t(:smtp) %></legend>
<div class="field">
<%= label_tag :mail_domain, Spree.t(:smtp_domain) %><br />
<%= text_field_tag :mail_domain, Spree::Config[:mail_domain], :class => 'fullwidth' %>
<%= text_field_tag :mail_domain, Spree::Config[:mail_domain], class: 'fullwidth' %>
</div>
<div class="field">
<%= label_tag :mail_host, Spree.t(:smtp_mail_host) %><br />
<%= text_field_tag :mail_host, Spree::Config[:mail_host], :class => 'fullwidth' %>
<%= text_field_tag :mail_host, Spree::Config[:mail_host], class: 'fullwidth' %>
</div>
<div class="field">
<%= label_tag :mail_port, Spree.t(:smtp_port) %><br />
<%= text_field_tag :mail_port, Spree::Config[:mail_port], :class => 'fullwidth' %>
</div>
<%= text_field_tag :mail_port, Spree::Config[:mail_port], class: 'fullwidth' %>
</div>
<div class="field">
<%= label_tag :secure_connection_type, Spree.t(:secure_connection_type) %><br />
<%= select_tag(:secure_connection_type,
options_from_collection_for_select(Spree::Core::MailSettings::SECURE_CONNECTION_TYPES, :to_s, :to_s, Spree::Config[:secure_connection_type]),
:class => 'select2 fullwidth') %>
class: 'select2 fullwidth') %>
</div>
<div class="field">
<%= label_tag :mail_auth_type, Spree.t(:smtp_authentication_type) %><br />
<%= select_tag(:mail_auth_type,
options_from_collection_for_select(Spree::Core::MailSettings::MAIL_AUTH, :to_s, :to_s, Spree::Config[:mail_auth_type]),
:class => 'select2 fullwidth') %>
class: 'select2 fullwidth') %>
</div>
<div class="field">
<%= label_tag :smtp_username, Spree.t(:smtp_username) %><br />
<%= text_field_tag :smtp_username, Spree::Config[:smtp_username], :class => 'fullwidth', :autocomplete => 'off' %>
<%= text_field_tag :smtp_username, Spree::Config[:smtp_username], class: 'fullwidth', autocomplete: 'off' %>
</div>
<div class="field">
<%= label_tag :preferred_smtp_password, Spree.t(:smtp_password) %><br />
<%= password_field_tag :smtp_password, Spree::Config[:smtp_password], :class => 'fullwidth', :autocomplete => 'off' %>
<%= password_field_tag :smtp_password, Spree::Config[:smtp_password], class: 'fullwidth', autocomplete: 'off' %>
</div>
</fieldset>
</div>
Expand Down
10 changes: 5 additions & 5 deletions app/views/spree/admin/mail_methods/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
<%= render partial: 'spree/admin/shared/configuration_menu' %>

<% content_for :page_title do %>
<%= Spree.t(:mail_method_settings) %>
Expand All @@ -7,15 +7,15 @@
<% content_for :page_actions do %>
<li>
<%= 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' %>
method: :post, title: Spree.t('admin.mail_methods.send_testmail'), class: 'send_mail button no-text' %>
</li>
<% end %>

<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @mail_method } %>
<%= render partial: 'spree/shared/error_messages', locals: { target: @mail_method } %>

<%= form_tag admin_mail_method_path, :method => :put do |f| %>
<%= form_tag admin_mail_method_path, method: :put do |f| %>
<fieldset class="no-border-top">
<%= render :partial => 'form', :locals => { :f => f } %>
<%= render partial: 'form', locals: { f: f } %>
<div class="form-buttons filter-actions actions" data-hook="buttons"><%= button Spree.t('actions.update'), 'icon-refresh' %></div>
</fieldset>
<% end %>
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Spree::Core::Engine.routes.append do
namespace :admin do
resource :mail_method, :only => [:edit, :update] do
post :testmail, :on => :collection
resource :mail_method, only: [:edit, :update] do
post :testmail, on: :collection
end
end
end
18 changes: 11 additions & 7 deletions lib/spree/core/mail_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ def mail_server_settings
basic_settings
end

settings.merge :enable_starttls_auto => secure_connection?
settings.merge enable_starttls_auto: secure_connection?
end

private

def user_credentials
{ :user_name => Config.smtp_username,
:password => Config.smtp_password }
{
user_name: Config.smtp_username,
password: Config.smtp_password
}
end

def basic_settings
{ :address => Config.mail_host,
:domain => Config.mail_domain,
:port => Config.mail_port,
:authentication => Config.mail_auth_type }
{
address: Config.mail_host,
domain: Config.mail_domain,
port: Config.mail_port,
authentication: Config.mail_auth_type
}
end

def need_authentication?
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/spree/admin/mail_methods_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

context "#update" do
it "should reinitialize the mail settings" do
spree_put :update, { :enable_mail_delivery => "1", :mails_from => "[email protected]" }
spree_put :update, { enable_mail_delivery: "1", mails_from: "[email protected]" }
response.should be_redirect
end
end

it "can trigger testmail" do
user = create(:user, email: '[email protected]')
controller.stub(:try_spree_current_user => user)
controller.stub(try_spree_current_user: user)
Spree::Config[:enable_mail_delivery] = "1"

expect {
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/configuration/mail_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it "should be able to edit mail method settings" do
fill_in "mail_bcc", :with => "[email protected]"
fill_in "mail_bcc", with: "[email protected]"
click_button "Update"
page.should have_content("successfully updated!")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/mail_interceptor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# We'll use the OrderMailer as a quick and easy way to test. IF it works here
# it works for all email (in theory.)
describe Spree::OrderMailer do
let(:order) { Spree::Order.new(:email => "[email protected]") }
let(:order) { Spree::Order.new(email: "[email protected]") }
let(:message) { Spree::OrderMailer.confirm_email(order) }

before(:all) do
Expand Down

0 comments on commit 750b772

Please sign in to comment.