diff --git a/.rubocop.yml b/.rubocop.yml index fb5297e0b..2f2b2f8e0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,6 +8,11 @@ AllCops: - 'db/schema.rb' - 'vendor/**/*' +Style/FileName: + Exclude: + - 'Gemfile' + - 'Gemfile.lock' + Style/StringLiterals: Enabled: false @@ -37,11 +42,8 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 1108 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives. -# URISchemes: http, https Metrics/LineLength: - Max: 223 + Max: 120 # Offense count: 8 Metrics/PerceivedComplexity: diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index f6af048e6..abf2102ae 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -215,6 +215,15 @@ class CropsController < ApplicationController private def crop_params - params.require(:crop).permit(:en_wikipedia_url, :name, :parent_id, :creator_id, :approval_status, :request_notes, :reason_for_rejection, :rejection_notes, scientific_names_attributes: [:scientific_name, :_destroy, :id]) + params.require(:crop).permit(:en_wikipedia_url, + :name, + :parent_id, + :creator_id, + :approval_status, + :request_notes, + :reason_for_rejection, + :rejection_notes, scientific_names_attributes: [:scientific_name, + :_destroy, + :id]) end end diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index 68bb919c4..6fe5347be 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -87,7 +87,9 @@ class GardensController < ApplicationController expire_fragment("homepage_stats") respond_to do |format| - format.html { redirect_to gardens_by_owner_path(owner: @garden.owner), notice: 'Garden was successfully deleted.' } + format.html do + redirect_to gardens_by_owner_path(owner: @garden.owner), notice: 'Garden was successfully deleted.' + end format.json { head :no_content } end end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index e3c48785e..027b40f21 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -15,7 +15,11 @@ class MembersController < ApplicationController respond_to do |format| format.html # index.html.haml - format.json { render json: @members.to_json(only: [:id, :login_name, :slug, :bio, :created_at, :location, :latitude, :longitude]) } + format.json { + render json: @members.to_json(only: [ + :id, :login_name, :slug, :bio, :created_at, :location, :latitude, :longitude + ]) + } end end @@ -32,7 +36,11 @@ class MembersController < ApplicationController respond_to do |format| format.html # show.html.haml - format.json { render json: @member.to_json(only: [:id, :login_name, :bio, :created_at, :slug, :location, :latitude, :longitude]) } + format.json { + render json: @member.to_json(only: [ + :id, :login_name, :bio, :created_at, :slug, :location, :latitude, :longitude + ]) + } format.rss { render( layout: false, locals: { member: @member } diff --git a/app/controllers/places_controller.rb b/app/controllers/places_controller.rb index 13c0bd05c..2f7331b3a 100644 --- a/app/controllers/places_controller.rb +++ b/app/controllers/places_controller.rb @@ -5,7 +5,11 @@ class PlacesController < ApplicationController respond_to do |format| format.html # json response is whatever we want to map here - format.json { render json: Member.located.to_json(only: [:id, :login_name, :slug, :location, :latitude, :longitude]) } + format.json do + render json: Member.located.to_json(only: [ + :id, :login_name, :slug, :location, :latitude, :longitude + ]) + end end end @@ -16,7 +20,11 @@ class PlacesController < ApplicationController @nearby_members = Member.nearest_to(params[:place]) respond_to do |format| format.html # show.html.haml - format.json { render json: @nearby_members.to_json(only: [:id, :login_name, :slug, :location, :latitude, :longitude]) } + format.json do + render json: @nearby_members.to_json(only: [ + :id, :login_name, :slug, :location, :latitude, :longitude + ]) + end end end diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 276024309..ca9de8ef0 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -71,7 +71,8 @@ class PlantingsController < ApplicationController respond_to do |format| if @planting.save - @planting.update_attribute(:days_before_maturity, update_days_before_maturity(@planting, planting_params[:crop_id])) + @planting.update_attribute(:days_before_maturity, + update_days_before_maturity(@planting, planting_params[:crop_id])) format.html { redirect_to @planting, notice: 'Planting was successfully created.' } format.json { render json: @planting, status: :created, location: @planting } expire_fragment("homepage_stats") @@ -90,7 +91,8 @@ class PlantingsController < ApplicationController respond_to do |format| if @planting.update(planting_params) - @planting.update_attribute(:days_before_maturity, update_days_before_maturity(@planting, planting_params[:crop_id])) + @planting.update_attribute(:days_before_maturity, + update_days_before_maturity(@planting, planting_params[:crop_id])) format.html { redirect_to @planting, notice: 'Planting was successfully updated.' } format.json { head :no_content } else diff --git a/app/helpers/auto_suggest_helper.rb b/app/helpers/auto_suggest_helper.rb index f7722c59c..9750b342b 100644 --- a/app/helpers/auto_suggest_helper.rb +++ b/app/helpers/auto_suggest_helper.rb @@ -13,9 +13,14 @@ module AutoSuggestHelper source_path = Rails.application.routes.url_helpers.send("#{source}s_search_path") %Q{ - - - + + + }.html_safe end diff --git a/app/helpers/gardens_helper.rb b/app/helpers/gardens_helper.rb index 57f0c7bc6..fc2beae4f 100644 --- a/app/helpers/gardens_helper.rb +++ b/app/helpers/gardens_helper.rb @@ -4,7 +4,9 @@ module GardensHelper if garden.description.nil? "no description provided." else - truncate(garden.description, length: 130, separator: ' ', omission: '... ') { link_to "Read more", garden_path(garden) } + truncate(garden.description, length: 130, separator: ' ', omission: '... ') do + link_to "Read more", garden_path(garden) + end end end diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index e81605912..57974620c 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -3,7 +3,10 @@ class Notifier < ActionMailer::Base default from: "Growstuff " def verifier - raise "RAILS_SECRET_TOKEN environment variable not set - have you created config/application.yml?" unless ENV['RAILS_SECRET_TOKEN'] + unless ENV['RAILS_SECRET_TOKEN'] + raise "RAILS_SECRET_TOKEN environment variable"\ + "not set - have you created config/application.yml?" + end return ActiveSupport::MessageVerifier.new(ENV['RAILS_SECRET_TOKEN']) end diff --git a/app/models/crop.rb b/app/models/crop.rb index 02acbdcf7..7de010b1e 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -1,4 +1,4 @@ -class Crop < ActiveRecord::Base +class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength extend FriendlyId friendly_id :name, use: [:slugged, :finders] @@ -22,10 +22,19 @@ class Crop < ActiveRecord::Base before_destroy {|crop| crop.posts.clear} default_scope { order("lower(name) asc") } - scope :recent, -> { where(approval_status: "approved").reorder("created_at desc") } - scope :toplevel, -> { where(approval_status: "approved", parent_id: nil) } - scope :popular, -> { where(approval_status: "approved").reorder("plantings_count desc, lower(name) asc") } - scope :randomized, -> { where(approval_status: "approved").reorder('random()') } # ok on sqlite and psql, but not on mysql + scope :recent, lambda { + where(approval_status: "approved").reorder("created_at desc") + } + scope :toplevel, lambda { + where(approval_status: "approved", parent_id: nil) + } + scope :popular, lambda { + where(approval_status: "approved").reorder("plantings_count desc, lower(name) asc") + } + scope :randomized, lambda { + # ok on sqlite and psql, but not on mysql + where(approval_status: "approved").reorder('random()') + } scope :pending_approval, -> { where(approval_status: "pending") } scope :approved, -> { where(approval_status: "approved") } scope :rejected, -> { where(approval_status: "rejected") } diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 3370d62a1..176562d9d 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -125,7 +125,8 @@ class Harvest < ActiveRecord::Base end if self.weight_quantity - string += " weighing #{number_to_human(self.weight_quantity, strip_insignificant_zeros: true)} #{self.weight_unit}" + string += " weighing #{number_to_human(self.weight_quantity, strip_insignificant_zeros: true)}"\ + " #{self.weight_unit}" end return string diff --git a/config/database.yml b/config/database.yml index eb75b3791..72f6533ae 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,16 +1,10 @@ development: adapter: postgresql database: growstuff_dev - host: localhost - user: postgres - password: postgres test: adapter: postgresql database: growstuff_test - host: localhost - user: postgres - password: postgres production: adapter: postgresql diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index d37c92188..3a7e49d44 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,3 +1,4 @@ +# rubocop:disable Metrics/LineLength # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| diff --git a/config/routes.rb b/config/routes.rb index 8d373feff..4f0438a11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,15 @@ -Growstuff::Application.routes.draw do +Growstuff::Application.routes.draw do # rubocop:disable Metrics/BlockLength get '/robots.txt' => 'robots#robots' resources :plant_parts - devise_for :members, controllers: { registrations: "registrations", passwords: "passwords", sessions: "sessions", omniauth_callbacks: "omniauth_callbacks" } + devise_for :members, controllers: { + registrations: "registrations", + passwords: "passwords", + sessions: "sessions", + omniauth_callbacks: "omniauth_callbacks" + } devise_scope :member do get '/members/unsubscribe/:message' => 'members#unsubscribe', :as => 'unsubscribe_member' end diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index 7d5d8a13f..89be5f63f 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -128,14 +128,18 @@ namespace :growstuff do puts "Adding products..." Product.find_or_create_by( name: "Annual subscription", - description: "An annual subscription gives you access to paid account features for one year. Does not auto-renew.", + description: "An annual subscription gives you access "\ + "to paid account features for one year. Does not auto-renew.", min_price: 3000, account_type_id: @paid_account.id, paid_months: 12 ) Product.find_or_create_by( name: "Seed account", - description: "A seed account helps Growstuff grow in its early days. It gives you all the features of a paid account, in perpetuity. This account type never expires.", + description: "A seed account helps Growstuff grow in its "\ + "early days. It gives you all the features of "\ + "a paid account, in perpetuity. This account "\ + "type never expires.", min_price: 15000, account_type_id: @seed_account.id, ) diff --git a/script/rails b/script/rails index f8da2cffd..8c7d72b27 100755 --- a/script/rails +++ b/script/rails @@ -1,5 +1,6 @@ #!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. +# 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__) diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 849762ad8..ca24daf83 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -20,7 +20,8 @@ feature "products" do click_link "New Product" expect(current_path).to eq new_product_path fill_in 'Name', with: 'Special offer' - # note that failing to fill in a mandatory field has a messy error. This is not a priority defect but should be raised at some point. + # note that failing to fill in a mandatory field has a messy error. + # This is not a priority defect but should be raised at some point. fill_in 'Minimum price', with: '150' click_button 'Save' expect(current_path).to eq product_path(Product.last) diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index ef07fb99c..3e6a71cea 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -137,11 +137,13 @@ feature "crop detail page", js: true do end scenario "has a link to OpenFarm" do - expect(page).to have_link "OpenFarm - Growing guide", href: "https://openfarm.cc/en/crops/#{URI.escape crop.name}" + expect(page).to have_link "OpenFarm - Growing guide", + href: "https://openfarm.cc/en/crops/#{URI.escape crop.name}" end scenario "has a link to gardenate" do - expect(page).to have_link "Gardenate - Planting reminders", href: "http://www.gardenate.com/plant/#{URI.escape crop.name}" + expect(page).to have_link "Gardenate - Planting reminders", + href: "http://www.gardenate.com/plant/#{URI.escape crop.name}" end end end diff --git a/spec/features/rss/plantings_spec.rb b/spec/features/rss/plantings_spec.rb index effad2969..597d82c01 100644 --- a/spec/features/rss/plantings_spec.rb +++ b/spec/features/rss/plantings_spec.rb @@ -8,6 +8,7 @@ feature 'Plantings RSS feed' do scenario 'The index title is what we expect' do visit plantings_path(format: 'rss') - expect(page).to have_content "Recent plantings from #{ @owner ? @owner : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})" + expect(page).to have_content "Recent plantings from "\ + "#{ @owner ? @owner : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})" end end diff --git a/spec/features/rss/posts_spec.rb b/spec/features/rss/posts_spec.rb index 2d900ebe4..8c48ad5d2 100644 --- a/spec/features/rss/posts_spec.rb +++ b/spec/features/rss/posts_spec.rb @@ -8,6 +8,7 @@ feature 'Posts RSS feed' do scenario 'The index title is what we expect' do visit posts_path(format: 'rss') - expect(page).to have_content "Recent posts from #{ @author ? @author : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})" + expect(page).to have_content "Recent posts from "\ + "#{ @author ? @author : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})" end end diff --git a/spec/features/rss/seeds_spec.rb b/spec/features/rss/seeds_spec.rb index 7e5320655..0d3957f19 100644 --- a/spec/features/rss/seeds_spec.rb +++ b/spec/features/rss/seeds_spec.rb @@ -8,6 +8,7 @@ feature 'Seeds RSS feed' do scenario 'The index title is what we expect' do visit seeds_path(format: 'rss') - expect(page).to have_content "Recent seeds from #{ @owner ? @owner : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})" + expect(page).to have_content "Recent seeds from "\ + "#{ @owner ? @owner : 'all members' } (#{ENV['GROWSTUFF_SITE_NAME']})" end end diff --git a/spec/helpers/crops_helper_spec.rb b/spec/helpers/crops_helper_spec.rb index 67714f4f0..49a570836 100644 --- a/spec/helpers/crops_helper_spec.rb +++ b/spec/helpers/crops_helper_spec.rb @@ -19,7 +19,9 @@ describe CropsHelper do end it 'should render' do - expect(helper.display_seed_availability(@member, @crop)).to eq "You have an unknown quantity of seeds of this crop." + expect( + helper.display_seed_availability(@member, @crop) + ).to eq "You have an unknown quantity of seeds of this crop." end end diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 4d59bdc68..6ff1bd47b 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -597,8 +597,17 @@ describe Crop do end context "crop rejections" do - let!(:rejected_reason) { FactoryGirl.create(:crop, name: 'tomato', approval_status: 'rejected', reason_for_rejection: 'not edible') } - let!(:rejected_other) { FactoryGirl.create(:crop, name: 'tomato', approval_status: 'rejected', reason_for_rejection: 'other', rejection_notes: 'blah blah blah') } + let!(:rejected_reason) do + FactoryGirl.create(:crop, name: 'tomato', + approval_status: 'rejected', + reason_for_rejection: 'not edible') + end + let!(:rejected_other) do + FactoryGirl.create(:crop, name: 'tomato', + approval_status: 'rejected', + reason_for_rejection: 'other', + rejection_notes: 'blah blah blah') + end describe "rejecting a crop" do it "should give reason if a default option" do diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index 58ae5f906..aa2238d54 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -48,7 +48,10 @@ describe Seed do it 'should refuse invalid tradable_to values' do @seed = FactoryGirl.build(:seed, tradable_to: 'not valid') @seed.should_not be_valid - @seed.errors[:tradable_to].should include("You may only trade seed nowhere, locally, nationally, or internationally") + @seed.errors[:tradable_to].should include( + "You may only trade seed nowhere, locally, "\ + "nationally, or internationally" + ) end it 'should not allow nil or blank values' do