outrigger 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/outrigger.rb +1 -1
- data/lib/outrigger/cops/migration/tagged.rb +15 -5
- data/lib/outrigger/railtie.rb +0 -3
- data/lib/outrigger/version.rb +1 -1
- data/spec/outrigger/cops/migration/tagged_spec.rb +142 -0
- data/spec/outrigger/railtie_spec.rb +9 -0
- data/spec/spec_helper.rb +5 -1
- metadata +26 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71510d6681f003b4789cf0d0a01ee95c30906fcf
|
4
|
+
data.tar.gz: a17a22273ad13306a31f5b00d9ce8c49017328ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b438bb3bb8a44fe6aa4ad55144a464a18b3ec7cb6829449069ac5f5120a2ec49462af7b0943ed79fbd931b285e529ca84ad5e3e38be2cccc47620a83ad8f64d5
|
7
|
+
data.tar.gz: 8fd3fcc001452e8dd981a86dddccdb1a66fc5755821fee215c976b0d9bc8a0313b0670445f3e3f827a677170adf0974f22cd37c4675aa12b36c4f1c2752a182b
|
data/lib/outrigger.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_record' unless defined? ActiveRecord
|
|
3
3
|
require 'outrigger/taggable'
|
4
4
|
require 'outrigger/taggable_proxy'
|
5
5
|
|
6
|
-
require 'outrigger/railtie' if defined? Rails
|
6
|
+
require 'outrigger/railtie' if defined? Rails::Railtie
|
7
7
|
|
8
8
|
module Outrigger
|
9
9
|
def self.filter(*tags)
|
@@ -3,16 +3,26 @@ module RuboCop
|
|
3
3
|
module Migration
|
4
4
|
class Tagged < Cop
|
5
5
|
def on_class(node)
|
6
|
-
_name,
|
7
|
-
return unless body &&
|
6
|
+
_name, _superclass, body = *node
|
7
|
+
return unless body && migration_class?(node)
|
8
8
|
check(node, body)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def_node_matcher :migration_class?, <<~PATTERN
|
14
|
+
{
|
15
|
+
(class
|
16
|
+
(const nil _)
|
17
|
+
(const
|
18
|
+
(const nil :ActiveRecord) :Migration) ...)
|
19
|
+
(class
|
20
|
+
(const nil _)
|
21
|
+
(send
|
22
|
+
(const
|
23
|
+
(const nil :ActiveRecord) :Migration) :[] _) ...)
|
24
|
+
}
|
25
|
+
PATTERN
|
16
26
|
|
17
27
|
def check(klass, node)
|
18
28
|
tag = tag_node(node)
|
data/lib/outrigger/railtie.rb
CHANGED
data/lib/outrigger/version.rb
CHANGED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'outrigger/cops/migration/tagged'
|
3
|
+
|
4
|
+
RSpec.describe RuboCop::Cop::Migration::Tagged do # rubocop:disable Metrics/BlockLength
|
5
|
+
let(:config_hash) do
|
6
|
+
{
|
7
|
+
'Migration/Tagged' => {
|
8
|
+
'AllowedTags' => %w[predeploy deploy],
|
9
|
+
'Enabled' => true
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:config) { RuboCop::Config.new(config_hash) }
|
15
|
+
|
16
|
+
let(:migration_class) do
|
17
|
+
<<-RUBY
|
18
|
+
class Test < ActiveRecord::Migration
|
19
|
+
tag :predeploy
|
20
|
+
def change
|
21
|
+
end
|
22
|
+
end
|
23
|
+
RUBY
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:migration_class_42) do
|
27
|
+
<<-RUBY
|
28
|
+
class Test < ActiveRecord::Migration[4.2]
|
29
|
+
tag :predeploy
|
30
|
+
def change
|
31
|
+
end
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
end
|
35
|
+
|
36
|
+
subject(:cop) { described_class.new(config) }
|
37
|
+
|
38
|
+
shared_examples_for 'valid migrations' do
|
39
|
+
it 'passes valid unversioned migration' do
|
40
|
+
inspect_source(migration_class)
|
41
|
+
expect(cop.offenses.empty?).to be(true)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'passes valid versioned migration' do
|
45
|
+
inspect_source(migration_class_42)
|
46
|
+
expect(cop.offenses.empty?).to be(true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'valid config' do # rubocop:disable Metrics/BlockLength
|
51
|
+
include_examples 'valid migrations'
|
52
|
+
|
53
|
+
context 'missing tags' do # rubocop:disable Metrics/BlockLength
|
54
|
+
let(:migration_class) do
|
55
|
+
<<-RUBY
|
56
|
+
class Test < ActiveRecord::Migration
|
57
|
+
def change
|
58
|
+
end
|
59
|
+
end
|
60
|
+
RUBY
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:migration_class_42) do
|
64
|
+
<<-RUBY
|
65
|
+
class Test < ActiveRecord::Migration[4.2]
|
66
|
+
def change
|
67
|
+
end
|
68
|
+
end
|
69
|
+
RUBY
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'finds missing tag in unversioned migration' do
|
73
|
+
inspect_source(migration_class)
|
74
|
+
expect(cop.offenses.empty?).to be(false)
|
75
|
+
expect(cop.offenses.first.message).to match(/All migrations require a tag from/)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'finds missing tag in versioned migration' do
|
79
|
+
inspect_source(migration_class_42)
|
80
|
+
expect(cop.offenses.empty?).to be(false)
|
81
|
+
expect(cop.offenses.first.message).to match(/All migrations require a tag from/)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'invalid tag' do # rubocop:disable Metrics/BlockLength
|
86
|
+
let(:migration_class) do
|
87
|
+
<<-RUBY
|
88
|
+
class Test < ActiveRecord::Migration
|
89
|
+
tag :foobar
|
90
|
+
def change
|
91
|
+
end
|
92
|
+
end
|
93
|
+
RUBY
|
94
|
+
end
|
95
|
+
|
96
|
+
let(:migration_class_42) do
|
97
|
+
<<-RUBY
|
98
|
+
class Test < ActiveRecord::Migration[4.2]
|
99
|
+
tag :foobar
|
100
|
+
def change
|
101
|
+
end
|
102
|
+
end
|
103
|
+
RUBY
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'fails on invalid tag in unversioned migration' do
|
107
|
+
inspect_source(migration_class)
|
108
|
+
expect(cop.offenses.empty?).to be(false)
|
109
|
+
expect(cop.offenses.first.message).to match(/Tags may only be one of/)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'fails on invalid tag in versioned migration' do
|
113
|
+
inspect_source(migration_class_42)
|
114
|
+
expect(cop.offenses.empty?).to be(false)
|
115
|
+
expect(cop.offenses.first.message).to match(/Tags may only be one of/)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'invalid config' do
|
121
|
+
let(:config_hash) do
|
122
|
+
{
|
123
|
+
'Migration/Tagged' => {
|
124
|
+
'AllowedTags' => [],
|
125
|
+
'Enabled' => true
|
126
|
+
}
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'fails on missing tags in configuration on unversioned migration' do
|
131
|
+
inspect_source(migration_class)
|
132
|
+
expect(cop.offenses.empty?).to be(false)
|
133
|
+
expect(cop.offenses.first.message).to match(/No allowed tags have been defined/)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'fails on missing tags in configuration on versioned migration' do
|
137
|
+
inspect_source(migration_class_42)
|
138
|
+
expect(cop.offenses.empty?).to be(false)
|
139
|
+
expect(cop.offenses.first.message).to match(/No allowed tags have been defined/)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,13 @@ SimpleCov.start do
|
|
4
4
|
add_filter 'spec'
|
5
5
|
track_files 'lib/**/*.rb'
|
6
6
|
end
|
7
|
-
SimpleCov.minimum_coverage(
|
7
|
+
SimpleCov.minimum_coverage(75)
|
8
8
|
|
9
9
|
require 'bundler/setup'
|
10
|
+
require 'rails/railtie'
|
11
|
+
require 'rubocop'
|
12
|
+
require 'rubocop/rspec/support'
|
13
|
+
|
10
14
|
require 'outrigger'
|
11
15
|
|
12
16
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outrigger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Bowman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -44,6 +44,26 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.15'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: railties
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '4.2'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '5.2'
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '4.2'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '5.2'
|
47
67
|
- !ruby/object:Gem::Dependency
|
48
68
|
name: rake
|
49
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +138,9 @@ files:
|
|
118
138
|
- spec/gemfiles/rails-4.2.gemfile.lock
|
119
139
|
- spec/gemfiles/rails-5.0.gemfile
|
120
140
|
- spec/gemfiles/rails-5.0.gemfile.lock
|
141
|
+
- spec/outrigger/cops/migration/tagged_spec.rb
|
121
142
|
- spec/outrigger/outrigger_spec.rb
|
143
|
+
- spec/outrigger/railtie_spec.rb
|
122
144
|
- spec/outrigger/taggable_proxy_spec.rb
|
123
145
|
- spec/outrigger/taggable_spec.rb
|
124
146
|
- spec/spec_helper.rb
|
@@ -151,7 +173,9 @@ test_files:
|
|
151
173
|
- spec/gemfiles/rails-4.2.gemfile.lock
|
152
174
|
- spec/gemfiles/rails-5.0.gemfile
|
153
175
|
- spec/gemfiles/rails-5.0.gemfile.lock
|
176
|
+
- spec/outrigger/cops/migration/tagged_spec.rb
|
154
177
|
- spec/outrigger/outrigger_spec.rb
|
178
|
+
- spec/outrigger/railtie_spec.rb
|
155
179
|
- spec/outrigger/taggable_proxy_spec.rb
|
156
180
|
- spec/outrigger/taggable_spec.rb
|
157
181
|
- spec/spec_helper.rb
|