Skip to content

Commit

Permalink
rubocop fix Style/AlignHash
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinKo committed Apr 8, 2015
1 parent 32c66dd commit f30e9f0
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 130 deletions.
8 changes: 1 addition & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Metrics/BlockNesting:
# Offense count: 10
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 177
Max: 190

# Offense count: 7
Metrics/CyclomaticComplexity:
Expand Down Expand Up @@ -93,12 +93,6 @@ Rails/Validation:
Style/AccessorMethodName:
Enabled: false

# Offense count: 46
# Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
Style/AlignHash:
Enabled: false

# Offense count: 46
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
32 changes: 20 additions & 12 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ArticlesController < ApplicationController
before_action :set_article, only: [:edit, :update, :destroy, :show]

# Authorization
skip_before_action :authenticate_user!, only: [:show, :index, :new, :autocomplete]
skip_before_action :authenticate_user!,
only: [:show, :index, :new, :autocomplete]
before_action :seller_sign_in, only: :new
skip_after_filter :verify_authorized_with_exceptions, only: [:autocomplete]

Expand All @@ -37,23 +38,30 @@ class ArticlesController < ApplicationController

#search_cache
before_action :build_search_cache, only: :index
before_action :category_specific_search, only: :index,
unless: lambda { request.xhr? || request.format == :json }
before_action :category_specific_search,
only: :index,
unless: lambda { request.xhr? || request.format == :json }

# Calculate value of active goods
before_action :check_value_of_goods, only: [:update], if: :activate_params_present?
before_action :check_value_of_goods, only: [:update],
if: :activate_params_present?

# Calculate fees and donations
before_action :calculate_fees_and_donations, only: :show,
if: lambda { !@article.active? && policy(@article).activate? }
before_action :calculate_fees_and_donations,
only: :show,
if: lambda { !@article.active? && policy(@article).activate? }

# Flash image processing message
before_action :flash_image_processing_message, only: :show,
if: lambda { !flash.now[:notice] &&
@article.owned_by?(current_user) &&
at_least_one_image_processing? }
before_action :flash_image_processing_message,
only: :show,
if: lambda {
!flash.now[:notice] &&
@article.owned_by?(current_user) &&
at_least_one_image_processing?
}

rescue_from ActiveRecord::RecordNotFound, with: :similar_articles, only: :show
rescue_from ActiveRecord::RecordNotFound, with: :similar_articles,
only: :show

#Autocomplete
def autocomplete
Expand Down Expand Up @@ -157,7 +165,7 @@ def set_article

def similar_articles query
query ||= params[:id].gsub(/\-/," ")
@similar_articles = ArticleSearchForm.new(q: query ).search(1)
@similar_articles = ArticleSearchForm.new(q: query).search(1)
respond_with @similar_articles do |format|
format.html { render "article_closed" }
format.json { render "article_closed" }
Expand Down
32 changes: 16 additions & 16 deletions app/helpers/container_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ module ContainerHelper
def accordion_item(accordion_name, options = {}, &block)
header_class = options[:header_class] || ""
content_class = options[:content_class] || ""
render layout: "accordion_layout",
locals: {
accordion_name: accordion_name,
accordion_title: options[:title] || t(accordion_name, :scope => "#{controller_name}.boxes"),
accordion_tooltip: options[:tooltip],
accordion_header_class: header_class,
accordion_content_class: content_class,
accordion_item_class: options[:item_class] || '',
accordion_arrow: options[:arrow]==false ? false : true
}, &block
render layout: "accordion_layout",
locals: {
accordion_name: accordion_name,
accordion_title: options[:title] || t(accordion_name, :scope => "#{controller_name}.boxes"),
accordion_tooltip: options[:tooltip],
accordion_header_class: header_class,
accordion_content_class: content_class,
accordion_item_class: options[:item_class] || '',
accordion_arrow: options[:arrow]==false ? false : true
}, &block
end

def gray_box(heading, options = {}, &block)
render layout: "gray_box_layout",
locals: {
heading: heading,
frame_class: options[:frame_class] || "",
title_addition: options[:title_addition],
}, &block
render layout: "gray_box_layout",
locals: {
heading: heading,
frame_class: options[:frame_class] || "",
title_addition: options[:title_addition],
}, &block
end

end
5 changes: 1 addition & 4 deletions app/models/article/validations.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Article::Validations
extend ActiveSupport::Concern


included do
extend Tokenize

Expand Down Expand Up @@ -32,7 +31,7 @@ module Article::Validations
}

