rubocop-discourse 3.1.0 → 3.9.3
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/.github/workflows/ci.yml +2 -2
- data/.rspec +1 -0
- data/.rubocop.yml +7 -0
- data/config/default.yml +51 -24
- data/lib/rubocop/cop/discourse/fabricator_shorthand.rb +62 -0
- data/lib/rubocop/cop/discourse/no_add_reference_active_record_migrations.rb +9 -7
- data/lib/rubocop/cop/discourse/no_chdir.rb +1 -1
- data/lib/rubocop/cop/discourse/no_direct_multisite_manipulation.rb +3 -2
- data/lib/rubocop/cop/discourse/no_json_parse_response.rb +2 -4
- data/lib/rubocop/cop/discourse/no_mixing_multisite_and_standard_specs.rb +4 -7
- data/lib/rubocop/cop/discourse/no_mocking_jobs.rb +3 -2
- data/lib/rubocop/cop/discourse/no_nokogiri_html_fragment.rb +1 -1
- data/lib/rubocop/cop/discourse/no_reset_column_information_in_migrations.rb +6 -5
- data/lib/rubocop/cop/discourse/no_time_new_without_args.rb +2 -4
- data/lib/rubocop/cop/discourse/no_uri_escape_encode.rb +11 -8
- data/lib/rubocop/cop/discourse/only_top_level_multisite_specs.rb +2 -6
- data/lib/rubocop/cop/discourse/plugins/call_requires_plugin.rb +71 -0
- data/lib/rubocop/cop/discourse/plugins/namespace_constants.rb +35 -0
- data/lib/rubocop/cop/discourse/plugins/namespace_methods.rb +37 -0
- data/lib/rubocop/cop/discourse/plugins/no_monkey_patching.rb +92 -0
- data/lib/rubocop/cop/discourse/plugins/use_plugin_instance_on.rb +42 -0
- data/lib/rubocop/cop/discourse/plugins/use_require_relative.rb +32 -0
- data/lib/rubocop/cop/discourse/services/empty_lines_around_blocks.rb +114 -0
- data/lib/rubocop/cop/discourse/services/group_keywords.rb +92 -0
- data/lib/rubocop/cop/discourse/time_eq_matcher.rb +2 -4
- data/lib/rubocop/cop/discourse_cops.rb +1 -1
- data/lib/rubocop/discourse.rb +3 -3
- data/lib/rubocop-discourse.rb +4 -0
- data/rubocop-capybara.yml +5 -0
- data/rubocop-core.yml +81 -4
- data/rubocop-discourse.gemspec +15 -10
- data/rubocop-factory_bot.yml +11 -0
- data/rubocop-layout.yml +4 -0
- data/rubocop-rails.yml +14 -0
- data/rubocop-rspec.yml +29 -23
- data/spec/fixtures/controllers/bad_controller.rb +5 -0
- data/spec/fixtures/controllers/base_controller.rb +11 -0
- data/spec/fixtures/controllers/good_controller.rb +4 -0
- data/spec/fixtures/controllers/inherit_from_outside_controller.rb +5 -0
- data/spec/fixtures/controllers/namespaced_parent_controller.rb +5 -0
- data/spec/fixtures/controllers/no_requires_plugin_controller.rb +5 -0
- data/spec/fixtures/controllers/requires_plugin_controller.rb +6 -0
- data/spec/lib/rubocop/cop/discourse/services/empty_lines_around_blocks_spec.rb +309 -0
- data/spec/lib/rubocop/cop/discourse/services/group_keywords_spec.rb +137 -0
- data/spec/lib/rubocop/cop/fabricator_shorthand_spec.rb +47 -0
- data/spec/lib/rubocop/cop/no_add_reference_active_record_migrations_spec.rb +13 -16
- data/spec/lib/rubocop/cop/no_mixing_multisite_and_standard_specs_spec.rb +10 -14
- data/spec/lib/rubocop/cop/no_mocking_jobs_enqueue_spec.rb +8 -12
- data/spec/lib/rubocop/cop/no_reset_column_information_migrations_spec.rb +8 -10
- data/spec/lib/rubocop/cop/only_top_level_multisite_specs_spec.rb +14 -18
- data/spec/lib/rubocop/cop/plugins/call_requires_plugin_spec.rb +79 -0
- data/spec/lib/rubocop/cop/plugins/namespace_constants_spec.rb +40 -0
- data/spec/lib/rubocop/cop/plugins/namespace_methods_spec.rb +84 -0
- data/spec/lib/rubocop/cop/plugins/no_monkey_patching_spec.rb +91 -0
- data/spec/lib/rubocop/cop/plugins/use_plugin_instance_on_spec.rb +37 -0
- data/spec/lib/rubocop/cop/plugins/use_require_relative_spec.rb +24 -0
- data/spec/lib/rubocop/cop/time_eq_matcher_spec.rb +6 -10
- data/spec/spec_helper.rb +4 -4
- data/stree-compat.yml +10 -1
- metadata +110 -16
@@ -0,0 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class InheritFromOutsideController < MyPlugin::ApplicationController
|
4
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/Plugins/CallRequiresPlugin: Use `requires_plugin` in controllers to prevent routes from being accessible when plugin is disabled.
|
5
|
+
end
|
@@ -0,0 +1,309 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RuboCop::Cop::Discourse::Services::EmptyLinesAroundBlocks,
|
4
|
+
:config do
|
5
|
+
subject(:cop) { described_class.new(config) }
|
6
|
+
|
7
|
+
let(:config) { RuboCop::Config.new }
|
8
|
+
|
9
|
+
context "when not in a service class" do
|
10
|
+
it "does nothing" do
|
11
|
+
expect_no_offenses(<<~RUBY)
|
12
|
+
class NotAService
|
13
|
+
step :first_step
|
14
|
+
params do
|
15
|
+
attribute :my_attribute
|
16
|
+
end
|
17
|
+
step :another_step
|
18
|
+
end
|
19
|
+
RUBY
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when in a service class" do
|
24
|
+
context "when a blank line is missing before a block" do
|
25
|
+
it "registers an offense" do
|
26
|
+
expect_offense(<<~RUBY)
|
27
|
+
class MyService
|
28
|
+
include Service::Base
|
29
|
+
|
30
|
+
step :first_step
|
31
|
+
params do
|
32
|
+
^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
33
|
+
attribute :my_attribute
|
34
|
+
end
|
35
|
+
end
|
36
|
+
RUBY
|
37
|
+
|
38
|
+
expect_correction(<<~RUBY)
|
39
|
+
class MyService
|
40
|
+
include Service::Base
|
41
|
+
|
42
|
+
step :first_step
|
43
|
+
|
44
|
+
params do
|
45
|
+
attribute :my_attribute
|
46
|
+
end
|
47
|
+
end
|
48
|
+
RUBY
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when a blank line is missing after a block" do
|
53
|
+
it "registers an offense" do
|
54
|
+
expect_offense(<<~RUBY)
|
55
|
+
class MyService
|
56
|
+
include Service::Base
|
57
|
+
|
58
|
+
params do
|
59
|
+
^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
60
|
+
attribute :my_attribute
|
61
|
+
end
|
62
|
+
step :last_step
|
63
|
+
end
|
64
|
+
RUBY
|
65
|
+
|
66
|
+
expect_correction(<<~RUBY)
|
67
|
+
class MyService
|
68
|
+
include Service::Base
|
69
|
+
|
70
|
+
params do
|
71
|
+
attribute :my_attribute
|
72
|
+
end
|
73
|
+
|
74
|
+
step :last_step
|
75
|
+
end
|
76
|
+
RUBY
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when two blocks are next to each other" do
|
81
|
+
it "registers an offense" do
|
82
|
+
expect_offense(<<~RUBY)
|
83
|
+
class MyService
|
84
|
+
include Service::Base
|
85
|
+
|
86
|
+
params do
|
87
|
+
^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
88
|
+
attribute :attribute
|
89
|
+
validates :attribute, presence: true
|
90
|
+
end
|
91
|
+
transaction do
|
92
|
+
^^^^^^^^^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
93
|
+
step :first
|
94
|
+
step :second
|
95
|
+
end
|
96
|
+
end
|
97
|
+
RUBY
|
98
|
+
|
99
|
+
expect_correction(<<~RUBY)
|
100
|
+
class MyService
|
101
|
+
include Service::Base
|
102
|
+
|
103
|
+
params do
|
104
|
+
attribute :attribute
|
105
|
+
validates :attribute, presence: true
|
106
|
+
end
|
107
|
+
|
108
|
+
transaction do
|
109
|
+
step :first
|
110
|
+
step :second
|
111
|
+
end
|
112
|
+
end
|
113
|
+
RUBY
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when a block is a one-liner" do
|
118
|
+
it "does not register an offense" do
|
119
|
+
expect_no_offenses(<<~RUBY)
|
120
|
+
class MyService
|
121
|
+
include Service::Base
|
122
|
+
|
123
|
+
try { step :might_raise }
|
124
|
+
step :last_step
|
125
|
+
end
|
126
|
+
RUBY
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when blocks are nested" do
|
131
|
+
context "when there is just one nested block" do
|
132
|
+
it "does not register an offense" do
|
133
|
+
expect_no_offenses(<<~RUBY)
|
134
|
+
class MyService
|
135
|
+
include Service::Base
|
136
|
+
|
137
|
+
transaction do
|
138
|
+
try do
|
139
|
+
step :first_step
|
140
|
+
step :second_step
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
RUBY
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when the nested block is in the first position" do
|
149
|
+
context "when there is no empty line before" do
|
150
|
+
it "does not register an offense" do
|
151
|
+
expect_no_offenses(<<~RUBY)
|
152
|
+
class MyService
|
153
|
+
include Service::Base
|
154
|
+
|
155
|
+
transaction do
|
156
|
+
try do
|
157
|
+
step :first_step
|
158
|
+
step :second_step
|
159
|
+
end
|
160
|
+
|
161
|
+
step :third_step
|
162
|
+
end
|
163
|
+
end
|
164
|
+
RUBY
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "when there is no empty line after" do
|
169
|
+
it "registers an offense" do
|
170
|
+
expect_offense(<<~RUBY)
|
171
|
+
class MyService
|
172
|
+
include Service::Base
|
173
|
+
|
174
|
+
transaction do
|
175
|
+
try do
|
176
|
+
^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
177
|
+
step :first_step
|
178
|
+
step :second_step
|
179
|
+
end
|
180
|
+
step :third_step
|
181
|
+
end
|
182
|
+
end
|
183
|
+
RUBY
|
184
|
+
|
185
|
+
expect_correction(<<~RUBY)
|
186
|
+
class MyService
|
187
|
+
include Service::Base
|
188
|
+
|
189
|
+
transaction do
|
190
|
+
try do
|
191
|
+
step :first_step
|
192
|
+
step :second_step
|
193
|
+
end
|
194
|
+
|
195
|
+
step :third_step
|
196
|
+
end
|
197
|
+
end
|
198
|
+
RUBY
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when the nested block is in the last position" do
|
204
|
+
context "when there is no empty line after" do
|
205
|
+
it "does not register an offense" do
|
206
|
+
expect_no_offenses(<<~RUBY)
|
207
|
+
class MyService
|
208
|
+
include Service::Base
|
209
|
+
|
210
|
+
transaction do
|
211
|
+
step :first_step
|
212
|
+
|
213
|
+
try do
|
214
|
+
step :second_step
|
215
|
+
step :third_step
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
RUBY
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "when there is no empty line before" do
|
224
|
+
it "registers an offense" do
|
225
|
+
expect_offense(<<~RUBY)
|
226
|
+
class MyService
|
227
|
+
include Service::Base
|
228
|
+
|
229
|
+
transaction do
|
230
|
+
step :first_step
|
231
|
+
try do
|
232
|
+
^^^^^^ Discourse/Services/EmptyLinesAroundBlocks: Add empty lines around a step block.
|
233
|
+
step :second_step
|
234
|
+
step :third_step
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
RUBY
|
239
|
+
|
240
|
+
expect_correction(<<~RUBY)
|
241
|
+
class MyService
|
242
|
+
include Service::Base
|
243
|
+
|
244
|
+
transaction do
|
245
|
+
step :first_step
|
246
|
+
|
247
|
+
try do
|
248
|
+
step :second_step
|
249
|
+
step :third_step
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
RUBY
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context "when blocks are used in methods" do
|
260
|
+
it "does not register an offense" do
|
261
|
+
expect_no_offenses(<<~RUBY)
|
262
|
+
class MyService
|
263
|
+
include Service::Base
|
264
|
+
|
265
|
+
step :first_step
|
266
|
+
|
267
|
+
def first_step(model:)
|
268
|
+
model.transaction do
|
269
|
+
do_something
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
RUBY
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "with a full valid example" do
|
278
|
+
it "does not register an offense" do
|
279
|
+
expect_no_offenses(<<~RUBY)
|
280
|
+
class MyService
|
281
|
+
include Service::Base
|
282
|
+
|
283
|
+
step :first_step
|
284
|
+
|
285
|
+
params do
|
286
|
+
attribute :my_attribute
|
287
|
+
|
288
|
+
validates :my_attributes, presence: true
|
289
|
+
end
|
290
|
+
|
291
|
+
policy :allowed?
|
292
|
+
model :user
|
293
|
+
|
294
|
+
transaction do
|
295
|
+
try do
|
296
|
+
step :save_user
|
297
|
+
step :log
|
298
|
+
end
|
299
|
+
|
300
|
+
step :other_step
|
301
|
+
end
|
302
|
+
|
303
|
+
step :last_step
|
304
|
+
end
|
305
|
+
RUBY
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RuboCop::Cop::Discourse::Services::GroupKeywords, :config do
|
4
|
+
subject(:cop) { described_class.new(config) }
|
5
|
+
|
6
|
+
let(:config) { RuboCop::Config.new }
|
7
|
+
|
8
|
+
context "when not in a service class" do
|
9
|
+
it "does nothing" do
|
10
|
+
expect_no_offenses(<<~RUBY)
|
11
|
+
class NotAService
|
12
|
+
step :first_step
|
13
|
+
|
14
|
+
step :another_step
|
15
|
+
end
|
16
|
+
RUBY
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when in a service class" do
|
21
|
+
context "when keywords are not grouped together" do
|
22
|
+
it "reports an offense" do
|
23
|
+
expect_offense(<<~RUBY)
|
24
|
+
class MyService
|
25
|
+
include Service::Base
|
26
|
+
|
27
|
+
model :user
|
28
|
+
^^^^^^^^^^^ Discourse/Services/GroupKeywords: Group one-liner steps together by removing extra empty lines.
|
29
|
+
|
30
|
+
policy :allowed?
|
31
|
+
step :save
|
32
|
+
end
|
33
|
+
RUBY
|
34
|
+
|
35
|
+
expect_correction(<<~RUBY)
|
36
|
+
class MyService
|
37
|
+
include Service::Base
|
38
|
+
|
39
|
+
model :user
|
40
|
+
policy :allowed?
|
41
|
+
step :save
|
42
|
+
end
|
43
|
+
RUBY
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when a one-liner block has an empty line before a keyword" do
|
48
|
+
it "reports an offense" do
|
49
|
+
expect_offense(<<~RUBY)
|
50
|
+
class MyService
|
51
|
+
include Service::Base
|
52
|
+
|
53
|
+
model :user
|
54
|
+
policy :allowed?
|
55
|
+
^^^^^^^^^^^^^^^^ Discourse/Services/GroupKeywords: Group one-liner steps together by removing extra empty lines.
|
56
|
+
|
57
|
+
try { step :save }
|
58
|
+
end
|
59
|
+
RUBY
|
60
|
+
|
61
|
+
expect_correction(<<~RUBY)
|
62
|
+
class MyService
|
63
|
+
include Service::Base
|
64
|
+
|
65
|
+
model :user
|
66
|
+
policy :allowed?
|
67
|
+
try { step :save }
|
68
|
+
end
|
69
|
+
RUBY
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when keywords with empty lines appear in a nested block" do
|
74
|
+
it "reports an offense" do
|
75
|
+
expect_offense(<<~RUBY)
|
76
|
+
class MyService
|
77
|
+
include Service::Base
|
78
|
+
|
79
|
+
transaction do
|
80
|
+
step :save
|
81
|
+
^^^^^^^^^^ Discourse/Services/GroupKeywords: Group one-liner steps together by removing extra empty lines.
|
82
|
+
|
83
|
+
step :log
|
84
|
+
end
|
85
|
+
end
|
86
|
+
RUBY
|
87
|
+
|
88
|
+
expect_correction(<<~RUBY)
|
89
|
+
class MyService
|
90
|
+
include Service::Base
|
91
|
+
|
92
|
+
transaction do
|
93
|
+
step :save
|
94
|
+
step :log
|
95
|
+
end
|
96
|
+
end
|
97
|
+
RUBY
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when keywords are grouped together" do
|
102
|
+
it "does not report an offense" do
|
103
|
+
expect_no_offenses(<<~RUBY)
|
104
|
+
class MyService
|
105
|
+
include Service::Base
|
106
|
+
|
107
|
+
model :user
|
108
|
+
policy :allowed?
|
109
|
+
|
110
|
+
transaction do
|
111
|
+
step :save
|
112
|
+
step :log
|
113
|
+
end
|
114
|
+
end
|
115
|
+
RUBY
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when keywords are not at the top level" do
|
120
|
+
it "does not report an offense" do
|
121
|
+
expect_no_offenses(<<~RUBY)
|
122
|
+
class MyService
|
123
|
+
include Service::Base
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def my_method
|
128
|
+
step(:save)
|
129
|
+
|
130
|
+
step(:log)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
RUBY
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe RuboCop::Cop::Discourse::FabricatorShorthand, :config do
|
4
|
+
subject(:cop) { described_class.new(config) }
|
5
|
+
|
6
|
+
let(:config) { RuboCop::Config.new }
|
7
|
+
|
8
|
+
it "registers an offense when not using the fabricator shorthand" do
|
9
|
+
expect_offense(<<~RUBY)
|
10
|
+
RSpec.describe "Foo" do
|
11
|
+
fab!(:foo) { Fabricate(:foo) }
|
12
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
|
13
|
+
end
|
14
|
+
RUBY
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not register an offense when the fabricator has attributes" do
|
18
|
+
expect_no_offenses(<<~RUBY)
|
19
|
+
RSpec.describe "Foo" do
|
20
|
+
fab!(:foo) { Fabricate(:foo, bar: 1) }
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
it "does not register an offense when the identifier doesn't match" do
|
26
|
+
expect_no_offenses(<<~RUBY)
|
27
|
+
RSpec.describe "Foo" do
|
28
|
+
fab!(:bar) { Fabricate(:foo) }
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
end
|
32
|
+
|
33
|
+
it "supports autocorrect" do
|
34
|
+
expect_offense(<<~RUBY)
|
35
|
+
RSpec.describe "Foo" do
|
36
|
+
fab!(:foo) { Fabricate(:foo) }
|
37
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Discourse/FabricatorShorthand: Use the fabricator shorthand: `fab!(:foo)`
|
38
|
+
end
|
39
|
+
RUBY
|
40
|
+
|
41
|
+
expect_correction(<<~RUBY)
|
42
|
+
RSpec.describe "Foo" do
|
43
|
+
fab!(:foo)
|
44
|
+
end
|
45
|
+
RUBY
|
46
|
+
end
|
47
|
+
end
|
@@ -1,29 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration, :config do
|
3
|
+
RSpec.describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration, :config do
|
6
4
|
subject(:cop) { described_class.new(config) }
|
7
|
-
|
8
|
-
|
9
|
-
end
|
5
|
+
|
6
|
+
let(:config) { RuboCop::Config.new }
|
10
7
|
|
11
8
|
it "raises an offense if add_reference is used, with or without arguments" do
|
12
|
-
inspect_source(<<~RUBY)
|
9
|
+
offenses = inspect_source(<<~RUBY)
|
13
10
|
add_reference :posts, :users, foreign_key: true, null: false
|
14
11
|
RUBY
|
15
|
-
expect(
|
12
|
+
expect(offenses.first.message).to match(described_class::MSG)
|
16
13
|
end
|
17
14
|
|
18
15
|
it "raises an offense if add_belongs_to is used, with or without arguments" do
|
19
|
-
inspect_source(<<~RUBY)
|
16
|
+
offenses = inspect_source(<<~RUBY)
|
20
17
|
add_belongs_to :posts, :users, foreign_key: true, null: false
|
21
18
|
RUBY
|
22
|
-
expect(
|
19
|
+
expect(offenses.first.message).to match(described_class::MSG)
|
23
20
|
end
|
24
21
|
|
25
22
|
it "raises an offense if t.references, or any variable.references is used, with or without arguments" do
|
26
|
-
inspect_source(<<~RUBY)
|
23
|
+
offenses = inspect_source(<<~RUBY)
|
27
24
|
create_table do |t|
|
28
25
|
t.references :topic, null: false
|
29
26
|
end
|
@@ -31,12 +28,12 @@ describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
|
|
31
28
|
mytable.references :topic, null: false
|
32
29
|
end
|
33
30
|
RUBY
|
34
|
-
expect(
|
35
|
-
expect(
|
31
|
+
expect(offenses.count).to eq(2)
|
32
|
+
expect(offenses.first.message).to match(described_class::MSG)
|
36
33
|
end
|
37
34
|
|
38
35
|
it "raises an offense if t.belongs_to, or any variable.belongs_to is used, with or without arguments" do
|
39
|
-
inspect_source(<<~RUBY)
|
36
|
+
offenses = inspect_source(<<~RUBY)
|
40
37
|
create_table do |t|
|
41
38
|
t.belongs_to :topic, null: false
|
42
39
|
end
|
@@ -44,7 +41,7 @@ describe RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration,
|
|
44
41
|
mytable.belongs_to :topic, null: false
|
45
42
|
end
|
46
43
|
RUBY
|
47
|
-
expect(
|
48
|
-
expect(
|
44
|
+
expect(offenses.count).to eq(2)
|
45
|
+
expect(offenses.first.message).to match(described_class::MSG)
|
49
46
|
end
|
50
47
|
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
3
|
+
RSpec.describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
6
4
|
subject(:cop) { described_class.new(config) }
|
7
5
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
6
|
+
let(:config) { RuboCop::Config.new }
|
11
7
|
|
12
8
|
it "raises an offense if there are multisite and standard top-level describes" do
|
13
|
-
inspect_source(<<~RUBY)
|
9
|
+
offenses = inspect_source(<<~RUBY)
|
14
10
|
RSpec.describe "test" do
|
15
11
|
end
|
16
12
|
|
@@ -18,11 +14,11 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
|
18
14
|
end
|
19
15
|
RUBY
|
20
16
|
|
21
|
-
expect(
|
17
|
+
expect(offenses.first.message).to match(described_class::MSG)
|
22
18
|
end
|
23
19
|
|
24
20
|
it "raises an offense if there are multiple multisite and standard top-level describes" do
|
25
|
-
inspect_source(<<~RUBY)
|
21
|
+
offenses = inspect_source(<<~RUBY)
|
26
22
|
describe "test", type: :multisite do
|
27
23
|
end
|
28
24
|
|
@@ -33,11 +29,11 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
|
33
29
|
end
|
34
30
|
RUBY
|
35
31
|
|
36
|
-
expect(
|
32
|
+
expect(offenses.first.message).to match(described_class::MSG)
|
37
33
|
end
|
38
34
|
|
39
35
|
it "does not raise an offense if there are only multisite describes" do
|
40
|
-
inspect_source(<<~RUBY)
|
36
|
+
offenses = inspect_source(<<~RUBY)
|
41
37
|
require "foo"
|
42
38
|
|
43
39
|
describe "test", type: :multisite do
|
@@ -51,11 +47,11 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
|
51
47
|
end
|
52
48
|
RUBY
|
53
49
|
|
54
|
-
expect(
|
50
|
+
expect(offenses).to eq([])
|
55
51
|
end
|
56
52
|
|
57
53
|
it "does not raise an offense if there are only standard describes" do
|
58
|
-
inspect_source(<<~RUBY)
|
54
|
+
offenses = inspect_source(<<~RUBY)
|
59
55
|
require "rails_helper"
|
60
56
|
|
61
57
|
describe "test" do
|
@@ -67,6 +63,6 @@ describe RuboCop::Cop::Discourse::NoMixingMultisiteAndStandardSpecs, :config do
|
|
67
63
|
end
|
68
64
|
RUBY
|
69
65
|
|
70
|
-
expect(
|
66
|
+
expect(offenses).to eq([])
|
71
67
|
end
|
72
68
|
end
|
@@ -1,35 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe RuboCop::Cop::Discourse::NoMockingJobs, :config do
|
3
|
+
RSpec.describe RuboCop::Cop::Discourse::NoMockingJobs, :config do
|
6
4
|
subject(:cop) { described_class.new(config) }
|
7
5
|
|
8
|
-
let(:config)
|
9
|
-
RuboCop::Config.new
|
10
|
-
end
|
6
|
+
let(:config) { RuboCop::Config.new }
|
11
7
|
|
12
8
|
it "raises an offense if Jobs is mocked with :enqueue" do
|
13
|
-
inspect_source(<<~RUBY)
|
9
|
+
offenses = inspect_source(<<~RUBY)
|
14
10
|
Jobs.expects(:enqueue)
|
15
11
|
RUBY
|
16
12
|
|
17
|
-
expect(
|
13
|
+
expect(offenses.first.message).to end_with(described_class::MSG)
|
18
14
|
end
|
19
15
|
|
20
16
|
it "raises an offense if Jobs is mocked with :enqueue_in" do
|
21
|
-
inspect_source(<<~RUBY)
|
17
|
+
offenses = inspect_source(<<~RUBY)
|
22
18
|
Jobs.expects(:enqueue_in)
|
23
19
|
RUBY
|
24
20
|
|
25
|
-
expect(
|
21
|
+
expect(offenses.first.message).to end_with(described_class::MSG)
|
26
22
|
end
|
27
23
|
|
28
24
|
it "does not raise an offense if Jobs is not mocked with :enqueue or :enqueue_in" do
|
29
|
-
inspect_source(<<~RUBY)
|
25
|
+
offenses = inspect_source(<<~RUBY)
|
30
26
|
Jobs.enqueue(:some_job)
|
31
27
|
RUBY
|
32
28
|
|
33
|
-
expect(
|
29
|
+
expect(offenses).to eq([])
|
34
30
|
end
|
35
31
|
end
|