From eb70f6dc571d3148eacf825ca079666368dc844e Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 14 Jan 2017 20:48:19 +1300 Subject: [PATCH] Rubocop compliance for the seed model --- .rubocop_todo.yml | 7 ------- app/models/seed.rb | 29 ++++++++++++++++------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1e333f2cb..19d6d5f50 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -58,7 +58,6 @@ Lint/Void: Performance/StringReplacement: Exclude: - 'app/models/planting.rb' - - 'app/models/seed.rb' - 'spec/rails_helper.rb' # Offense count: 10 @@ -217,7 +216,6 @@ Style/ClassMethods: Exclude: - 'app/models/member.rb' - 'app/models/planting.rb' - - 'app/models/seed.rb' # Offense count: 2 # Cop supports --auto-correct. @@ -288,7 +286,6 @@ Style/IfUnlessModifier: - 'app/helpers/crops_helper.rb' - 'app/models/member.rb' - 'app/models/planting.rb' - - 'app/models/seed.rb' - 'config/initializers/geocoder.rb' - 'lib/tasks/growstuff.rake' @@ -316,7 +313,6 @@ Style/MethodCallParentheses: # SupportedStyles: symmetrical, new_line, same_line Style/MultilineArrayBraceLayout: Exclude: - - 'app/models/seed.rb' # Offense count: 8 # Cop supports --auto-correct. @@ -336,7 +332,6 @@ Style/MultilineHashBraceLayout: Exclude: - 'app/models/planting.rb' - 'app/models/product.rb' - - 'app/models/seed.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -413,7 +408,6 @@ Style/MutableConstant: Exclude: - 'app/controllers/members_controller.rb' - 'app/models/planting.rb' - - 'app/models/seed.rb' # Offense count: 7 # Cop supports --auto-correct. @@ -539,7 +533,6 @@ Style/RedundantSelf: - 'app/models/notification.rb' - 'app/models/photo.rb' - 'app/models/planting.rb' - - 'app/models/seed.rb' - 'lib/geocodable.rb' # Offense count: 9 diff --git a/app/models/seed.rb b/app/models/seed.rb index 6f441964a..a47c3cbf3 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -14,22 +14,25 @@ class Seed < ActiveRecord::Base validates :quantity, numericality: { only_integer: true, - greater_than_or_equal_to: 0 }, + greater_than_or_equal_to: 0 + }, allow_nil: true validates :days_until_maturity_min, numericality: { only_integer: true, - greater_than_or_equal_to: 0 }, + greater_than_or_equal_to: 0 + }, allow_nil: true validates :days_until_maturity_max, numericality: { only_integer: true, - greater_than_or_equal_to: 0 }, + greater_than_or_equal_to: 0 + }, allow_nil: true scope :tradable, -> { where("tradable_to != 'nowhere'") } - TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally) + TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze validates :tradable_to, inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\ "locally, nationally, or internationally" }, @@ -40,7 +43,8 @@ class Seed < ActiveRecord::Base 'certified organic', 'non-certified organic', 'conventional/non-organic', - 'unknown'] + 'unknown' + ].freeze validates :organic, inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\ "are organic or not, or that you don't know" }, @@ -51,21 +55,22 @@ class Seed < ActiveRecord::Base 'certified GMO-free', 'non-certified GMO-free', 'GMO', - 'unknown'] + 'unknown' + ].freeze validates :gmo, inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\ "genetically modified or not, or that you don't know" }, allow_nil: false, allow_blank: false - HEIRLOOM_VALUES = %w(heirloom hybrid unknown) + HEIRLOOM_VALUES = %w(heirloom hybrid unknown).freeze validates :heirloom, inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds are heirloom, hybrid, or unknown" }, allow_nil: false, allow_blank: false def tradable? - if self.tradable_to == 'nowhere' + if tradable_to == 'nowhere' false else true @@ -81,21 +86,19 @@ class Seed < ActiveRecord::Base # Seed.interesting # returns a list of interesting seeds, for use on the homepage etc - def Seed.interesting + def self.interesting howmany = 12 # max number to find interesting_seeds = [] Seed.tradable.each do |s| break if interesting_seeds.size == howmany - if s.interesting? - interesting_seeds.push(s) - end + interesting_seeds.push(s) if s.interesting? end interesting_seeds end def seed_slug - "#{owner.login_name}-#{crop}".downcase.gsub(' ', '-') + "#{owner.login_name}-#{crop}".downcase.tr(' ', '-') end end