Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Rubocop cleanup
Browse files Browse the repository at this point in the history
Since we change the rubocop config, I thought it would be good to clean
up some simple violations across the code (no major changes like
renaming functions)
  • Loading branch information
Jacob Harris committed Apr 29, 2016
1 parent d6659e6 commit ec19e86
Show file tree
Hide file tree
Showing 50 changed files with 453 additions and 126 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -102,6 +102,10 @@ Style/DotPosition:
- leading
- trailing

Style/IfUnlessModifier:
MaxLineLength: 80
Enabled: false

Style/NumericLiterals:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/auctions_controller.rb
Expand Up @@ -66,7 +66,7 @@ def update
format.html { redirect_to "/admin/auctions" }
format.json do
render json: auction, serializer: Admin::AuctionSerializer
exit end
end
end
rescue ArgumentError => e
respond_error(e)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/dashboards_controller.rb
Expand Up @@ -20,7 +20,7 @@ def drafts
private

def to_presenter(auctions)
auctions.map {|a| Presenter::AdminAuction.new(a) }
auctions.map { |a| Presenter::AdminAuction.new(a) }
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/auctions_controller.rb
Expand Up @@ -40,7 +40,7 @@ def previous_winners_archive

@view_model = ViewModel::AuctionsIndex.new(current_user, collection)

@auctions_json = @view_model.auctions.each {|a| AuctionSerializer.new(a, root: false)}.as_json
@auctions_json = @view_model.auctions.each { |a| AuctionSerializer.new(a, root: false) }.as_json
respond_to do |format|
format.html
end
Expand All @@ -50,7 +50,7 @@ def previous_winners
collection = AuctionQuery.new.public_index
@view_model = ViewModel::AuctionsIndex.new(current_user, collection)

@auctions_json = @view_model.auctions.each {|a| AuctionSerializer.new(a, root: false)}.as_json
@auctions_json = @view_model.auctions.each { |a| AuctionSerializer.new(a, root: false) }.as_json

respond_to do |format|
format.html
Expand Down
2 changes: 1 addition & 1 deletion app/credentials/concerns/user_provided_service.rb
Expand Up @@ -8,7 +8,7 @@ def use_env_var?(force_vcap)
end

def user_provided_service(name)
user_provided_services.find {|service| service['name'] == name }
user_provided_services.find { |service| service['name'] == name }
end

def user_provided_services
Expand Down
8 changes: 3 additions & 5 deletions app/models/admin_report.rb
Expand Up @@ -6,11 +6,11 @@ def initialize(users: [])
end

def non_admin_users
@users.select {|u| !Admins.verify?(u.github_id) }
@users.select { |u| !Admins.verify?(u.github_id) }
end

def admin_users
@users.select {|u| Admins.verify?(u.github_id) }
@users.select { |u| Admins.verify?(u.github_id) }
end

def quick_stats
Expand All @@ -27,8 +27,6 @@ def non_admin_users_with_duns
end

def non_admin_users_in_sam
non_admin_users.select do |user|
user.sam_accepted?
end
non_admin_users.select(&:sam_accepted?)
end
end
2 changes: 1 addition & 1 deletion app/models/auction.rb
Expand Up @@ -17,7 +17,7 @@ def lowest_bid
end

def lowest_bids
bids.select {|b| b.amount == lowest_amount }.sort_by(&:created_at)
bids.select { |b| b.amount == lowest_amount }.sort_by(&:created_at)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/models/auction_parser.rb
Expand Up @@ -48,7 +48,7 @@ def general_attributes
end

def delivery_deadline
if params.has_key?(:due_in_days)
if params.key?(:due_in_days)
real_days = params[:due_in_days].to_i.business_days
end_of_workday(real_days.after(end_datetime.to_date))
else
Expand Down
4 changes: 2 additions & 2 deletions app/models/place_bid.rb
Expand Up @@ -51,7 +51,7 @@ def max_allowed_bid
presenter_auction.max_allowed_bid
end

# rubocop:disable Style/IfUnlessModifier, Style/GuardClause
# rubocop:disable Style/IfUnlessModifier
def validate_bid_data
unless auction_available?
fail UnauthorizedError, 'Auction not available'
Expand All @@ -77,7 +77,7 @@ def validate_bid_data
fail UnauthorizedError, "Bids cannot be greater than the current max bid"
end
end
# rubocop:enable Style/IfUnlessModifier, Style/GuardClause
# rubocop:enable Style/IfUnlessModifier

def amount
params_amount = params[:bid][:amount]
Expand Down
10 changes: 5 additions & 5 deletions app/models/presenter/auction.rb
Expand Up @@ -42,14 +42,14 @@ def initialize(auction)
to: :lowest_bid,
prefix: :lowest_bid
)