validates :vat , presence: true , inclusion: { in: [0, 7 ,19] },
if: :belongs_to_legal_entity?
if: :belongs_to_legal_entity?
validates :basic_price_cents, numericality: {
greater_than_or_equal_to: 0, less_than_or_equal_to: 1000000
}, allow_nil: false
Expand Down Expand Up @@ -76,7 +75,6 @@ module Article::Validations
validate :only_one_title_image
validate :bike_courier_requires_paypal, if: :transport_bike_courier
validate :right_zip_for_courier, if: :transport_bike_courier

end

private
Expand Down Expand Up @@ -144,5 +142,4 @@ def right_zip_for_courier
errors.add(:transport_bike_courier, I18n.t('article.form.errors.wrong_zip_for_bike_transport'))
end
end

end
75 changes: 43 additions & 32 deletions app/models/mass_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,51 @@ class MassUpload < ActiveRecord::Base
delegate :nickname, to: :user, prefix: true

validates_attachment :file, presence: true,
size: { in: 0..100.megabytes },
content_type: { :content_type => ['text/csv','application/excel','application/vnd.msexcel','text/anytext','application/vnd.ms-excel', 'application/octet-stream', 'application/force-download', 'text/comma-separated-values'] }
size: { in: 0..100.megabytes },
content_type: {
content_type: %w(
text/csv application/excel text/anytext
application/vnd.msexcel
application/vnd.ms-excel
application/octet-stream
application/force-download
text/comma-separated-values
)
}

def self.article_attributes
["€", "id", "title", "categories", "condition", "condition_extra",
"content", "quantity", "price_cents", "basic_price_cents",
"basic_price_amount", "vat", "external_title_image_url", "image_2_url",
"transport_pickup", "transport_type1",
"transport_type1_provider", "transport_type1_price_cents",
"transport_type1_number", "transport_type2", "transport_type2_provider",
"transport_type2_price_cents", "transport_type2_number", "transport_time",
"transport_details", "unified_transport",
"payment_bank_transfer", "payment_cash", "payment_paypal",
"payment_cash_on_delivery", "payment_voucher",
"payment_cash_on_delivery_price_cents", "payment_invoice",
"payment_details", "fair_kind", "fair_seal", "support",
"support_checkboxes", "support_other", "support_explanation",
"labor_conditions", "labor_conditions_checkboxes",
"labor_conditions_other", "labor_conditions_explanation",
"environment_protection", "environment_protection_checkboxes",
"environment_protection_other",
"environment_protection_explanation", "controlling",
"controlling_checkboxes", "controlling_other",
"controlling_explanation", "awareness_raising",
"awareness_raising_checkboxes", "awareness_raising_other",
"awareness_raising_explanation", "nonprofit_association",
"nonprofit_association_checkboxes",
"social_businesses_muhammad_yunus",
"social_businesses_muhammad_yunus_checkboxes",
"social_entrepreneur", "social_entrepreneur_checkboxes",
"social_entrepreneur_explanation", "ecologic_seal",
"upcycling_reason", "small_and_precious_eu_small_enterprise",
"small_and_precious_reason", "small_and_precious_handmade",
"gtin", "custom_seller_identifier", "action"]
%w(
id title categories condition condition_extra
content quantity price_cents basic_price_cents
basic_price_amount vat external_title_image_url image_2_url
transport_pickup transport_type1
transport_type1_provider transport_type1_price_cents
transport_type1_number transport_type2 transport_type2_provider
transport_type2_price_cents transport_type2_number transport_time
transport_details unified_transport
payment_bank_transfer payment_cash payment_paypal
payment_cash_on_delivery payment_voucher
payment_cash_on_delivery_price_cents payment_invoice
payment_details fair_kind fair_seal support
support_checkboxes support_other support_explanation
labor_conditions labor_conditions_checkboxes
labor_conditions_other labor_conditions_explanation
environment_protection environment_protection_checkboxes
environment_protection_other
environment_protection_explanation controlling
controlling_checkboxes controlling_other
controlling_explanation awareness_raising
awareness_raising_checkboxes awareness_raising_other
awareness_raising_explanation nonprofit_association
nonprofit_association_checkboxes
social_businesses_muhammad_yunus
social_businesses_muhammad_yunus_checkboxes
social_entrepreneur social_entrepreneur_checkboxes
social_entrepreneur_explanation ecologic_seal
upcycling_reason small_and_precious_eu_small_enterprise
small_and_precious_reason small_and_precious_handmade
gtin custom_seller_identifier action
)
end

