From a6a7f789a3dcf07e87de8d9a4f07aeeb3dc304a2 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 1 Dec 2017 21:07:39 +1300 Subject: [PATCH 01/31] Rubocop upgrade (and some style fixes) --- .rubocop.yml | 2 ++ Gemfile | 5 ++-- Gemfile.lock | 6 ++-- Guardfile | 8 +++--- Rakefile | 0 app/controllers/alternate_names_controller.rb | 2 +- app/controllers/comments_controller.rb | 2 +- app/controllers/crops_controller.rb | 14 +++++----- app/controllers/gardens_controller.rb | 4 +-- app/controllers/members_controller.rb | 15 +++++----- app/controllers/photos_controller.rb | 4 +-- app/controllers/places_controller.rb | 12 ++++---- app/controllers/posts_controller.rb | 4 +-- .../scientific_names_controller.rb | 2 +- app/controllers/seeds_controller.rb | 2 +- app/helpers/crops_helper.rb | 2 +- app/helpers/harvests_helper.rb | 2 +- app/helpers/plantings_helper.rb | 4 +-- app/models/crop.rb | 2 +- app/models/csv_importer.rb | 2 +- app/models/seed.rb | 2 +- config/initializers/devise.rb | 2 +- config/routes.rb | 8 +++--- ...109130033_add_creation_index_to_updates.rb | 2 +- ...130215131921_rename_notification_fields.rb | 2 +- .../20140928044231_add_crops_posts_table.rb | 2 +- ...41002022459_create_index_harvest_photos.rb | 2 +- ...20150127043022_add_gardens_photos_table.rb | 2 +- db/migrate/20150201052245_create_cms.rb | 28 +++++++++---------- .../20161201154922_add_photos_seeds_table.rb | 2 +- lib/geocodable.rb | 2 +- spec/factories/member.rb | 2 +- spec/models/seed_spec.rb | 4 +-- spec/spec_helper.rb | 4 +-- 34 files changed, 81 insertions(+), 77 deletions(-) mode change 100644 => 100755 Rakefile diff --git a/.rubocop.yml b/.rubocop.yml index 8f8ebda37..5ddc01ccd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,12 +7,14 @@ AllCops: Exclude: - 'db/schema.rb' - 'vendor/**/*' + TargetRailsVersion: 4.0 Rails: Enabled: true Style/FileName: Exclude: + - 'Guardfile' - 'Gemfile' - 'Gemfile.lock' diff --git a/Gemfile b/Gemfile index 36a8608c0..c5d5d1fe1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source 'https://rubygems.org' ruby '2.4.1' @@ -46,8 +47,8 @@ gem 'comfortable_mexican_sofa' # content management system gem 'bootstrap-kaminari-views' # bootstrap views for kaminari gem 'kaminari' # pagination -gem 'activemerchant' gem 'active_utils' +gem 'activemerchant' gem 'sidekiq' # Markdown formatting for updates etc @@ -144,7 +145,7 @@ group :development, :test do gem 'rainbow', '< 2.2.0' # See https://github.com/sickill/rainbow/issues/44 gem 'rspec-activemodel-mocks' gem 'rspec-rails' # unit testing framework - gem 'rubocop', '<= 0.47.1', require: false # Pin to rubocop (0.47.1) as 0.48.0 is buggy + gem 'rubocop' gem 'selenium-webdriver' gem 'webrat' # provides HTML matchers for view tests end diff --git a/Gemfile.lock b/Gemfile.lock index 74118c7e9..af96def6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -366,6 +366,7 @@ GEM cocaine (~> 0.5.5) mime-types mimemagic (~> 0.3.0) + parallel (1.12.0) parser (2.4.0.2) ast (~> 2.3) pg (0.21.0) @@ -461,7 +462,8 @@ GEM rspec-mocks (~> 3.7.0) rspec-support (~> 3.7.0) rspec-support (3.7.0) - rubocop (0.47.1) + rubocop (0.49.1) + parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) @@ -623,7 +625,7 @@ DEPENDENCIES responders rspec-activemodel-mocks rspec-rails - rubocop (<= 0.47.1) + rubocop ruby-units sass-rails selenium-webdriver diff --git a/Guardfile b/Guardfile index edc8164d3..4b5f3ccb5 100644 --- a/Guardfile +++ b/Guardfile @@ -1,13 +1,13 @@ guard :rspec, - cmd: 'bundle exec rspec --format documentation', - failed_mode: :keep do + cmd: 'bundle exec rspec --format documentation', + failed_mode: :keep do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/libs/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } + watch('spec/spec_helper.rb') { "spec" } # Rails example watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } watch(%r{^spec/support/(.+)\.rb$}) { "spec" } watch('config/routes.rb') { "spec/routing" } -end \ No newline at end of file +end diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index b673a63d7..0f1471a8c 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -1,5 +1,5 @@ class AlternateNamesController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] + before_action :authenticate_member!, except: %i(index show) load_and_authorize_resource respond_to :html, :json responders :flash diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f85302d74..389efb825 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,5 +1,5 @@ class CommentsController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] + before_action :authenticate_member!, except: %i(index show) load_and_authorize_resource respond_to :html, :json respond_to :rss, only: :index diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 2a16206bb..0bdd06635 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -1,9 +1,9 @@ require 'will_paginate/array' class CropsController < ApplicationController - before_action :authenticate_member!, except: [:index, :hierarchy, :search, :show] + before_action :authenticate_member!, except: %i(index hierarchy search show) load_and_authorize_resource - skip_authorize_resource only: [:hierarchy, :search] + skip_authorize_resource only: %i(hierarchy search) respond_to :html, :json, :rss, :csv responders :flash @@ -134,7 +134,7 @@ class CropsController < ApplicationController end def recreate_names(param_name, name_type) - return unless params[param_name].present? + return if params[param_name].blank? destroy_names(name_type) params[param_name].each do |_i, value| create_name!(name_type, value) unless value.empty? @@ -159,9 +159,9 @@ class CropsController < ApplicationController :request_notes, :reason_for_rejection, :rejection_notes, - scientific_names_attributes: [:scientific_name, - :_destroy, - :id]) + scientific_names_attributes: %i(scientific_name + _destroy + id)) end def filename @@ -173,7 +173,7 @@ class CropsController < ApplicationController include: { plantings: { include: { - owner: { only: [:id, :login_name, :location, :latitude, :longitude] } + owner: { only: %i(id login_name location latitude longitude) } } }, scientific_names: { only: [:name] }, diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index 6b345dc70..ede5c2602 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -1,6 +1,6 @@ class GardensController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] - after_action :expire_homepage, only: [:create, :delete] + before_action :authenticate_member!, except: %i(index show) + after_action :expire_homepage, only: %i(create delete) load_and_authorize_resource respond_to :html, :json diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 1353a8720..c346eb8e3 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -1,6 +1,6 @@ class MembersController < ApplicationController - load_and_authorize_resource except: [:finish_signup, :unsubscribe, :view_follows, :view_followers, :show] - skip_authorize_resource only: [:nearby, :unsubscribe, :finish_signup] + load_and_authorize_resource except: %i(finish_signup unsubscribe view_follows view_followers show) + skip_authorize_resource only: %i(nearby unsubscribe finish_signup) respond_to :html, :json, :rss after_action :expire_homepage, only: :create @@ -62,7 +62,6 @@ class MembersController < ApplicationController @member.update(@type => false) flash.now[:notice] = I18n.t('members.unsubscribed', email_type: EMAIL_TYPE_STRING[@type]) - rescue ActiveSupport::MessageVerifier::InvalidSignature flash.now[:alert] = I18n.t('members.unsubscribe.error') end @@ -88,11 +87,11 @@ class MembersController < ApplicationController end def member_json_fields - [ - :id, :login_name, - :slug, :bio, :created_at, - :location, :latitude, :longitude - ] + %i( + id login_name + slug bio created_at + location latitude longitude + ) end def members diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 1f091b19b..18e95302b 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -1,6 +1,6 @@ class PhotosController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] - after_action :expire_homepage, only: [:create, :delete] + before_action :authenticate_member!, except: %i(index show) + after_action :expire_homepage, only: %i(create delete) load_and_authorize_resource respond_to :html, :json responders :flash diff --git a/app/controllers/places_controller.rb b/app/controllers/places_controller.rb index cf821e32b..4586b5d39 100644 --- a/app/controllers/places_controller.rb +++ b/app/controllers/places_controller.rb @@ -7,9 +7,9 @@ class PlacesController < ApplicationController format.html # json response is whatever we want to map here format.json do - render json: Member.located.to_json(only: [ - :id, :login_name, :slug, :location, :latitude, :longitude - ]) + render json: Member.located.to_json(only: %i( + id login_name slug location latitude longitude + )) end end end @@ -22,9 +22,9 @@ class PlacesController < ApplicationController respond_to do |format| format.html # show.html.haml format.json do - render json: @nearby_members.to_json(only: [ - :id, :login_name, :slug, :location, :latitude, :longitude - ]) + render json: @nearby_members.to_json(only: %i( + id login_name slug location latitude longitude + )) end end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 287ef6f2a..47aa6bd18 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,8 +1,8 @@ class PostsController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] + before_action :authenticate_member!, except: %i(index show) load_and_authorize_resource respond_to :html, :json - respond_to :rss, only: [:index, :show] + respond_to :rss, only: %i(index show) # GET /posts # GET /posts.json diff --git a/app/controllers/scientific_names_controller.rb b/app/controllers/scientific_names_controller.rb index 954a94dbc..cf58fd4f7 100644 --- a/app/controllers/scientific_names_controller.rb +++ b/app/controllers/scientific_names_controller.rb @@ -1,5 +1,5 @@ class ScientificNamesController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] + before_action :authenticate_member!, except: %i(index show) load_and_authorize_resource respond_to :html, :json responders :flash diff --git a/app/controllers/seeds_controller.rb b/app/controllers/seeds_controller.rb index f21b1b61a..f7cf530eb 100644 --- a/app/controllers/seeds_controller.rb +++ b/app/controllers/seeds_controller.rb @@ -1,5 +1,5 @@ class SeedsController < ApplicationController - before_action :authenticate_member!, except: [:index, :show] + before_action :authenticate_member!, except: %i(index show) load_and_authorize_resource respond_to :html, :json respond_to :csv, only: :index diff --git a/app/helpers/crops_helper.rb b/app/helpers/crops_helper.rb index c4dc00c0c..ea5003c3b 100644 --- a/app/helpers/crops_helper.rb +++ b/app/helpers/crops_helper.rb @@ -8,7 +8,7 @@ module CropsHelper total_quantity += seed.quantity if seed.quantity end - if !seeds.any? + if seeds.none? return "You don't have any seeds of this crop." end diff --git a/app/helpers/harvests_helper.rb b/app/helpers/harvests_helper.rb index 55aa92a2e..14277817b 100644 --- a/app/helpers/harvests_helper.rb +++ b/app/helpers/harvests_helper.rb @@ -15,7 +15,7 @@ module HarvestsHelper if harvest.unit == 'individual' # just the number number_to_human(harvest.quantity, strip_insignificant_zeros: true) - elsif !harvest.unit.blank? # pluralize anything else + elsif harvest.unit.present? # pluralize anything else pluralize(number_to_human(harvest.quantity, strip_insignificant_zeros: true), harvest.unit) else "#{number_to_human(harvest.quantity, strip_insignificant_zeros: true)} #{harvest.unit}" diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index b8e2b257c..f71dc8158 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -10,11 +10,11 @@ module PlantingsHelper end def display_planted_from(planting) - !planting.planted_from.blank? ? planting.planted_from : "not specified" + planting.planted_from.present? ? planting.planted_from : "not specified" end def display_planting_quantity(planting) - !planting.quantity.blank? ? planting.quantity : "not specified" + planting.quantity.present? ? planting.quantity : "not specified" end def display_planting(planting) diff --git a/app/models/crop.rb b/app/models/crop.rb index 4d21c4894..f103af1a3 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -1,6 +1,6 @@ class Crop < ActiveRecord::Base extend FriendlyId - friendly_id :name, use: [:slugged, :finders] + friendly_id :name, use: %i(slugged finders) ## ## Triggers diff --git a/app/models/csv_importer.rb b/app/models/csv_importer.rb index dadff9978..66297b13c 100644 --- a/app/models/csv_importer.rb +++ b/app/models/csv_importer.rb @@ -34,7 +34,7 @@ class CsvImporter def add_scientific_names(scientific_names) names_to_add = [] - if !scientific_names.blank? # i.e. we actually passed something in, which isn't a given + if scientific_names.present? # i.e. we actually passed something in, which isn't a given names_to_add = scientific_names.split(/,\s*/) elsif @crop.parent && !@crop.parent.scientific_names.empty? # pick up from parent names_to_add = @crop.parent.scientific_names.map(&:name) diff --git a/app/models/seed.rb b/app/models/seed.rb index 4213a7886..56c9f809d 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -1,7 +1,7 @@ class Seed < ActiveRecord::Base extend FriendlyId include PhotoCapable - friendly_id :seed_slug, use: [:slugged, :finders] + friendly_id :seed_slug, use: %i(slugged finders) TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally).freeze ORGANIC_VALUES = ['certified organic', 'non-certified organic', 'conventional/non-organic', 'unknown'].freeze diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ad33e335d..ec28eb983 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -43,7 +43,7 @@ Devise.setup do |config| # Configure which authentication keys should have whitespace stripped. # These keys will have whitespace before and after removed upon creating or # modifying a user and when used to authenticate or find a user. Default is :email. - config.strip_whitespace_keys = [:email, :login_name] + config.strip_whitespace_keys = %i(email login_name) # Tell if authentication through request.params is enabled. True by default. # It can be set to an array that will enable params authentication only for the diff --git a/config/routes.rb b/config/routes.rb index 30327901b..1f22a521a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,14 +12,14 @@ Growstuff::Application.routes.draw do devise_scope :member do get '/members/unsubscribe/:message' => 'members#unsubscribe', :as => 'unsubscribe_member' end - match '/members/:id/finish_signup' => 'members#finish_signup', via: [:get, :patch], :as => :finish_signup + match '/members/:id/finish_signup' => 'members#finish_signup', via: %i(get patch), :as => :finish_signup resources :members resources :photos delete 'photo_associations' => 'photo_associations#destroy' - resources :authentications, only: [:create, :destroy] + resources :authentications, only: %i(create destroy) resources :plantings do resources :harvests @@ -59,7 +59,7 @@ Growstuff::Application.routes.draw do get 'reply', on: :member end - resources :follows, only: [:create, :destroy] + resources :follows, only: %i(create destroy) get '/members/:login_name/follows' => 'members#view_follows', :as => 'member_follows' get '/members/:login_name/followers' => 'members#view_followers', :as => 'member_followers' @@ -78,7 +78,7 @@ Growstuff::Application.routes.draw do resources :order_items resources :products - resources :likes, only: [:create, :destroy] + resources :likes, only: %i(create destroy) get "home/index" root to: 'home#index' diff --git a/db/migrate/20121109130033_add_creation_index_to_updates.rb b/db/migrate/20121109130033_add_creation_index_to_updates.rb index 4e3f4c560..46601ef3d 100644 --- a/db/migrate/20121109130033_add_creation_index_to_updates.rb +++ b/db/migrate/20121109130033_add_creation_index_to_updates.rb @@ -1,5 +1,5 @@ class AddCreationIndexToUpdates < ActiveRecord::Migration def change - add_index :updates, [:created_at, :user_id] + add_index :updates, %i(created_at user_id) end end diff --git a/db/migrate/20130215131921_rename_notification_fields.rb b/db/migrate/20130215131921_rename_notification_fields.rb index 3f11af8af..63f52ae6d 100644 --- a/db/migrate/20130215131921_rename_notification_fields.rb +++ b/db/migrate/20130215131921_rename_notification_fields.rb @@ -1,6 +1,6 @@ class RenameNotificationFields < ActiveRecord::Migration def change - change_table :notifications do |t| # rubocop:disable Rails/ReversibleMigration + change_table :notifications do |t| t.rename :to_id, :recipient_id t.rename :from_id, :sender_id end diff --git a/db/migrate/20140928044231_add_crops_posts_table.rb b/db/migrate/20140928044231_add_crops_posts_table.rb index 475a993f5..6dcf9a494 100644 --- a/db/migrate/20140928044231_add_crops_posts_table.rb +++ b/db/migrate/20140928044231_add_crops_posts_table.rb @@ -4,7 +4,7 @@ class AddCropsPostsTable < ActiveRecord::Migration t.integer :crop_id t.integer :post_id end - add_index :crops_posts, [:crop_id, :post_id] + add_index :crops_posts, %i(crop_id post_id) add_index :crops_posts, :crop_id end end diff --git a/db/migrate/20141002022459_create_index_harvest_photos.rb b/db/migrate/20141002022459_create_index_harvest_photos.rb index 75ef69d36..95913bd04 100644 --- a/db/migrate/20141002022459_create_index_harvest_photos.rb +++ b/db/migrate/20141002022459_create_index_harvest_photos.rb @@ -1,5 +1,5 @@ class CreateIndexHarvestPhotos < ActiveRecord::Migration def change - add_index(:harvests_photos, [:harvest_id, :photo_id]) + add_index(:harvests_photos, %i(harvest_id photo_id)) end end diff --git a/db/migrate/20150127043022_add_gardens_photos_table.rb b/db/migrate/20150127043022_add_gardens_photos_table.rb index 7e8f8bd81..0c2b99dfe 100644 --- a/db/migrate/20150127043022_add_gardens_photos_table.rb +++ b/db/migrate/20150127043022_add_gardens_photos_table.rb @@ -4,6 +4,6 @@ class AddGardensPhotosTable < ActiveRecord::Migration t.integer :photo_id t.integer :garden_id end - add_index(:gardens_photos, [:garden_id, :photo_id]) + add_index(:gardens_photos, %i(garden_id photo_id)) end end diff --git a/db/migrate/20150201052245_create_cms.rb b/db/migrate/20150201052245_create_cms.rb index b52816813..e8ba4fb9e 100644 --- a/db/migrate/20150201052245_create_cms.rb +++ b/db/migrate/20150201052245_create_cms.rb @@ -33,8 +33,8 @@ class CreateCms < ActiveRecord::Migration t.boolean :is_shared, null: false, default: false t.timestamps null: true end - add_index :comfy_cms_layouts, [:parent_id, :position] - add_index :comfy_cms_layouts, [:site_id, :identifier], unique: true + add_index :comfy_cms_layouts, %i(parent_id position) + add_index :comfy_cms_layouts, %i(site_id identifier), unique: true # -- Pages -------------------------------------------------------------- create_table :comfy_cms_pages do |t| @@ -52,8 +52,8 @@ class CreateCms < ActiveRecord::Migration t.boolean :is_shared, null: false, default: false t.timestamps null: true end - add_index :comfy_cms_pages, [:site_id, :full_path] - add_index :comfy_cms_pages, [:parent_id, :position] + add_index :comfy_cms_pages, %i(site_id full_path) + add_index :comfy_cms_pages, %i(parent_id position) # -- Page Blocks -------------------------------------------------------- create_table :comfy_cms_blocks do |t| @@ -63,7 +63,7 @@ class CreateCms < ActiveRecord::Migration t.timestamps null: true end add_index :comfy_cms_blocks, [:identifier] - add_index :comfy_cms_blocks, [:blockable_id, :blockable_type] + add_index :comfy_cms_blocks, %i(blockable_id blockable_type) # -- Snippets ----------------------------------------------------------- create_table :comfy_cms_snippets do |t| @@ -75,8 +75,8 @@ class CreateCms < ActiveRecord::Migration t.boolean :is_shared, null: false, default: false t.timestamps null: true end - add_index :comfy_cms_snippets, [:site_id, :identifier], unique: true - add_index :comfy_cms_snippets, [:site_id, :position] + add_index :comfy_cms_snippets, %i(site_id identifier), unique: true + add_index :comfy_cms_snippets, %i(site_id position) # -- Files -------------------------------------------------------------- create_table :comfy_cms_files do |t| @@ -90,10 +90,10 @@ class CreateCms < ActiveRecord::Migration t.integer :position, null: false, default: 0 t.timestamps null: true end - add_index :comfy_cms_files, [:site_id, :label] - add_index :comfy_cms_files, [:site_id, :file_file_name] - add_index :comfy_cms_files, [:site_id, :position] - add_index :comfy_cms_files, [:site_id, :block_id] + add_index :comfy_cms_files, %i(site_id label) + add_index :comfy_cms_files, %i(site_id file_file_name) + add_index :comfy_cms_files, %i(site_id position) + add_index :comfy_cms_files, %i(site_id block_id) # -- Revisions ----------------------------------------------------------- create_table :comfy_cms_revisions, force: true do |t| @@ -102,7 +102,7 @@ class CreateCms < ActiveRecord::Migration t.text :data, text_limit t.datetime :created_at end - add_index :comfy_cms_revisions, [:record_type, :record_id, :created_at], + add_index :comfy_cms_revisions, %i(record_type record_id created_at), name: 'index_cms_revisions_on_rtype_and_rid_and_created_at' # -- Categories --------------------------------------------------------- @@ -111,7 +111,7 @@ class CreateCms < ActiveRecord::Migration t.string :label, null: false t.string :categorized_type, null: false end - add_index :comfy_cms_categories, [:site_id, :categorized_type, :label], + add_index :comfy_cms_categories, %i(site_id categorized_type label), unique: true, name: 'index_cms_categories_on_site_id_and_cat_type_and_label' @@ -120,7 +120,7 @@ class CreateCms < ActiveRecord::Migration t.string :categorized_type, null: false t.integer :categorized_id, null: false end - add_index :comfy_cms_categorizations, [:category_id, :categorized_type, :categorized_id], + add_index :comfy_cms_categorizations, %i(category_id categorized_type categorized_id), unique: true, name: 'index_cms_categorizations_on_cat_id_and_catd_type_and_catd_id' end diff --git a/db/migrate/20161201154922_add_photos_seeds_table.rb b/db/migrate/20161201154922_add_photos_seeds_table.rb index 31693d225..f4a2f18fe 100644 --- a/db/migrate/20161201154922_add_photos_seeds_table.rb +++ b/db/migrate/20161201154922_add_photos_seeds_table.rb @@ -4,6 +4,6 @@ class AddPhotosSeedsTable < ActiveRecord::Migration t.integer :photo_id t.integer :seed_id end - add_index(:photos_seeds, [:seed_id, :photo_id]) + add_index(:photos_seeds, %i(seed_id photo_id)) end end diff --git a/lib/geocodable.rb b/lib/geocodable.rb index 93a09aaf7..7e00c7566 100644 --- a/lib/geocodable.rb +++ b/lib/geocodable.rb @@ -6,7 +6,7 @@ module Geocodable private def empty_unwanted_geocodes - return unless location.blank? + return if location.present? self.latitude = nil self.longitude = nil end diff --git a/spec/factories/member.rb b/spec/factories/member.rb index b3380e628..619e7d4f2 100644 --- a/spec/factories/member.rb +++ b/spec/factories/member.rb @@ -2,7 +2,7 @@ FactoryBot.define do sequence(:email) { |n| "member#{n}@example.com" } sequence(:login_name) { |n| "member#{n}" } - factory :member, aliases: [:author, :owner, :sender, :recipient, :creator] do + factory :member, aliases: %i(author owner sender recipient creator) do login_name { generate(:login_name) } password 'password1' email { generate(:email) } diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index aa06af6eb..c1cd95cbd 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -112,7 +112,7 @@ describe Seed do end it 'should refuse invalid organic/GMO/heirloom values' do - [:organic, :gmo, :heirloom].each do |field| + %i(organic gmo heirloom).each do |field| @seed = FactoryBot.build(:seed, field => 'not valid') @seed.should_not be_valid @seed.errors[field].should_not be_empty @@ -120,7 +120,7 @@ describe Seed do end it 'should not allow nil or blank values' do - [:organic, :gmo, :heirloom].each do |field| + %i(organic gmo heirloom).each do |field| @seed = FactoryBot.build(:seed, field => nil) @seed.should_not be_valid @seed = FactoryBot.build(:seed, field => '') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 488353ff7..9a0b542df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,7 @@ RSpec.configure do |config| # # => "be bigger than 2 and smaller than 4" # ...rather than: # # => "be bigger than 2" - expectations.syntax = [:should, :expect] + expectations.syntax = %i(should expect) expectations.include_chain_clauses_in_custom_matcher_descriptions = true end @@ -39,7 +39,7 @@ RSpec.configure do |config| # a real object. This is generally recommended, and will default to # `true` in RSpec 4. mocks.verify_partial_doubles = false - mocks.syntax = [:should, :expect] + mocks.syntax = %i(should expect) end # The settings below are suggested to provide a good initial experience From 00395ae68b528c587796e02fdb8a8b6016b444ac Mon Sep 17 00:00:00 2001 From: deppbot Date: Tue, 5 Dec 2017 08:13:00 +0800 Subject: [PATCH 02/31] Bundle Update on 2017-12-05 --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 71addf491..7042c04c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,7 +58,7 @@ GEM public_suffix (>= 2.0.2, < 4.0) arel (6.0.4) ast (2.3.0) - autoprefixer-rails (7.1.6) + autoprefixer-rails (7.2.1) execjs bcrypt (3.1.11) better_errors (2.2.0) @@ -81,7 +81,7 @@ GEM sass (>= 3.3.4) bootstrap_form (2.7.0) builder (3.2.3) - bullet (5.6.1) + bullet (5.7.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.10.0) byebug (9.1.0) @@ -523,7 +523,7 @@ GEM trollop (1.16.2) tzinfo (1.2.4) thread_safe (~> 0.1) - uglifier (3.2.0) + uglifier (4.0.1) execjs (>= 0.3.0, < 3) unicode-display_width (1.3.0) unicorn (5.3.1) From 5b588bf9e96fd06a45a34210082d79d8e26224ac Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 11:21:25 +1300 Subject: [PATCH 03/31] Rubocop change namespace of some cops --- .rubocop.yml | 4 ++-- .rubocop_todo.yml | 22 ++-------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5ddc01ccd..545e1c1fa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -28,12 +28,12 @@ Style/PercentLiteralDelimiters: '%i': () '%w': () -Style/MultilineMethodCallIndentation: +Layout/MultilineMethodCallIndentation: EnforcedStyle: indented # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: with_first_parameter, with_fixed_indentation -Style/AlignParameters: +Layout/AlignParameters: EnforcedStyle: with_fixed_indentation Metrics/LineLength: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 211de1ca6..4adb2f125 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --no-offense-counts` -# on 2017-11-05 20:41:45 +1300 using RuboCop version 0.47.1. +# on 2017-12-06 11:20:15 +1300 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -18,7 +18,6 @@ Lint/UnusedMethodArgument: - 'app/controllers/passwords_controller.rb' - 'app/controllers/registrations_controller.rb' - 'app/validators/approved_validator.rb' - - 'spec/views/plantings/show.html.haml_spec.rb' # Cop supports --auto-correct. Performance/StringReplacement: @@ -78,7 +77,6 @@ Style/BarePercentLiterals: # IgnoredMethods: lambda, proc, it Style/BlockDelimiters: Exclude: - - 'spec/controllers/order_items_controller_spec.rb' - 'spec/features/notifications_spec.rb' - 'spec/models/ability_spec.rb' - 'spec/models/comment_spec.rb' @@ -87,12 +85,6 @@ Style/BlockDelimiters: - 'spec/models/post_spec.rb' - 'spec/views/crops/edit.html.haml_spec.rb' -# Cop supports --auto-correct. -Style/BlockEndNewline: - Exclude: - - 'spec/models/ability_spec.rb' - - 'spec/models/member_spec.rb' - # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: @@ -111,8 +103,8 @@ Style/ColonMethodCall: Style/EachForSimpleLoop: Exclude: - 'spec/models/crop_spec.rb' - - 'spec/views/home/_crops.html.haml_spec.rb' +# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: format, sprintf, percent Style/FormatString: @@ -146,20 +138,11 @@ Style/MultilineIfModifier: Exclude: - 'spec/rails_helper.rb' -Style/MultilineTernaryOperator: - Exclude: - - 'app/controllers/order_items_controller.rb' - # Cop supports --auto-correct. Style/MutableConstant: Exclude: - 'app/models/planting.rb' -# Cop supports --auto-correct. -Style/NegatedIf: - Exclude: - - 'app/helpers/crops_helper.rb' - # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. # SupportedStyles: skip_modifier_ifs, always @@ -193,7 +176,6 @@ Style/PercentLiteralDelimiters: Exclude: - 'app/helpers/auto_suggest_helper.rb' - 'spec/features/signin_spec.rb' - - 'spec/features/signout_spec.rb' # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. From 1f7f4f52d1698db9eabd4ad883e02e8e1e0f36de Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:02:48 +1300 Subject: [PATCH 04/31] Updated ability_spec.rb to use block end new lines --- spec/models/ability_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index f855a6cfd..587cde7ba 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -113,17 +113,21 @@ describe Ability do let(:order) { FactoryBot.create(:order, member: member) } let(:strangers_order) { FactoryBot.create(:order, - member: FactoryBot.create(:member)) } + member: FactoryBot.create(:member)) + } let(:completed_order) { FactoryBot.create(:completed_order, - member: member) } + member: member) + } let(:order_item) { FactoryBot.create(:order_item, order: order) } let(:strangers_order_item) { FactoryBot.create(:order_item, - order: strangers_order) } + order: strangers_order) + } let(:completed_order_item) { FactoryBot.create(:order_item, - order: completed_order) } + order: completed_order) + } context "standard member" do it "can read their own orders" do From 35414391c37967647bc1208dbf4a64f2caf343f5 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:07:18 +1300 Subject: [PATCH 05/31] modified spec to please rubocop --- spec/controllers/photo_associations_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/photo_associations_controller_spec.rb b/spec/controllers/photo_associations_controller_spec.rb index a15d2143d..42e0ccc37 100644 --- a/spec/controllers/photo_associations_controller_spec.rb +++ b/spec/controllers/photo_associations_controller_spec.rb @@ -33,7 +33,7 @@ describe PhotoAssociationsController do rescue nil end - end.not_to change { photo.harvests.count } + end.not_to change(photo.harvests, :count) end it { expect { delete :destroy, valid_params }.to raise_error(ActiveRecord::RecordNotFound) } end From f499f245de3acd8125648cd9bebf5cca924a0d34 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:08:05 +1300 Subject: [PATCH 06/31] Added new line after block end, for rubocpo --- spec/models/member_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 7dd56f1cb..df64a7038 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -355,7 +355,8 @@ describe 'member' do context "update account" do let(:product) { FactoryBot.create(:product, - paid_months: 3)} + paid_months: 3) + } let(:member) { FactoryBot.create(:member) } it "sets account_type" do From 2d00206abf95d5adef10b5e93331c445dbe86b82 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:10:26 +1300 Subject: [PATCH 07/31] Converted sprintf to format --- .rubocop_todo.yml | 9 --------- app/helpers/application_helper.rb | 4 ++-- spec/helpers/application_helper_spec.rb | 2 +- spec/views/shop/index_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4adb2f125..c1c42e7e8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -104,15 +104,6 @@ Style/EachForSimpleLoop: Exclude: - 'spec/models/crop_spec.rb' -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'app/helpers/application_helper.rb' - - 'spec/helpers/application_helper_spec.rb' - - 'spec/views/shop/index_spec.rb' - Style/IdenticalConditionalBranches: Exclude: - 'app/controllers/follows_controller.rb' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2fde0fcf8..639d27686 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,11 @@ module ApplicationHelper def price_in_dollars(price) - sprintf('%.2f', price / 100.0) + format('%.2f', price / 100.0) end # 999 cents becomes 9.99 AUD -- for products/orders/etc def price_with_currency(price) - sprintf('%.2f %s', price / 100.0, Growstuff::Application.config.currency) + format('%.2f %s', price / 100.0, Growstuff::Application.config.currency) end def parse_date(str) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index fe390bbc0..b3ea0ce52 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe ApplicationHelper do it "formats prices" do price_in_dollars(999).should eq '9.99' - price_with_currency(999).should eq '9.99 %s' % Growstuff::Application.config.currency + price_with_currency(999).should eq format('9.99 %s', Growstuff::Application.config.currency) end it "parses dates" do diff --git a/spec/views/shop/index_spec.rb b/spec/views/shop/index_spec.rb index 3bd0061d7..754f05c09 100644 --- a/spec/views/shop/index_spec.rb +++ b/spec/views/shop/index_spec.rb @@ -20,7 +20,7 @@ describe 'shop/index.html.haml', type: "view" do end it 'shows prices in configured currency' do - rendered.should have_content '9.99 %s' % Growstuff::Application.config.currency + rendered.should have_content format('9.99 %s', Growstuff::Application.config.currency) end it 'should contain an exchange rate link' do @@ -29,7 +29,7 @@ describe 'shop/index.html.haml', type: "view" do end it 'shows recommended price for products that have it' do - rendered.should have_content '12.00 %s' % Growstuff::Application.config.currency + rendered.should have_content format('12.00 %s', Growstuff::Application.config.currency) end it 'should contain an exchange rate link for recommended price' do From c925c9539881802e6da325754523407d17277f87 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:11:27 +1300 Subject: [PATCH 08/31] Use next, instead of a if wrapper --- .rubocop_todo.yml | 7 ------- lib/tasks/growstuff.rake | 11 +++++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c1c42e7e8..0895253dc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -134,13 +134,6 @@ Style/MutableConstant: Exclude: - 'app/models/planting.rb' -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Exclude: - - 'lib/tasks/growstuff.rake' - # Cop supports --auto-correct. Style/NilComparison: Exclude: diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index 1daab4175..25290dfb8 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -224,12 +224,11 @@ namespace :growstuff do task initialize_garden_locations: :environment do Member.located.find_each do |m| m.gardens.each do |g| - if g.location.blank? - g.location = m.location - g.latitude = m.latitude - g.longitude = m.longitude - g.save - end + next if g.location.present? + g.location = m.location + g.latitude = m.latitude + g.longitude = m.longitude + g.save end end end From 25b1836146a73b0676d922b8f79fcd3f9b50a811 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:13:01 +1300 Subject: [PATCH 09/31] Removed nil comparison --- .rubocop_todo.yml | 5 ----- lib/tasks/growstuff.rake | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0895253dc..5ee7657b5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -134,11 +134,6 @@ Style/MutableConstant: Exclude: - 'app/models/planting.rb' -# Cop supports --auto-correct. -Style/NilComparison: - Exclude: - - 'lib/tasks/growstuff.rake' - # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles. # SupportedStyles: predicate, comparison diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index 25290dfb8..f0c22aeeb 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -62,7 +62,7 @@ namespace :growstuff do # this fixes up anyone who has erroneously wound up with a 0,0 lat/long task depopulate_null_island: :environment do Member.find_each do |m| - if m.location and (m.latitude == nil and m.longitude == nil) + if m.location and (m.latitude.nil? and m.longitude.nil?) m.geocode m.save end From 515325c44e7f9e66f874729664cafdfb81e26939 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:14:31 +1300 Subject: [PATCH 10/31] Fixed up % delimiters --- .rubocop_todo.yml | 7 ------- app/helpers/auto_suggest_helper.rb | 4 ++-- spec/features/signin_spec.rb | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5ee7657b5..d965faff5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -149,13 +149,6 @@ Style/ParallelAssignment: Exclude: - 'app/mailers/notifier.rb' -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'app/helpers/auto_suggest_helper.rb' - - 'spec/features/signin_spec.rb' - # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed diff --git a/app/helpers/auto_suggest_helper.rb b/app/helpers/auto_suggest_helper.rb index a8a86de56..bd4b980c5 100644 --- a/app/helpers/auto_suggest_helper.rb +++ b/app/helpers/auto_suggest_helper.rb @@ -11,7 +11,7 @@ module AutoSuggestHelper resource = resource.class.name.downcase source_path = Rails.application.routes.url_helpers.send("#{source}s_search_path") - %Q{ + %Q( @@ -20,6 +20,6 @@ module AutoSuggestHelper - }.html_safe + ).html_safe end end diff --git a/spec/features/signin_spec.rb b/spec/features/signin_spec.rb index a6224e05a..acd9f5295 100644 --- a/spec/features/signin_spec.rb +++ b/spec/features/signin_spec.rb @@ -48,7 +48,7 @@ feature "signin", js: true do end describe "redirects to what you were trying to do" do - %w[plantings harvests posts photos gardens seeds].each do |m| + %w(plantings harvests posts photos gardens seeds).each do |m| it_behaves_like "redirects to what you were trying to do" do let(:model_name) { m } end From 3fdc23098e68359c9d8dae52d0e0f6aefa63a578 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:16:47 +1300 Subject: [PATCH 11/31] Use perl names for cli script variables --- .rubocop_todo.yml | 6 ------ script/check_contributors_md.rb | 2 +- script/heroku_maintenance.rb | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d965faff5..b4c4130f6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -160,12 +160,6 @@ Style/RegexpLiteral: - 'spec/views/members/index.html.haml_spec.rb' - 'spec/views/posts/index.html.haml_spec.rb' -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -# SupportedStyles: use_perl_names, use_english_names -Style/SpecialGlobalVars: - EnforcedStyle: use_perl_names - # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. # IgnoredMethods: respond_to, define_method diff --git a/script/check_contributors_md.rb b/script/check_contributors_md.rb index 444cf372d..3fca50489 100755 --- a/script/check_contributors_md.rb +++ b/script/check_contributors_md.rb @@ -18,7 +18,7 @@ if ENV['TRAVIS'] end else author = `git config github.user`.chomp - if $?.exitstatus.positive? + if $CHILD_STATUS.exitstatus.positive? abort %( Couldn't determine your GitHub username, and not in a Travis PR build Please set it using diff --git a/script/heroku_maintenance.rb b/script/heroku_maintenance.rb index c4cda6aa7..d2a20d67a 100755 --- a/script/heroku_maintenance.rb +++ b/script/heroku_maintenance.rb @@ -18,7 +18,7 @@ when "on" when "off" maintenance_state = false else - abort "usage: #{$0} (on|off)" + abort "usage: #{$PROGRAM_NAME} (on|off)" end puts "Turning #{maintenance_state} maintenance mode on app #{app}" From 878fc7ebcd99051a2c60ec26527e355d4ef9ffe1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:17:34 +1300 Subject: [PATCH 12/31] Use symbol procs --- .rubocop_todo.yml | 7 ------- lib/tasks/growstuff.rake | 8 ++------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b4c4130f6..e5d301c5c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -160,13 +160,6 @@ Style/RegexpLiteral: - 'spec/views/members/index.html.haml_spec.rb' - 'spec/views/posts/index.html.haml_spec.rb' -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -# IgnoredMethods: respond_to, define_method -Style/SymbolProc: - Exclude: - - 'lib/tasks/growstuff.rake' - # Cop supports --auto-correct. # Configuration parameters: SupportedStyles, WordRegex. # SupportedStyles: percent, brackets diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index f0c22aeeb..02827e126 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -276,16 +276,12 @@ namespace :growstuff do desc "October 2014: remove unused photos" task remove_unused_photos: :environment do - Photo.find_each do |p| - p.destroy_if_unused - end + Photo.find_each(&:destroy_if_unused) end desc "October 2014: generate crops_posts records for existing posts" task generate_crops_posts_records: :environment do - Post.find_each do |p| - p.save - end + Post.find_each(&:save) end desc "October 2014: add alternate names for crops" From ea2fcd09dc2aa7f2acbd18c90adace3407f9cd2b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:18:51 +1300 Subject: [PATCH 13/31] Fixed last old style word array --- .rubocop_todo.yml | 7 ------- app/controllers/omniauth_callbacks_controller.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e5d301c5c..bbde19b9d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -159,10 +159,3 @@ Style/RegexpLiteral: - 'spec/views/devise/registrations/edit_spec.rb' - 'spec/views/members/index.html.haml_spec.rb' - 'spec/views/posts/index.html.haml_spec.rb' - -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: 4 diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index afb56d3db..3d642cd3d 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -30,7 +30,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController @authentication = action.establish_authentication(auth, member) if action.member_created? - raise "Invalid provider" unless ['facebook', 'twitter', 'flickr'].index(auth['provider'].to_s) + raise "Invalid provider" unless %w(facebook twitter flickr).index(auth['provider'].to_s) session["devise.#{auth['provider']}_data"] = request.env["omniauth.auth"] sign_in member From 182c626226c50d82de99863ca0c04f0dd7d2d657 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:23:12 +1300 Subject: [PATCH 14/31] Prefer if/unless modifier --- .rubocop_todo.yml | 8 -------- app/helpers/crops_helper.rb | 4 +--- config/initializers/geocoder.rb | 4 +--- lib/tasks/growstuff.rake | 4 +--- 4 files changed, 3 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bbde19b9d..d57bd5d99 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -108,14 +108,6 @@ Style/IdenticalConditionalBranches: Exclude: - 'app/controllers/follows_controller.rb' -# Cop supports --auto-correct. -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Exclude: - - 'app/helpers/crops_helper.rb' - - 'config/initializers/geocoder.rb' - - 'lib/tasks/growstuff.rake' - # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: line_count_dependent, lambda, literal diff --git a/app/helpers/crops_helper.rb b/app/helpers/crops_helper.rb index ea5003c3b..b99d687aa 100644 --- a/app/helpers/crops_helper.rb +++ b/app/helpers/crops_helper.rb @@ -8,9 +8,7 @@ module CropsHelper total_quantity += seed.quantity if seed.quantity end - if seeds.none? - return "You don't have any seeds of this crop." - end + return "You don't have any seeds of this crop." if seeds.none? if total_quantity != 0 "You have #{total_quantity} #{Seed.model_name.human(count: total_quantity)} of this crop." diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb index 67ce37799..afe41f574 100644 --- a/config/initializers/geocoder.rb +++ b/config/initializers/geocoder.rb @@ -11,6 +11,4 @@ Geocoder.configure( ) # This configuration takes precedence over environment/test.rb # Reported as https://github.com/alexreisner/geocoder/issues/509 -if Geocoder.config.lookup != :test - Geocoder.configure(lookup: :nominatim) -end +Geocoder.configure(lookup: :nominatim) if Geocoder.config.lookup != :test diff --git a/lib/tasks/growstuff.rake b/lib/tasks/growstuff.rake index 02827e126..03b2e3d0e 100644 --- a/lib/tasks/growstuff.rake +++ b/lib/tasks/growstuff.rake @@ -140,9 +140,7 @@ namespace :growstuff do puts "Giving each member an account record..." Member.all.each do |m| - unless m.account - Account.create(member_id: m.id) - end + Account.create(member_id: m.id) unless m.account end puts "Making Skud a staff account..." From f516ef2e57cc9821c017c71a1a659f6974fde15a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:24:17 +1300 Subject: [PATCH 15/31] Don't use :: for method calls --- .rubocop_todo.yml | 6 ------ spec/lib/haml/filters/escaped_markdown_spec.rb | 2 +- spec/lib/haml/filters/growstuff_markdown_spec.rb | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d57bd5d99..ec6a11973 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -93,12 +93,6 @@ Style/ClassAndModuleChildren: - 'lib/actions/oauth_signup_action.rb' - 'lib/haml/filters/escaped_markdown.rb' -# Cop supports --auto-correct. -Style/ColonMethodCall: - Exclude: - - 'spec/lib/haml/filters/escaped_markdown_spec.rb' - - 'spec/lib/haml/filters/growstuff_markdown_spec.rb' - # Cop supports --auto-correct. Style/EachForSimpleLoop: Exclude: diff --git a/spec/lib/haml/filters/escaped_markdown_spec.rb b/spec/lib/haml/filters/escaped_markdown_spec.rb index 5afac0a04..415751293 100644 --- a/spec/lib/haml/filters/escaped_markdown_spec.rb +++ b/spec/lib/haml/filters/escaped_markdown_spec.rb @@ -5,7 +5,7 @@ require 'haml/helpers' describe 'Haml::Filters::Escaped_Markdown' do it 'is registered as the handler for :escaped_markdown' do - Haml::Filters::defined['escaped_markdown'].should == + Haml::Filters.defined['escaped_markdown'].should == Haml::Filters::EscapedMarkdown end diff --git a/spec/lib/haml/filters/growstuff_markdown_spec.rb b/spec/lib/haml/filters/growstuff_markdown_spec.rb index bc1b66b66..03ad3b0e1 100644 --- a/spec/lib/haml/filters/growstuff_markdown_spec.rb +++ b/spec/lib/haml/filters/growstuff_markdown_spec.rb @@ -24,7 +24,7 @@ end describe 'Haml::Filters::Growstuff_Markdown' do it 'is registered as the handler for :growstuff_markdown' do - Haml::Filters::defined['growstuff_markdown'].should == + Haml::Filters.defined['growstuff_markdown'].should == Haml::Filters::GrowstuffMarkdown end From 37f9dcd7ddf10027440a88a13af53125de7037f1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:26:58 +1300 Subject: [PATCH 16/31] for simple loops, use Integer.times --- .rubocop_todo.yml | 5 ----- spec/models/crop_spec.rb | 16 ++++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ec6a11973..80f225154 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -93,11 +93,6 @@ Style/ClassAndModuleChildren: - 'lib/actions/oauth_signup_action.rb' - 'lib/haml/filters/escaped_markdown.rb' -# Cop supports --auto-correct. -Style/EachForSimpleLoop: - Exclude: - - 'spec/models/crop_spec.rb' - Style/IdenticalConditionalBranches: Exclude: - 'app/controllers/follows_controller.rb' diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 5d9b671c0..73a460302 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -275,17 +275,17 @@ describe Crop do @crop2 = FactoryBot.create(:crop) # they need 3+ plantings each to be interesting - (1..3).each do + 3.times do FactoryBot.create(:planting, crop: @crop1) end - (1..3).each do + 3.times do FactoryBot.create(:planting, crop: @crop2) end # crops need 3+ photos to be interesting @photo = FactoryBot.create(:photo) [@crop1, @crop2].each do |c| - (1..3).each do + 3.times do c.plantings.first.photos << @photo c.plantings.first.save end @@ -302,13 +302,13 @@ describe Crop do @crop2 = FactoryBot.create(:crop) # only crop1 has plantings - (1..3).each do + 3.times do FactoryBot.create(:planting, crop: @crop1) end # ... and photos @photo = FactoryBot.create(:photo) - (1..3).each do + 3.times do @crop1.plantings.first.photos << @photo @crop1.plantings.first.save end @@ -324,16 +324,16 @@ describe Crop do @crop2 = FactoryBot.create(:crop) # both crops have plantings - (1..3).each do + 3.times do FactoryBot.create(:planting, crop: @crop1) end - (1..3).each do + 3.times do FactoryBot.create(:planting, crop: @crop2) end # but only crop1 has photos @photo = FactoryBot.create(:photo) - (1..3).each do + 3.times do @crop1.plantings.first.photos << @photo @crop1.plantings.first.save end From 3cc637017d330fb6e71ed7534c0963d99ba0011c Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:29:21 +1300 Subject: [PATCH 17/31] Avoid {} for multiline --- .rubocop_todo.yml | 16 ---------------- spec/features/notifications_spec.rb | 4 ++-- spec/models/ability_spec.rb | 16 ++++++++-------- spec/models/comment_spec.rb | 8 ++++---- spec/models/follow_spec.rb | 8 ++++---- spec/models/member_spec.rb | 4 ++-- spec/models/post_spec.rb | 16 ++++++++-------- spec/views/crops/edit.html.haml_spec.rb | 4 ++-- 8 files changed, 30 insertions(+), 46 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 80f225154..c3ce88de0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -69,22 +69,6 @@ Style/BarePercentLiterals: - 'app/helpers/auto_suggest_helper.rb' - 'spec/support/feature_helpers.rb' -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'spec/features/notifications_spec.rb' - - 'spec/models/ability_spec.rb' - - 'spec/models/comment_spec.rb' - - 'spec/models/follow_spec.rb' - - 'spec/models/member_spec.rb' - - 'spec/models/post_spec.rb' - - 'spec/views/crops/edit.html.haml_spec.rb' - # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index feaf5d351..aa81403d6 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -5,13 +5,13 @@ feature "Notifications", :js do let(:recipient) { create :member } context "On existing notification" do - let!(:notification) { + let!(:notification) do create :notification, sender: sender, recipient: recipient, body: "Notification body", post_id: nil - } + end background do login_as recipient diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 587cde7ba..ef746c8bc 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -111,23 +111,23 @@ describe Ability do context "orders" do let(:order) { FactoryBot.create(:order, member: member) } - let(:strangers_order) { + let(:strangers_order) do FactoryBot.create(:order, member: FactoryBot.create(:member)) - } - let(:completed_order) { + end + let(:completed_order) do FactoryBot.create(:completed_order, member: member) - } + end let(:order_item) { FactoryBot.create(:order_item, order: order) } - let(:strangers_order_item) { + let(:strangers_order_item) do FactoryBot.create(:order_item, order: strangers_order) - } - let(:completed_order_item) { + end + let(:completed_order_item) do FactoryBot.create(:order_item, order: completed_order) - } + end context "standard member" do it "can read their own orders" do diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index b98c52062..bc90ee8ba 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -17,9 +17,9 @@ describe Comment do let(:comment) { FactoryBot.create(:comment) } it "sends a notification when a comment is posted" do - expect { + expect do FactoryBot.create(:comment) - }.to change(Notification, :count).by(1) + end.to change(Notification, :count).by(1) end it "sets the notification fields" do @@ -35,9 +35,9 @@ describe Comment do it "doesn't send notifications to yourself" do @m = FactoryBot.create(:member) @p = FactoryBot.create(:post, author: @m) - expect { + expect do FactoryBot.create(:comment, post: @p, author: @m) - }.to change(Notification, :count).by(0) + end.to change(Notification, :count).by(0) end end diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index 4bf82f2b3..bd61fe2ee 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -7,16 +7,16 @@ describe Follow do end it "sends a notification when a follow is created" do - expect { + expect do Follow.create(follower_id: @member1.id, followed_id: @member2.id) - }.to change(Notification, :count).by(1) + end.to change(Notification, :count).by(1) end it "does not delete any members when follow is deleted" do - expect { + expect do follow = Follow.create(follower_id: @member1.id, followed_id: @member2.id) follow.destroy - }.not_to change(Member, :count) + end.not_to change(Member, :count) end context "when follow is created" do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index df64a7038..1911ae8da 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -353,10 +353,10 @@ describe 'member' do end context "update account" do - let(:product) { + let(:product) do FactoryBot.create(:product, paid_months: 3) - } + end let(:member) { FactoryBot.create(:member) } it "sets account_type" do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 566f451cb..cb8cbcc91 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -95,15 +95,15 @@ describe Post do let(:member2) { FactoryBot.create(:member) } it "sends a notification when a member is mentioned using @-syntax" do - expect { + expect do FactoryBot.create(:post, author: member, body: "Hey @#{member2}") - }.to change(Notification, :count).by(1) + end.to change(Notification, :count).by(1) end it "sends a notification when a member is mentioned using [](member) syntax" do - expect { + expect do FactoryBot.create(:post, author: member, body: "Hey [#{member2}](member)") - }.to change(Notification, :count).by(1) + end.to change(Notification, :count).by(1) end it "sets the notification field" do @@ -117,15 +117,15 @@ describe Post do it "sends notifications to all members mentioned" do member3 = FactoryBot.create(:member) - expect { + expect do FactoryBot.create(:post, author: member, body: "Hey @#{member2} & @#{member3}") - }.to change(Notification, :count).by(2) + end.to change(Notification, :count).by(2) end it "doesn't send notifications if you mention yourself" do - expect { + expect do FactoryBot.create(:post, author: member, body: "@#{member}") - }.to change(Notification, :count).by(0) + end.to change(Notification, :count).by(0) end end diff --git a/spec/views/crops/edit.html.haml_spec.rb b/spec/views/crops/edit.html.haml_spec.rb index eed85528d..19fac21af 100644 --- a/spec/views/crops/edit.html.haml_spec.rb +++ b/spec/views/crops/edit.html.haml_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' describe "crops/edit" do before(:each) do - controller.stub(:current_user) { + controller.stub(:current_user) do FactoryBot.create(:crop_wrangling_member) - } + end @crop = FactoryBot.create(:maize) 3.times do @crop.scientific_names.build From 24f18f78da48cc910854aaf2c802c3b1654d3fb1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 14:33:51 +1300 Subject: [PATCH 18/31] use bare percent literals --- .rubocop_todo.yml | 8 -------- app/helpers/auto_suggest_helper.rb | 2 +- spec/support/feature_helpers.rb | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c3ce88de0..2f5bce7a1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,14 +61,6 @@ Style/AsciiComments: Exclude: - 'config/initializers/comfortable_mexican_sofa.rb' -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: percent_q, bare_percent -Style/BarePercentLiterals: - Exclude: - - 'app/helpers/auto_suggest_helper.rb' - - 'spec/support/feature_helpers.rb' - # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: diff --git a/app/helpers/auto_suggest_helper.rb b/app/helpers/auto_suggest_helper.rb index bd4b980c5..caa0cd7ff 100644 --- a/app/helpers/auto_suggest_helper.rb +++ b/app/helpers/auto_suggest_helper.rb @@ -11,7 +11,7 @@ module AutoSuggestHelper resource = resource.class.name.downcase source_path = Rails.application.routes.url_helpers.send("#{source}s_search_path") - %Q( + %( diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index fd2d2c24b..f11a3a957 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -8,7 +8,7 @@ module FeatureHelpers def select_from_autocomplete(select) page.should have_selector('ul.ui-autocomplete li.ui-menu-item a') - selector = %Q{ul.ui-autocomplete li.ui-menu-item a:contains("#{select}")} + selector = %{ul.ui-autocomplete li.ui-menu-item a:contains("#{select}")} page.execute_script " $('#{selector}').mouseenter().click() " end end From 2b0f199329f058ee3ce1dd25a180e40c1b973365 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 15:19:34 +1300 Subject: [PATCH 19/31] change string replacement for performance reasons --- .rubocop_todo.yml | 5 ----- spec/rails_helper.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2f5bce7a1..4e0d899c7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -19,11 +19,6 @@ Lint/UnusedMethodArgument: - 'app/controllers/registrations_controller.rb' - 'app/validators/approved_validator.rb' -# Cop supports --auto-correct. -Performance/StringReplacement: - Exclude: - - 'spec/rails_helper.rb' - Rails/FilePath: Exclude: - 'spec/rails_helper.rb' diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 800df0ebb..e28dd6e24 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -37,7 +37,7 @@ if ENV['GROWSTUFF_CAPYBARA_DRIVER'].present? end Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example| - "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//, '')}" + "screenshot_#{example.description.tr(' ', '-').gsub(/^.*\/spec\//, '')}" end Capybara.app_host = 'http://localhost' From 8d03a3ffa8260294348fa5247d6e731c1a84c9c1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 6 Dec 2017 21:47:01 +1300 Subject: [PATCH 20/31] Most recent photos is a crop's default photo --- app/models/crop.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 4d21c4894..c3d4d7c7b 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -120,7 +120,8 @@ class Crop < ActiveRecord::Base # later we can choose a default photo based on different criteria, # eg. popularity def default_photo - return photos.first if photos.any? + # most recent photo + return photos.order(created_at: :desc).first if photos.any? # Crop has no photos? Look for the most recent harvest with a photo. harvest_with_photo = Harvest.where(crop_id: id).joins(:photos).order('harvests.id DESC').limit(1).first From 35d8461811a24e009e6c3b491fd93d0b80283197 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 7 Dec 2017 13:39:32 +1300 Subject: [PATCH 21/31] Order recent plantings by when they were planted --- app/views/members/_thumbnail.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/members/_thumbnail.html.haml b/app/views/members/_thumbnail.html.haml index 5ddce4c9f..f2939274e 100644 --- a/app/views/members/_thumbnail.html.haml +++ b/app/views/members/_thumbnail.html.haml @@ -13,7 +13,7 @@ %small %br/ Recently planted: - != member.plantings.first(3).map { |p| link_to p.crop_name, p }.join(", ") + != member.plantings.order(created_at:desc).first(3).map { |p| link_to p.crop_name, p }.join(", ") %p %small Joined @@ -24,4 +24,3 @@ = [localize_plural(member.gardens, Garden), localize_plural(member.plantings, Planting), localize_plural(member.seeds, Seed)].join(", ") - From cd35538b83b92c4ab4e419bf8a7d50fb2ff634f1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 7 Dec 2017 13:42:48 +1300 Subject: [PATCH 22/31] Order forums by name --- app/views/home/_discuss.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/home/_discuss.html.haml b/app/views/home/_discuss.html.haml index 9159cde46..9ffc6b502 100644 --- a/app/views/home/_discuss.html.haml +++ b/app/views/home/_discuss.html.haml @@ -5,7 +5,7 @@ = render partial: "posts/summary", locals: { posts: posts, howmany: 6 } - cache cache_key_for(Forum) do - - forums = Forum.all + - forums = Forum.all.order(:name) - if forums %ul.list-inline %li From 4ce3e8968f7f97a3479e0a4efe89a90b15125f0b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 7 Dec 2017 13:44:51 +1300 Subject: [PATCH 23/31] crops#show order posts by most recent first --- app/controllers/crops_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 2a16206bb..ffb5c49a1 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -50,7 +50,7 @@ class CropsController < ApplicationController def show @crop = Crop.includes(:scientific_names, plantings: :photos).find(params[:id]) - @posts = @crop.posts.paginate(page: params[:page]) + @posts = @crop.posts.order(created_at: :desc).paginate(page: params[:page]) respond_to do |format| format.html # show.html.haml From ac07f18b2d01f8848cc607fea795b824336a5525 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 7 Dec 2017 13:43:19 +1300 Subject: [PATCH 24/31] Show most recent seeds first --- app/views/home/_seeds.html.haml | 2 +- app/views/members/_thumbnail.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/home/_seeds.html.haml b/app/views/home/_seeds.html.haml index 6fc76779a..7469b90b0 100644 --- a/app/views/home/_seeds.html.haml +++ b/app/views/home/_seeds.html.haml @@ -2,7 +2,7 @@ %h2= t('.title') .row .col-md-8 - - Seed.includes(:owner, crop: :photos).interesting.first(6).each do |seed| + - Seed.includes(:owner, crop: :photos).order(created_at: :desc).interesting.first(6).each do |seed| .col-md-3 .thumbnail - cache cache_key_for(Crop, seed.id) do diff --git a/app/views/members/_thumbnail.html.haml b/app/views/members/_thumbnail.html.haml index f2939274e..c9504ea96 100644 --- a/app/views/members/_thumbnail.html.haml +++ b/app/views/members/_thumbnail.html.haml @@ -13,7 +13,7 @@ %small %br/ Recently planted: - != member.plantings.order(created_at:desc).first(3).map { |p| link_to p.crop_name, p }.join(", ") + != member.plantings.order(created_at: :desc).first(3).map { |p| link_to p.crop_name, p }.join(", ") %p %small Joined From ec149997b02e8fe1a50f8926b182f2bf5d41f612 Mon Sep 17 00:00:00 2001 From: deppbot Date: Fri, 8 Dec 2017 12:11:27 +0800 Subject: [PATCH 25/31] Bundle Update on 2017-12-08 --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7042c04c2..e8b7c8f13 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,7 +58,7 @@ GEM public_suffix (>= 2.0.2, < 4.0) arel (6.0.4) ast (2.3.0) - autoprefixer-rails (7.2.1) + autoprefixer-rails (7.2.2) execjs bcrypt (3.1.11) better_errors (2.2.0) @@ -181,8 +181,8 @@ GEM factory_bot_rails (4.8.2) factory_bot (~> 4.8.2) railties (>= 3.0.0) - faker (1.8.4) - i18n (~> 0.5) + faker (1.8.5) + i18n (~> 0.9.1) faraday (0.12.2) multipart-post (>= 1.2, < 3) ffi (1.9.18) @@ -468,7 +468,7 @@ GEM ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.9.0) - ruby-units (2.2.0) + ruby-units (2.2.1) ruby_dep (1.5.0) ruby_parser (3.10.1) sexp_processor (~> 4.9) @@ -519,7 +519,7 @@ GEM thread_safe (0.3.6) tilt (2.0.8) timecop (0.9.1) - tins (1.16.0) + tins (1.16.3) trollop (1.16.2) tzinfo (1.2.4) thread_safe (~> 0.1) From 08dc2a0513555a82343d649f7ad3447777632eae Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 9 Dec 2017 22:24:51 +1300 Subject: [PATCH 26/31] Show photos of a planting's harvests --- app/views/harvests/_card.html.haml | 29 +++++++++++++++++++ app/views/harvests/_thumbnail.html.haml | 38 ++++++------------------- app/views/harvests/index.html.haml | 2 +- app/views/plantings/_actions.html.haml | 2 +- app/views/plantings/_harvests.html.haml | 20 +++++++------ app/views/plantings/_progress.html.haml | 7 ++--- app/views/plantings/show.html.haml | 16 ++++++----- 7 files changed, 64 insertions(+), 50 deletions(-) create mode 100644 app/views/harvests/_card.html.haml diff --git a/app/views/harvests/_card.html.haml b/app/views/harvests/_card.html.haml new file mode 100644 index 000000000..e82d53725 --- /dev/null +++ b/app/views/harvests/_card.html.haml @@ -0,0 +1,29 @@ +.panel.panel-success + .panel-heading + %h3.panel-title + = link_to "#{harvest.owner.login_name}'s #{harvest.crop.name} harvest", harvest + - if can? :edit, harvest + %a.pull-right{ href: edit_harvest_path(harvest), role: "button", id: "edit_harvest_glyphicon" } + %span.glyphicon.glyphicon-pencil{ title: "Edit" } + .panel-body + .row + .col-md-4 + = link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'), + alt: harvest.crop.name, class: 'img'), + harvest + .col-md-8 + %dl.dl-horizontal + %dt Crop : + %dd= link_to harvest.crop.name, harvest.crop + %dt Plant part : + %dd= link_to harvest.plant_part, harvest.plant_part + %dt Quantity : + %dd= display_quantity(harvest) + %dt Harvest date : + %dd= harvest.harvested_at + .panel-footer + %dt Description + %dd.truncate + = display_harvest_description(harvest) + = if harvest.description.present? + - link_to "Read more", harvest_path(harvest) diff --git a/app/views/harvests/_thumbnail.html.haml b/app/views/harvests/_thumbnail.html.haml index e82d53725..9a9beac0c 100644 --- a/app/views/harvests/_thumbnail.html.haml +++ b/app/views/harvests/_thumbnail.html.haml @@ -1,29 +1,9 @@ -.panel.panel-success - .panel-heading - %h3.panel-title - = link_to "#{harvest.owner.login_name}'s #{harvest.crop.name} harvest", harvest - - if can? :edit, harvest - %a.pull-right{ href: edit_harvest_path(harvest), role: "button", id: "edit_harvest_glyphicon" } - %span.glyphicon.glyphicon-pencil{ title: "Edit" } - .panel-body - .row - .col-md-4 - = link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'), - alt: harvest.crop.name, class: 'img'), - harvest - .col-md-8 - %dl.dl-horizontal - %dt Crop : - %dd= link_to harvest.crop.name, harvest.crop - %dt Plant part : - %dd= link_to harvest.plant_part, harvest.plant_part - %dt Quantity : - %dd= display_quantity(harvest) - %dt Harvest date : - %dd= harvest.harvested_at - .panel-footer - %dt Description - %dd.truncate - = display_harvest_description(harvest) - = if harvest.description.present? - - link_to "Read more", harvest_path(harvest) +.thumbnail + .harvest-thumbnail + - if harvest + = link_to image_tag((harvest.default_photo ? harvest.default_photo.thumbnail_url : 'placeholder_150.png'), + alt: harvest.crop.name, class: 'img'), + harvest + .harvestinfo + .harvest-name + = link_to harvest, harvest diff --git a/app/views/harvests/index.html.haml b/app/views/harvests/index.html.haml index fa0be4ed3..f743f8ad3 100644 --- a/app/views/harvests/index.html.haml +++ b/app/views/harvests/index.html.haml @@ -15,7 +15,7 @@ - unless @harvests.empty? - @harvests.each do |harvest| .col-md-6 - = render partial: 'harvests/thumbnail', locals: { harvest: harvest } + = render 'harvests/card', harvest: harvest .pagination = page_entries_info @harvests diff --git a/app/views/plantings/_actions.html.haml b/app/views/plantings/_actions.html.haml index d72f6243b..b2c2d5f98 100644 --- a/app/views/plantings/_actions.html.haml +++ b/app/views/plantings/_actions.html.haml @@ -16,7 +16,7 @@ %span.glyphicon.glyphicon-ok{ title: "Finished" } Mark as finished - - if can?(:create, Harvest) + - if can? :edit, planting = link_to new_planting_harvest_path(planting), class: 'btn btn-default btn-xs' do %span.glyphicon.glyphicon-leaf{ title: "Harvest" } Harvest diff --git a/app/views/plantings/_harvests.html.haml b/app/views/plantings/_harvests.html.haml index 99535b6be..5edf14a3d 100644 --- a/app/views/plantings/_harvests.html.haml +++ b/app/views/plantings/_harvests.html.haml @@ -1,8 +1,12 @@ -- unless planting.harvests.empty? - Harvests: - %ul - - planting.harvests.includes(:crop).each do |harvest| - %li - = harvest.harvested_at ? harvest.harvested_at : "undated" - = link_to harvest, harvest_path(harvest) - = link_to "more harvests from this planting", planting_harvests_path(planting) +- if planting.harvests.empty? + %p no harvests yet +- else + .row + - planting.harvests.order(created_at: :desc).includes(:crop).each do |harvest| + .col-xs-6.col-md-2 + = render 'harvests/thumbnail', harvest: harvest + - if can? :edit, planting + .col-xs-6.col-md-2 + = link_to new_planting_harvest_path(planting), class: 'btn btn-primary' do + %span.glyphicon.glyphicon-leaf{ title: "Harvest" } + Harvest diff --git a/app/views/plantings/_progress.html.haml b/app/views/plantings/_progress.html.haml index 876259b85..a594de75d 100644 --- a/app/views/plantings/_progress.html.haml +++ b/app/views/plantings/_progress.html.haml @@ -1,15 +1,14 @@ - if planting.crop.perennial %p Perennial - elsif !planting.planted? - - if show_explanation == true - Progress: 0% - not planted yet + - if show_explanation + %p Progress: 0% - not planted yet = render "plantings/progress_bar", status: "not planted", progress: 0 - elsif planting.finished? = render "plantings/progress_bar", status: 'finished', progress: 100 - elsif planting.finish_predicted_at.nil? - if show_explanation == true - Progress: Not enough data + %p Progress: Not enough data = render "plantings/progress_bar", status: "unknown", progress: nil - - else = render "plantings/progress_bar", status: 'growing', progress: planting.percentage_grown diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index 099571218..7c197b7bd 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -9,6 +9,7 @@ = tag("meta", property: "og:url", content: request.original_url) = tag("meta", property: "og:site_name", content: ENV['GROWSTUFF_SITE_NAME']) +%p= render 'plantings/actions', planting: @planting .row.planting .col-md-6 %dl.dl-horizontal.planting-attributes @@ -45,11 +46,11 @@ %dd - if @planting.finish_predicted_at.present? = @planting.finish_predicted_at - - else + - elsif @planting.planted_at.blank? %strong Set planted date to get predictions - %dt Finished: - %dd= display_finished(@planting) - + - if @planting.finished? + %dt Finished: + %dd= display_finished(@planting) - if @planting.crop.median_lifespan.present? %dt Expected Lifespan: %dd #{@planting.crop.median_lifespan} days @@ -63,10 +64,11 @@ %dt Last Harvest: %dd #{@planting.days_to_last_harvest} days after planting - %p= render 'plantings/harvests', planting: @planting - %p= render 'plantings/progress', planting: @planting, show_explanation: true - = render 'plantings/actions', planting: @planting + %h2 Progress + %p= render 'plantings/progress', planting: @planting, show_explanation: true + %h2 Harvests + %p= render 'plantings/harvests', planting: @planting .col-md-6 = render partial: "crops/index_card", locals: { crop: @planting.crop } From 47e82eb0a70a80a8c4291641728c85cb764269a5 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 10 Dec 2017 19:50:08 +1300 Subject: [PATCH 27/31] Convert hashes in routes --- config/routes.rb | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 1f22a521a..2a9aa7d5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,9 +10,9 @@ Growstuff::Application.routes.draw do omniauth_callbacks: "omniauth_callbacks" } devise_scope :member do - get '/members/unsubscribe/:message' => 'members#unsubscribe', :as => 'unsubscribe_member' + get '/members/unsubscribe/:message' => 'members#unsubscribe', as: 'unsubscribe_member' end - match '/members/:id/finish_signup' => 'members#finish_signup', via: %i(get patch), :as => :finish_signup + match '/members/:id/finish_signup' => 'members#finish_signup', via: %i(get patch), as: :finish_signup resources :members @@ -24,30 +24,30 @@ Growstuff::Application.routes.draw do resources :plantings do resources :harvests end - get '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner' - get '/plantings/crop/:crop' => 'plantings#index', :as => 'plantings_by_crop' + get '/plantings/owner/:owner' => 'plantings#index', as: 'plantings_by_owner' + get '/plantings/crop/:crop' => 'plantings#index', as: 'plantings_by_crop' resources :gardens - get '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner' + get '/gardens/owner/:owner' => 'gardens#index', as: 'gardens_by_owner' resources :seeds - get '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' - get '/seeds/crop/:crop' => 'seeds#index', :as => 'seeds_by_crop' + get '/seeds/owner/:owner' => 'seeds#index', as: 'seeds_by_owner' + get '/seeds/crop/:crop' => 'seeds#index', as: 'seeds_by_crop' resources :harvests - get '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner' - get '/harvests/crop/:crop' => 'harvests#index', :as => 'harvests_by_crop' + get '/harvests/owner/:owner' => 'harvests#index', as: 'harvests_by_owner' + get '/harvests/crop/:crop' => 'harvests#index', as: 'harvests_by_crop' resources :posts - get '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' + get '/posts/author/:author' => 'posts#index', as: 'posts_by_author' resources :scientific_names resources :alternate_names - get 'crops/requested' => 'crops#requested', :as => 'requested_crops' - get 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' - get 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy' - get 'crops/search' => 'crops#search', :as => 'crops_search' + get 'crops/requested' => 'crops#requested', as: 'requested_crops' + get 'crops/wrangle' => 'crops#wrangle', as: 'wrangle_crops' + get 'crops/hierarchy' => 'crops#hierarchy', as: 'crops_hierarchy' + get 'crops/search' => 'crops#search', as: 'crops_search' resources :crops do get 'photos' => 'photos#index' end @@ -60,20 +60,20 @@ Growstuff::Application.routes.draw do end resources :follows, only: %i(create destroy) - get '/members/:login_name/follows' => 'members#view_follows', :as => 'member_follows' - get '/members/:login_name/followers' => 'members#view_followers', :as => 'member_followers' + get '/members/:login_name/follows' => 'members#view_follows', as: 'member_follows' + get '/members/:login_name/followers' => 'members#view_followers', as: 'member_followers' get '/places' => 'places#index' - get '/places/search' => 'places#search', :as => 'search_places' - get '/places/:place' => 'places#show', :as => 'place' + get '/places/search' => 'places#search', as: 'search_places' + get '/places/:place' => 'places#show', as: 'place' # everything for paid accounts etc resources :account_types resources :accounts resources :orders - get 'orders/:id/checkout' => 'orders#checkout', :as => 'checkout_order' - get 'orders/:id/complete' => 'orders#complete', :as => 'complete_order' - get 'orders/:id/cancel' => 'orders#cancel', :as => 'cancel_order' + get 'orders/:id/checkout' => 'orders#checkout', as: 'checkout_order' + get 'orders/:id/complete' => 'orders#complete', as: 'complete_order' + get 'orders/:id/cancel' => 'orders#cancel', as: 'cancel_order' resources :order_items resources :products @@ -93,7 +93,7 @@ Growstuff::Application.routes.draw do get '/admin/orders' => 'admin/orders#index' get '/admin/orders/:action' => 'admin/orders#:action' get '/admin' => 'admin#index' - get '/admin/newsletter' => 'admin#newsletter', :as => :admin_newsletter + get '/admin/newsletter' => 'admin#newsletter', as: :admin_newsletter get '/admin/:action' => 'admin#:action' namespace :api do From 291f865f7f7d6d19925a0217e92ad420b11f3878 Mon Sep 17 00:00:00 2001 From: deppbot Date: Mon, 11 Dec 2017 16:09:34 +0800 Subject: [PATCH 28/31] Bundle Update on 2017-12-11 --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6d22c1f1a..de0b44b30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -232,11 +232,11 @@ GEM haml (>= 4.0.6, < 6.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - haml_lint (0.25.1) + haml_lint (0.26.0) haml (>= 4.0, < 5.1) rainbow rake (>= 10, < 13) - rubocop (>= 0.47.0) + rubocop (>= 0.49.0) sysexits (~> 1.1) hashie (3.5.6) heroics (0.0.24) @@ -335,7 +335,7 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) - oauth (0.5.3) + oauth (0.5.4) oauth2 (1.4.0) faraday (>= 0.8, < 0.13) jwt (~> 1.0) @@ -525,7 +525,7 @@ GEM trollop (1.16.2) tzinfo (1.2.4) thread_safe (~> 0.1) - uglifier (4.0.1) + uglifier (4.0.2) execjs (>= 0.3.0, < 3) unicode-display_width (1.3.0) unicorn (5.3.1) From bafe2b7fd1c82cb9c552b30e17948627baddba29 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 12 Dec 2017 11:00:57 +0000 Subject: [PATCH 29/31] Bump coffeelint from 1.16.0 to 2.0.7 Bumps [coffeelint](https://github.com/clutchski/coffeelint) from 1.16.0 to 2.0.7. - [Commits](https://github.com/clutchski/coffeelint/commits) --- package-lock.json | 20 ++++++++++---------- package.json | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc703767c..013886a6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -195,19 +195,13 @@ "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, - "coffee-script": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.11.1.tgz", - "integrity": "sha1-vxxHrWREOg2V0S3ysUfMCk2q1uk=", - "dev": true - }, "coffeelint": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/coffeelint/-/coffeelint-1.16.0.tgz", - "integrity": "sha1-g9jtHa/eOmd95E57ihi+YHdh5tg=", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/coffeelint/-/coffeelint-2.0.7.tgz", + "integrity": "sha1-lg/VuXVrhFGU6fl6R1bmKGEha3Q=", "dev": true, "requires": { - "coffee-script": "1.11.1", + "coffeescript": "2.0.3", "glob": "7.1.2", "ignore": "3.3.7", "optimist": "0.6.1", @@ -215,6 +209,12 @@ "strip-json-comments": "1.0.4" } }, + "coffeescript": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.0.3.tgz", + "integrity": "sha512-iIfUN+71IyI2FQABXh1luzZeQgqwUPeWh6lDovJatQQs+30bvyGnBY0r4BnD0hoMAasNuZVHlL1U09Oy1ZfSeg==", + "dev": true + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/package.json b/package.json index a46ef1516..f41b67b64 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "dependencies": {}, "devDependencies": { - "coffeelint": "^1.16.0", + "coffeelint": "^2.0.7", "csslint": "^1.0.5", "eslint": "^3.17.1", "jshint": "^2.9.4" From 72f52230a19c148b6ac6a308edb3def86b17dc64 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 13 Dec 2017 22:15:11 +1300 Subject: [PATCH 30/31] Fix Growstuff::OauthSignupAction not found error when connecting flickr account --- app/controllers/authentications_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/authentications_controller.rb b/app/controllers/authentications_controller.rb index 311cf7a9b..fc18ff4d7 100644 --- a/app/controllers/authentications_controller.rb +++ b/app/controllers/authentications_controller.rb @@ -1,3 +1,4 @@ +require './lib/actions/oauth_signup_action' class AuthenticationsController < ApplicationController before_action :authenticate_member! load_and_authorize_resource From 1f66df074377c14f7c701a825007e1a555613804 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 13 Dec 2017 22:23:22 +1300 Subject: [PATCH 31/31] Fixed link to associated flickr, twitter, facebook accountss fixes #1479 --- app/views/devise/registrations/_edit_apps.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/devise/registrations/_edit_apps.html.haml b/app/views/devise/registrations/_edit_apps.html.haml index d0482e015..924a0db8a 100644 --- a/app/views/devise/registrations/_edit_apps.html.haml +++ b/app/views/devise/registrations/_edit_apps.html.haml @@ -16,7 +16,7 @@ confirm: "Are you sure you want to remove this connection?", method: :delete, class: "remove" - else - = link_to 'Connect to Twitter', '/auth/twitter' + = link_to 'Connect to Twitter', '/members/auth/twitter' .row .col-md-12 @@ -30,7 +30,7 @@ confirm: "Are you sure you want to remove this connection?", method: :delete, class: "remove" - else - = link_to 'Connect to Flickr', '/auth/flickr' + = link_to 'Connect to Flickr', '/members/auth/flickr' .row .col-md-12 @@ -44,4 +44,4 @@ confirm: "Are you sure you want to remove this connection?", method: :delete, class: "remove" - else - = link_to 'Connect to Facebook', '/auth/facebook' + = link_to 'Connect to Facebook', '/members/auth/facebook'