delegate(
:bidder_duns_number,
:bidder_name,
:bidder_name,
to: :lowest_bid,
prefix: :lowest
)

delegate(
:future?,
:expiring?,
Expand Down Expand Up @@ -78,13 +78,13 @@ def bids?

def bids
@bids ||= model.bids.to_a
.map {|bid| decorated_bid(bid) }
.map { |bid| decorated_bid(bid) }
.sort_by(&:created_at)
.reverse
end

def lowest_bids
model.lowest_bids.map {|b| decorated_bid(b) }
model.lowest_bids.map { |b| decorated_bid(b) }
end

def lowest_bid
Expand Down
2 changes: 1 addition & 1 deletion app/models/presenter/bid.rb
Expand Up @@ -100,7 +100,7 @@ def id
end

def amount
nil #NULL
nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/rules/basic.rb
Expand Up @@ -31,7 +31,7 @@ def show_bids?
true
end

def partial_path(name, base_dir='auctions')
def partial_path(name, base_dir = 'auctions')
if partial_prefix.blank?
"#{base_dir}/#{name}.html.erb"
else
Expand Down
8 changes: 4 additions & 4 deletions app/models/rules/sealed_bid.rb
Expand Up @@ -8,14 +8,14 @@ def winning_bid
def veiled_bids(user)
if auction.available?
return [] if user.nil?
auction.bids.select {|bid| bid.bidder_id == user.id }
auction.bids.select { |bid| bid.bidder_id == user.id }
else
auction.bids
end
end

def user_can_bid?(user)
super && !auction.bids.any? {|b| b.bidder_id == user.id }
super && !auction.bids.any? { |b| b.bidder_id == user.id }
end

def max_allowed_bid
Expand All @@ -25,7 +25,7 @@ def max_allowed_bid
def show_bids?
!auction.available?
end

def partial_prefix
'single_bid'
end
Expand All @@ -36,7 +36,7 @@ def formatted_type

def highlighted_bid(user)
if auction.available?
auction.bids.detect {|bid| bid.bidder_id == user.id } || Presenter::Bid::Null.new
auction.bids.detect { |bid| bid.bidder_id == user.id } || Presenter::Bid::Null.new
else
auction.lowest_bid
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/user.rb
@@ -1,7 +1,7 @@
class User < ActiveRecord::Base
has_many :bids

validates :credit_card_form_url, url: {allow_blank: true, no_local: true, schemes: ['http', 'https']}
validates :credit_card_form_url, url: { allow_blank: true, no_local: true, schemes: %w(http https) }
validates :duns_number, duns_number: true
validates :email, allow_blank: true, email: true

Expand All @@ -11,7 +11,7 @@ def from_oauth_hash(auth_hash)
set_if_blank('name', auth_hash)
set_if_blank('email', auth_hash)
self.github_login = auth_hash[:info][:nickname]
self.save!
save!
end

private
Expand All @@ -20,7 +20,7 @@ def set_if_blank(field, auth_hash)
attribute = field.to_sym

if send(attribute).blank?
self.send("#{attribute}=", auth_hash[:info][attribute])
send("#{attribute}=", auth_hash[:info][attribute])
end
end
end
2 changes: 1 addition & 1 deletion app/models/view_model/auction.rb
Expand Up @@ -80,7 +80,7 @@ def user_is_bidder?
end

def user_is_winning_bidder?
# fixme: who is calling this?
# FIXME: who is calling this?
return false unless auction.bids?
current_user.id == auction.winning_bidder_id
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/view_model/auction_show.rb
Expand Up @@ -19,7 +19,7 @@ def auction
to: :auction,
prefix: true
)

delegate(
:auction_rules_href,
:auction_status,
Expand All @@ -29,7 +29,7 @@ def auction
:highlighted_bid_amount_as_currency,
to: :auction
)

def auction_status_header
if auction_won?
"Winning bid (#{auction.highlighted_bidder_name}):"
Expand Down
2 changes: 1 addition & 1 deletion app/models/view_model/auction_status/future.rb
Expand Up @@ -6,7 +6,7 @@ class Future < Struct.new(:auction)
def status_text
'Closed'
end

def label_class
'auction-label-future'
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/view_model/auction_status/open.rb
Expand Up @@ -7,7 +7,7 @@ class Open < Struct.new(:auction)
def status_text
'Open'
end

def label_class
'auction-label-open'
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/view_model/auction_status/over.rb
Expand Up @@ -6,7 +6,7 @@ class Over < Struct.new(:auction)
def status_text
'Closed'
end

