Skip to content

Commit

Permalink
Re-enable rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
maiwald committed Mar 21, 2024
1 parent 5b8533c commit 3427205
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ jobs:
run: bundle
- name: Install appraisal
run: bundle exec appraisal install
- name: Run rubocop
run: bundle exec appraisal ${{ matrix.appraisal }} rubocop
- name: Run tests
run: bundle exec appraisal ${{ matrix.appraisal }} rspec
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ inherit_from: .rubocop_todo.yml
AllCops:
Exclude:
- bin/*
- 'vendor/**/*'
- 'gemfiles/**/*'
TargetRubyVersion: 2.2

Metrics/BlockLength:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Max: 120

Style/BlockDelimiters:
Expand Down
9 changes: 8 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-10-15 13:32:11 +0200 using RuboCop version 0.68.1.
# on 2024-03-21 09:05:20 UTC using RuboCop version 1.62.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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'permanent_records.gemspec'
13 changes: 5 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ namespace :db do
end
end

# TODO: add rubocop
# require 'rubocop/rake_task'
# RuboCop::RakeTask.new do |t|
# t.options = ['-d']
# end
require 'rubocop/rake_task'
RuboCop::RakeTask.new do |t|
t.options = ['-d']
end

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
Expand All @@ -38,13 +37,11 @@ task :pandoc do
system('pandoc -s -r markdown -w rst README.md -o README.rst')
end

task publish: %i[pandoc rspec] do # TODO: add rubocop
task publish: %i[pandoc rubocop rspec] do
# Ensure the gem builds
system('gem build permanent_records.gemspec') &&
# And we didn't leave anything (aside from the gem) uncommitted
!system('git status -s | egrep -v .') &&
system('git push') &&
system("gem push permanent_records-#{version}.gem")
end

task default: %i[rspec] # TODO: add rubocop
6 changes: 3 additions & 3 deletions lib/permanent_records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def is_permanent? # rubocop:disable Naming/PredicateName

def deleted?
if is_permanent?
!!deleted_at # rubocop:disable Style/DoubleNegation
!!deleted_at
else
destroyed?
end
Expand Down Expand Up @@ -177,7 +177,7 @@ def destroyed_dependent_relations

def attempt_notifying_observers(callback)
notify_observers(callback)
rescue NoMethodError # rubocop:disable Lint/HandleExceptions
rescue NoMethodError
# do nothing: this model isn't being observed
end

Expand Down Expand Up @@ -279,7 +279,7 @@ def self.dependent_permanent_reflections(klass)
end

ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.send(:include, PermanentRecords::ActiveRecord)
ActiveRecord::Base.include PermanentRecords::ActiveRecord

if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] || ActiveRecord::VERSION::MAJOR > 5
require 'permanent_records/active_record_5_2'
Expand Down
6 changes: 3 additions & 3 deletions permanent_records.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'activerecord', ver || '>= 5.0.0'
s.add_runtime_dependency 'activesupport', ver || '>= 5.0.0'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'database_cleaner', '>= 1.5.1'
s.add_development_dependency 'pry-byebug'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '>= 3.5.0'
# s.add_development_dependency 'rubocop'
# s.add_development_dependency 'rubocop-performance'
s.add_development_dependency 'rubocop', '~> 1.62.1'
s.add_development_dependency 'rubocop-performance', '~> 1.20.2'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'appraisal'
end
14 changes: 8 additions & 6 deletions spec/permanent_records_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
let!(:difficulty) { hole.create_difficulty }
let!(:comments) { 2.times.map { hole.comments.create! } }
let!(:bed) { Bed.create! }
let!(:kitty) { Kitty.create!(beds: [bed]) }
let!(:meerkat) { Meerkat.create!(holes: [hole]) }
let!(:kitty) { Kitty.create!(beds: [bed]) }
let!(:meerkat) { Meerkat.create!(holes: [hole]) }

describe '#destroy' do
let(:record) { hole }
Expand Down Expand Up @@ -363,8 +363,10 @@
end
end
it 'revives them' do
subject.comments.each { |c| expect(c).not_to be_deleted }
subject.comments.each { |c| expect(Comment.find_by_id(c.id)).to eq(c) }
subject.comments.each { |c|
expect(c).not_to be_deleted
expect(Comment.find_by_id(c.id)).to eq(c)
}
end
end
context 'with :has_one cardinality' do
Expand All @@ -391,7 +393,7 @@

context '.not_deleted' do
it 'counts' do
expect(Muskrat.not_deleted.count).to eq(Muskrat.all.reject(&:deleted?).size)
expect(Muskrat.not_deleted.count).to eq(Muskrat.all.count { |element| !element.deleted? })
end

it 'has no deleted records' do
Expand All @@ -401,7 +403,7 @@

context '.deleted' do
it 'counts' do
expect(Muskrat.deleted.count).to eq(Muskrat.all.select(&:deleted?).size)
expect(Muskrat.deleted.count).to eq(Muskrat.all.count(&:deleted?))
end

it 'has no non-deleted records' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.env

load 'schema.rb' if File.exist?(support.join('schema.rb'))

Dir.glob(support.join('*.rb')).each do |file|
Dir.glob(support.join('*.rb')).sort.each do |file|
autoload File.basename(file).chomp('.rb').camelcase.intern, file
require file
end
Expand Down

0 comments on commit 3427205

Please sign in to comment.