Skip to content

Commit

Permalink
cucumber tests now pass for both generating new themes and plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
djones committed Jul 28, 2010
1 parent c5cbaaa commit b5dcc62
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 75 deletions.
23 changes: 20 additions & 3 deletions features/refinery/plugin_generator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ Feature: Plugin generation

Scenario: Generating a plugin with a name
Given I have a refinery application
When I generate a plugin with the name of "product"
Then I should have a directory named "products"
And I should have a file named ""
When I generate a plugin with the arguments of "product title:string description:text image:image brochure:resource"
Then I should have a directory "vendor/plugins/products"
And I should have a directory "vendor/plugins/products/app"
And I should have a directory "vendor/plugins/products/config"
And I should have a directory "vendor/plugins/products/rails"
And I should have a directory "vendor/plugins/products/rails"
And I should have a file "vendor/plugins/products/rails/init.rb"
And I should have a file "vendor/plugins/products/app/controllers/admin/products_controller.rb"
And I should have a file "vendor/plugins/products/app/controllers/products_controller.rb"
And I should have a file "vendor/plugins/products/app/models/product.rb"
And I should have a file "vendor/plugins/products/config/routes.rb"
And I should have a file "vendor/plugins/products/config/locales/en.yml"
And I should have a file "vendor/plugins/products/app/views/admin/products/_form.html.erb"
And I should have a file "vendor/plugins/products/app/views/admin/products/_sortable_list.html.erb"
And I should have a file "vendor/plugins/products/app/views/admin/products/edit.html.erb"
And I should have a file "vendor/plugins/products/app/views/admin/products/index.html.erb"
And I should have a file "vendor/plugins/products/app/views/admin/products/new.html.erb"
And I should have a file "vendor/plugins/products/app/views/admin/products/_product.html.erb"
And I should have a file "vendor/plugins/products/app/views/products/index.html.erb"
And I should have a file "vendor/plugins/products/app/views/products/show.html.erb"
16 changes: 8 additions & 8 deletions features/refinery/theme_generator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Feature: Theme generation
Scenario: Generating a theme with a name
Given I have a refinery application
When I generate a theme with the name of "modern"
Then I should have a directory named "modern"
And I should have a stylesheet named "modern/stylesheets/application.css"
And I should have a stylesheet named "modern/stylesheets/home.css"
And I should have a stylesheet named "modern/stylesheets/formatting.css"
And I should have a layout named "modern/views/layouts/application.html.erb"
And I should have a layout named "modern/views/pages/home.html.erb"
And I should have a layout named "modern/views/pages/show.html.erb"
And I should have a directory named "modern/javascripts"
Then I should have a directory "themes/modern"
And I should have a file "themes/modern/stylesheets/application.css"
And I should have a file "themes/modern/stylesheets/home.css"
And I should have a file "themes/modern/stylesheets/formatting.css"
And I should have a file "themes/modern/views/layouts/application.html.erb"
And I should have a file "themes/modern/views/pages/home.html.erb"
And I should have a file "themes/modern/views/pages/show.html.erb"
And I should have a directory "themes/modern/javascripts"
15 changes: 2 additions & 13 deletions features/step_definitions/refinery/plugin_generator_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,7 @@
FileUtils.rm_rf(@tmp_refinery_app_root)
end

Given /^I have a refinery application$/ do
FileUtils.mkdir(File.join(@app_root))
When /^I generate a plugin with the arguments of "([^"]*)"$/ do |arguments|
Rails::Generator::Scripts::Generate.new.run((["refinery_plugin"] | arguments.split(" ")), {:quiet => true, :destination => @app_root})
end

When /^I generate a plugin with the name of "([^"]*)"$/ do |name|
Rails::Generator::Scripts::Generate.new.run([:theme, name], {:destination => @app_root, :quiet => true})
end

Then /^I should have a directory named "([^"]*)"$/ do |name|
File.exist?(File.join(@tmp_refinery_app_root, '/vendor/plugins/products', name)).should be_true
end

Then /^I should have a file named "([^"]*)"$/ do |name|
File.exist?(File.join(@tmp_refinery_app_root, '/vendor/plugins/products', name)).should be_true
end
27 changes: 3 additions & 24 deletions features/step_definitions/refinery/theme_generator_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,13 @@
@tmp_refinery_app_name = "tmp_refinery_app"
@tmp_refinery_app_root = File.join(@theme_generator_root, @tmp_refinery_app_name)
@app_root = @tmp_refinery_app_root
Rails::Generator::Base.append_sources(Rails::Generator::PathSource.new(:plugin, "#{@theme_generator_root}/generators/"))
Rails::Generator::Base.append_sources(Rails::Generator::PathSource.new(:theme, "#{@theme_generator_root}/generators/"))
end

