rubocop-sequel 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4023b536f86132312aefef7c17bbef5f85b3036bb0a1ac61fb8b53a532afbc19
|
4
|
+
data.tar.gz: 2a317cc181637b43163e3757e11235298ff49d3bf2a8cb284a1a30302623432a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9992c88db3726a7ffa555f3a978f3985245d4cf606fecf5710a02e850b04325849c9b48c11c86e7e80d3a4c24efcc909399d77181e51ad0e51db2f5aff0ffc8b
|
7
|
+
data.tar.gz: a195f6dab7e9bcec0e129cb1cee6f9cacfccde5db0ef7e99d5e7d7960e71442add297face4f04b72d874e7b328aa0262b03ad1be09e75ccab514fe5fd57c2ac8
|
data/config/default.yml
CHANGED
@@ -17,7 +17,7 @@ Sequel/IrreversibleMigration:
|
|
17
17
|
Reference: https://www.rubydoc.info/gems/rubocop-sequel/RuboCop/Cop/Sequel/IrreversibleMigration
|
18
18
|
Enabled: true
|
19
19
|
VersionAdded: 0.3.5
|
20
|
-
VersionChanged: 0.3.
|
20
|
+
VersionChanged: 0.3.7
|
21
21
|
|
22
22
|
Sequel/JSONColumn:
|
23
23
|
Description: >-
|
@@ -44,15 +44,29 @@ module RuboCop
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def validate_node(node)
|
47
|
-
|
47
|
+
return if within_create_table_block?(node)
|
48
48
|
|
49
|
-
add_offense(node.loc.selector, message: format(MSG, name:
|
49
|
+
add_offense(node.loc.selector, message: format(MSG, name: node.method_name)) unless valid_change_method?(node)
|
50
50
|
|
51
|
-
|
51
|
+
add_offense(node.loc.selector, message: PRIMARY_KEY_MSG) if invalid_primary_key_method?(node)
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_change_method?(node)
|
55
|
+
VALID_CHANGE_METHODS.include?(node.method_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def invalid_primary_key_method?(node)
|
59
|
+
return false unless node.method_name == :add_primary_key
|
60
|
+
|
61
|
+
node.arguments.any?(&:array_type?)
|
62
|
+
end
|
52
63
|
|
53
|
-
|
64
|
+
def within_create_table_block?(node)
|
65
|
+
return true if node.method_name == :create_table
|
54
66
|
|
55
|
-
|
67
|
+
node.each_ancestor(:block).any? do |ancestor|
|
68
|
+
ancestor.method_name == :create_table
|
69
|
+
end
|
56
70
|
end
|
57
71
|
end
|
58
72
|
end
|
data/rubocop-sequel.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
13
|
gem.name = 'rubocop-sequel'
|
14
14
|
gem.require_paths = ['lib']
|
15
|
-
gem.version = '0.3.
|
15
|
+
gem.version = '0.3.7'
|
16
16
|
gem.metadata['rubygems_mfa_required'] = 'true'
|
17
17
|
|
18
18
|
gem.required_ruby_version = '>= 2.5'
|
@@ -39,6 +39,54 @@ RSpec.describe RuboCop::Cop::Sequel::IrreversibleMigration do
|
|
39
39
|
expect(offenses).to be_empty
|
40
40
|
end
|
41
41
|
|
42
|
+
describe 'and using a create_table block' do
|
43
|
+
let(:source) do
|
44
|
+
<<~SOURCE
|
45
|
+
change do
|
46
|
+
create_table(:artists) do
|
47
|
+
primary_key :id
|
48
|
+
String :name, null: false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
SOURCE
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'does not register any offenses' do
|
55
|
+
offenses = inspect_source_within_migration(source)
|
56
|
+
expect(offenses).to be_empty
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'and using a create_table block and alter_table block' do
|
61
|
+
let(:source) do
|
62
|
+
<<~SOURCE
|
63
|
+
change do
|
64
|
+
alter_table(:stores) do
|
65
|
+
drop_column(:products, :name)
|
66
|
+
drop_index(:products, :price)
|
67
|
+
end
|
68
|
+
|
69
|
+
add_column :books, :name, String
|
70
|
+
|
71
|
+
create_table(:artists) do
|
72
|
+
primary_key :id
|
73
|
+
String :name, null: false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
SOURCE
|
77
|
+
end
|
78
|
+
let(:expected_methods) { %w[drop_column drop_index] }
|
79
|
+
|
80
|
+
it 'only registers offenses from within alter_table block' do
|
81
|
+
messages = inspect_source_within_migration(source).map(&:message)
|
82
|
+
expected_methods_present = expected_methods.all? do |method|
|
83
|
+
messages.any? { |message| message.include?(method) }
|
84
|
+
end
|
85
|
+
|
86
|
+
expect(expected_methods_present).to be(true)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
42
90
|
describe 'and an array is passed into `add_primary_key`' do
|
43
91
|
let(:source) do
|
44
92
|
<<~SOURCE
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothée Peignier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|