Skip to content

Commit

Permalink
Merge branch 'issue_1532'
Browse files Browse the repository at this point in the history
  • Loading branch information
ugisozols committed May 23, 2012
2 parents 800867d + dc50f40 commit c5f3301
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/lib/generators/refinery/engine/engine_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def generate

merge_locales!

copy_or_merge_seeds!

append_extension_to_gemfile!

finalize_extension!
Expand Down
2 changes: 2 additions & 0 deletions core/lib/generators/refinery/form/form_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def generate

merge_locales!

copy_or_merge_seeds!

append_extension_to_gemfile!

finalize_extension!
Expand Down
22 changes: 22 additions & 0 deletions core/lib/refinery/extension_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def evaluate_templates!
reject_template?(f)
}.sort.each do |path|
if (template_path = extension_path_for(path, extension_name)).present?
next if path.to_s =~ /seeds.rb/
template path, template_path
end
end
Expand Down Expand Up @@ -209,6 +210,27 @@ def merge_locales!
end
end

def copy_or_merge_seeds!
source_seed_file = source_pathname.join("db/seeds.rb")
destination_seed_file = destination_pathname.join(extension_path_for(source_seed_file, extension_name))

if existing_extension?
# create temp seeds file
temp_seed_file = destination_pathname.join(extension_path_for("tmp/seeds.rb", extension_name))

# copy/evaluate seeds template to temp file
template source_seed_file, temp_seed_file, :verbose => false

# append temp seeds file content to extension seeds file
destination_seed_file.open('a+') { |file| file.puts temp_seed_file.read.to_s }

# remove temp file
FileUtils.rm_rf temp_seed_file
else
template source_seed_file, destination_seed_file
end
end

def puts_instructions!
unless Rails.env.test?
puts "------------------------"
Expand Down
15 changes: 15 additions & 0 deletions core/spec/lib/generators/refinery/engine/engine_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,20 @@ module Refinery
end
}
end

context "when generating extension inside existing extensions dir" do
before do
Refinery::EngineGenerator.any_instance.stub(:merge_locales!).and_return(true)
Refinery::EngineGenerator.any_instance.stub(:existing_extension?).and_return(true)

run_generator %w{ rspec_item_test title:string --extension rspec_product_tests --skip }
end

it "appends existing seeds file" do
File.open("#{destination_root}/vendor/extensions/rspec_product_tests/db/seeds.rb") do |file|
file.grep(%r{/rspec_product_tests|/rspec_item_tests}).count.should eq(2)
end
end
end
end
end

0 comments on commit c5f3301

Please sign in to comment.