Compare commits

..

12 Commits

Author SHA1 Message Date
Daniel O'Connor
fe4dd5c185 Merge pull request #4549 from Growstuff/Rails/WhereMissing
Rubocop: Rails/WhereMissing
2026-04-24 00:13:37 +09:30
Daniel O'Connor
2019d0e952 Rubocop: Rails/WhereMissing 2026-04-23 14:27:10 +00:00
Daniel O'Connor
e7659a75a4 Merge pull request #4548 from Growstuff/RSpecRails/HaveHttpStatus
Rubocop: RSpecRails/HaveHttpStatus
2026-04-23 23:52:40 +09:30
Daniel O'Connor
4a66bdc9fe Merge pull request #4546 from Growstuff/Rails/RedundantActiveRecordAllMethod
Rubocop: Rails/RedundantActiveRecordAllMethod
2026-04-23 23:46:39 +09:30
Daniel O'Connor
8de6b083f9 Rubocop: RSpecRails/HaveHttpStatus 2026-04-23 14:13:47 +00:00
Daniel O'Connor
accab7f84c Merge pull request #4545 from Growstuff/RSpecRails/InferredSpecType
Rubocop: RSpecRails/InferredSpecType
2026-04-23 23:29:17 +09:30
Daniel O'Connor
3f6dd59dfa Rubocop: Rails/RedundantActiveRecordAllMethod 2026-04-23 13:48:17 +00:00
Daniel O'Connor
0a71b44dea Merge pull request #4542 from Growstuff/RSpec/ContextMethod
Rubocop: RSpec/ContextMethod
2026-04-23 23:10:33 +09:30
Daniel O'Connor
ba75afb3f5 Rubocop: RSpecRails/InferredSpecType 2026-04-23 13:39:46 +00:00
Daniel O'Connor
aa1c9ceb05 Merge pull request #4543 from Growstuff/RSpec/ExpectChange
Rubocop: RSpec/ExpectChange
2026-04-23 23:02:03 +09:30
Daniel O'Connor
6f59635ca7 Rubocop: RSpec/ExpectChange 2026-04-23 13:23:14 +00:00
Daniel O'Connor
6736ae3142 Rubocop: RSpec/ContextMethod 2026-04-23 13:20:47 +00:00
38 changed files with 101 additions and 119 deletions

View File

@@ -242,12 +242,6 @@ RSpec/BeforeAfterAll:
Exclude:
- 'spec/tasks/import_spec.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
RSpec/ContextMethod:
Exclude:
- 'spec/requests/api/v1/activities_request_spec.rb'
# Offense count: 299
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
@@ -299,14 +293,6 @@ RSpec/EmptyLineAfterExample:
RSpec/ExampleLength:
Max: 27
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: method_call, block
RSpec/ExpectChange:
Exclude:
- 'spec/models/crop_spec.rb'
# Offense count: 32
RSpec/ExpectInHook:
Exclude:
@@ -334,6 +320,26 @@ RSpec/HooksBeforeExamples:
Exclude:
- 'spec/features/crops/creating_a_crop_spec.rb'
# Offense count: 53
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/IncludeExamples:
Exclude:
- 'spec/features/conversations/index_spec.rb'
- 'spec/features/crops/alternate_name_spec.rb'
- 'spec/features/crops/browse_crops_spec.rb'
- 'spec/features/crops/creating_a_crop_spec.rb'
- 'spec/features/crops/crop_photos_spec.rb'
- 'spec/features/crops/delete_crop_spec.rb'
- 'spec/features/gardens/actions_spec.rb'
- 'spec/features/gardens/adding_gardens_spec.rb'
- 'spec/features/gardens/index_spec.rb'
- 'spec/features/likeable_spec.rb'
- 'spec/features/signout_spec.rb'
- 'spec/models/crop_spec.rb'
- 'spec/support/feature_helpers.rb'
- 'spec/views/photos/show.html.haml_spec.rb'
- 'spec/views/seeds/index.rss.haml_spec.rb'
# Offense count: 37
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
RSpec/IndexedLet:
@@ -466,23 +472,6 @@ RSpec/VerifiedDoubles:
- 'spec/controllers/gardens_controller_spec.rb'
- 'spec/views/devise/shared/_links_spec.rb'
# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ResponseMethods.
# ResponseMethods: response, last_response
RSpecRails/HaveHttpStatus:
Exclude:
- 'spec/controllers/api/v1/plantings_controller_spec.rb'
- 'spec/controllers/harvests_controller_spec.rb'
- 'spec/controllers/likes_controller_spec.rb'
- 'spec/requests/harvests_spec.rb'
# Offense count: 17
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Inferences.
RSpecRails/InferredSpecType:
Enabled: false
# Offense count: 30
# Configuration parameters: Database.
# SupportedDatabases: mysql, postgresql
@@ -602,7 +591,6 @@ Rails/RedundantActiveRecordAllMethod:
- 'app/controllers/scientific_names_controller.rb'
- 'spec/features/members/deletion_spec.rb'
- 'spec/features/percy/percy_spec.rb'
- 'spec/models/harvest_spec.rb'
# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -684,12 +672,6 @@ Rails/WhereEquals:
- 'app/models/harvest.rb'
- 'app/models/planting.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Rails/WhereMissing:
Exclude:
- 'app/controllers/crops_controller.rb'
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/WhereRange:

