@@ -16,8 +16,8 @@ class Post < ApplicationRecord
16
16
17
17
expect_correction ( <<~RUBY )
18
18
class Post < ApplicationRecord
19
- belongs_to :bar
20
19
belongs_to :foo
20
+ belongs_to :bar
21
21
belongs_to :blah
22
22
end
23
23
RUBY
@@ -37,8 +37,8 @@ class Post < ApplicationRecord
37
37
38
38
expect_correction ( <<~RUBY )
39
39
class Post < ApplicationRecord
40
- belongs_to :bar
41
40
belongs_to :foo, -> { active }
41
+ belongs_to :bar
42
42
belongs_to :blah
43
43
end
44
44
RUBY
@@ -60,8 +60,8 @@ class Post < ApplicationRecord
60
60
61
61
expect_correction ( <<~RUBY )
62
62
class Post < ApplicationRecord
63
- has_many :bars
64
63
has_many :foos
64
+ has_many :bars
65
65
has_many :blahs
66
66
end
67
67
RUBY
@@ -81,12 +81,31 @@ class Post < ApplicationRecord
81
81
82
82
expect_correction ( <<~RUBY )
83
83
class Post < ApplicationRecord
84
- has_many :bars
85
84
has_many 'foos', -> { active }
85
+ has_many :bars
86
86
has_many :blahs
87
87
end
88
88
RUBY
89
89
end
90
+
91
+ it 'registers an offense with alias' do
92
+ expect_offense ( <<~RUBY )
93
+ class Post < ApplicationRecord
94
+ belongs_to :foos, -> { active }
95
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Association `foos` is defined multiple times. Don't repeat associations.
96
+ alias bars foos
97
+ belongs_to :foos
98
+ ^^^^^^^^^^^^^^^^ Association `foos` is defined multiple times. Don't repeat associations.
99
+ end
100
+ RUBY
101
+
102
+ expect_correction ( <<~RUBY )
103
+ class Post < ApplicationRecord
104
+ belongs_to :foos
105
+ alias bars foos
106
+ end
107
+ RUBY
108
+ end
90
109
end
91
110
92
111
describe 'has_one' do
@@ -104,8 +123,8 @@ class Post < ApplicationRecord
104
123
105
124
expect_correction ( <<~RUBY )
106
125
class Post < ApplicationRecord
107
- has_one :bar
108
126
has_one :foo
127
+ has_one :bar
109
128
has_one :blah
110
129
end
111
130
RUBY
@@ -125,8 +144,8 @@ class Post < ApplicationRecord
125
144
126
145
expect_correction ( <<~RUBY )
127
146
class Post < ApplicationRecord
128
- has_one :bar
129
147
has_one :foo, -> { active }
148
+ has_one :bar
130
149
has_one :blah
131
150
end
132
151
RUBY
@@ -148,8 +167,8 @@ class Post < ApplicationRecord
148
167
149
168
expect_correction ( <<~RUBY )
150
169
class Post < ApplicationRecord
151
- has_and_belongs_to_many :bars
152
170
has_and_belongs_to_many :foos
171
+ has_and_belongs_to_many :bars
153
172
has_and_belongs_to_many :blahs
154
173
end
155
174
RUBY
@@ -169,8 +188,8 @@ class Post < ApplicationRecord
169
188
170
189
expect_correction ( <<~RUBY )
171
190
class Post < ApplicationRecord
172
- has_and_belongs_to_many :bars
173
191
has_and_belongs_to_many :foos, -> { active }
192
+ has_and_belongs_to_many :bars
174
193
has_and_belongs_to_many :blahs
175
194
end
176
195
RUBY
@@ -200,12 +219,12 @@ class Post < ApplicationRecord
200
219
201
220
expect_correction ( <<~RUBY )
202
221
class Post < ApplicationRecord
203
- has_and_belongs_to_many :bars
204
222
has_and_belongs_to_many :foos, -> { active }
223
+ has_and_belongs_to_many :bars
205
224
has_and_belongs_to_many :blahs
206
225
207
- has_one :top_comment, -> { order(likes: :desc) }, class_name: 'Comment'
208
226
belongs_to :author
227
+ has_one :top_comment, -> { order(likes: :desc) }, class_name: 'Comment'
209
228
end
210
229
RUBY
211
230
end
0 commit comments