After do
FileUtils.rm_rf(@tmp_refinery_app_root)
end

Given /^I have a refinery application$/ do
FileUtils.mkdir(File.join(@app_root))
end

When /^I generate a theme with the name of "([^"]*)"$/ do |name|
Rails::Generator::Scripts::Generate.new.run([:theme, name], {:destination => @app_root, :quiet => true})
end

Then /^I should have a directory named "([^"]*)"$/ do |name|
File.exist?(File.join(@tmp_refinery_app_root, '/themes', name)).should be_true
end

Then /^I should have a stylesheet named "([^"]*)"$/ do |name|
File.exist?(File.join(@tmp_refinery_app_root, '/themes', name)).should be_true
end

Then /^I should have a layout named "([^"]*)"$/ do |name|
File.exist?(File.join(@tmp_refinery_app_root, '/themes', name)).should be_true
end

Then /^I should have a "([^"]*)"$/ do |name|
File.exist?(File.join(@tmp_refinery_app_root, '/themes', 'modern', name)).should be_true
end

Rails::Generator::Scripts::Generate.new.run(['refinery_theme', name], {:quiet => true, :destination => @app_root})
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ def initialize(*runtime_args)
end

def banner
"Usage: ./script/generate refinery_plugin singular_model_name attribute:type [attribute2:type ...]"
"Usage: ruby script/generate refinery_plugin singular_model_name attribute:type [attribute2:type ...]"
end

def manifest
if @args[0].nil? and @args[1].nil?
puts "You must specify a singular model name and a first attribute"
puts banner
exit
end

record do |m|
# Copy controller, model and migration
directories = ["#{plural_name}", "#{plural_name}/app", "#{plural_name}/app/controllers",
Expand Down Expand Up @@ -62,8 +68,8 @@ def manifest
m.migration_template 'migration.rb', 'db/migrate',
:assigns => {:migration_name => "Create#{class_name.pluralize}"},
:migration_file_name => "create_#{singular_name.pluralize}"

m.readme "MIGRATE"
m.readme "MIGRATE" unless RAILS_ENV == "test"
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
class RefineryThemeGenerator < Rails::Generator::Base

def manifest
unless @args[0].nil?
record do |m|
m.directory "themes"
m.directory "themes/#{theme_name}"
m.directory "themes/#{theme_name}/javascripts"

m.directory "themes/#{theme_name}/stylesheets"
m.file "stylesheets/application.css", "themes/#{theme_name}/stylesheets/application.css"
m.file "stylesheets/formatting.css", "themes/#{theme_name}/stylesheets/formatting.css"
m.file "stylesheets/home.css", "themes/#{theme_name}/stylesheets/home.css"
def banner
"Usage: ruby script/generate refinery_theme theme_name"
end

m.directory "themes/#{theme_name}/views"
m.directory "themes/#{theme_name}/views/layouts"
m.file "views/layouts/application.html.erb", "themes/#{theme_name}/views/layouts/application.html.erb"

m.directory "themes/#{theme_name}/views/pages"
m.file "views/pages/show.html.erb", "themes/#{theme_name}/views/pages/show.html.erb"
m.file "views/pages/home.html.erb", "themes/#{theme_name}/views/pages/home.html.erb"

puts 'NOTE: If you want this new theme to be the current theme used, set the "theme"
setting in the Refinery backend to the name of this theme.'
end
else
def manifest
if @args[0].nil?
puts "You must specify a theme name."
puts "Eg: ruby script/generate refinery_theme modern"
puts banner
exit
end

record do |m|
m.directory "themes"
m.directory "themes/#{theme_name}"
m.directory "themes/#{theme_name}/javascripts"

m.directory "themes/#{theme_name}/stylesheets"
m.file "stylesheets/application.css", "themes/#{theme_name}/stylesheets/application.css"
m.file "stylesheets/formatting.css", "themes/#{theme_name}/stylesheets/formatting.css"
m.file "stylesheets/home.css", "themes/#{theme_name}/stylesheets/home.css"

m.directory "themes/#{theme_name}/views"
m.directory "themes/#{theme_name}/views/layouts"
m.file "views/layouts/application.html.erb", "themes/#{theme_name}/views/layouts/application.html.erb"

m.directory "themes/#{theme_name}/views/pages"
m.file "views/pages/show.html.erb", "themes/#{theme_name}/views/pages/show.html.erb"
m.file "views/pages/home.html.erb", "themes/#{theme_name}/views/pages/home.html.erb"

puts 'NOTE: If you want this new theme to be the current theme used, set the "theme"
setting in the Refinery backend to the name of this theme.' unless RAILS_ENV == "test"
end
end

Expand Down

0 comments on commit b5dcc62

Please sign in to comment.