-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #866 from Floppy/add-rubocop
Add rubocop to lint Rails and RSpec usage
- Loading branch information
Showing
60 changed files
with
219 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
bundle exec standardrb | ||
yarn run ts-standard | ||
bundle exec rubocop --autocorrect | ||
yarn run lint:ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
inherit_from: .rubocop_todo.yml | ||
|
||
require: | ||
- standard | ||
- rubocop-rails | ||
- rubocop-rspec | ||
|
||
inherit_gem: | ||
standard: config/base.yml | ||
|
||
AllCops: | ||
NewCops: enable | ||
Exclude: | ||
- db/schema.rb | ||
- bin/* | ||
- 'node_modules/**/*' | ||
- 'tmp/**/*' | ||
- 'vendor/**/*' | ||
- '.git/**/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Offense count: 6 | ||
RSpec/BeforeAfterAll: | ||
Exclude: | ||
- 'spec/jobs/library_scan_job_spec.rb' | ||
- 'spec/jobs/model_file_scan_job_spec.rb' | ||
- 'spec/jobs/model_scan_job_spec.rb' | ||
- 'spec/requests/creators_request_spec.rb' | ||
- 'spec/requests/libraries_request_spec.rb' | ||
- 'spec/requests/models_request_spec.rb' | ||
|
||
# Offense count: 4 | ||
# Configuration parameters: Prefixes, AllowedPatterns. | ||
# Prefixes: when, with, without | ||
RSpec/ContextWording: | ||
Exclude: | ||
- 'spec/jobs/model_scan_job_spec.rb' | ||
- 'spec/models/model_spec.rb' | ||
|
||
# Offense count: 6 | ||
# Configuration parameters: CountAsOne. | ||
RSpec/ExampleLength: | ||
Max: 11 | ||
|
||
# Offense count: 29 | ||
# Configuration parameters: AssignmentOnly. | ||
RSpec/InstanceVariable: | ||
Exclude: | ||
- 'spec/models/model_spec.rb' | ||
- 'spec/requests/libraries_request_spec.rb' | ||
- 'spec/requests/models_request_spec.rb' | ||
|
||
# Offense count: 14 | ||
RSpec/MultipleExpectations: | ||
Max: 5 | ||
|
||
# Offense count: 4 | ||
RSpec/RepeatedExample: | ||
Exclude: | ||
- 'spec/models/model_spec.rb' | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: Include. | ||
# Include: db/migrate/*.rb | ||
Rails/CreateTableWithTimestamps: | ||
Exclude: | ||
- 'db/migrate/20220612220116_create_active_storage_variant_records.active_storage.rb' | ||
|
||
# Offense count: 2 | ||
Rails/I18nLocaleTexts: | ||
Exclude: | ||
- 'app/admin/delayed_job.rb' | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: Include. | ||
# Include: db/migrate/*.rb | ||
Rails/NotNullColumn: | ||
Exclude: | ||
- 'db/migrate/20220614211256_add_username_to_users.rb' | ||
|
||
# Offense count: 4 | ||
Rails/OutputSafety: | ||
Exclude: | ||
- 'app/admin/delayed_job.rb' | ||
- 'app/helpers/application_helper.rb' | ||
- 'config/initializers/field_with_errors.rb' | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: Include. | ||
# Include: db/**/*.rb | ||
Rails/ReversibleMigration: | ||
Exclude: | ||
- 'db/migrate/20220106220519_remove_images_table.rb' | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: ForbiddenMethods, AllowedMethods. | ||
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all | ||
Rails/SkipsModelValidations: | ||
Exclude: | ||
- 'app/admin/delayed_job.rb' | ||
- 'db/migrate/20220612220115_add_service_name_to_active_storage_blobs.active_storage.rb' | ||
|
||
# Offense count: 4 | ||
# Configuration parameters: Include. | ||
# Include: app/models/**/*.rb | ||
Rails/UniqueValidationWithoutIndex: | ||
Exclude: | ||
- 'app/models/library.rb' | ||
- 'app/models/model.rb' | ||
- 'app/models/model_file.rb' | ||
- 'app/models/problem.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ def up | |
end | ||
|
||
def down | ||
User.find_by_username("admin").destroy | ||
User.find_by(username: "admin").destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
class DropLinkFieldsFromCreators < ActiveRecord::Migration[6.1] | ||
def change | ||
remove_column :creators, :thingiverse_user | ||
remove_column :creators, :cults3d_user | ||
remove_column :creators, :mmf_user | ||
remove_column :creators, :cgtrader_user | ||
remove_column :creators, :thingiverse_user, :string | ||
remove_column :creators, :cults3d_user, :string | ||
remove_column :creators, :mmf_user, :string | ||
remove_column :creators, :cgtrader_user, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FactoryBot.define do | ||
factory :model_file do | ||
filename { Faker::File.file_name(ext: "stl") } | ||
model { build :model } | ||
model { build(:model) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe LibraryScanJob, type: :job do | ||
RSpec.describe LibraryScanJob do | ||
before :all do | ||
ActiveJob::Base.queue_adapter = :test | ||
end | ||
|
||
let(:library) do | ||
create(:library, path: File.join(Rails.root, "spec", "fixtures", "library")) | ||
create(:library, path: Rails.root.join("spec/fixtures/library")) | ||
end | ||
|
||
it "generates a case-insensitive pattern for files" do | ||
expect(LibraryScanJob.file_pattern).to include "*.{stl,STL" | ||
expect(described_class.file_pattern).to include "*.{stl,STL" | ||
end | ||
|
||
it "can scan a library directory" do | ||
expect { LibraryScanJob.perform_now(library) }.to change { library.models.count }.to(4) | ||
expect { described_class.perform_now(library) }.to change { library.models.count }.to(4) | ||
expect(library.models.map(&:name)).to match_array ["Model One", "Model Two", "Nested Model", "Thingiverse Model"] | ||
expect(library.models.map(&:path)).to match_array ["/model_one", "/subfolder/model_two", "/model_one/nested_model", "/thingiverse_model"] | ||
end | ||
|
||
it "queues up model scans" do | ||
expect { LibraryScanJob.perform_now(library) }.to have_enqueued_job(ModelScanJob).exactly(4).times | ||
expect { described_class.perform_now(library) }.to have_enqueued_job(ModelScanJob).exactly(4).times | ||
end | ||
|
||
it "only scans models with changes on rescan" do | ||
model_one = create(:model, path: "model_one", library: library) | ||
ModelScanJob.perform_now(model_one) | ||
expect { LibraryScanJob.perform_now(library) }.to have_enqueued_job(ModelScanJob).exactly(3).times | ||
expect { described_class.perform_now(library) }.to have_enqueued_job(ModelScanJob).exactly(3).times | ||
end | ||
|
||
it "flags models with no files as problems" do | ||
lib = create(:library, path: File.join("/", "tmp")) | ||
create(:model, library: lib, path: "missing") | ||
expect { LibraryScanJob.perform_now(lib) }.to change { Problem.count }.from(0).to(1) | ||
expect { described_class.perform_now(lib) }.to change(Problem, :count).from(0).to(1) | ||
end | ||
end |
Oops, something went wrong.