aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-02-25 21:02:00 -0300
committerRafael França <rafaelmfranca@gmail.com>2016-02-25 21:02:00 -0300
commit1cc96c2e5fe08bc69bd768febbb5e3150343aa30 (patch)
treec8f13ca094921e5466542cc11e38f1ae16a31b3a /activerecord
parentfcec068bf913d74146703a02388608aa54d4f3a8 (diff)
parent9614f9317fef91ab74aa259f5e7dabb4c9a1d874 (diff)
downloadrails-1cc96c2e5fe08bc69bd768febbb5e3150343aa30.tar.gz
rails-1cc96c2e5fe08bc69bd768febbb5e3150343aa30.tar.bz2
rails-1cc96c2e5fe08bc69bd768febbb5e3150343aa30.zip
Merge pull request #23846 from y-yagi/correctly_check_ApplicationRecord_in_mountable_engine
correctly check `ApplicationRecord` is exist in moutable engine
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/rails/generators/active_record/model/model_generator.rb26
-rw-r--r--activerecord/lib/rails/generators/active_record/model/templates/application_record.rb2
2 files changed, 17 insertions, 11 deletions
diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb
index 179a4dc91e..f191eff5bf 100644
--- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb
+++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb
@@ -41,8 +41,8 @@ module ActiveRecord
# FIXME: Change this file to a symlink once RubyGems 2.5.0 is required.
def generate_application_record
- if self.behavior == :invoke && !File.exist?('app/models/application_record.rb')
- template 'application_record.rb', 'app/models/application_record.rb'
+ if self.behavior == :invoke && !application_record_exist?
+ template 'application_record.rb', application_record_file_name
end
end
@@ -51,18 +51,22 @@ module ActiveRecord
options[:parent] || determine_default_parent_class
end
- def determine_default_parent_class
- application_record = nil
+ def application_record_exist?
+ file_exist = nil
+ in_root { file_exist = File.exist?(application_record_file_name) }
+ file_exist
+ end
- in_root do
- application_record = if mountable_engine?
- File.exist?("app/models/#{namespaced_path}/application_record.rb")
- else
- File.exist?('app/models/application_record.rb')
- end
+ def application_record_file_name
+ @application_record_file_name ||= if mountable_engine?
+ "app/models/#{namespaced_path}/application_record.rb"
+ else
+ 'app/models/application_record.rb'
end
+ end
- if application_record
+ def determine_default_parent_class
+ if application_record_exist?
"ApplicationRecord"
else
"ActiveRecord::Base"
diff --git a/activerecord/lib/rails/generators/active_record/model/templates/application_record.rb b/activerecord/lib/rails/generators/active_record/model/templates/application_record.rb
index 10a4cba84d..60050e0bf8 100644
--- a/activerecord/lib/rails/generators/active_record/model/templates/application_record.rb
+++ b/activerecord/lib/rails/generators/active_record/model/templates/application_record.rb
@@ -1,3 +1,5 @@
+<% module_namespacing do -%>
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
+<% end -%>