Skip to content

Commit

Permalink
rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shua123 committed Sep 14, 2016
1 parent dd62714 commit 6e18de6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 77 deletions.
3 changes: 1 addition & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class ApplicationController < ActionController::Base
# before_action :user_needed, if: request.format == :json

before_action :set_paper_trail_whodunnit

before_filter :set_global_search_variable
before_action :set_global_search_variable

def set_global_search_variable
@q = Person.ransack(params[:q])
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/gift_cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
end
format.csv do
@gift_cards = @q_giftcards.result.includes(:person)
send_data @gift_cards.export_csv, filename: "GiftCards-#{Date.today}.csv"
send_data @gift_cards.export_csv, filename: "GiftCards-#{Time.zone.today}.csv"
end
end
end
Expand All @@ -42,7 +42,7 @@ def edit
def create
@gift_card = GiftCard.new(gift_card_params)
respond_to do |format|
if @create_result = @gift_card.with_user(current_user).save
if @create_result == @gift_card.with_user(current_user).save
@total = @gift_card.person.blank? ? @gift_card.amount : @gift_card.person.gift_card_total
format.js {}
format.json {}
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ def index_ransack
@mce = MailchimpExport.new(name: list_name, recipients: @results_mailchimp.collect(&:email_address), created_by: current_user.id)
if @mce.with_user(current_user).save
Rails.logger.info("[SearchController#export] Sent #{@mce.recipients.size} email addresses to a static segment named #{@mce.name}")
#render text: "failed to send event to mailchimp: #{@mce.errors.inspect}"
@success = "Sent #{@mce.recipients.size} email addresses to a static segment named #{@mce.name}"
flash[:success] = "Successfully sent to mailchimp: #{@mce.errors.inspect}"
else
Rails.logger.error("[SearchController#export] failed to send event to mailchimp: #{@mce.errors.inspect}")
#render text: "failed to send event to mailchimp: #{@mce.errors.inspect}"
@error = "failed to send search to mailchimp: #{@mce.errors.inspect}"
flash[:failure] = "failed to send search to mailchimp: #{@mce.errors.inspect}"
end
Expand Down Expand Up @@ -158,7 +156,6 @@ def export
list_name = params.delete(:segment_name)
@q = Person.ransack(params[:q])
@people = @q.result.includes(:tags)
#@people = Person.complex_search(params, 10000)
@mce = MailchimpExport.new(name: list_name, recipients: @people.collect(&:email_address), created_by: current_user.id)

if @mce.with_user(current_user).save
Expand Down Expand Up @@ -186,8 +183,6 @@ def exportTwilio
smsCampaign = params.delete(:twiliowufoo_campaign)
@q = Person.ransack(params[:q])
@people = @q.result.includes(:tags)
#@people = Person.complex_search(params, 10000)
# people_count = @people.length
Rails.logger.info("[SearchController#exportTwilio] people #{@people}")
phone_numbers = @people.collect(&:phone_number)
Rails.logger.info("[SearchController#exportTwilio] people #{phone_numbers}")
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/twilio_messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ def uploadnumbers
smsCampaign = params.delete(:twiliowufoo_campaign)
infile = params[:file].read
contentType = params[:file].content_type
statusMessage = ''

if contentType == 'text/csv'
CSV.parse(infile, headers: true, header_converters: :downcase) do |row|
if row['phone_number'].present?
if row['phone_number'].present?
# @person << row
Rails.logger.info("[TwilioMessagesController#sendmessages] #{row}")
phone_numbers.push(row['phone_number'])
Expand All @@ -82,13 +81,13 @@ def uploadnumbers
flash[:success] = "Sent Messages: #{messages} to Phone Numbers: #{phone_numbers}"
else
Rails.logger.error('[TwilioMessagesController#sendmessages] failed to send text messages')
flash[:error] = "Failed to send messages."
flash[:error] = 'Failed to send messages.'
end
else
flash[:error] = "Please upload a CSV instead."
flash[:error] = 'Please upload a CSV instead.'
end
respond_to do |format|
format.html { redirect_to '/twilio_messages/sendmessages' }
format.html { redirect_to '/twilio_messages/sendmessages' }
end
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Style/VariableName
Expand Down
52 changes: 1 addition & 51 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,14 @@ def person_column_headers
end

def person_column_fields
%i(id first_name last_name email created updated).freeze
%i(id first_name last_name email_address created updated).freeze
end

def results_limit
# max number of search results to display
10
end

def post_title_length
# max number of characters in posts titles to display
14
end

def post_title_header_labels
%w(1 2 3).freeze
end

def user_posts_and_comments
%w(posts comments).freeze
end

def condition_fields
%w(fields condition).freeze
end
Expand All @@ -74,41 +61,4 @@ def display_query_sql(people)
tag.p('SQL:') + tag.code(people.to_sql)
end

def display_results_header(count)
if count > results_limit
"Your first #{results_limit} results out of #{count} total"
else
"Your #{pluralize(count, 'result')}"
end
end