def label_class
'auction-label-over'
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/view_model/auctions_index.rb
@@ -1,15 +1,15 @@
module ViewModel
class AuctionsIndex < Struct.new(:current_user, :auctions_query)
def auctions
@auctions ||= auctions_query.map {|auction| ViewModel::Auction.new(current_user, auction) }
@auctions ||= auctions_query.map { |auction| ViewModel::Auction.new(current_user, auction) }
end

def active_auction_count
auctions.count {|i| i.start_datetime < Time.now && Time.now < i.end_datetime }
auctions.count { |i| i.start_datetime < Time.now && Time.now < i.end_datetime }
end

def upcoming_auction_count
auctions.count {|i| Time.now < i.start_datetime }
auctions.count { |i| Time.now < i.start_datetime }
end

def header_partial
Expand Down
2 changes: 1 addition & 1 deletion app/models/view_model/user_bids.rb
Expand Up @@ -4,7 +4,7 @@ class UserBids

def initialize(user, all_bids)
@user = user
@bids = all_bids.select {|b| b.bidder.id == user.id }
@bids = all_bids.select { |b| b.bidder.id == user.id }
end

def has_bid?
Expand Down
10 changes: 4 additions & 6 deletions app/validators/duns_number_validator.rb
Expand Up @@ -3,7 +3,7 @@
class DunsNumberValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value.present? && invalid_duns_number?(value)
record.errors[attribute] << (I18n.t('activerecord.errors.models.user.attributes.duns_number.invalid'))
record.errors[attribute] << I18n.t('activerecord.errors.models.user.attributes.duns_number.invalid')
end
end

Expand All @@ -14,11 +14,9 @@ def invalid_duns_number?(value)
end

def formatted_duns(value)
begin
Samwise::Util.format_duns(duns: value)
rescue Samwise::Error::InvalidFormat
nil
end
Samwise::Util.format_duns(duns: value)
rescue Samwise::Error::InvalidFormat
nil
end

def contains_thirteen_integers?(duns_number)
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/business_time.rb
@@ -1,3 +1,3 @@
Holidays.between(Date.today, 5.years.from_now, :us, :observed).map{
Holidays.between(Date.today, 5.years.from_now, :us, :observed).map do
|holiday| BusinessTime::Config.holidays << holiday[:date]
}
end
1 change: 0 additions & 1 deletion features/step_definitions/admin_auctions_steps.rb
Expand Up @@ -51,7 +51,6 @@
select("published", from: "auction_published")
end


Then(/^I should be able to edit the existing auction form$/) do
@title = 'This is the form-edited title'
fill_in("auction_title", with: @title)
Expand Down
1 change: 0 additions & 1 deletion features/step_definitions/admin_users_steps.rb
Expand Up @@ -24,4 +24,3 @@
Then(/^I expect the page to show me the number of admin users$/) do
expect(page).to have_text("Admins (1)")
end

7 changes: 4 additions & 3 deletions features/step_definitions/auction_steps.rb
Expand Up @@ -52,9 +52,10 @@
Then(/^I should see the auction's (.+)$/) do |field|
if field == 'deadline'
expect(page).to have_text(
Presenter::DcTime.convert(@auction.end_datetime).
beginning_of_day.strftime(Presenter::DcTime::FORMAT)
)
Presenter::DcTime
.convert(@auction.end_datetime)
.beginning_of_day
.strftime(Presenter::DcTime::FORMAT))
else
expect(page).to have_text(@auction.send(field))
end
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/closed_auctions_steps.rb
Expand Up @@ -26,10 +26,10 @@
expect(page).not_to have_content("Current bid:")
end


Then(/^I should see the auction had a winning bid with name$/) do
auction = ViewModel::Auction.new(nil, @auction)
expect(page).to have_content("Winning bid (#{auction.highlighted_bidder_name}): #{auction.highlighted_bid_amount_as_currency}")
expect(page)
.to have_content("Winning bid (#{auction.highlighted_bidder_name}): #{auction.highlighted_bid_amount_as_currency}")
expect(page).not_to have_content("Current bid:")
end

Expand Down
1 change: 0 additions & 1 deletion features/step_definitions/flash_message_steps.rb
Expand Up @@ -27,4 +27,3 @@
expect(page).to have_content(message)
end
end

2 changes: 1 addition & 1 deletion features/step_definitions/login_steps.rb
Expand Up @@ -92,7 +92,7 @@ def fake_value_for_attribute(attribute)

When(/^I fill in the (.+) field on my profile page with "([^"]+)"$/) do |attribute, value|
attribute = attribute.parameterize('_')
@new_values ||= {}
@new_values ||= { }
@new_values[attribute] = value

step("I fill in the \"user_#{attribute}\" field with \"#{value}\"")
Expand Down

0 comments on commit ec19e86

Please sign in to comment.