Skip to content

Commit

Permalink
Fixes most common cop offenses.
Browse files Browse the repository at this point in the history
  • Loading branch information
futhr committed Jan 23, 2015
1 parent a784f52 commit 995c0cf
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 37 deletions.
4 changes: 1 addition & 3 deletions app/controllers/spree/admin/captcha_settings_controller.rb
Expand Up @@ -5,9 +5,7 @@ def update
Spree::Captcha::Config.set(params[:preferences])

respond_to do |format|
format.html {
redirect_to edit_admin_captcha_settings_path
}
format.html { redirect_to edit_admin_captcha_settings_path }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/email_sender_controller.rb
Expand Up @@ -38,7 +38,7 @@ def mail_to_friend

# Extract send message to make easier to override
def send_message(object, mail_to_friend)
Spree::ToFriendMailer.mail_to_friend(object,@mail_to_friend).deliver
Spree::ToFriendMailer.mail_to_friend(object, mail_to_friend).deliver
end

def find_object
Expand Down
1 change: 0 additions & 1 deletion app/mailers/spree/to_friend_mailer.rb
@@ -1,7 +1,6 @@
class Spree::ToFriendMailer < ActionMailer::Base
default from: Spree::Config[:mails_from] || ''


def mail_to_friend(object, mail)
@object = object
@mail = mail
Expand Down
6 changes: 3 additions & 3 deletions app/models/spree/mail_to_friend.rb
Expand Up @@ -8,8 +8,8 @@ class Spree::MailToFriend
validates :subject, :sender_name, presence: true
validates :recipient_name, presence: true, unless: :is_multi
validates :sender_email, format: { with: EMAILREGEX }
validates :recipients, length: {minimum: 1, message: Spree.t(:recipients, scope: :validation) }
validates :invalid_recipients, length: {maximum: 0, message: Spree.t(:invalid_recipients, scope: :validation) }
validates :recipients, length: { minimum: 1, message: Spree.t(:recipients, scope: :validation) }
validates :invalid_recipients, length: { maximum: 0, message: Spree.t(:invalid_recipients, scope: :validation) }

def initialize(opts = {})
@sender_email = opts[:sender_email] || ' '
Expand All @@ -19,7 +19,7 @@ def initialize(opts = {})
@recipients = []
@invalid_recipients = []

addresses = (opts[:recipient_email] || '').gsub(';', ',').gsub(/\s/ , '')
addresses = (opts[:recipient_email] || '').gsub(';', ',').gsub(/\s/, '')
addresses.split(',').each do |address|
if address =~ EMAILREGEX
@recipients << address
Expand Down
@@ -1,4 +1,6 @@
Deface::Override.new(virtual_path: "spree/admin/shared/_configuration_menu",
name: "add_captcha_admin_option",
insert_bottom: "[data-hook='admin_configurations_sidebar_menu']",
text: "<%= configurations_sidebar_menu_item Spree.t('captcha.captcha_settings'), edit_admin_captcha_settings_path %>")
Deface::Override.new(
virtual_path: 'spree/admin/shared/_configuration_menu',
name: 'add_captcha_admin_option',
insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]',
text: '<%= configurations_sidebar_menu_item Spree.t(:captcha_settings, scope: :captcha), edit_admin_captcha_settings_path %>'
)
12 changes: 7 additions & 5 deletions app/overrides/add_email_to_friend_link_to_products.rb
@@ -1,5 +1,7 @@
Deface::Override.new(virtual_path: "spree/products/show",
name: "converted_product_description_351026984",
insert_bottom: "[data-hook='product_description'], #product_description[data-hook]",
text: "<p class=\"email_to_friend\"><%= link_to Spree.t('email_to_friend.send_to_friend'), email_to_friend_path('product', @product) %></p>",
original: "23a81432df67f93cad7563f7b118d6f901b8e42b")
Deface::Override.new(
virtual_path: 'spree/products/show',
name: 'converted_product_description_351026984',
insert_bottom: '[data-hook="product_description"], #product_description[data-hook]',
text: '<p class="email_to_friend"><%= link_to Spree.t(:send_to_friend, scope: :email_to_friend), email_to_friend_path("product", @product) %></p>',
original: '23a81432df67f93cad7563f7b118d6f901b8e42b'
)
5 changes: 2 additions & 3 deletions config/routes.rb
@@ -1,6 +1,5 @@
routes = lambda do