def processed_articles_count
Expand Down
27 changes: 14 additions & 13 deletions app/models/mass_upload_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ class MassUploadArticle < ActiveRecord::Base
has_one :user, through: :mass_upload
default_scope -> { order('row_index ASC') }

ACTION_MAPPING = { 'c' => :create ,
'create' => :create,
'u' => :update,
'update' => :update,
'x' => :delete,
'delete' => :delete,
'a' => :activate,
'activate' => :activate,
'd' => :deactivate,
'deactivate' => :deactivate,
'nothing' => :nothing
}
IDENTIFIERS = ['id', 'custom_seller_identifier']
ACTION_MAPPING = {
'c' => :create ,
'create' => :create,
'u' => :update,
'update' => :update,
'x' => :delete,
'delete' => :delete,
'a' => :activate,
'activate' => :activate,
'd' => :deactivate,
'deactivate' => :deactivate,
'nothing' => :nothing
}
IDENTIFIERS = %w(id custom_seller_identifier)


def done?
Expand Down
2 changes: 1 addition & 1 deletion app/models/social_producer_questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SocialProducerQuestionnaire < ActiveRecord::Base
validates :social_businesses_muhammad_yunus_checkboxes, :size => {:in => 1..-1}, :if => :social_businesses_muhammad_yunus?
validates :social_entrepreneur_checkboxes, :size => {:in => 1..-1}, :if => :social_entrepreneur?
validates :social_entrepreneur_explanation, length: {minimum: 150, maximum: 10000},
if: :social_entrepreneur?
if: :social_entrepreneur?
validates_presence_of :social_entrepreneur_explanation, :if => :social_entrepreneur?


Expand Down
4 changes: 2 additions & 2 deletions app/workers/broken_image_finder_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class BrokenImageFinderWorker
include Sidekiq::Worker

sidekiq_options queue: :broken_file_finder,
retry: 0,
backtrace: true
retry: 0,
backtrace: true

def perform image_id
path = ArticleImage.select("image_file_name,id").find(image_id).image.path
Expand Down
4 changes: 2 additions & 2 deletions app/workers/cancellation_form_normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class CancellationFormNormalizer
include Sidekiq::Worker

sidekiq_options queue: :cancellation_normalizer,
retry: 5,
backtrace: true
retry: 5,
backtrace: true

def perform user_id
user = User.find user_id
Expand Down
4 changes: 2 additions & 2 deletions app/workers/file_fixer_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class FileFixerWorker
include Sidekiq::Worker

sidekiq_options queue: :file_normalizer,
retry: 5,
backtrace: true
retry: 5,
backtrace: true

def perform image_id
image = Image.find(image_id)
Expand Down
4 changes: 2 additions & 2 deletions app/workers/file_normalizer_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class FileNormalizerWorker
include Sidekiq::Worker

sidekiq_options queue: :file_normalizer,
retry: 5,
backtrace: true
retry: 5,
backtrace: true

def perform article_id
article = Article.unscoped.find article_id
Expand Down
13 changes: 8 additions & 5 deletions lib/autoload/belboon_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def save_belboon_tracking_token_in_session

def save_belboon_tracking_token_in_user
if session[:belboon]
current_user.update_attributes({ belboon_tracking_token: session[:belboon],
belboon_tracking_token_set_at: Time.now })
current_user.update_attributes(
belboon_tracking_token: session[:belboon],
belboon_tracking_token_set_at: Time.now
)
session[:belboon] = nil
end
end
Expand All @@ -23,13 +25,14 @@ def clear_belboon_tracking_token_from_user
end

def clear_void_belboon_tracking_token_from_user
if current_user.belboon_tracking_token && current_user.belboon_tracking_token_set_at < 1.week.ago
if current_user.belboon_tracking_token &&
current_user.belboon_tracking_token_set_at < 1.week.ago
clear_token
end
end

def clear_token
current_user.update_attributes({ belboon_tracking_token: nil,
belboon_tracking_token_set_at: nil })
current_user.update_attributes( belboon_tracking_token: nil,
belboon_tracking_token_set_at: nil )
end
end
6 changes: 4 additions & 2 deletions lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ namespace :db do
print "Creating an article for each entry."
articles.each_pair do |name, description|
print "."
@article = FactoryGirl.build :article, :seller => user.sample,
:title => name, :content => description, :categories => [category.sample]
@article = FactoryGirl.build :article, seller: user.sample,
title: name,
content: description,
categories: [category.sample]
article_list << @article
count += 1
end
Expand Down
Loading

0 comments on commit f30e9f0

Please sign in to comment.