diff --git a/vendor/plugins/blitz/features/controller_generator.feature b/vendor/plugins/blitz/features/controller_generator.feature index bb5c492..6306fdd 100644 --- a/vendor/plugins/blitz/features/controller_generator.feature +++ b/vendor/plugins/blitz/features/controller_generator.feature @@ -5,49 +5,49 @@ Feature: Rails controller generator Scenario: Controller generator for index action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "index" action And an empty "index" controller action for "posts" should be generated Scenario: Controller generator for new action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "new" action And a "new" controller action for "posts" should be generated Scenario: Controller generator for create action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "create" action And a "create" controller action for "posts" should be generated Scenario: Controller generator for create action when Cucumber is installed Given a Rails app with Cucumber - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "create" action And a "create" controller action for "posts" should be generated Scenario: Controller generator for show action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "show" action And a "show" controller action for "posts" should be generated Scenario: Controller generator for edit action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "edit" action And a "edit" controller action for "posts" should be generated Scenario: Controller generator for update action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "update" action And a "update" controller action for "posts" should be generated Scenario: Controller generator for destroy action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" controller with "destroy" action And a "destroy" controller action for "posts" should be generated diff --git a/vendor/plugins/blitz/features/feature_generator.feature b/vendor/plugins/blitz/features/feature_generator.feature index 3c8063f..cbd6a40 100644 --- a/vendor/plugins/blitz/features/feature_generator.feature +++ b/vendor/plugins/blitz/features/feature_generator.feature @@ -5,7 +5,7 @@ Feature: Rails controller generator Scenario: Feature generator for new action Given a Rails app with Cucumber - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "new" feature for "Posts" Then a "posts" feature for the "create" scenario should be generated And a "create posts" step definition should be generated @@ -13,7 +13,7 @@ Feature: Rails controller generator Scenario: Feature generator for create action same as new Given a Rails app with Cucumber - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "create" feature for "Posts" Then a "posts" feature for the "create" scenario should be generated And a "create posts" step definition should be generated @@ -21,7 +21,7 @@ Feature: Rails controller generator Scenario: Feature generator for edit action Given a Rails app with Cucumber - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "edit" feature for "Posts" Then a "posts" feature for the "edit" scenario should be generated And a "update posts" step definition should be generated @@ -29,7 +29,7 @@ Feature: Rails controller generator Scenario: Feature generator for update action same as edit Given a Rails app with Cucumber - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "update" feature for "Posts" Then a "posts" feature for the "update" scenario should be generated And a "update posts" step definition should be generated diff --git a/vendor/plugins/blitz/features/functional_test_generator.feature b/vendor/plugins/blitz/features/functional_test_generator.feature index da715ed..50f1bc4 100644 --- a/vendor/plugins/blitz/features/functional_test_generator.feature +++ b/vendor/plugins/blitz/features/functional_test_generator.feature @@ -5,49 +5,49 @@ Feature: Rails controller generator Scenario: Functional test generator for index action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "index" action Then a standard "index" functional test for "posts" should be generated Scenario: Functional test generator for new action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "new" action Then a standard "new" functional test for "posts" should be generated Scenario: Functional test generator for create action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "create" action Then a standard "create" functional test for "posts" should be generated Scenario: Functional test generator for create action when Cucumber is installed Given a Rails app with Cucumber - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "create" action Then a standard "create" functional test for "posts" should be generated Scenario: Functional test generator for show action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "show" action Then a standard "show" functional test for "posts" should be generated Scenario: Functional test generator for edit action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "edit" action Then a standard "edit" functional test for "posts" should be generated Scenario: Functional test generator for update action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "update" action Then a standard "update" functional test for "posts" should be generated Scenario: Functional test generator for destroy action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "Posts" functional test with "destroy" action Then a standard "destroy" functional test for "posts" should be generated diff --git a/vendor/plugins/blitz/features/helper_generator.feature b/vendor/plugins/blitz/features/helper_generator.feature index f0e0af7..ec0382f 100644 --- a/vendor/plugins/blitz/features/helper_generator.feature +++ b/vendor/plugins/blitz/features/helper_generator.feature @@ -5,7 +5,7 @@ Feature: Rails helper generator Scenario: Helper Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a helper named "Navigation" Then a helper should be generated for "Navigation" And a helper test should be generated for "Navigation" diff --git a/vendor/plugins/blitz/features/model_generator.feature b/vendor/plugins/blitz/features/model_generator.feature index 35e4e05..a8b3375 100644 --- a/vendor/plugins/blitz/features/model_generator.feature +++ b/vendor/plugins/blitz/features/model_generator.feature @@ -5,21 +5,21 @@ Feature: Rails model generator Scenario: Model generator without attributes Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a model named "User" Then a factory should be generated for "User" And a unit test should be generated for "User" Scenario: Model generator with attributes Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a model "User" with a string "email" Then a factory for "User" should have an "email" string And a unit test should be generated for "User" Scenario: Model generator with association Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a model "Post" that belongs to a "User" Then a factory for "Post" should have an association to "User" And the "Post" unit test should have "should_belong_to :user" macro @@ -29,7 +29,7 @@ Feature: Rails model generator Scenario: Model generator with Paperclip Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a model "Design" with file "Image" Then the "Design" model should have "has_attached_file :image" macro And the "Design" unit test should have "should_have_attached_file :image" macro diff --git a/vendor/plugins/blitz/features/step_definitions/controller_steps.rb b/vendor/plugins/blitz/features/step_definitions/controller_steps.rb index ad81dee..df60687 100644 --- a/vendor/plugins/blitz/features/step_definitions/controller_steps.rb +++ b/vendor/plugins/blitz/features/step_definitions/controller_steps.rb @@ -18,7 +18,7 @@ Then /^a "create" controller action for "posts" should be generated$/ do " @post = Post.new(params[:post])\n" << " @post.save\n" << " flash[:success] = 'Post created.'\n" << - " redirect_to posts_path\n" << + " redirect_to root_path\n" << " end" end end @@ -45,7 +45,7 @@ Then /^a "update" controller action for "posts" should be generated$/ do " @post = Post.find(params[:id])\n" << " @post.update_attributes(params[:post])\n" << " flash[:success] = 'Post updated.'\n" << - " redirect_to posts_path\n" << + " redirect_to root_path\n" << " end" end end @@ -56,7 +56,7 @@ Then /^a "destroy" controller action for "posts" should be generated$/ do " @post = Post.find(params[:id])\n" << " @post.destroy\n" << " flash[:success] = 'Post deleted.'\n" << - " redirect_to posts_path\n" << + " redirect_to root_path\n" << " end" end end diff --git a/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb b/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb index 9e83ae6..062e04a 100644 --- a/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb +++ b/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb @@ -14,6 +14,7 @@ end Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action| if %w(new create).include?(action) assert_generated_file("features/posts.feature") do + "Feature: Posts\n\n" << " Scenario: Create a new post\n" << " Given I am on the new post page\n" << " When I create a post named \"A new post\"\n" << @@ -21,6 +22,7 @@ Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |a end elsif %w(edit update).include?(action) assert_generated_file("features/posts.feature") do + "Feature: Posts\n\n" << " Scenario: Update a post\n" << " Given I am on the edit \"An existing post\" post page\n" << " When I update the post\n" << @@ -32,8 +34,8 @@ end Then /^a "create posts" step definition should be generated$/ do assert_generated_file("features/step_definitions/posts_steps.rb") do "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" << - " fills_in :name, :with => name\n" << - " click_button 'Create'\n" + " fill_in :name, :with => name\n" << + " click_button 'Create'\n" << "end" end end @@ -48,8 +50,8 @@ end Then /^a "update posts" step definition should be generated$/ do assert_generated_file("features/step_definitions/posts_steps.rb") do "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" << - " fills_in :name, :with => name\n" << - " click_button 'Update'\n" + " fill_in :name, :with => name\n" << + " click_button 'Update'\n" << "end" end end diff --git a/vendor/plugins/blitz/features/step_definitions/generator_steps.rb b/vendor/plugins/blitz/features/step_definitions/generator_steps.rb index 3df26cd..1ed01e3 100644 --- a/vendor/plugins/blitz/features/step_definitions/generator_steps.rb +++ b/vendor/plugins/blitz/features/step_definitions/generator_steps.rb @@ -3,11 +3,11 @@ Given 'a Rails app' do @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") end -Given /^the coulda plugin is installed$/ do +Given /^the blitz plugin is installed$/ do plugin_dir = File.join(@rails_root, "vendor", "plugins") target = File.join(File.dirname(__FILE__), "..", "..", "generators") - FileUtils.mkdir_p "#{plugin_dir}/coulda" - system "cp -r #{target} #{plugin_dir}/coulda" + FileUtils.mkdir_p "#{plugin_dir}/blitz" + system "cp -r #{target} #{plugin_dir}/blitz" end After do diff --git a/vendor/plugins/blitz/features/step_definitions/view_steps.rb b/vendor/plugins/blitz/features/step_definitions/view_steps.rb index e8e8158..a99ffb8 100644 --- a/vendor/plugins/blitz/features/step_definitions/view_steps.rb +++ b/vendor/plugins/blitz/features/step_definitions/view_steps.rb @@ -4,6 +4,12 @@ When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource| "cd .." end +When /^I generate a "([^\"]*)" view for "([^\"]*)" with the empty option$/ do |view, resource| + system "cd #{@rails_root} && " << + "script/generate view #{resource} #{view} --empty && " << + "cd .." +end + When /^a SemiFormal "new" view for "posts" should be generated$/ do assert_generated_file("app/views/posts/new.html.erb") do "

