Style fixes after rubocop upgrade

This commit is contained in:
Brenda Wallace
2018-04-02 15:48:16 +12:00
parent 11fd95e2b8
commit a00237dfcb
20 changed files with 29 additions and 35 deletions

View File

@@ -3,6 +3,6 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require 'rake/dsl_definition'
require File.expand_path('../config/application', __FILE__)
require File.expand_path('config/application', __dir__)
Rails.application.load_tasks

View File

@@ -11,7 +11,7 @@ class LikesController < ApplicationController
def destroy
@like = Like.find_by(id: params[:id], member: current_member)
return failed(@like, message: 'Unable to unlike') unless @like && @like.destroy
return failed(@like, message: 'Unable to unlike') unless @like&.destroy
success(@like, liked_by_member: false, status_code: :ok)
end
@@ -46,7 +46,7 @@ class LikesController < ApplicationController
format.json { render(json: { 'error': message }, status: :forbidden) }
format.html do
flash[:error] = message
if like && like.likeable
if like&.likeable
redirect_to like.likeable
else
redirect_to root_path

View File

@@ -10,6 +10,6 @@ class RobotsController < ApplicationController
private
def subdomain
request.subdomain.present? ? request.subdomain : nil
request.subdomain.presence
end
end

View File

@@ -61,9 +61,7 @@ module ApplicationHelper
# http://graph.facebook.com/12345678/picture?width=150&height=150
uri = URI.parse(member.preferred_avatar_uri)
if uri.host == 'graph.facebook.com'
uri.query = "&width=#{size}&height=#{size}"
end
uri.query = "&width=#{size}&height=#{size}" if uri.host == 'graph.facebook.com'
# TODO: Assess twitter - https://dev.twitter.com/overview/general/user-profile-images-and-banners
# TODO: Assess flickr - https://www.flickr.com/services/api/misc.buddyicons.html

View File

@@ -10,11 +10,11 @@ module PlantingsHelper
end
def display_planted_from(planting)
planting.planted_from.present? ? planting.planted_from : "not specified"
planting.planted_from.presence || "not specified"
end
def display_planting_quantity(planting)
planting.quantity.present? ? planting.quantity : "not specified"
planting.quantity.presence || "not specified"
end
def display_planting(planting)

View File

@@ -9,7 +9,7 @@ class CsvImporter
name, en_wikipedia_url, parent_name, scientific_names, alternate_names = row
@crop = Crop.find_or_create_by(name: name)
@crop.update_attributes(
@crop.update(
en_wikipedia_url: en_wikipedia_url,
creator_id: cropbot.id
)
@@ -26,7 +26,7 @@ class CsvImporter
def add_parent(parent_name)
parent = Crop.find_by(name: parent_name)
if parent
@crop.update_attributes(parent_id: parent.id)
@crop.update(parent_id: parent.id)
else
@crop.logger.warn("Warning: parent crop #{parent_name} not found")
end

View File

@@ -48,7 +48,7 @@ class Garden < ApplicationRecord
after_validation :cleanup_area
def cleanup_area
self.area = nil if area && area.zero?
self.area = nil if area&.zero?
self.area_unit = nil if area.blank?
end

View File

@@ -82,9 +82,9 @@ class Harvest < ApplicationRecord
end
def cleanup_quantities
self.quantity = nil if quantity && quantity.zero?
self.quantity = nil if quantity&.zero?
self.unit = nil if quantity.blank?
self.weight_quantity = nil if weight_quantity && weight_quantity.zero?
self.weight_quantity = nil if weight_quantity&.zero?
self.weight_unit = nil if weight_quantity.blank?
end

View File

@@ -157,9 +157,7 @@ class Member < ApplicationRecord
nearby_members = []
if place
latitude, longitude = Geocoder.coordinates(place, params: { limit: 1 })
if latitude && longitude
nearby_members = Member.located.sort_by { |x| x.distance_from([latitude, longitude]) }
end
nearby_members = Member.located.sort_by { |x| x.distance_from([latitude, longitude]) } if latitude && longitude
end
nearby_members
end

View File

@@ -51,7 +51,7 @@ class Photo < ApplicationRecord
end
def set_flickr_metadata!
update_attributes(flickr_metadata)
update(flickr_metadata)
end
def to_s

View File

@@ -95,9 +95,7 @@ class Planting < ApplicationRecord
end
def expected_lifespan
if planted_at.present? && finished_at.present?
return (finished_at - planted_at).to_i
end
return (finished_at - planted_at).to_i if planted_at.present? && finished_at.present?
crop.median_lifespan
end

View File

@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')

View File

@@ -4,7 +4,7 @@ require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")

View File

@@ -4,7 +4,7 @@ require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")

View File

@@ -4,8 +4,8 @@ Dir.chdir(VENDOR_PATH) do
begin
exec "yarnpkg #{ARGV.join(" ")}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
warn "Yarn executable was not detected in the system."
warn "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end

View File

@@ -1,4 +1,4 @@
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
if ENV['MY_RUBY_HOME']&.include?('rvm')
begin
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))

View File

@@ -2,6 +2,6 @@
# This command will automatically be run when you run "rails"
# with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
APP_PATH = File.expand_path('../config/application', __dir__)
require File.expand_path('../config/boot', __dir__)
require 'rails/commands'

View File

@@ -67,22 +67,22 @@ describe 'member' do
end
it 'has location and lat/long fields' do
member.update_attributes(location: 'Greenwich, UK')
member.update(location: 'Greenwich, UK')
member.location.should eq 'Greenwich, UK'
member.latitude.round(2).should eq 51.48
member.longitude.round(2).should eq 0.00
end
it 'empties the lat/long if location removed' do
member.update_attributes(location: 'Greenwich, UK')
member.update_attributes(location: '')
member.update(location: 'Greenwich, UK')
member.update(location: '')
member.location.should eq ''
member.latitude.should be_nil
member.longitude.should be_nil
end
it 'fails gracefully for unfound locations' do
member.update_attributes(location: 'Tatooine')
member.update(location: 'Tatooine')
member.location.should eq 'Tatooine'
member.latitude.should be_nil
member.longitude.should be_nil

View File

@@ -145,7 +145,7 @@ describe Post do
end
it "should be updated when post was modified" do
post.update_attributes(body: "[chard](crop)")
post.update(body: "[chard](crop)")
expect(post.crops).to eq [chard]
expect(chard.posts).to eq [post]

View File

@@ -17,7 +17,7 @@ SimpleCov.start :rails do
end
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
Rails.application.eager_load!