def display_sort_column_headers(search)
person_column_headers.reduce(String.new) do |string, field|
string << (tag.th sort_link(search, field, {}, method: action))
end +
post_title_header_labels.reduce(String.new) do |str, i|
str << (tag.th "Post #{i} title")
end
end

def display_search_results(objects)
objects.limit(results_limit).reduce(String.new) do |string, object|
string << (tag.tr display_search_results_row(object))
end
end

def display_search_results_row(object)
user_column_fields.reduce(String.new) do |string, field|
string << (tag.td object.send(field))
end.html_safe +
display_user_posts(object.posts)
end

def display_user_posts(posts)
posts.reduce(String.new) do |string, post|
string << (tag.td truncate(post.title, length: post_title_length))
end
.html_safe
end

end
6 changes: 3 additions & 3 deletions app/models/gift_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GiftCard < ActiveRecord::Base
validates_presence_of :amount
validates_presence_of :reason

validates_format_of :expiration_date, with: /\A(0|1)([0-9])\/([0-9]{2})\z/i ,unless: proc { |c| c.expiration_date.blank? }
validates_format_of :expiration_date, with: /\A(0|1)([0-9])\/([0-9]{2})\z/i, unless: proc { |c| c.expiration_date.blank? }

validates_length_of :proxy_id, is: 4, unless: proc { |c| c.proxy_id.blank? }
validates_numericality_of :proxy_id, unless: proc { |c| c.proxy_id.blank? }
Expand Down Expand Up @@ -77,9 +77,9 @@ def self.export_csv
CSV.generate do |csv|
csv_column_names = ['Gift Card ID', 'Batch ID', 'Gift Card Number', 'Expiration Date', 'Reason', 'Person ID', 'Name', 'Address', 'Phone Number', 'Email']
csv << csv_column_names
all.each do |gift_card|
all.find_each do |gift_card|
this_person = gift_card.person
row_items = [gift_card.id, gift_card.batch_id, gift_card.gift_card_number, gift_card.expiration_date, gift_card.reason.titleize, this_person.id || "", this_person.full_name || "", this_person.address_fields_to_sentence || ""]
row_items = [gift_card.id, gift_card.batch_id, gift_card.gift_card_number, gift_card.expiration_date, gift_card.reason.titleize, this_person.id || '', this_person.full_name || '', this_person.address_fields_to_sentence || '']
if this_person.phone_number.present?
row_items.push(this_person.phone_number.phony_formatted(format: :national, spaces: '-'))
else
Expand Down
17 changes: 8 additions & 9 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ class Person < ActiveRecord::Base

ransacker :full_name, formatter: proc { |v| v.mb_chars.downcase.to_s } do |parent|
Arel::Nodes::NamedFunction.new('lower',
[ Arel::Nodes::NamedFunction.new('concat_ws',
[ Arel::Nodes.build_quoted(' '), parent.table[:first_name], parent.table[:last_name] ]) ]
)
end
[Arel::Nodes::NamedFunction.new('concat_ws',
[Arel::Nodes.build_quoted(' '), parent.table[:first_name], parent.table[:last_name]])])
end
ransack_alias :nav_bar_search, :full_name_or_email_address_or_phone_number

def signup_gc_sent
Expand All @@ -122,7 +121,7 @@ def signup_gc_sent

def gift_card_total
total = gift_cards.sum(:amount_cents)
total = Money.new(total, 'USD')
Money.new(total, 'USD')
end

WUFOO_FIELD_MAPPING = {
Expand Down Expand Up @@ -381,7 +380,7 @@ def possible_duplicates
if email_address.present?
email_address_duplicates = Person.where(email_address: email_address).where.not(id: id)
email_address_duplicates.each do |duplicate|
if @duplicates.has_key? duplicate.id
if @duplicates.key? duplicate.id
@duplicates[duplicate.id]['match_count'] += 1
@duplicates[duplicate.id]['matches_on'].push('Email Address')
else
Expand All @@ -396,7 +395,7 @@ def possible_duplicates
if phone_number.present?
phone_number_duplicates = Person.where(phone_number: phone_number).where.not(id: id)
phone_number_duplicates.each do |duplicate|
if @duplicates.has_key? duplicate.id
if @duplicates.key? duplicate.id
@duplicates[duplicate.id]['match_count'] += 1
@duplicates[duplicate.id]['matches_on'].push('Phone Number')
else
Expand All @@ -411,7 +410,7 @@ def possible_duplicates
if address_1.present?
address_1_duplicates = Person.where(address_1: address_1).where.not(id: id)
address_1_duplicates.each do |duplicate|
if @duplicates.has_key? duplicate.id
if @duplicates.key? duplicate.id
@duplicates[duplicate.id]['match_count'] += 1
@duplicates[duplicate.id]['matches_on'].push('Address_1')
else
Expand All @@ -423,7 +422,7 @@ def possible_duplicates
@duplicates[duplicate.id]['address_1_match'] = true
end
end
return @duplicates
@duplicates
end

end
Expand Down

0 comments on commit 6e18de6

Please sign in to comment.