Skip to content

Commit b3aa361

Browse files
authored
ActiveAdmin: Allow for both singular and plural model names (#776)
This is an addition to this PR: #692 I've seen it's been stale for a while and it's rather simple fix. I noticed my ActiveAdmin resources are not being annotated. I know ActiveAdmin uses plural model names, but, as far as I remember, they used to use singular model names in the past. We can see some "evidence" of that here: https://activeadmin.info/2-resource-customization.html#customizing-parent-menu-items Probably in other places as well. In order to keep the gem working as expected for singular ActiveAdmin resources, I suggest we annotate both singular and plural model names. I just tested this out in a project of mine where I renamed one file to be in singular form and left the other files in plural form. It worked like a charm. :)
1 parent 508d06a commit b3aa361

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/annotate/annotate_models/file_patterns.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ def generate(root_directory, pattern_type, options)
5959
when 'controller'
6060
[File.join(root_directory, CONTROLLER_DIR, '%PLURALIZED_MODEL_NAME%_controller.rb')]
6161
when 'admin'
62-
[File.join(root_directory, ACTIVEADMIN_DIR, '%MODEL_NAME%.rb')]
62+
[
63+
File.join(root_directory, ACTIVEADMIN_DIR, '%MODEL_NAME%.rb'),
64+
File.join(root_directory, ACTIVEADMIN_DIR, '%PLURALIZED_MODEL_NAME%.rb')
65+
]
6366
when 'helper'
6467
[File.join(root_directory, HELPER_DIR, '%PLURALIZED_MODEL_NAME%_helper.rb')]
6568
else

spec/lib/annotate/annotate_models/file_patterns_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@
119119
context 'when pattern_type is "admin"' do
120120
let(:pattern_type) { 'admin' }
121121

122-
it 'returns patterns of admin files' do
123-
is_expected.to eq([
124-
'/root/app/admin/%MODEL_NAME%.rb'
125-
])
122+
it 'returns both singular and pluralized model names' do
123+
is_expected.to eq(['/root/app/admin/%MODEL_NAME%.rb', '/root/app/admin/%PLURALIZED_MODEL_NAME%.rb'])
126124
end
127125
end
128126

0 commit comments

Comments
 (0)