match "/email_to_friend/:type/:id" => 'email_sender#send_mail', as: :email_to_friend, via: [:get, :post]
match '/email_to_friend/:type/:id' => 'email_sender#send_mail', as: :email_to_friend, via: [:get, :post]

namespace :admin do
resource :captcha_settings
Expand All @@ -11,4 +10,4 @@
Spree::Core::Engine.add_routes(&routes)
else
Spree::Core::Engine.routes.draw(&routes)
end
end
15 changes: 6 additions & 9 deletions lib/spree_email_to_friend/engine.rb
Expand Up @@ -9,20 +9,17 @@ class Engine < Rails::Engine

config.autoload_paths += %W(#{config.root}/lib)

initializer 'spree.email_to_friend.preferences', after: 'spree.environment' do |app|
initializer 'spree.email_to_friend.preferences', after: 'spree.environment' do
Spree::Captcha::Config = Spree::CaptchaConfiguration.new
end

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), '../../app/overrides/*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
def activate
cache_klasses = %W(#{config.root}/app/**/*_decorator*.rb #{config.root}/app/overrides/*.rb)
Dir.glob(cache_klasses) do |klass|
Rails.configuration.cache_classes ? require(klass) : load(klass)
end
end

config.to_prepare &method(:activate).to_proc
config.to_prepare(&method(:activate).to_proc)
end
end
1 change: 0 additions & 1 deletion lib/spree_email_to_friend/version.rb
@@ -1,5 +1,4 @@
module SpreeEmailToFriend

# Returns the version of the currently loaded SpreeEmailToFriend as a
# <tt>Gem::Version</tt>.
def self.version
Expand Down
1 change: 0 additions & 1 deletion spec/controllers/admin/captcha_settings_controller_spec.rb
Expand Up @@ -17,7 +17,6 @@
private_key: FAKE,
public_key: FAKE,
use_captcha: false' do

it 'sets preferred_theme to clean' do
spree_put :update, preferences: { theme: 'clean' }
expect(Spree::Captcha::Config.preferred_theme).to eq 'clean'
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/email_sender_controller_spec.rb
Expand Up @@ -8,7 +8,7 @@
context '#send_mail' do
# can be different types but no clue what they can be except from product
specify do
spree_get :send_mail, { type: 'product', id: product.id }
spree_get :send_mail, type: 'product', id: product.id
expect(response).to be_success
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/mail_factory.rb
Expand Up @@ -9,7 +9,7 @@
subject 'Check this out!'
message 'Its totally awesome..'

recipients { Array(1..4).sample.times.map{ Faker::Internet.email } }
recipients { Array(1..4).sample.times.map { Faker::Internet.email } }
invalid_recipients []
end
end
end
1 change: 0 additions & 1 deletion spec/features/email_sender_spec.rb
@@ -1,5 +1,4 @@
RSpec.feature 'Email to friend', :js do

given(:product) { create(:product) }
given(:mail) { build(:mail) }

Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -15,7 +15,6 @@
require 'ffaker'

RSpec.configure do |config|

config.fail_fast = false
config.filter_run focus: true
config.run_all_when_everything_filtered = true
Expand Down
1 change: 0 additions & 1 deletion spec/support/database_cleaner.rb
@@ -1,7 +1,6 @@
require 'database_cleaner'

RSpec.configure do |config|

config.before(:suite) do
DatabaseCleaner.clean_with :deletion
end
Expand Down

0 comments on commit 995c0cf

Please sign in to comment.