Skip to content

Commit f6cda07

Browse files
authored
Merge pull request #21 from nulogy/support-rubocop-49
Support rubocop >= 0.49.0
2 parents 3001324 + c071356 commit f6cda07

File tree

8 files changed

+89
-10
lines changed

8 files changed

+89
-10
lines changed

.rubocop_schema.49.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configuration for Rubocop >= 0.49.0
2+
3+
Layout/AlignHash:
4+
EnforcedColonStyle: 'key'
5+
EnforcedHashRocketStyle: 'key'
6+
7+
Layout/ExtraSpacing:
8+
# When true, allows most uses of extra spacing if the intent is to align
9+
# things with the previous or next line, not counting empty lines or comment
10+
# lines.
11+
AllowForAlignment: false
12+
13+
Layout/SpaceBeforeFirstArg:
14+
Enabled: true
15+
16+
Style/NumericLiterals:
17+
Enabled: false
18+
19+
Metrics/BlockNesting:
20+
Max: 2
21+
22+
Style/WordArray:
23+
Enabled: false
24+
25+
Style/TrailingCommaInLiteral:
26+
EnforcedStyleForMultiline: 'comma'
27+
28+
Style/TrailingCommaInArguments:
29+
EnforcedStyleForMultiline: 'comma'
30+
31+
Style/HashSyntax:
32+
EnforcedStyle: 'ruby19'
33+
34+
Style/StringLiterals:
35+
EnforcedStyle: double_quotes

.rubocop_schema.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Configuration for Rubocop >= 0.38.0, < 0.49.0
2+
13
Style/ExtraSpacing:
24
# When true, allows most uses of extra spacing if the intent is to align
35
# things with the previous or next line, not counting empty lines or comment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module FixDBSchemaConflicts
2+
class AutocorrectConfiguration
3+
def self.load
4+
new.load
5+
end
6+
7+
def load
8+
at_least_rubocop_49? ? '.rubocop_schema.49.yml' : '.rubocop_schema.yml'
9+
end
10+
11+
private
12+
13+
def at_least_rubocop_49?
14+
Gem::Version.new('0.49.0') <= Gem.loaded_specs['rubocop'].version
15+
end
16+
end
17+
end

lib/fix_db_schema_conflicts/tasks/db.rake

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
require 'shellwords'
2+
require_relative '../autocorrect_configuration'
23

34
namespace :db do
45
namespace :schema do
56
task :dump do
67
puts "Dumping database schema with fix-db-schema-conflicts gem"
8+
79
filename = ENV['SCHEMA'] || if defined? ActiveRecord::Tasks::DatabaseTasks
810
File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, 'schema.rb')
911
else
1012
"#{Rails.root}/db/schema.rb"
1113
end
12-
rubocop_yml = File.expand_path('../../../../.rubocop_schema.yml', __FILE__)
14+
autocorrect_config = FixDBSchemaConflicts::AutocorrectConfiguration.load
15+
rubocop_yml = File.expand_path("../../../../#{autocorrect_config}", __FILE__)
1316
`bundle exec rubocop --auto-correct --config #{rubocop_yml} #{filename.shellescape}`
1417
end
1518
end
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module FixDBSchemaConflicts
2-
VERSION='3.0.1'
2+
VERSION='3.0.2'
33
end

spec/integration/integration_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'spec_helper'
22

3-
describe 'Fix DB Schema Conflicts' do
3+
RSpec.describe 'Fix DB Schema Conflicts' do
44

55
let(:expected_lines) { reference_db_schema.lines }
66

77
it 'generates a sorted schema with no extra spacing' do
88

9-
`cd spec/test-app && rm db/schema.rb && rake db:migrate`
9+
`cd spec/test-app && rm -f db/schema.rb && rake db:migrate`
1010

1111
generated_lines = File.readlines('spec/test-app/db/schema.rb')
1212

spec/spec_helper.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
mocks.verify_partial_doubles = true
4141
end
4242

43-
# The settings below are suggested to provide a good initial experience
44-
# with RSpec, but feel free to customize to your heart's content.
45-
=begin
43+
# The settings below are suggested to provide a good initial experience
44+
# with RSpec, but feel free to customize to your heart's content.
45+
4646
# These two settings work together to allow you to limit a spec run
4747
# to individual examples or groups you care about by tagging them with
4848
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
@@ -53,7 +53,7 @@
5353
# Allows RSpec to persist some state between runs in order to support
5454
# the `--only-failures` and `--next-failure` CLI options. We recommend
5555
# you configure your source control system to ignore this file.
56-
config.example_status_persistence_file_path = "spec/examples.txt"
56+
# config.example_status_persistence_file_path = "spec/examples.txt"
5757

5858
# Limits the available syntax to the non-monkey patched syntax that is
5959
# recommended. For more details, see:
@@ -79,7 +79,7 @@
7979
# Print the 10 slowest examples and example groups at the
8080
# end of the spec run, to help surface which specs are running
8181
# particularly slow.
82-
config.profile_examples = 10
82+
# config.profile_examples = 10
8383

8484
# Run specs in random order to surface order dependencies. If you find an
8585
# order dependency and want to debug it, you can fix the order by providing
@@ -92,5 +92,4 @@
9292
# test failures related to randomization by passing the same `--seed` value
9393
# as the one that triggered the failure.
9494
Kernel.srand config.seed
95-
=end
9695
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'spec_helper'
2+
require 'fix_db_schema_conflicts/autocorrect_configuration'
3+
4+
RSpec.describe FixDBSchemaConflicts::AutocorrectConfiguration do
5+
subject(:autocorrect_config) { described_class }
6+
7+
it 'for versions up to 0.49.0' do
8+
installed_rubocop(version: '0.39.0')
9+
10+
expect(autocorrect_config.load).to eq('.rubocop_schema.yml')
11+
end
12+
13+
it 'for versions 0.49.0 and above' do
14+
installed_rubocop(version: '0.49.0')
15+
16+
expect(autocorrect_config.load).to eq('.rubocop_schema.49.yml')
17+
end
18+
19+
def installed_rubocop(version:)
20+
allow(Gem).to receive_message_chain(:loaded_specs, :[], :version)
21+
.and_return(Gem::Version.new(version))
22+
end
23+
end

0 commit comments

Comments
 (0)