New post

\n\n" << @@ -24,8 +30,9 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do "<% form_for(@post) do |form| %>\n" << " <%= form.error_messages %>\n" << "
\n" << - " <%= form.string :title %>\n" << - " <%= form.text :body %>\n" << + " <%= form.string :title %>\n" << + " <%= form.text :body %>\n" << + " <%= form.collection :user %>\n" << "
\n" << "
\n" << " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << @@ -34,3 +41,7 @@ Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do end end +Then /^an empty "new" view for "posts" should be generated$/ do + assert_generated_empty_file("app/views/posts/new.html.erb") +end + diff --git a/vendor/plugins/blitz/features/support/env.rb b/vendor/plugins/blitz/features/support/env.rb index 40deba8..594d7b1 100644 --- a/vendor/plugins/blitz/features/support/env.rb +++ b/vendor/plugins/blitz/features/support/env.rb @@ -14,6 +14,15 @@ module Test::Unit::Assertions end end + def assert_generated_empty_file(path) + assert_file_exists(path) + File.open(File.join(@rails_root, path)) do |file| + body = file.read + assert body.empty?, + "expected body to be empty but was #{body.inspect}" + end + end + def assert_file_exists(path) file = File.join(@rails_root, path) diff --git a/vendor/plugins/blitz/features/view_generator.feature b/vendor/plugins/blitz/features/view_generator.feature index a5730d0..14cd203 100644 --- a/vendor/plugins/blitz/features/view_generator.feature +++ b/vendor/plugins/blitz/features/view_generator.feature @@ -5,14 +5,21 @@ Feature: Rails view generator Scenario: View generator for new action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a "new" view for "Posts" Then a SemiFormal "new" view for "posts" should be generated Scenario: View generator for new action Given a Rails app - And the coulda plugin is installed + And the blitz plugin is installed When I generate a Post model with title, body, and User And I generate a "new" view for "Posts" Then a SemiFormal "new" view for "posts" should be generated with fields + Scenario: View generator for new action + Given a Rails app + And the blitz plugin is installed + When I generate a Post model with title, body, and User + When I generate a "new" view for "Posts" with the empty option + Then an empty "new" view for "posts" should be generated + diff --git a/vendor/plugins/blitz/generators/controller/templates/controller.rb b/vendor/plugins/blitz/generators/controller/templates/controller.rb index b1fcb6f..40e933f 100644 --- a/vendor/plugins/blitz/generators/controller/templates/controller.rb +++ b/vendor/plugins/blitz/generators/controller/templates/controller.rb @@ -15,7 +15,7 @@ class <%= class_name %>Controller < ApplicationController @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) @<%= resource %>.save flash[:success] = '<%= resource_class %> created.' - redirect_to <%= resources %>_path + redirect_to root_path end <% end -%> @@ -36,7 +36,7 @@ class <%= class_name %>Controller < ApplicationController @<%= resource %> = <%= resource_class %>.find(params[:id]) @<%= resource %>.update_attributes(params[:<%= resource %>]) flash[:success] = '<%= resource_class %> updated.' - redirect_to <%= resources %>_path + redirect_to root_path end <% end -%> @@ -45,7 +45,7 @@ class <%= class_name %>Controller < ApplicationController @<%= resource %> = <%= resource_class %>.find(params[:id]) @<%= resource %>.destroy flash[:success] = '<%= resource_class %> deleted.' - redirect_to <%= resources %>_path + redirect_to root_path end <% end -%> diff --git a/vendor/plugins/blitz/generators/feature/templates/feature.feature b/vendor/plugins/blitz/generators/feature/templates/feature.feature index 5d6b1f5..16066ef 100644 --- a/vendor/plugins/blitz/generators/feature/templates/feature.feature +++ b/vendor/plugins/blitz/generators/feature/templates/feature.feature @@ -1,3 +1,5 @@ +Feature: <%= resource_class.pluralize %> + <% if %w(new create).any? { |action| actions.include?(action) } -%> Scenario: Create a new <%= resource %> Given I am on the new <%= resource %> page diff --git a/vendor/plugins/blitz/generators/feature/templates/step_definition.rb b/vendor/plugins/blitz/generators/feature/templates/step_definition.rb index 78572d3..309da6c 100644 --- a/vendor/plugins/blitz/generators/feature/templates/step_definition.rb +++ b/vendor/plugins/blitz/generators/feature/templates/step_definition.rb @@ -1,11 +1,11 @@ <% if %w(new create).any? { |action| actions.include?(action) } -%> When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| - fills_in :name, :with => name + fill_in :name, :with => name click_button 'Create' end <% elsif %w(edit update).any? { |action| actions.include?(action) } -%> When /^I update a post named "([^\"]*)"$/ do |name| - fills_in :name, :with => name + fill_in :name, :with => name click_button 'Update' end <% end -%> diff --git a/vendor/plugins/blitz/generators/support/generator_helper.rb b/vendor/plugins/blitz/generators/support/generator_helper.rb index 68a6289..af472e3 100644 --- a/vendor/plugins/blitz/generators/support/generator_helper.rb +++ b/vendor/plugins/blitz/generators/support/generator_helper.rb @@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), "insert_commands") module Blitz module GeneratorHelper - REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed", + REMOVABLE_COLUMNS = ["id", "created_at", "updated_at", "email_confirmed", "encrypted_password", "salt", "token", "token_expires_at"] def resource @@ -18,8 +18,8 @@ module Blitz end def columns_for_form - resource_class.constantize.content_columns. - collect { |column| [column.name, column.type] }. + resource_class.constantize.columns. + collect { |column| name_and_type(column) }. delete_if { |column| remove_column?(column.first) } end @@ -30,9 +30,21 @@ module Blitz models.include?(resource_class) end + def belongs_to_column?(column_name) + !(column_name =~ /_id$/).nil? + end + + def name_and_type(column) + if belongs_to_column?(column.name) + [column.name.gsub("_id", ""), :collection] + else + [column.name, column.type] + end + end + def remove_column?(column) REMOVABLE_COLUMNS.include?(column) || - !(column =~ /_id$/).nil? + !(column =~ /_count$/).nil? end end end diff --git a/vendor/plugins/blitz/generators/view/templates/empty.html.erb b/vendor/plugins/blitz/generators/view/templates/empty.html.erb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/plugins/blitz/generators/view/templates/empty.html.erb diff --git a/vendor/plugins/blitz/generators/view/templates/new.html.erb b/vendor/plugins/blitz/generators/view/templates/new.html.erb new file mode 100644 index 0000000..6174b80 --- /dev/null +++ b/vendor/plugins/blitz/generators/view/templates/new.html.erb @@ -0,0 +1,15 @@ +

New <%= resource %>

+ +<%% form_for(@<%= resource %>) do |form| %> + <%%= form.error_messages %> +
+<% if active_record_defined? -%> +<% columns_for_form.each do |attribute_name, attribute_type| -%> + <%%= form.<%= attribute_type %> :<%= attribute_name %> %> +<% end -%> +<% end -%> +
+
+ <%%= form.submit 'Create', :disable_with => 'Please wait...' %> +
+<%% end %> diff --git a/vendor/plugins/blitz/generators/view/templates/view_new.html.erb b/vendor/plugins/blitz/generators/view/templates/view_new.html.erb deleted file mode 100644 index 6174b80..0000000 --- a/vendor/plugins/blitz/generators/view/templates/view_new.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -

New <%= resource %>

- -<%% form_for(@<%= resource %>) do |form| %> - <%%= form.error_messages %> -
-<% if active_record_defined? -%> -<% columns_for_form.each do |attribute_name, attribute_type| -%> - <%%= form.<%= attribute_type %> :<%= attribute_name %> %> -<% end -%> -<% end -%> -
-
- <%%= form.submit 'Create', :disable_with => 'Please wait...' %> -
-<%% end %> diff --git a/vendor/plugins/blitz/generators/view/view_generator.rb b/vendor/plugins/blitz/generators/view/view_generator.rb index a87426a..beb1bbe 100644 --- a/vendor/plugins/blitz/generators/view/view_generator.rb +++ b/vendor/plugins/blitz/generators/view/view_generator.rb @@ -1,14 +1,24 @@ require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") class ViewGenerator < Rails::Generator::NamedBase + default_options :empty => false + def manifest record do |m| m.directory File.join('app/views', class_path, file_name) if actions.include?("new") path = File.join('app/views', class_path, file_name, "new.html.erb") - m.template 'view_new.html.erb', path + if options[:empty] + m.file 'empty.html.erb', path + else + m.template 'new.html.erb', path + end end end end + + def add_options!(opt) + opt.on('-e', '--empty') { options[:empty] = true } + end end diff --git a/vendor/plugins/semi_formal/README.markdown b/vendor/plugins/semi_formal/README.markdown index 1b1a722..6fd5426 100644 --- a/vendor/plugins/semi_formal/README.markdown +++ b/vendor/plugins/semi_formal/README.markdown @@ -1,7 +1,7 @@ SemiFormal ========== -A FormBuilder meant to play well with [Coulda](http://github.com/dancroak/coulda) and [Evergreen](http://github.com/dancroak/evergreen). +A FormBuilder meant to play well with [Blitz](http://github.com/dancroak/blitz) and [Evergreen](http://github.com/dancroak/evergreen). Examples -------- diff --git a/vendor/plugins/semi_formal/lib/semi_formal.rb b/vendor/plugins/semi_formal/lib/semi_formal.rb index a7ba8a3..e03ca13 100644 --- a/vendor/plugins/semi_formal/lib/semi_formal.rb +++ b/vendor/plugins/semi_formal/lib/semi_formal.rb @@ -41,6 +41,26 @@ class SemiFormal < ActionView::Helpers::FormBuilder text_area(field, options[:text_area] || {}) + "
" end + + def collection(field, *args) + options = args.extract_options! + + reflection = @object.class.reflect_on_association(field) + collection = reflection.class.all.collect {|each| [each.name, each.id] } + + html_options = {} + options[:include_blank] = true + + if [:has_many, :has_and_belongs_to_many].include?(reflection.macro) + html_options[:multiple] ||= true + html_options[:size] ||= 5 + end + + "
" + + label(field, options[:label] || {}) + + select(field, collection, options, html_options) + "
" + end end ActionView::Base.default_form_builder = SemiFormal -- libgit2 0.21.2