Unverified Commit b3aa361f by Viktor Fonic Committed by GitHub

ActiveAdmin: Allow for both singular and plural model names (#776)

This is an addition to this PR: https://github.com/ctran/annotate_models/pull/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. :)
parent 508d06a8
...@@ -59,7 +59,10 @@ module AnnotateModels ...@@ -59,7 +59,10 @@ module AnnotateModels
when 'controller' when 'controller'
[File.join(root_directory, CONTROLLER_DIR, '%PLURALIZED_MODEL_NAME%_controller.rb')] [File.join(root_directory, CONTROLLER_DIR, '%PLURALIZED_MODEL_NAME%_controller.rb')]
when 'admin' when 'admin'
[File.join(root_directory, ACTIVEADMIN_DIR, '%MODEL_NAME%.rb')] [
File.join(root_directory, ACTIVEADMIN_DIR, '%MODEL_NAME%.rb'),
File.join(root_directory, ACTIVEADMIN_DIR, '%PLURALIZED_MODEL_NAME%.rb')
]
when 'helper' when 'helper'
[File.join(root_directory, HELPER_DIR, '%PLURALIZED_MODEL_NAME%_helper.rb')] [File.join(root_directory, HELPER_DIR, '%PLURALIZED_MODEL_NAME%_helper.rb')]
else else
......
...@@ -119,10 +119,8 @@ describe AnnotateModels::FilePatterns do ...@@ -119,10 +119,8 @@ describe AnnotateModels::FilePatterns do
context 'when pattern_type is "admin"' do context 'when pattern_type is "admin"' do
let(:pattern_type) { 'admin' } let(:pattern_type) { 'admin' }
it 'returns patterns of admin files' do it 'returns both singular and pluralized model names' do
is_expected.to eq([ is_expected.to eq(['/root/app/admin/%MODEL_NAME%.rb', '/root/app/admin/%PLURALIZED_MODEL_NAME%.rb'])
'/root/app/admin/%MODEL_NAME%.rb'
])
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment