Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'simplelogica/fix/engine-generator-multi…

…ple-resources-migrations-routes'
  • Loading branch information...
commit 9c2261e2c79e7f353bc4985ceb93bf5733ba3896 2 parents af29dff + 9290f94
@parndt parndt authored
View
18 core/lib/refinery/extension_generation.rb
@@ -122,7 +122,7 @@ def extension_path_for(path, extension, apply_tmp = true)
if options[:namespace].present? || options[:extension].present?
# Increment the migration file leading number
# Only relevant for nested or namespaced extensions, where a previous migration exists
- if %r{/migrate/\d+\w*.rb\z} === path
+ if %r{/migrate/\d+.*\.rb.erb\z} === path
if last_migration = Dir["#{destination_pathname.join(path.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR), '*.rb')}"].sort.last
path.gsub!(%r{\d+_}) { |m| "#{last_migration.match(%r{migrate/(\d+)_})[1].to_i + 1}_" }
end
@@ -130,10 +130,12 @@ def extension_path_for(path, extension, apply_tmp = true)
# Detect whether this is a special file that needs to get merged not overwritten.
# This is important only when nesting extensions.
- if extension.present? && File.exist?(path)
+ # Routes and #{gem_name}\.rb have an .erb extension as path points to the generator template
+ # We have to exclude it when checking if the file already exists and include it in the regexps
+ if extension.present? && File.exist?(path.gsub(/\.erb$/, ""))
if %r{/locales/.*\.yml$} === path ||
- %r{/routes.rb$} === path ||
- %r{/#{gem_name}.rb$} === path
+ %r{/routes\.rb\.erb$} === path ||
+ %r{/#{gem_name}\.rb\.erb$} === path
# put new translations into a tmp directory
if apply_tmp
path = path.split(File::SEPARATOR).insert(-2, "tmp").
@@ -210,13 +212,15 @@ def merge_locales!
if existing_extension?
# go through all of the temporary files and merge what we need into the current files.
tmp_directories = []
- Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb,lib/refinerycms-extension_plural_name.rb}"), File::FNM_DOTMATCH).sort.each do |path|
+ Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb.erb,lib/refinerycms-extension_plural_name.rb.erb}"), File::FNM_DOTMATCH).sort.each do |path|
# get the path to the current tmp file.
- new_file_path = extension_path_for(path, extension_name)
+ # Both the new and current paths need to strip the .erb portion from the generator template
+ new_file_path = Pathname.new extension_path_for(path, extension_name).to_s.gsub(/\.erb$/, "")
tmp_directories << Pathname.new(new_file_path.to_s.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)) # save for later
# get the path to the existing file and perform a deep hash merge.
- current_path = extension_path_for(path, extension_name, false)
+ current_path = Pathname.new extension_path_for(path, extension_name, false).to_s.gsub(/\.erb$/, "")
new_contents = nil
+
if File.exist?(new_file_path) && %r{.yml$} === new_file_path.to_s
# merge translation files together.
new_contents = YAML::load(new_file_path.read).deep_merge(
View
45 core/spec/lib/generators/refinery/engine/engine_generator_multiple_resources_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+require 'generator_spec/test_case'
+require 'generators/refinery/engine/engine_generator'
+
+module Refinery
+ describe EngineGenerator do
+ include GeneratorSpec::TestCase
+ destination File.expand_path("../../../../../../tmp", __FILE__)
+
+ before do
+ prepare_destination
+ run_generator %w{ rspec_product_test title:string description:text image:image brochure:resource }
+ end
+
+ context "when generating a resource inside existing extensions dir" do
+
+ before do
+ run_generator %w{ rspec_item_test title:string --extension rspec_product_tests --namespace rspec_product_tests --skip }
+ end
+
+ it "creates a new migration with the new resource" do
+ destination_root.should have_structure {
+ directory "vendor" do
+ directory "extensions" do
+ directory "rspec_product_tests" do
+ directory "db" do
+ directory "migrate" do
+ file "2_create_rspec_product_tests_rspec_item_tests.rb"
+ end
+ end
+ end
+ end
+ end
+ }
+ end
+
+ it "appends routes to the routes file" do
+ File.open("#{destination_root}/vendor/extensions/rspec_product_tests/config/routes.rb") do |file|
+ file.grep(%r{rspec_item_tests}).count.should eq(2)
+ end
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.