Skip to content

Commit

Permalink
Fix issues with rails g spree:site generator. Also
Browse files Browse the repository at this point in the history
compatible with the sandbox and test_app rake tasks.

[Fixes spree#761]
  • Loading branch information
LBRapid authored and schof committed Nov 15, 2011
1 parent 7ab7668 commit 2477b32
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 7 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ Update your bundle

$ bundle install

Then use the install generator to do the basic setup
Use the install generator to do the basic setup. The install generator will prompt you to run migrations, setup some
basic data, and load sample products, orders, etc.

$ rails g spree:site

Now you just need to run the new migrations, and setup some basic data
To auto accept all prompts while running the install generator, pass -A as an option

$ rails g spree:site -A

If you chose to ignore the prompts while running the basic install
generator you can manually run migrations and load basic data with the following
commands

$ bundle exec rake db:migrate
$ bundle exec rake db:seed

If you also want some sample products, orders, etc. to play with you can run the appropriate rake task.
To manually load sample products, orders, etc., run the following rake task

$ bundle exec rake spree_sample:load

Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rake'
require 'rubygems/package_task'
require 'thor/group'
require 'lib/generators/spree/site/site_generator'

spec = eval(File.read('spree.gemspec'))
Gem::PackageTask.new(spec) do |pkg|
Expand Down Expand Up @@ -95,7 +96,7 @@ task :sandbox do
require 'spree_core'

Spree::SandboxGenerator.start ["--lib_name=spree", "--database=#{ENV['DB_NAME']}"]
Spree::SiteGenerator.start
Spree::SiteGenerator.start ["--auto-accept", "--skip-install-data"]

cmd = "bundle exec rake db:bootstrap AUTO_ACCEPT=true"; puts cmd; system cmd
cmd = "bundle exec rake assets:precompile:nondigest"; puts cmd; system cmd
Expand Down
1 change: 0 additions & 1 deletion core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module Core
require 'spree/core/version'

require 'spree/core/engine'
require 'generators/spree/site/site_generator'
require 'generators/spree/dummy/dummy_generator'
require 'generators/spree/sandbox/sandbox_generator'

Expand Down
5 changes: 4 additions & 1 deletion core/lib/spree/core/testing_support/common_rake.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
require '../lib/generators/spree/site/site_generator'

desc "Generates a dummy app for testing"
namespace :common do
task :test_app do
require "#{ENV['LIB_NAME']}"

Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--database=#{ENV['DB_NAME']}", "--quiet"]
Spree::SiteGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet"]
Spree::SiteGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet", "--auto-accept", "--skip-install-data"]
puts "Setting up dummy database..."
cmd = "bundle exec rake db:drop db:create db:migrate db:seed RAILS_ENV=test AUTO_ACCEPT=true"

if RUBY_PLATFORM =~ /mswin/ #windows
cmd += " >nul"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ module Spree
class SiteGenerator < Rails::Generators::Base
argument :after_bundle_only, :type => :string, :default => "false"

class_option :auto_accept, :type => :boolean, :default => false, :aliases => '-A', :desc => "Answer yes to all prompts"
class_option :skip_install_data, :type => :boolean, :default => false
class_option :lib_name, :default => 'spree'
attr :lib_name
attr :auto_accept
attr :skip_install_data
attr :test_app

def self.source_paths
[File.expand_path('../templates', __FILE__)]
paths = self.superclass.source_paths
paths << File.expand_path('../templates', "../../#{__FILE__}")
paths << File.expand_path('../templates', "../#{__FILE__}")
paths << File.expand_path('../templates', __FILE__)
paths.flatten
end

def config_spree_yml
Expand Down Expand Up @@ -94,5 +103,50 @@ def install_migrations
end
end

def run_migrations
unless options[:skip_install_data]
unless options[:auto_accept]
res = ask "Would you like to run migrations?"
end
if res.present? && res.downcase =~ /y[es]*/ || options[:auto_accept]
puts "Running migrations"
rake('db:migrate')
else
@migrations_skipped = true
puts "Skipping rake db:migrate, don't forget to run it!"
end
end
end

def populate_seed_data
unless options[:skip_install_data]
unless options[:auto_accept] || @migrations_skipped
res = ask "Would you like to load the seed data?"
end
if options[:auto_accept]
puts "Loading seed data"
rake('db:seed AUTO_ACCEPT=true')
elsif res.present? && res.downcase =~ /y[es]*/
puts "Loading seed data"
rake('db:seed')
else
puts "Skipping rake db:seed."
end
end
end

def load_sample_data
unless options[:skip_install_data]
unless options[:auto_accept] || @migrations_skipped
res = ask "Would you like to load the sample data?"
end
if res.present? && res.downcase =~ /y[es]*/ || options[:auto_accept]
puts "Loading sample data"
rake('spree_sample:load')
else
puts "Skipping loading sample data. You can always run this later with rake spree_sample:load."
end
end
end
end
end

0 comments on commit 2477b32

Please sign in to comment.