View File

@@ -160,7 +160,7 @@ class CropsController < ApplicationController
when 'youtube'
Crop.approved.where(en_youtube_url: [nil, '']).order(plantings_count: :desc)
when 'alternate_names'
Crop.approved.left_joins(:alternate_names).where(alternate_names: { id: nil }).order(plantings_count: :desc)
Crop.approved.where.missing(:alternate_names).order(plantings_count: :desc)
when 'wikidata'
crops_with_wikidata = Crop.joins(:scientific_names).where.not(scientific_names: { wikidata_id: nil }).distinct
Crop.approved.where.not(id: crops_with_wikidata).order(plantings_count: :desc)

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe Api::V1::PlantingsController, type: :controller do
RSpec.describe Api::V1::PlantingsController do
subject { JSON.parse response.body }
let!(:member) { create(:member) }
@@ -42,7 +42,7 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do
it { expect(matching_planting).to include('id' => my_planting.id.to_s) }
it { expect(matching_planting['attributes']).to eq expected_attributes }
it { expect(response.status).to eq 200 }
it { expect(response).to have_http_status :ok }
end
context 'with photo' do
@@ -81,7 +81,7 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do
it { expect(matching_planting).to include('id' => my_planting.id.to_s) }
it { expect(matching_planting['attributes']).to eq expected_attributes }
it { expect(response.status).to eq 200 }
it { expect(response).to have_http_status :ok }
end
end
end

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe GardenTypesController, type: :controller do
RSpec.describe GardenTypesController do
include Devise::Test::ControllerHelpers
let(:valid_params) { { name: 'My second GardenType' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe GardensController, type: :controller do
RSpec.describe GardensController do
include Devise::Test::ControllerHelpers
let(:valid_params) { { name: 'My second Garden' } }

View File

@@ -51,7 +51,7 @@ describe HarvestsController, :search do
describe "generates a csv" do
before { get :index, format: "csv" }
it { expect(response.status).to eq 200 }
it { expect(response).to have_http_status :ok }
end
end

View File

@@ -19,7 +19,7 @@ describe LikesController do
it { JSON.parse(response.body)["description"] == "1 like" }
describe "Liking someone else's post" do
it { expect(response.code).to eq('201') }
it { expect(response).to have_http_status(:created) }
end
end
@@ -29,14 +29,14 @@ describe LikesController do
it { expect(response.content_type).to eq "application/json; charset=utf-8" }
describe "un-liking something i liked before" do
it { expect(response.code).to eq('200') }
it { expect(response).to have_http_status(:ok) }
it { JSON.parse(response.body)["description"] == "0 likes" }
end
describe "Deleting someone else's like" do
let(:like) { create(:like) }
it { expect(response.code).to eq('403') }
it { expect(response).to have_http_status(:forbidden) }
it { JSON.parse(response.body)["error"] == "Unable to like" }
end
end

View File

@@ -18,7 +18,7 @@ describe "Conversations", :js do
click_link 'Inbox'
end
it_behaves_like 'is accessible'
include_examples 'is accessible'
it { expect(page).to have_content 'something i want to say' }
it { page.percy_snapshot(page, name: 'conversations#index') }

View File

@@ -83,23 +83,23 @@ describe "Alternate names", :js do
end
context 'Anonymous' do
it_behaves_like 'show alt names'
include_examples 'show alt names'
end
context 'Signed in member' do
include_context 'signed in member'
it_behaves_like 'show alt names'
include_examples 'show alt names'
end
context 'Crop wrangler' do
include_context 'signed in crop wrangler'
it_behaves_like 'show alt names'
it_behaves_like 'edit alt names'
include_examples 'show alt names'
include_examples 'edit alt names'
end
context 'Admin' do
include_context 'signed in admin'
it_behaves_like 'show alt names'
it_behaves_like 'edit alt names'
include_examples 'show alt names'
include_examples 'edit alt names'
end
end

View File

@@ -34,25 +34,25 @@ describe "browse crops", :search do
end
context 'anon' do
it_behaves_like 'shows crops'
include_examples 'shows crops'
it { expect(page).to have_no_link "Add New Crop" }
end
context 'member' do
include_context 'signed in member'
it_behaves_like 'shows crops'
it_behaves_like 'add new crop'
include_examples 'shows crops'
include_examples 'add new crop'
end
context 'wrangler' do
include_context 'signed in crop wrangler'
it_behaves_like 'shows crops'
it_behaves_like 'add new crop'
include_examples 'shows crops'
include_examples 'add new crop'
end
context 'admin' do
include_context 'signed in admin'
it_behaves_like 'shows crops'
it_behaves_like 'add new crop'
include_examples 'shows crops'
include_examples 'add new crop'
end
end

View File

@@ -33,7 +33,7 @@ describe "Crop", :js do
shared_examples 'request crop' do
describe "requesting a crop with multiple scientific and alternate name" do
it_behaves_like 'fill in form'
include_examples 'fill in form'
before do
within "form#new_crop" do
fill_in "request_notes", with: "This is the Philippine national flower."
@@ -50,7 +50,7 @@ describe "Crop", :js do
shared_examples 'create crop' do
describe "creating a crop with multiple scientific and alternate name" do
it_behaves_like 'fill in form'
include_examples 'fill in form'
before do
click_button "Save"
end
@@ -69,16 +69,16 @@ describe "Crop", :js do
context 'member' do
include_context 'signed in member'
it_behaves_like 'request crop'
include_examples 'request crop'
end
context 'crop wrangler' do
include_context 'signed in crop wrangler'
it_behaves_like 'create crop'
include_examples 'create crop'
end
context 'admin' do
include_context 'signed in admin'
it_behaves_like 'create crop'
include_examples 'create crop'
end
end

View File

@@ -59,17 +59,17 @@ describe "crop detail page", :js, :search do
context "when signed in" do
include_context 'signed in member'
it_behaves_like "shows photos"
include_examples "shows photos"
end
context "when signed in as photos owner" do
include_context 'signed in member'
let(:member) { owner_member }
it_behaves_like "shows photos"
include_examples "shows photos"
end
context "when not signed in" do
it_behaves_like "shows photos"
include_examples "shows photos"
end
end

View File

@@ -27,11 +27,11 @@ describe "Delete crop spec" do
context "As a crop wrangler" do
include_context 'signed in crop wrangler'
it_behaves_like 'delete crop'
include_examples 'delete crop'
end
context 'admin' do
include_context 'signed in admin'
it_behaves_like 'delete crop'
include_examples 'delete crop'
end
end

View File

@@ -25,7 +25,7 @@ describe "Gardens" do
context 'my gardens' do
before { visit gardens_path(member_slug: member.slug) }
it_behaves_like "has buttons bar at top"
include_examples "has buttons bar at top"
context 'with actions menu expanded' do
before { click_link 'Actions' }
@@ -43,13 +43,13 @@ describe "Gardens" do
context 'all gardens' do
before { visit gardens_path }
it_behaves_like "has buttons bar at top"
include_examples "has buttons bar at top"
end
context "other member's garden" do
before { visit gardens_path(member_slug: create(:member).slug) }
it_behaves_like "has buttons bar at top"
include_examples "has buttons bar at top"
describe 'does not show actions on other member garden' do
it { is_expected.to have_no_link 'Actions' }
end

View File

@@ -8,7 +8,7 @@ describe "Gardens", :js do
include_context 'signed in member'
before { visit new_garden_path }
it_behaves_like 'is accessible'
include_examples 'is accessible'
it "displays required and optional fields properly" do
expect(page).to have_css ".required", text: "Name"

View File

@@ -14,7 +14,7 @@ describe "Gardens#index", :js do
visit member_gardens_path(member_slug: member.slug)
end
it_behaves_like 'is accessible'
include_examples 'is accessible'
it "displays each of the gardens" do
member.gardens.each do |garden|

View File

@@ -58,13 +58,13 @@ describe 'Likeable', :js, :search do
describe 'photos#index' do
let(:path) { photos_path }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
describe 'photos#show' do
let(:path) { photo_path(photo) }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
describe 'crops#show' do
@@ -74,7 +74,7 @@ describe 'Likeable', :js, :search do
before { planting.photos << photo }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
end
@@ -82,27 +82,27 @@ describe 'Likeable', :js, :search do
let(:like_count_class) { ".post-#{post.id} .like-count" }
let(:path) { post_path(post) }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
describe 'activities' do
let(:like_count_class) { ".activity-#{activity.id} .like-count" }
let(:path) { activity_path(activity) }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
describe 'plantings' do
let(:like_count_class) { ".planting-#{planting.id} .like-count" }
let(:path) { planting_path(planting) }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
describe 'harvests' do
let(:like_count_class) { ".harvest-#{harvest.id} .like-count" }
let(:path) { harvest_path(harvest) }
it_behaves_like 'object can be liked'
include_examples 'object can be liked'
end
end

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Test with visual testing', :js, type: :feature do
describe 'Test with visual testing', :js do
# Use the same random seed every time so our random data is the same
# on every run, so doesn't trigger percy to see changes
before { Faker::Config.random = Random.new(42) }

View File

@@ -34,11 +34,11 @@ describe "signout" do
end
describe 'after signout, redirect to signin page if page needs authentication' do
it_behaves_like "sign-in redirects", "/plantings/new"
it_behaves_like "sign-in redirects", "/harvests/new"
it_behaves_like "sign-in redirects", "/posts/new"
it_behaves_like "sign-in redirects", "/gardens/new"
it_behaves_like "sign-in redirects", "/seeds/new"
include_examples "sign-in redirects", "/plantings/new"
include_examples "sign-in redirects", "/harvests/new"
include_examples "sign-in redirects", "/posts/new"
include_examples "sign-in redirects", "/gardens/new"
include_examples "sign-in redirects", "/seeds/new"
end
it 'photos' do

View File

@@ -12,7 +12,7 @@ require 'rails_helper'
# end
# end
# end
RSpec.describe ButtonsHelper, type: :helper do
RSpec.describe ButtonsHelper do
before { allow(self).to receive(:can?).and_return(true) }
let(:garden) { create(:garden) }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe EventHelper, type: :helper do
RSpec.describe EventHelper do
subject { resolve_model(event) }
let(:planting) { create(:planting) }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe CropCompanion, type: :model do
RSpec.describe CropCompanion do
it 'has a crop' do
cc = described_class.new
cc.crop_a = create :tomato

View File

@@ -154,7 +154,7 @@ describe Crop do
it { expect(crop.default_photo).to eq photo }
it_behaves_like 'has default photo'
include_examples 'has default photo'
end
context 'with a harvest photo' do
@@ -165,7 +165,7 @@ describe Crop do
it { expect(crop.default_photo).to eq photo }
it_behaves_like 'has default photo'
include_examples 'has default photo'
context 'and planting photo' do
let(:planting) { create(:planting, crop:) }
@@ -554,7 +554,7 @@ describe Crop do
end
it "destroys companion links" do
expect { crop_a.destroy }.to change { CropCompanion.count }.from(2).to(0)
expect { crop_a.destroy }.to change(CropCompanion, :count).from(2).to(0)
end
end

View File

@@ -144,7 +144,7 @@ describe Harvest do
it 'lists most recent harvests first' do
@h1 = create(:harvest, created_at: 1.day.ago)
@h2 = create(:harvest, created_at: 1.hour.ago)
expect(described_class.all.order(created_at: :desc)).to eq [@h2, @h1]
expect(described_class.order(created_at: :desc)).to eq [@h2, @h1]
end
end

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Activities', type: :request do
RSpec.describe 'Activities' do
subject { JSON.parse response.body }
let(:member) { create(:member) }
@@ -60,7 +60,7 @@ RSpec.describe 'Activities', type: :request do
end
end
context '#update' do
describe '#update' do
let(:params) do
{
'data' => {

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Crops', type: :request do
RSpec.describe 'Crops' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Gardens', type: :request do
RSpec.describe 'Gardens' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Harvests', type: :request do
RSpec.describe 'Harvests' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Members', type: :request do
RSpec.describe 'Members' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Photos', type: :request do
RSpec.describe 'Photos' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Plantings', type: :request do
RSpec.describe 'Plantings' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe 'Seeds', type: :request do
RSpec.describe 'Seeds' do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe "GardenTypes", type: :request do
RSpec.describe "GardenTypes" do
describe "GET /garden_types" do
it "works! (now write some real specs)" do
get garden_types_path

View File

@@ -6,7 +6,7 @@ describe "Harvests" do
describe "GET /harvests" do
it "works! (now write some real specs)" do
get harvests_path
expect(response.status).to be 200
expect(response).to have_http_status :ok
end
end
end

View File

@@ -14,17 +14,17 @@ module FeatureHelpers
shared_context 'signed in member' do
let(:member) { create(:member) }
it_behaves_like 'sign in'
include_examples 'sign in'
end
shared_context 'signed in crop wrangler' do
let(:member) { create(:crop_wrangling_member) }
it_behaves_like 'sign in'
include_examples 'sign in'
end
shared_context 'signed in admin' do
let(:member) { create(:admin_member) }
it_behaves_like 'sign in'
include_examples 'sign in'
end
shared_context 'sign in' do

View File

@@ -58,7 +58,7 @@ describe "photos/show" do
render
end
it_behaves_like "photo data renders"
include_examples "photo data renders"
it "has a delete button" do
assert_select "a[href='#{photo_path(@photo)}']"
@@ -71,8 +71,8 @@ describe "photos/show" do
render
end
it_behaves_like "photo data renders"
it_behaves_like "No links to change data"
include_examples "photo data renders"
include_examples "No links to change data"
end
context "not signed in" do
@@ -81,8 +81,8 @@ describe "photos/show" do
render
end
it_behaves_like "photo data renders"
it_behaves_like "No links to change data"
include_examples "photo data renders"
include_examples "No links to change data"
end
context "CC-licensed photo" do

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
describe "places/_map_attribution.html.haml", type: :view do
describe "places/_map_attribution.html.haml" do
before do
render
end

View File

@@ -31,7 +31,7 @@ describe 'seeds/index.rss.haml', :search do
render
end
it_behaves_like 'displays seed in rss feed'
include_examples 'displays seed in rss feed'
it 'shows RSS feed title' do
expect(rendered).to have_content "Recent seeds from all members"
@@ -60,6 +60,6 @@ describe 'seeds/index.rss.haml', :search do
expect(rendered).to have_content "Recent seeds from #{seed.owner}"
end
it_behaves_like 'displays seed in rss feed'
include_examples 'displays seed in rss feed'
end
end