diff --git a/README.markdown b/README.markdown index 14c4a6e..616bf2b 100644 --- a/README.markdown +++ b/README.markdown @@ -21,7 +21,7 @@ This will create a Rails 2.3.2 app with Heroku-recommended code: * Clearance for authentication * Cucumber, Shoulda, Factory Girl, & Mocha for testing * Evergreen for CSS framework -* Coulda for features, model, controller, & helper generators +* Blitz for features, model, controller, & helper generators If you don't have all the necessary gems, they will be installed. diff --git a/doc/README_FOR_TEMPLATE b/doc/README_FOR_TEMPLATE index 5d6169c..ef5b211 100644 --- a/doc/README_FOR_TEMPLATE +++ b/doc/README_FOR_TEMPLATE @@ -57,7 +57,7 @@ For exception notification: For models, controllers, helpers, & features generators: - coulda + blitz For rake tasks: @@ -89,7 +89,7 @@ Two time formats are available by default, :short_date and :long_date. Add other Testing ------- -Testing is done utilizing Test::Unit, Shoulda, factory_girl, and mocha. +Testing is done utilizing Cucumber, Test::Unit, Shoulda, Factory Girl, and Mocha. Shoulda is a pragmatic testing framework for TDD built on top of Test::Unit. @@ -121,8 +121,8 @@ It imports the Stylus framework: @import url("framework/reset.css"); @import url("framework/typography.css"); - @import url("framework/layout.css"); - @import url("framework/forms.css"); + @import url("framework/grid.css"); + @import url("framework/spacing.css"); Add another import for your own styles, by convention named after your app. diff --git a/vendor/plugins/blitz/CHANGELOG.textile b/vendor/plugins/blitz/CHANGELOG.textile new file mode 100644 index 0000000..efe4da3 --- /dev/null +++ b/vendor/plugins/blitz/CHANGELOG.textile @@ -0,0 +1,9 @@ +h1. March 8, 2009 + +* Updated functional tests to use shoulda 2.10 should_redirect_to block syntax + +h1. March 7, 2009 + +* Added Paperclip option to model generator +* Removed comments on model per complaints by thoughtbot + diff --git a/vendor/plugins/blitz/README.textile b/vendor/plugins/blitz/README.textile new file mode 100644 index 0000000..dfb4a3f --- /dev/null +++ b/vendor/plugins/blitz/README.textile @@ -0,0 +1,174 @@ +h1. Blitz generators + +A Rails plugin for feature, view, controller, model, & helper generators. It is meant to be used as part of an "Outside-In" Test-Driven Development cycle. + +h2. Generated code may contain + +* "Cucumber":http://github.com/aslakhellesoy/cucumber +* "Shoulda":http://github.com/thoughtbot/shoulda +* "Factory Girl":http://github.com/thoughtbot/factory_girl +* "Mocha":http://github.com/jferris/mocha + +h2. Installation + + $ script/plugin install git://github.com/dancroak/blitz.git + +h2. Feature generator + + $ script/generate feature Posts new create + +generates... + +
  Scenario: Create a new post
+    Given I am on the new post page
+    When I create a 'post' named 'A new post'
+    Then I should see 'A new post'
+ +Now run it: + + $ cucumber features/posts.feature + +The failure will be: + + undefined method `new_post_path' + +To get past this error, we'll create just the route we need: + + map.resources :posts, :only => [:new] + +Running the test again, we have a new failure: + + uninitialized constant PostsController + +h2. Controller test generator + +We've reached a point in our Outside-In cycle where we want to spiral down into a tighter feedback loop to unit test the non-existant controller. + + $ script/generate controller_test Posts new create + +h2. Controller generator + + $ script/generate controller Posts new create + +generates... + + +h2. Model generator + + $ script/generate model User + +* factory (Factory Girl) +* unit test (Shoulda) +* migration +* model + +h2. Helper generator + + $ script/generate helper Navigation + +* empty helper test file +* empty helper module + +h2. View generator + + $ script/generate view Posts new + +h2. Model generator: belongs_to + + $ script/generate model post user:belongs_to + +generates... + +
class CreatePosts < ActiveRecord::Migration
+  def self.up
+    create_table :posts do |t|
+      t.belongs_to :user
+      t.timestamps
+    end
+
+    add_index :posts, :user_id
+  end
+
+  def self.down
+    remove_index :posts, :user_id
+    drop_table :posts
+  end
+end
+
+class Post < ActiveRecord::Base
+  belongs_to :user
+end
+
+class PostTest < ActiveSupport::TestCase
+  should_belong_to :user
+  should_have_index :user_id
+end
+
+Factory.define :post do |post|
+  post.association(:user)
+end
+ +h2. Model generator: paperclip + + $ script/generate model design image:paperclip + +* all the necessary columns in the migration +* "has_attached_file" in the model +* "should_have_attached_file" in unit test + +
class CreateDesigns < ActiveRecord::Migration
+  def self.up
+    create_table :designs do |t|
+      t.string :image_file_name
+      t.string :image_content_type
+      t.integer :image_file_size
+      t.datetime :image_updated_at
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :designs
+  end
+end
+
+class Design < ActiveRecord::Base
+  has_attached_file :image
+end
+
+class DesignTest < ActiveSupport::TestCase
+  should "be valid with factory" do
+    assert_valid Factory.build(:design)
+  end
+  should_have_attached_file :image
+end
+ +h2. Attribution + +"Dan Croak":http://github.com/dancroak and "Mike Breen":http://github.com/hardbap + +Inspired by "shoulda_generator":http://github.com/technicalpickles/shoulda_generator, "model_generator_with_factories":http://github.com/vigetlabs/model_generator_with_factories, and "nifty_generators":http://github.com/ryanb/nifty-generators + +h2. License + +The MIT License + +Copyright (c) 2008, 2009 Dan Croak + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/plugins/blitz/Rakefile b/vendor/plugins/blitz/Rakefile new file mode 100644 index 0000000..b521a0a --- /dev/null +++ b/vendor/plugins/blitz/Rakefile @@ -0,0 +1,10 @@ +require 'rake' +require 'rake/testtask' + +require 'cucumber/rake/task' +Cucumber::Rake::Task.new(:features) do |features| + features.cucumber_opts = "features --format progress" +end + +task :default => [:features] + diff --git a/vendor/plugins/blitz/features/controller_generator.feature b/vendor/plugins/blitz/features/controller_generator.feature new file mode 100644 index 0000000..bb5c492 --- /dev/null +++ b/vendor/plugins/blitz/features/controller_generator.feature @@ -0,0 +1,53 @@ +Feature: Rails controller generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. + + Scenario: Controller generator for index action + Given a Rails app + And the coulda 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 new file mode 100644 index 0000000..3c8063f --- /dev/null +++ b/vendor/plugins/blitz/features/feature_generator.feature @@ -0,0 +1,37 @@ +Feature: Rails controller generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. + + Scenario: Feature generator for new action + Given a Rails app with Cucumber + And the coulda 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 + And a new post page path should be generated + + Scenario: Feature generator for create action same as new + Given a Rails app with Cucumber + And the coulda 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 + And a new post page path should be generated + + Scenario: Feature generator for edit action + Given a Rails app with Cucumber + And the coulda 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 + And a edit post page path should be generated + + Scenario: Feature generator for update action same as edit + Given a Rails app with Cucumber + And the coulda 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 + And a edit post page path should be generated + diff --git a/vendor/plugins/blitz/features/functional_test_generator.feature b/vendor/plugins/blitz/features/functional_test_generator.feature new file mode 100644 index 0000000..da715ed --- /dev/null +++ b/vendor/plugins/blitz/features/functional_test_generator.feature @@ -0,0 +1,53 @@ +Feature: Rails controller generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. + + Scenario: Functional test generator for index action + Given a Rails app + And the coulda 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 + 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 + 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 + 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 + 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 + 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 + 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 + 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 new file mode 100644 index 0000000..f0e0af7 --- /dev/null +++ b/vendor/plugins/blitz/features/helper_generator.feature @@ -0,0 +1,12 @@ +Feature: Rails helper generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate just the module and test I need. + + Scenario: Helper + Given a Rails app + And the coulda 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 new file mode 100644 index 0000000..35e4e05 --- /dev/null +++ b/vendor/plugins/blitz/features/model_generator.feature @@ -0,0 +1,37 @@ +Feature: Rails model generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate a Factory definition and Shoulda tests. + + Scenario: Model generator without attributes + Given a Rails app + And the coulda 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 + 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 + 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 + And the "Post" unit test should have "should_have_db_index :user_id" macro + And the "posts" table should have db index on "user_id" + And the "Post" model should have "belongs_to :user" macro + + Scenario: Model generator with Paperclip + Given a Rails app + And the coulda 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 + And the "designs" table should have paperclip columns for "image" + diff --git a/vendor/plugins/blitz/features/step_definitions/controller_steps.rb b/vendor/plugins/blitz/features/step_definitions/controller_steps.rb new file mode 100644 index 0000000..ad81dee --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/controller_steps.rb @@ -0,0 +1,67 @@ +When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, action| + system "cd #{@rails_root} && " << + "script/generate controller #{controller} #{action} && " << + "cd .." +end + +Then /^a "new" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def new\n" << + " @post = Post.new\n" << + " end" + end +end + +Then /^a "create" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def create\n" << + " @post = Post.new(params[:post])\n" << + " @post.save\n" << + " flash[:success] = 'Post created.'\n" << + " redirect_to posts_path\n" << + " end" + end +end + +Then /^a "show" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def show\n" << + " @post = Post.find(params[:id])\n" << + " end" + end +end + +Then /^a "edit" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def edit\n" << + " @post = Post.find(params[:id])\n" << + " end" + end +end + +Then /^a "update" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def update\n" << + " @post = Post.find(params[:id])\n" << + " @post.update_attributes(params[:post])\n" << + " flash[:success] = 'Post updated.'\n" << + " redirect_to posts_path\n" << + " end" + end +end + +Then /^a "destroy" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def destroy\n" << + " @post = Post.find(params[:id])\n" << + " @post.destroy\n" << + " flash[:success] = 'Post deleted.'\n" << + " redirect_to posts_path\n" << + " end" + end +end + +Then /^only a "([^\"]*)" action for RESTful "([^\"]*)" route should be generated$/ do |action, resource| + assert_generated_route_for resource, action +end + diff --git a/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb b/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb new file mode 100644 index 0000000..9e83ae6 --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb @@ -0,0 +1,64 @@ +Given /^a Rails app with Cucumber$/ do + system "rails rails_root" + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") + require 'cucumber' + system "cd #{@rails_root} && ruby script/generate cucumber" +end + +When /^I generate a "([^\"]*)" feature for "([^\"]*)"$/ do |feature, resource| + system "cd #{@rails_root} && " << + "script/generate feature #{resource} #{feature} && " << + "cd .." +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 + " 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" << + " Then I should see \"A new post\"" + end + elsif %w(edit update).include?(action) + assert_generated_file("features/posts.feature") do + " Scenario: Update a post\n" << + " Given I am on the edit \"An existing post\" post page\n" << + " When I update the post\n" << + " Then I should see \"Post updated\"" + end + end +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" + "end" + end +end + +Then /^a new post page path should be generated$/ do + assert_generated_file("features/support/paths.rb") do + " when /the new post page/i\n" << + " new_post_path" + end +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" + "end" + end +end + +Then /^a edit post page path should be generated$/ do + assert_generated_file("features/support/paths.rb") do + " when /the edit \"([^\\\"]*)\" post page/i do |name|\n" << + " post = Post.find_by_name(name)\n" + " edit_post_path(post)" + end +end + diff --git a/vendor/plugins/blitz/features/step_definitions/functional_test_steps.rb b/vendor/plugins/blitz/features/step_definitions/functional_test_steps.rb new file mode 100644 index 0000000..c0e7972 --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/functional_test_steps.rb @@ -0,0 +1,101 @@ +When /^I generate a "(.*)" functional test with "(.*)" action$/ do |controller, action| + system "cd #{@rails_root} && " << + "script/generate functional_test #{controller} #{action} && " << + "cd .." +end + +Then /^a standard "index" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'GET to index' do\n" << + " setup { get :index }\n\n" << + " should_render_template :index\n" << + " should_respond_with :success\n" << + " end" + end +end + +Then /^an empty "index" controller action for "posts" should be generated$/ do + assert_generated_file("app/controllers/posts_controller.rb") do + " def index\n" << + " end" + end +end + +Then /^a standard "new" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'GET to new' do\n" << + " setup { get :new }\n\n" << + " should_assign_to :post\n" << + " should_render_template :new\n" << + " should_respond_with :success\n" << + " end" + end +end + +Then /^a standard "create" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'POST to create with valid parameters' do\n" << + " setup do\n" << + " post :create, :post => Factory.attributes_for(:post)\n" << + " end\n\n" << + " should_set_the_flash_to /created/i\n" << + " should_redirect_to('posts index') { posts_path }\n" << + " end" + end +end + +Then /^a standard "show" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'GET to show for existing post' do\n" << + " setup do\n" << + " @post = Factory(:post)\n" << + " get :show, :id => @post.to_param\n" << + " end\n\n" << + " should_assign_to :post, :equals => '@post'\n" << + " should_render_template :show\n" << + " should_respond_with :success\n" << + " end" + end +end + +Then /^a standard "edit" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'GET to edit for existing post' do\n" << + " setup do\n" << + " @post = Factory(:post)\n" << + " get :edit, :id => @post.to_param\n" << + " end\n\n" << + " should_assign_to :post, :equals => '@post'\n" << + " should_render_template :edit\n" << + " should_respond_with :success\n" << + " end" + end +end + +Then /^a standard "update" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'PUT to update for existing post' do\n" << + " setup do\n" << + " @post = Factory(:post)\n" << + " put :update, :id => @post.to_param,\n" << + " :post => Factory.attributes_for(:post)\n" << + " end\n\n" << + " should_set_the_flash_to /updated/i\n" << + " should_redirect_to('posts index') { posts_path }\n" << + " end" + end +end + +Then /^a standard "destroy" functional test for "posts" should be generated$/ do + assert_generated_file("test/functional/posts_controller_test.rb") do + " context 'given a post' do\n" << + " setup { @post = Factory(:post) }\n\n" << + " context 'DELETE to destroy' do\n" << + " setup { delete :destroy, :id => @post.to_param }\n\n" << + " should_set_the_flash_to /deleted/i\n" << + " should_redirect_to('posts index') { posts_path }\n" << + " end\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 new file mode 100644 index 0000000..3df26cd --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/generator_steps.rb @@ -0,0 +1,16 @@ +Given 'a Rails app' do + system "rails rails_root" + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") +end + +Given /^the coulda 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" +end + +After do + FileUtils.rm_rf @rails_root if @rails_root +end + diff --git a/vendor/plugins/blitz/features/step_definitions/helper_steps.rb b/vendor/plugins/blitz/features/step_definitions/helper_steps.rb new file mode 100644 index 0000000..240eaa9 --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/helper_steps.rb @@ -0,0 +1,14 @@ +When /^I generate a helper named "(.*)"$/ do |name| + system "cd #{@rails_root} && " << + "script/generate helper #{name} && " << + "cd .." +end + +Then /^a helper should be generated for "(.*)"$/ do |name| + assert_generated_file("app/helpers/#{name}_helper.rb") +end + +Then /^a helper test should be generated for "(.*)"$/ do |name| + assert_generated_file("test/unit/helpers/#{name}_helper_test.rb") +end + diff --git a/vendor/plugins/blitz/features/step_definitions/migration_steps.rb b/vendor/plugins/blitz/features/step_definitions/migration_steps.rb new file mode 100644 index 0000000..24d6881 --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/migration_steps.rb @@ -0,0 +1,30 @@ +Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table| + assert_generated_migration(table) do + " add_column :#{table}, :#{attr}_file_name, :string, :default => \"\"\n" << + " add_column :#{table}, :#{attr}_content_type, :string, :default => \"\"\n" << + " add_column :#{table}, :#{attr}_file_size, :integer, :default => \"\"\n" << + " add_column :#{table}, :#{attr}_updated_at, :datetime, :default => \"\"" + end + assert_generated_migration(table) do + " remove_column :#{table}, :#{attr}_file_name\n" << + " remove_column :#{table}, :#{attr}_content_type\n" << + " remove_column :#{table}, :#{attr}_file_size\n" << + " remove_column :#{table}, :#{attr}_updated_at" + end +end + +Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key| + assert_generated_migration(table) do + "add_index :#{table}, :#{foreign_key}" + end +end + +Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr| + assert_generated_migration(table) do + " table.string :#{attr}_file_name, :default => \"\"\n" << + " table.string :#{attr}_content_type, :default => \"\"\n" << + " table.integer :#{attr}_file_size\n" << + " table.datetime :#{attr}_updated_at" + end +end + diff --git a/vendor/plugins/blitz/features/step_definitions/model_steps.rb b/vendor/plugins/blitz/features/step_definitions/model_steps.rb new file mode 100644 index 0000000..a89f90f --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/model_steps.rb @@ -0,0 +1,89 @@ +# GENERATION + +When /^I generate a model named "(.*)"$/ do |model| + system "cd #{@rails_root} && " << + "script/generate model #{model} && " << + "cd .." +end + +When /^I generate a model "(.*)" with a (.*) "(.*)"$/ do |model, attr_type, attr_name| + system "cd #{@rails_root} && " << + "script/generate model #{model} #{attr_name}:#{attr_type} && " << + "cd .." +end + +When /^I generate a model "(.*)" that belongs to a "(.*)"$/ do |model, association| + association.downcase! + system "cd #{@rails_root} && " << + "script/generate model #{model} #{association}:belongs_to && " << + "cd .." +end + +When /^I generate a model "(.*)" with file "(.*)"$/ do |model, file| + file.downcase! + system "cd #{@rails_root} && " << + "script/generate model #{model} #{file}:paperclip && " << + "cd .." +end + +When /^I generate a Post model with title, body, and User$/ do + system "cd #{@rails_root} && " << + "script/generate model Post title:string body:text user:belongs_to && " << + "rake db:migrate " << + "cd .." +end + +# MODEL + +Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro| + model.downcase! + assert_generated_file("app/models/#{model}.rb") do + macro + end +end + +# FACTORY + +Then /^a factory should be generated for "(.*)"$/ do |model| + model.downcase! + assert_generated_file("test/factories/#{model}.rb") do + "Factory.define :#{model.downcase} do |#{model.downcase}|\n" << + "end\n" + end +end + +Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type| + model.downcase! + assert_generated_file("test/factories/#{model}.rb") do + "Factory.define :#{model} do |#{model}|\n" << + " #{model}.#{attr_name} { '#{attr_type}' }\n" << + "end\n" + end +end + +Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model| + model.downcase! + associated_model.downcase! + assert_generated_file("test/factories/#{model}.rb") do + "Factory.define :#{model} do |#{model}|\n" << + " #{model}.association(:#{associated_model})\n" << + "end\n" + end +end + +# UNIT TEST + +Then /^a unit test should be generated for "(.*)"$/ do |model| + model.downcase! + assert_generated_file("test/unit/#{model}_test.rb") do + "assert_valid Factory.build(:#{model})" + end +end + +Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro| + model.downcase! + assert_generated_file("test/unit/#{model}_test.rb") do + macro + end +end + diff --git a/vendor/plugins/blitz/features/step_definitions/view_steps.rb b/vendor/plugins/blitz/features/step_definitions/view_steps.rb new file mode 100644 index 0000000..e8e8158 --- /dev/null +++ b/vendor/plugins/blitz/features/step_definitions/view_steps.rb @@ -0,0 +1,36 @@ +When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource| + system "cd #{@rails_root} && " << + "script/generate view #{resource} #{view} && " << + "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" << + "<% form_for(@post) do |form| %>\n" << + " <%= form.error_messages %>\n" << + "
\n" << + "
\n" << + "
\n" << + " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << + "
\n" << + "<% end %>" + end +end + +Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do + assert_generated_file("app/views/posts/new.html.erb") do + "

New post

\n\n" << + "<% form_for(@post) do |form| %>\n" << + " <%= form.error_messages %>\n" << + "
\n" << + " <%= form.string :title %>\n" << + " <%= form.text :body %>\n" << + "
\n" << + "
\n" << + " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << + "
\n" << + "<% end %>" + end +end + diff --git a/vendor/plugins/blitz/features/support/env.rb b/vendor/plugins/blitz/features/support/env.rb new file mode 100644 index 0000000..40deba8 --- /dev/null +++ b/vendor/plugins/blitz/features/support/env.rb @@ -0,0 +1,63 @@ +require 'test/unit' + +module Test::Unit::Assertions + + def assert_generated_file(path) + assert_file_exists(path) + if block_given? + File.open(File.join(@rails_root, path)) do |file| + expected = yield + body = file.read + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end + end + end + + def assert_file_exists(path) + file = File.join(@rails_root, path) + + assert File.exists?(file), "#{file} expected to exist, but did not" + assert File.file?(file), "#{file} expected to be a file, but is not" + end + + def assert_generated_views_for(name, *actions) + actions.each do |action| + assert_generated_file("app/views/#{name}/#{action}.html.erb") do + yield if block_given? + end + end + end + + def assert_generated_migration(name) + file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first + file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb" + assert_generated_file(file) { "timestamps" } + assert_generated_file(file) { yield if block_given? } + end + + def assert_generated_route_for(name, *actions) + routeable_actions = actions.collect { |action| ":#{action}" }.join(", ") + assert_generated_file("config/routes.rb") do + " map.resources :#{name.to_s}, :only => [#{routeable_actions}]" + end + end + + def assert_has_empty_method(body, *methods) + methods.each do |name| + assert body.include?(" def #{name}\n end"), + "should have method #{name} in #{body.inspect}" + yield(name, $2) if block_given? + end + end + +end + +class BlitzWorld + include Test::Unit::Assertions +end + +World do + BlitzWorld.new +end + diff --git a/vendor/plugins/blitz/features/view_generator.feature b/vendor/plugins/blitz/features/view_generator.feature new file mode 100644 index 0000000..a5730d0 --- /dev/null +++ b/vendor/plugins/blitz/features/view_generator.feature @@ -0,0 +1,18 @@ +Feature: Rails view generator + In order to do Test-Driven Development with Rails + As a developer + I want to generate a view to make a functional test pass + + Scenario: View generator for new action + Given a Rails app + And the coulda 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 + 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 + diff --git a/vendor/plugins/blitz/generators/controller/controller_generator.rb b/vendor/plugins/blitz/generators/controller/controller_generator.rb new file mode 100644 index 0000000..19288b6 --- /dev/null +++ b/vendor/plugins/blitz/generators/controller/controller_generator.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") + +class ControllerGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.class_collisions "#{class_name}Controller" + + m.directory File.join('app/controllers', class_path) + + m.template 'controller.rb', + File.join('app/controllers', + class_path, + "#{file_name}_controller.rb") + end + end +end diff --git a/vendor/plugins/blitz/generators/controller/templates/controller.rb b/vendor/plugins/blitz/generators/controller/templates/controller.rb new file mode 100644 index 0000000..b1fcb6f --- /dev/null +++ b/vendor/plugins/blitz/generators/controller/templates/controller.rb @@ -0,0 +1,52 @@ +class <%= class_name %>Controller < ApplicationController +<% if actions.include?("index") -%> + def index + end + +<% end -%> +<% if actions.include?("new") -%> + def new + @<%= resource %> = <%= resource_class %>.new + end + +<% end -%> +<% if actions.include?("create") -%> + def create + @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) + @<%= resource %>.save + flash[:success] = '<%= resource_class %> created.' + redirect_to <%= resources %>_path + end + +<% end -%> +<% if actions.include?("show") -%> + def show + @<%= resource %> = <%= resource_class %>.find(params[:id]) + end + +<% end -%> +<% if actions.include?("edit") -%> + def edit + @<%= resource %> = <%= resource_class %>.find(params[:id]) + end + +<% end -%> +<% if actions.include?("update") -%> + def update + @<%= resource %> = <%= resource_class %>.find(params[:id]) + @<%= resource %>.update_attributes(params[:<%= resource %>]) + flash[:success] = '<%= resource_class %> updated.' + redirect_to <%= resources %>_path + end + +<% end -%> +<% if actions.include?("destroy") -%> + def destroy + @<%= resource %> = <%= resource_class %>.find(params[:id]) + @<%= resource %>.destroy + flash[:success] = '<%= resource_class %> deleted.' + redirect_to <%= resources %>_path + end + +<% end -%> +end diff --git a/vendor/plugins/blitz/generators/feature/feature_generator.rb b/vendor/plugins/blitz/generators/feature/feature_generator.rb new file mode 100644 index 0000000..da28bd1 --- /dev/null +++ b/vendor/plugins/blitz/generators/feature/feature_generator.rb @@ -0,0 +1,32 @@ +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") + +class FeatureGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.directory 'features' + m.directory 'features/step_definitions' + m.directory 'features/support' + + path = File.join('features', "#{resources}.feature") + m.template 'feature.feature', path + + path = File.join('features', 'step_definitions', "#{resources}_steps.rb") + m.template 'step_definition.rb', path + + path = File.join('features', 'support', "paths.rb") + m.insert_cucumber_path path, insertable_path + end + end + + def insertable_path + if %w(new create).any? { |action| actions.include?(action) } + " when /the new #{resource} page/i\n" << + " new_#{resource}_path\n" + elsif %w(edit update).any? { |action| actions.include?(action) } + " when /the edit \"([^\\\"]*)\" #{resource} page/i do |name|\n" << + " post = #{resource_class}.find_by_name(name)\n" + " edit_#{resource}_path(#{resource})" + end + end +end + diff --git a/vendor/plugins/blitz/generators/feature/templates/feature.feature b/vendor/plugins/blitz/generators/feature/templates/feature.feature new file mode 100644 index 0000000..5d6b1f5 --- /dev/null +++ b/vendor/plugins/blitz/generators/feature/templates/feature.feature @@ -0,0 +1,11 @@ +<% if %w(new create).any? { |action| actions.include?(action) } -%> + Scenario: Create a new <%= resource %> + Given I am on the new <%= resource %> page + When I create a <%= resource %> named "A new <%= resource %>" + Then I should see "A new <%= resource %>" +<% elsif %w(edit update).any? { |action| actions.include?(action) } -%> + Scenario: Update a <%= resource %> + Given I am on the edit "An existing <%= resource %>" <%= resource %> page + When I update the <%= resource %> + Then I should see "<%= resource_class %> updated" +<% end -%> diff --git a/vendor/plugins/blitz/generators/feature/templates/step_definition.rb b/vendor/plugins/blitz/generators/feature/templates/step_definition.rb new file mode 100644 index 0000000..78572d3 --- /dev/null +++ b/vendor/plugins/blitz/generators/feature/templates/step_definition.rb @@ -0,0 +1,12 @@ +<% if %w(new create).any? { |action| actions.include?(action) } -%> +When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| + fills_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 + click_button 'Update' +end +<% end -%> + diff --git a/vendor/plugins/blitz/generators/functional_test/functional_test_generator.rb b/vendor/plugins/blitz/generators/functional_test/functional_test_generator.rb new file mode 100644 index 0000000..fb0a47b --- /dev/null +++ b/vendor/plugins/blitz/generators/functional_test/functional_test_generator.rb @@ -0,0 +1,17 @@ +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") + +class FunctionalTestGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.class_collisions "#{class_name}ControllerTest" + + m.directory File.join('test/functional', class_path) + + m.template 'functional_test.rb', + File.join('test/functional', + class_path, + "#{file_name}_controller_test.rb") + end + end +end + diff --git a/vendor/plugins/blitz/generators/functional_test/templates/functional_test.rb b/vendor/plugins/blitz/generators/functional_test/templates/functional_test.rb new file mode 100644 index 0000000..dee9c05 --- /dev/null +++ b/vendor/plugins/blitz/generators/functional_test/templates/functional_test.rb @@ -0,0 +1,87 @@ +require 'test_helper' + +class <%= class_name %>ControllerTest < ActionController::TestCase +<% if actions.include?("index") -%> + context 'GET to index' do + setup { get :index } + + should_render_template :index + should_respond_with :success + end + +<% end -%> +<% if actions.include?("new") -%> + context 'GET to new' do + setup { get :new } + + should_assign_to :<%= resource %> + should_render_template :new + should_respond_with :success + end + +<% end -%> +<% if actions.include?("create") -%> + context 'POST to create with valid parameters' do + setup do + post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>) + end + + should_set_the_flash_to /created/i + should_redirect_to('<%= resources %> index') { <%= resources %>_path } + end + +<% end -%> +<% if actions.include?("show") -%> + context 'GET to show for existing <%= resource %>' do + setup do + @<%= resource %> = Factory(:<%= resource %>) + get :show, :id => @<%= resource %>.to_param + end + + should_assign_to :<%= resource %>, :equals => '@<%= resource %>' + should_render_template :show + should_respond_with :success + end + +<% end -%> +<% if actions.include?("edit") -%> + context 'GET to edit for existing <%= resource %>' do + setup do + @<%= resource %> = Factory(:<%= resource %>) + get :edit, :id => @<%= resource %>.to_param + end + + should_assign_to :<%= resource %>, :equals => '@<%= resource %>' + should_render_template :edit + should_respond_with :success + end + +<% end -%> +<% if actions.include?("update") -%> + context 'PUT to update for existing <%= resource %>' do + setup do + @<%= resource %> = Factory(:<%= resource %>) + put :update, :id => @<%= resource %>.to_param, + :<%= resource %> => Factory.attributes_for(:<%= resource %>) + end + + should_set_the_flash_to /updated/i + should_redirect_to('<%= resources %> index') { <%= resources %>_path } + end + +<% end -%> +<% if actions.include?("destroy") -%> + context 'given a <%= resource %>' do + setup { @<%= resource %> = Factory(:<%= resource %>) } + + context 'DELETE to destroy' do + setup { delete :destroy, :id => @<%= resource %>.to_param } + + should_set_the_flash_to /deleted/i + should_redirect_to('<%= resources %> index') { <%= resources %>_path } + end + end + +<% end -%> +end + diff --git a/vendor/plugins/blitz/generators/helper/helper_generator.rb b/vendor/plugins/blitz/generators/helper/helper_generator.rb new file mode 100644 index 0000000..2eb4f83 --- /dev/null +++ b/vendor/plugins/blitz/generators/helper/helper_generator.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") + +class HelperGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions "#{class_name}Helper", "#{class_name}HelperTest" + + # Helper and test directories. + m.directory File.join('app/helpers', class_path) + m.directory File.join('test/unit/helpers', class_path) + + # Helper module and test. + m.template 'helper.rb', + File.join('app/helpers', + class_path, + "#{file_name}_helper.rb") + + m.template 'helper_test.rb', + File.join('test/unit/helpers', + class_path, + "#{file_name}_helper_test.rb") + end + end +end diff --git a/vendor/plugins/blitz/generators/helper/templates/helper.rb b/vendor/plugins/blitz/generators/helper/templates/helper.rb new file mode 100644 index 0000000..3fe2ecd --- /dev/null +++ b/vendor/plugins/blitz/generators/helper/templates/helper.rb @@ -0,0 +1,2 @@ +module <%= class_name %>Helper +end diff --git a/vendor/plugins/blitz/generators/helper/templates/helper_test.rb b/vendor/plugins/blitz/generators/helper/templates/helper_test.rb new file mode 100644 index 0000000..591e409 --- /dev/null +++ b/vendor/plugins/blitz/generators/helper/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/vendor/plugins/blitz/generators/model/model_generator.rb b/vendor/plugins/blitz/generators/model/model_generator.rb new file mode 100644 index 0000000..9a3aa57 --- /dev/null +++ b/vendor/plugins/blitz/generators/model/model_generator.rb @@ -0,0 +1,81 @@ +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") + +class ModelGenerator < Rails::Generator::NamedBase + default_options :skip_timestamps => false, + :skip_migration => false, + :skip_factories => false + + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_name, "#{class_name}Test" + + # Model, test, and factories directories. + m.directory File.join('app/models', class_path) + m.directory File.join('test/unit', class_path) + m.directory File.join('test/factories', class_path) + + # Model class, unit test, and factories. + m.template 'model.rb', File.join('app/models', class_path, + "#{file_name}.rb") + m.template 'unit_test.rb', File.join('test/unit', class_path, + "#{file_name}_test.rb") + + m.template 'factory.rb', File.join('test/factories', "#{file_name}.rb") + + unless options[:skip_migration] + m.migration_template 'migration.rb', 'db/migrate', :assigns => { + :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" + }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" + end + end + end + + def factory_line(attribute, file_name) + if attribute.reference? + "#{file_name}.association(:#{attribute.name})" + else + "#{file_name}.#{attribute.name} #{attribute.default_for_factory}" + end + end + + protected + + def banner + "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]" + end + + def add_options!(opt) + opt.separator '' + opt.separator 'Options:' + opt.on("--skip-timestamps", + "Don't add timestamps to the migration file for this model") { |v| + options[:skip_timestamps] = v + } + opt.on("--skip-migration", + "Don't generate a migration file for this model") { |v| + options[:skip_migration] = v + } + end +end + +module Rails + module Generator + class GeneratedAttribute + def default_for_factory + @default ||= case type + when :integer then "{ 1 }" + when :float then "{ 1.5 }" + when :decimal then "{ 9.99 }" + when :datetime, :timestamp, :time then "{ Time.now.to_s(:db) }" + when :date then "{ Date.today.to_s(:db) }" + when :string then "{ 'string' }" + when :text then "{ 'text' }" + when :boolean then "{ false }" + else + "" + end + end + end + end +end diff --git a/vendor/plugins/blitz/generators/model/templates/factory.rb b/vendor/plugins/blitz/generators/model/templates/factory.rb new file mode 100644 index 0000000..1bc9bba --- /dev/null +++ b/vendor/plugins/blitz/generators/model/templates/factory.rb @@ -0,0 +1,5 @@ +Factory.define :<%= file_name %> do |<%= file_name %>| +<% attributes.each do |attribute| -%> + <%= factory_line(attribute, file_name) %> +<% end -%> +end diff --git a/vendor/plugins/blitz/generators/model/templates/migration.rb b/vendor/plugins/blitz/generators/model/templates/migration.rb new file mode 100644 index 0000000..2530587 --- /dev/null +++ b/vendor/plugins/blitz/generators/model/templates/migration.rb @@ -0,0 +1,32 @@ +class <%= migration_name %> < ActiveRecord::Migration + def self.up + create_table :<%= table_name %> do |table| +<% attributes.each do |attribute| -%> +<% if attribute.type == :paperclip -%> + table.string :<%= attribute.name %>_file_name, :default => "" + table.string :<%= attribute.name %>_content_type, :default => "" + table.integer :<%= attribute.name %>_file_size + table.datetime :<%= attribute.name %>_updated_at +<% elsif attribute.type == :string -%> + table.string :<%= attribute.name %>, :default => "" +<% else -%> + table.<%= attribute.type %> :<%= attribute.name %> +<% end -%> +<% end -%> +<% unless options[:skip_timestamps] -%> + table.timestamps +<% end -%> + end + +<% attributes.select(&:reference?).each do |attribute| -%> + add_index :<%= table_name %>, :<%= attribute.name %>_id +<% end -%> + end + + def self.down +<% attributes.select(&:reference?).each do |attribute| -%> + remove_index :<%= table_name %>, :<%= attribute.name %>_id +<% end -%> + drop_table :<%= table_name %> + end +end diff --git a/vendor/plugins/blitz/generators/model/templates/model.rb b/vendor/plugins/blitz/generators/model/templates/model.rb new file mode 100644 index 0000000..8ba98a8 --- /dev/null +++ b/vendor/plugins/blitz/generators/model/templates/model.rb @@ -0,0 +1,8 @@ +class <%= class_name %> < ActiveRecord::Base +<% attributes.select(&:reference?).each do |each| -%> + belongs_to :<%= each.name %> +<% end -%> +<% attributes.select { |each| each.type == :paperclip }.each do |each| -%> + has_attached_file :<%= each.name %> +<% end -%> +end diff --git a/vendor/plugins/blitz/generators/model/templates/unit_test.rb b/vendor/plugins/blitz/generators/model/templates/unit_test.rb new file mode 100644 index 0000000..9021608 --- /dev/null +++ b/vendor/plugins/blitz/generators/model/templates/unit_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class <%= class_name %>Test < ActiveSupport::TestCase + should "be valid with factory" do + assert_valid Factory.build(:<%= file_name -%>) + end +<% attributes.each do |attribute| -%> +<% if attribute.reference? -%> + should_belong_to :<%= attribute.name %> + should_have_db_index :<%= attribute.name %>_id +<% end -%> +<% if attribute.type == :paperclip -%> + should_have_attached_file :<%= attribute.name %> +<% end -%> +<% end -%> +end diff --git a/vendor/plugins/blitz/generators/support/generator_helper.rb b/vendor/plugins/blitz/generators/support/generator_helper.rb new file mode 100644 index 0000000..68a6289 --- /dev/null +++ b/vendor/plugins/blitz/generators/support/generator_helper.rb @@ -0,0 +1,43 @@ +require File.join(File.dirname(__FILE__), "insert_commands") + +module Blitz + module GeneratorHelper + REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed", + "encrypted_password", "salt", "token", "token_expires_at"] + + def resource + file_name.singularize + end + + def resources + file_name.pluralize + end + + def resource_class + class_name.singularize + end + + def columns_for_form + resource_class.constantize.content_columns. + collect { |column| [column.name, column.type] }. + delete_if { |column| remove_column?(column.first) } + end + + def active_record_defined? + models = Dir.glob(File.join( RAILS_ROOT, 'app', 'models', '*.rb')). + collect { |path| path[/.+\/(.+).rb/,1] }. + collect {|model| model.classify } + models.include?(resource_class) + end + + def remove_column?(column) + REMOVABLE_COLUMNS.include?(column) || + !(column =~ /_id$/).nil? + end + end +end + +class Rails::Generator::NamedBase + include Blitz::GeneratorHelper +end + diff --git a/vendor/plugins/blitz/generators/support/insert_commands.rb b/vendor/plugins/blitz/generators/support/insert_commands.rb new file mode 100644 index 0000000..1eb212d --- /dev/null +++ b/vendor/plugins/blitz/generators/support/insert_commands.rb @@ -0,0 +1,53 @@ +# Pinched some from http://github.com/ryanb/nifty-generators + +Rails::Generator::Commands::Base.class_eval do + def file_contains?(relative_destination, line) + File.read(destination_path(relative_destination)).include?(line) + end +end + +Rails::Generator::Commands::Create.class_eval do + def insert_into(file, line) + logger.insert "#{line} into #{file}" + unless file_contains?(file, line) + gsub_file file, /^(class|module|#{Blitz::Insertable.routes}) .+$/ do |match| + "#{match}\n #{line}" + end + end + end + + def insert_cucumber_path(file, line) + logger.insert "#{line} into #{file}" + unless file_contains?(file, line) + gsub_file file, /#{Blitz::Insertable.cucumber_paths}/ do |match| + "#{match}\n#{line}" + end + end + end +end + +Rails::Generator::Commands::Destroy.class_eval do + def insert_into(file, line) + logger.remove "#{line} from #{file}" + gsub_file file, "\n #{line}", '' + end +end + +Rails::Generator::Commands::List.class_eval do + def insert_into(file, line) + logger.insert "#{line} into #{file}" + end +end + +module Blitz + module Insertable + def self.routes + "ActionController::Routing::Routes.draw" + end + + def self.cucumber_paths + "case page_name\n" + end + end +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 new file mode 100644 index 0000000..6174b80 --- /dev/null +++ b/vendor/plugins/blitz/generators/view/templates/view_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_show.html.erb b/vendor/plugins/blitz/generators/view/templates/view_show.html.erb new file mode 100644 index 0000000..71375ad --- /dev/null +++ b/vendor/plugins/blitz/generators/view/templates/view_show.html.erb @@ -0,0 +1,4 @@ +

<%= resource %>

+ +<%%= link_to 'Edit', edit_<%= resource %>_path(@<%= resource %>) %> + diff --git a/vendor/plugins/blitz/generators/view/view_generator.rb b/vendor/plugins/blitz/generators/view/view_generator.rb new file mode 100644 index 0000000..a87426a --- /dev/null +++ b/vendor/plugins/blitz/generators/view/view_generator.rb @@ -0,0 +1,14 @@ +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") + +class ViewGenerator < Rails::Generator::NamedBase + 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 + end + end + end +end diff --git a/vendor/plugins/coulda/CHANGELOG.textile b/vendor/plugins/coulda/CHANGELOG.textile deleted file mode 100644 index efe4da3..0000000 --- a/vendor/plugins/coulda/CHANGELOG.textile +++ /dev/null @@ -1,9 +0,0 @@ -h1. March 8, 2009 - -* Updated functional tests to use shoulda 2.10 should_redirect_to block syntax - -h1. March 7, 2009 - -* Added Paperclip option to model generator -* Removed comments on model per complaints by thoughtbot - diff --git a/vendor/plugins/coulda/README.textile b/vendor/plugins/coulda/README.textile deleted file mode 100644 index 780ddb5..0000000 --- a/vendor/plugins/coulda/README.textile +++ /dev/null @@ -1,174 +0,0 @@ -h1. Coulda generators - -A Rails plugin for feature, view, controller, model, & helper generators. It is meant to be used as part of an "Outside-In" Test-Driven Development cycle. - -h2. Requirements - -* "Cucumber":http://github.com/aslakhellesoy/cucumber -* "Shoulda":http://github.com/thoughtbot/shoulda -* "Factory Girl":http://github.com/thoughtbot/factory_girl -* "Mocha":http://github.com/jferris/mocha - -h2. Installation - - $ script/plugin install git://github.com/dancroak/coulda.git - -h2. Feature generator - - $ script/generate feature Posts new create - -generates... - -
  Scenario: Create a new post
-    Given I am on the new post page
-    When I create a 'post' named 'A new post'
-    Then I should see 'A new post'
- -Now run it: - - $ cucumber features/posts.feature - -The failure will be: - - undefined method `new_post_path' - -To get past this error, we'll create just the route we need: - - map.resources :posts, :only => [:new] - -Running the test again, we have a new failure: - - uninitialized constant PostsController - -h2. Controller test generator - -We've reached a point in our Outside-In cycle where we want to spiral down into a tighter feedback loop to unit test the non-existant controller. - - $ script/generate controller_test Posts new create - -h2. Controller generator - - $ script/generate controller Posts new create - -generates... - - -h2. Model generator - - $ script/generate model User - -* factory (Factory Girl) -* unit test (Shoulda) -* migration -* model - -h2. Helper generator - - $ script/generate helper Navigation - -* empty helper test file -* empty helper module - -h2. View generator - - $ script/generate view Posts new - -h2. Model generator: belongs_to - - $ script/generate model post user:belongs_to - -generates... - -
class CreatePosts < ActiveRecord::Migration
-  def self.up
-    create_table :posts do |t|
-      t.belongs_to :user
-      t.timestamps
-    end
-
-    add_index :posts, :user_id
-  end
-
-  def self.down
-    remove_index :posts, :user_id
-    drop_table :posts
-  end
-end
-
-class Post < ActiveRecord::Base
-  belongs_to :user
-end
-
-class PostTest < ActiveSupport::TestCase
-  should_belong_to :user
-  should_have_index :user_id
-end
-
-Factory.define :post do |post|
-  post.association(:user)
-end
- -h2. Model generator: paperclip - - $ script/generate model design image:paperclip - -* all the necessary columns in the migration -* "has_attached_file" in the model -* "should_have_attached_file" in unit test - -
class CreateDesigns < ActiveRecord::Migration
-  def self.up
-    create_table :designs do |t|
-      t.string :image_file_name
-      t.string :image_content_type
-      t.integer :image_file_size
-      t.datetime :image_updated_at
-      t.timestamps
-    end
-  end
-
-  def self.down
-    drop_table :designs
-  end
-end
-
-class Design < ActiveRecord::Base
-  has_attached_file :image
-end
-
-class DesignTest < ActiveSupport::TestCase
-  should "be valid with factory" do
-    assert_valid Factory.build(:design)
-  end
-  should_have_attached_file :image
-end
- -h2. Attribution - -"Mike Breen":http://github.com/hardbap and "Dan Croak":http://github.com/dancroak - -Inspired by "shoulda_generator":http://github.com/technicalpickles/shoulda_generator, "model_generator_with_factories":http://github.com/vigetlabs/model_generator_with_factories, and "nifty_generators":http://github.com/ryanb/nifty-generators - -h2. License - -The MIT License - -Copyright (c) 2008, 2009 Mike Breen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/plugins/coulda/Rakefile b/vendor/plugins/coulda/Rakefile deleted file mode 100644 index b521a0a..0000000 --- a/vendor/plugins/coulda/Rakefile +++ /dev/null @@ -1,10 +0,0 @@ -require 'rake' -require 'rake/testtask' - -require 'cucumber/rake/task' -Cucumber::Rake::Task.new(:features) do |features| - features.cucumber_opts = "features --format progress" -end - -task :default => [:features] - diff --git a/vendor/plugins/coulda/features/controller_generator.feature b/vendor/plugins/coulda/features/controller_generator.feature deleted file mode 100644 index e4986ac..0000000 --- a/vendor/plugins/coulda/features/controller_generator.feature +++ /dev/null @@ -1,61 +0,0 @@ -Feature: Rails controller generator - In order to better do Test-Driven Development with Rails - As a user - I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. - - Scenario: Controller generator for index action - Given a Rails app - And the coulda plugin is installed - When I generate a "Posts" controller with "index" action - Then a standard "index" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "new" action - Then a standard "new" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "create" action - Then a standard "create" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "create" action - Then a standard "create" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "show" action - Then a standard "show" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "edit" action - Then a standard "edit" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "update" action - Then a standard "update" functional test for "posts" should be generated - 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 - When I generate a "Posts" controller with "destroy" action - Then a standard "destroy" functional test for "posts" should be generated - And a "destroy" controller action for "posts" should be generated - diff --git a/vendor/plugins/coulda/features/feature_generator.feature b/vendor/plugins/coulda/features/feature_generator.feature deleted file mode 100644 index 3c8063f..0000000 --- a/vendor/plugins/coulda/features/feature_generator.feature +++ /dev/null @@ -1,37 +0,0 @@ -Feature: Rails controller generator - In order to better do Test-Driven Development with Rails - As a user - I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. - - Scenario: Feature generator for new action - Given a Rails app with Cucumber - And the coulda 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 - And a new post page path should be generated - - Scenario: Feature generator for create action same as new - Given a Rails app with Cucumber - And the coulda 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 - And a new post page path should be generated - - Scenario: Feature generator for edit action - Given a Rails app with Cucumber - And the coulda 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 - And a edit post page path should be generated - - Scenario: Feature generator for update action same as edit - Given a Rails app with Cucumber - And the coulda 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 - And a edit post page path should be generated - diff --git a/vendor/plugins/coulda/features/helper_generator.feature b/vendor/plugins/coulda/features/helper_generator.feature deleted file mode 100644 index f0e0af7..0000000 --- a/vendor/plugins/coulda/features/helper_generator.feature +++ /dev/null @@ -1,12 +0,0 @@ -Feature: Rails helper generator - In order to better do Test-Driven Development with Rails - As a user - I want to generate just the module and test I need. - - Scenario: Helper - Given a Rails app - And the coulda 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/coulda/features/model_generator.feature b/vendor/plugins/coulda/features/model_generator.feature deleted file mode 100644 index 35e4e05..0000000 --- a/vendor/plugins/coulda/features/model_generator.feature +++ /dev/null @@ -1,37 +0,0 @@ -Feature: Rails model generator - In order to better do Test-Driven Development with Rails - As a user - I want to generate a Factory definition and Shoulda tests. - - Scenario: Model generator without attributes - Given a Rails app - And the coulda 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 - 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 - 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 - And the "Post" unit test should have "should_have_db_index :user_id" macro - And the "posts" table should have db index on "user_id" - And the "Post" model should have "belongs_to :user" macro - - Scenario: Model generator with Paperclip - Given a Rails app - And the coulda 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 - And the "designs" table should have paperclip columns for "image" - diff --git a/vendor/plugins/coulda/features/step_definitions/controller_steps.rb b/vendor/plugins/coulda/features/step_definitions/controller_steps.rb deleted file mode 100644 index d8adfe1..0000000 --- a/vendor/plugins/coulda/features/step_definitions/controller_steps.rb +++ /dev/null @@ -1,163 +0,0 @@ -When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, action| - system "cd #{@rails_root} && " << - "script/generate controller #{controller} #{action} && " << - "cd .." -end - -Then /^a standard "index" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'GET to index' do\n" << - " setup { get :index }\n\n" << - " should_render_template :index\n" << - " should_respond_with :success\n" << - " end" - end -end - -Then /^an empty "index" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def index\n" << - " end" - end -end - -Then /^a standard "new" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'GET to new' do\n" << - " setup { get :new }\n\n" << - " should_assign_to :post\n" << - " should_render_template :new\n" << - " should_respond_with :success\n" << - " end" - end -end - -Then /^a standard "create" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'POST to create with valid parameters' do\n" << - " setup do\n" << - " post :create, :post => Factory.attributes_for(:post)\n" << - " end\n\n" << - " should_set_the_flash_to /created/i\n" << - " should_redirect_to('posts index') { posts_path }\n" << - " end" - end -end - -Then /^a standard "show" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'GET to show for existing post' do\n" << - " setup do\n" << - " @post = Factory(:post)\n" << - " get :show, :id => @post.to_param\n" << - " end\n\n" << - " should_assign_to :post, :equals => '@post'\n" << - " should_render_template :show\n" << - " should_respond_with :success\n" << - " end" - end -end - -Then /^a standard "edit" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'GET to edit for existing post' do\n" << - " setup do\n" << - " @post = Factory(:post)\n" << - " get :edit, :id => @post.to_param\n" << - " end\n\n" << - " should_assign_to :post, :equals => '@post'\n" << - " should_render_template :edit\n" << - " should_respond_with :success\n" << - " end" - end -end - -Then /^a standard "update" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'PUT to update for existing post' do\n" << - " setup do\n" << - " @post = Factory(:post)\n" << - " put :update, :id => @post.to_param,\n" << - " :post => Factory.attributes_for(:post)\n" << - " end\n\n" << - " should_set_the_flash_to /updated/i\n" << - " should_redirect_to('posts index') { posts_path }\n" << - " end" - end -end - -Then /^a standard "destroy" functional test for "posts" should be generated$/ do - assert_generated_file("test/functional/posts_controller_test.rb") do - " context 'given a post' do\n" << - " setup { @post = Factory(:post) }\n\n" << - " context 'DELETE to destroy' do\n" << - " setup { delete :destroy, :id => @post.to_param }\n\n" << - " should_destroy :post\n" << - " should_set_the_flash_to /deleted/i\n" << - " should_redirect_to('posts index') { posts_path }\n" << - " end\n" << - " end" - end -end - -Then /^a "new" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def new\n" << - " @post = Post.new\n" << - " end" - end -end - -Then /^a "create" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def create\n" << - " @post = Post.new(params[:post])\n" << - " @post.save\n" << - " flash[:success] = 'Post created.'\n" << - " redirect_to posts_path\n" << - " end" - end -end - -Then /^a "show" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def show\n" << - " @post = Post.find(params[:id])\n" << - " end" - end -end - -Then /^a "edit" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def edit\n" << - " @post = Post.find(params[:id])\n" << - " end" - end -end - -Then /^a "update" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def update\n" << - " @post = Post.find(params[:id])\n" << - " @post.update_attributes(params[:post])\n" << - " flash[:success] = 'Post updated.'\n" << - " redirect_to posts_path\n" << - " end" - end -end - -Then /^a "destroy" controller action for "posts" should be generated$/ do - assert_generated_file("app/controllers/posts_controller.rb") do - " def destroy\n" << - " @post = Post.find(params[:id])\n" << - " @post.destroy\n" << - " flash[:success] = 'Post deleted.'\n" << - " redirect_to posts_path\n" << - " end" - end -end - -Then /^only a "([^\"]*)" action for RESTful "([^\"]*)" route should be generated$/ do |action, resource| - assert_generated_route_for resource, action -end - diff --git a/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb b/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb deleted file mode 100644 index 9e83ae6..0000000 --- a/vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb +++ /dev/null @@ -1,64 +0,0 @@ -Given /^a Rails app with Cucumber$/ do - system "rails rails_root" - @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") - require 'cucumber' - system "cd #{@rails_root} && ruby script/generate cucumber" -end - -When /^I generate a "([^\"]*)" feature for "([^\"]*)"$/ do |feature, resource| - system "cd #{@rails_root} && " << - "script/generate feature #{resource} #{feature} && " << - "cd .." -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 - " 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" << - " Then I should see \"A new post\"" - end - elsif %w(edit update).include?(action) - assert_generated_file("features/posts.feature") do - " Scenario: Update a post\n" << - " Given I am on the edit \"An existing post\" post page\n" << - " When I update the post\n" << - " Then I should see \"Post updated\"" - end - end -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" - "end" - end -end - -Then /^a new post page path should be generated$/ do - assert_generated_file("features/support/paths.rb") do - " when /the new post page/i\n" << - " new_post_path" - end -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" - "end" - end -end - -Then /^a edit post page path should be generated$/ do - assert_generated_file("features/support/paths.rb") do - " when /the edit \"([^\\\"]*)\" post page/i do |name|\n" << - " post = Post.find_by_name(name)\n" - " edit_post_path(post)" - end -end - diff --git a/vendor/plugins/coulda/features/step_definitions/generator_steps.rb b/vendor/plugins/coulda/features/step_definitions/generator_steps.rb deleted file mode 100644 index 3df26cd..0000000 --- a/vendor/plugins/coulda/features/step_definitions/generator_steps.rb +++ /dev/null @@ -1,16 +0,0 @@ -Given 'a Rails app' do - system "rails rails_root" - @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") -end - -Given /^the coulda 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" -end - -After do - FileUtils.rm_rf @rails_root if @rails_root -end - diff --git a/vendor/plugins/coulda/features/step_definitions/helper_steps.rb b/vendor/plugins/coulda/features/step_definitions/helper_steps.rb deleted file mode 100644 index 240eaa9..0000000 --- a/vendor/plugins/coulda/features/step_definitions/helper_steps.rb +++ /dev/null @@ -1,14 +0,0 @@ -When /^I generate a helper named "(.*)"$/ do |name| - system "cd #{@rails_root} && " << - "script/generate helper #{name} && " << - "cd .." -end - -Then /^a helper should be generated for "(.*)"$/ do |name| - assert_generated_file("app/helpers/#{name}_helper.rb") -end - -Then /^a helper test should be generated for "(.*)"$/ do |name| - assert_generated_file("test/unit/helpers/#{name}_helper_test.rb") -end - diff --git a/vendor/plugins/coulda/features/step_definitions/migration_steps.rb b/vendor/plugins/coulda/features/step_definitions/migration_steps.rb deleted file mode 100644 index 24d6881..0000000 --- a/vendor/plugins/coulda/features/step_definitions/migration_steps.rb +++ /dev/null @@ -1,30 +0,0 @@ -Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table| - assert_generated_migration(table) do - " add_column :#{table}, :#{attr}_file_name, :string, :default => \"\"\n" << - " add_column :#{table}, :#{attr}_content_type, :string, :default => \"\"\n" << - " add_column :#{table}, :#{attr}_file_size, :integer, :default => \"\"\n" << - " add_column :#{table}, :#{attr}_updated_at, :datetime, :default => \"\"" - end - assert_generated_migration(table) do - " remove_column :#{table}, :#{attr}_file_name\n" << - " remove_column :#{table}, :#{attr}_content_type\n" << - " remove_column :#{table}, :#{attr}_file_size\n" << - " remove_column :#{table}, :#{attr}_updated_at" - end -end - -Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key| - assert_generated_migration(table) do - "add_index :#{table}, :#{foreign_key}" - end -end - -Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr| - assert_generated_migration(table) do - " table.string :#{attr}_file_name, :default => \"\"\n" << - " table.string :#{attr}_content_type, :default => \"\"\n" << - " table.integer :#{attr}_file_size\n" << - " table.datetime :#{attr}_updated_at" - end -end - diff --git a/vendor/plugins/coulda/features/step_definitions/model_steps.rb b/vendor/plugins/coulda/features/step_definitions/model_steps.rb deleted file mode 100644 index a89f90f..0000000 --- a/vendor/plugins/coulda/features/step_definitions/model_steps.rb +++ /dev/null @@ -1,89 +0,0 @@ -# GENERATION - -When /^I generate a model named "(.*)"$/ do |model| - system "cd #{@rails_root} && " << - "script/generate model #{model} && " << - "cd .." -end - -When /^I generate a model "(.*)" with a (.*) "(.*)"$/ do |model, attr_type, attr_name| - system "cd #{@rails_root} && " << - "script/generate model #{model} #{attr_name}:#{attr_type} && " << - "cd .." -end - -When /^I generate a model "(.*)" that belongs to a "(.*)"$/ do |model, association| - association.downcase! - system "cd #{@rails_root} && " << - "script/generate model #{model} #{association}:belongs_to && " << - "cd .." -end - -When /^I generate a model "(.*)" with file "(.*)"$/ do |model, file| - file.downcase! - system "cd #{@rails_root} && " << - "script/generate model #{model} #{file}:paperclip && " << - "cd .." -end - -When /^I generate a Post model with title, body, and User$/ do - system "cd #{@rails_root} && " << - "script/generate model Post title:string body:text user:belongs_to && " << - "rake db:migrate " << - "cd .." -end - -# MODEL - -Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro| - model.downcase! - assert_generated_file("app/models/#{model}.rb") do - macro - end -end - -# FACTORY - -Then /^a factory should be generated for "(.*)"$/ do |model| - model.downcase! - assert_generated_file("test/factories/#{model}.rb") do - "Factory.define :#{model.downcase} do |#{model.downcase}|\n" << - "end\n" - end -end - -Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type| - model.downcase! - assert_generated_file("test/factories/#{model}.rb") do - "Factory.define :#{model} do |#{model}|\n" << - " #{model}.#{attr_name} { '#{attr_type}' }\n" << - "end\n" - end -end - -Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model| - model.downcase! - associated_model.downcase! - assert_generated_file("test/factories/#{model}.rb") do - "Factory.define :#{model} do |#{model}|\n" << - " #{model}.association(:#{associated_model})\n" << - "end\n" - end -end - -# UNIT TEST - -Then /^a unit test should be generated for "(.*)"$/ do |model| - model.downcase! - assert_generated_file("test/unit/#{model}_test.rb") do - "assert_valid Factory.build(:#{model})" - end -end - -Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro| - model.downcase! - assert_generated_file("test/unit/#{model}_test.rb") do - macro - end -end - diff --git a/vendor/plugins/coulda/features/step_definitions/view_steps.rb b/vendor/plugins/coulda/features/step_definitions/view_steps.rb deleted file mode 100644 index e8e8158..0000000 --- a/vendor/plugins/coulda/features/step_definitions/view_steps.rb +++ /dev/null @@ -1,36 +0,0 @@ -When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource| - system "cd #{@rails_root} && " << - "script/generate view #{resource} #{view} && " << - "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" << - "<% form_for(@post) do |form| %>\n" << - " <%= form.error_messages %>\n" << - "
\n" << - "
\n" << - "
\n" << - " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << - "
\n" << - "<% end %>" - end -end - -Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do - assert_generated_file("app/views/posts/new.html.erb") do - "

New post

\n\n" << - "<% form_for(@post) do |form| %>\n" << - " <%= form.error_messages %>\n" << - "
\n" << - " <%= form.string :title %>\n" << - " <%= form.text :body %>\n" << - "
\n" << - "
\n" << - " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" << - "
\n" << - "<% end %>" - end -end - diff --git a/vendor/plugins/coulda/features/support/env.rb b/vendor/plugins/coulda/features/support/env.rb deleted file mode 100644 index f7bbc24..0000000 --- a/vendor/plugins/coulda/features/support/env.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'test/unit' - -module Test::Unit::Assertions - - def assert_generated_file(path) - assert_file_exists(path) - if block_given? - File.open(File.join(@rails_root, path)) do |file| - expected = yield - body = file.read - assert body.include?(expected), - "expected #{expected} but was #{body.inspect}" - end - end - end - - def assert_file_exists(path) - file = File.join(@rails_root, path) - - assert File.exists?(file), "#{file} expected to exist, but did not" - assert File.file?(file), "#{file} expected to be a file, but is not" - end - - def assert_generated_views_for(name, *actions) - actions.each do |action| - assert_generated_file("app/views/#{name}/#{action}.html.erb") do - yield if block_given? - end - end - end - - def assert_generated_migration(name) - file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first - file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb" - assert_generated_file(file) { "timestamps" } - assert_generated_file(file) { yield if block_given? } - end - - def assert_generated_route_for(name, *actions) - routeable_actions = actions.collect { |action| ":#{action}" }.join(", ") - assert_generated_file("config/routes.rb") do - " map.resources :#{name.to_s}, :only => [#{routeable_actions}]" - end - end - - def assert_has_empty_method(body, *methods) - methods.each do |name| - assert body.include?(" def #{name}\n end"), - "should have method #{name} in #{body.inspect}" - yield(name, $2) if block_given? - end - end - -end - -class CouldaWorld - include Test::Unit::Assertions -end - -World do - CouldaWorld.new -end - diff --git a/vendor/plugins/coulda/features/view_generator.feature b/vendor/plugins/coulda/features/view_generator.feature deleted file mode 100644 index a5730d0..0000000 --- a/vendor/plugins/coulda/features/view_generator.feature +++ /dev/null @@ -1,18 +0,0 @@ -Feature: Rails view generator - In order to do Test-Driven Development with Rails - As a developer - I want to generate a view to make a functional test pass - - Scenario: View generator for new action - Given a Rails app - And the coulda 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 - 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 - diff --git a/vendor/plugins/coulda/generators/controller/controller_generator.rb b/vendor/plugins/coulda/generators/controller/controller_generator.rb deleted file mode 100644 index 550527a..0000000 --- a/vendor/plugins/coulda/generators/controller/controller_generator.rb +++ /dev/null @@ -1,26 +0,0 @@ -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") - -class ControllerGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest" - - m.directory File.join('app/controllers', class_path) - m.directory File.join('test/functional', class_path) - - m.template 'controller.rb', - File.join('app/controllers', - class_path, - "#{file_name}_controller.rb") - - m.template 'functional_test.rb', - File.join('test/functional', - class_path, - "#{file_name}_controller_test.rb") - end - end - - def routeable_actions - actions.collect { |action| ":#{action}" }.join(", ") - end -end diff --git a/vendor/plugins/coulda/generators/controller/templates/controller.rb b/vendor/plugins/coulda/generators/controller/templates/controller.rb deleted file mode 100644 index b1fcb6f..0000000 --- a/vendor/plugins/coulda/generators/controller/templates/controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -class <%= class_name %>Controller < ApplicationController -<% if actions.include?("index") -%> - def index - end - -<% end -%> -<% if actions.include?("new") -%> - def new - @<%= resource %> = <%= resource_class %>.new - end - -<% end -%> -<% if actions.include?("create") -%> - def create - @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) - @<%= resource %>.save - flash[:success] = '<%= resource_class %> created.' - redirect_to <%= resources %>_path - end - -<% end -%> -<% if actions.include?("show") -%> - def show - @<%= resource %> = <%= resource_class %>.find(params[:id]) - end - -<% end -%> -<% if actions.include?("edit") -%> - def edit - @<%= resource %> = <%= resource_class %>.find(params[:id]) - end - -<% end -%> -<% if actions.include?("update") -%> - def update - @<%= resource %> = <%= resource_class %>.find(params[:id]) - @<%= resource %>.update_attributes(params[:<%= resource %>]) - flash[:success] = '<%= resource_class %> updated.' - redirect_to <%= resources %>_path - end - -<% end -%> -<% if actions.include?("destroy") -%> - def destroy - @<%= resource %> = <%= resource_class %>.find(params[:id]) - @<%= resource %>.destroy - flash[:success] = '<%= resource_class %> deleted.' - redirect_to <%= resources %>_path - end - -<% end -%> -end diff --git a/vendor/plugins/coulda/generators/controller/templates/functional_test.rb b/vendor/plugins/coulda/generators/controller/templates/functional_test.rb deleted file mode 100644 index ef9a2a4..0000000 --- a/vendor/plugins/coulda/generators/controller/templates/functional_test.rb +++ /dev/null @@ -1,88 +0,0 @@ -require 'test_helper' - -class <%= class_name %>ControllerTest < ActionController::TestCase -<% if actions.include?("index") -%> - context 'GET to index' do - setup { get :index } - - should_render_template :index - should_respond_with :success - end - -<% end -%> -<% if actions.include?("new") -%> - context 'GET to new' do - setup { get :new } - - should_assign_to :<%= resource %> - should_render_template :new - should_respond_with :success - end - -<% end -%> -<% if actions.include?("create") -%> - context 'POST to create with valid parameters' do - setup do - post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>) - end - - should_set_the_flash_to /created/i - should_redirect_to('<%= resources %> index') { <%= resources %>_path } - end - -<% end -%> -<% if actions.include?("show") -%> - context 'GET to show for existing <%= resource %>' do - setup do - @<%= resource %> = Factory(:<%= resource %>) - get :show, :id => @<%= resource %>.to_param - end - - should_assign_to :<%= resource %>, :equals => '@<%= resource %>' - should_render_template :show - should_respond_with :success - end - -<% end -%> -<% if actions.include?("edit") -%> - context 'GET to edit for existing <%= resource %>' do - setup do - @<%= resource %> = Factory(:<%= resource %>) - get :edit, :id => @<%= resource %>.to_param - end - - should_assign_to :<%= resource %>, :equals => '@<%= resource %>' - should_render_template :edit - should_respond_with :success - end - -<% end -%> -<% if actions.include?("update") -%> - context 'PUT to update for existing <%= resource %>' do - setup do - @<%= resource %> = Factory(:<%= resource %>) - put :update, :id => @<%= resource %>.to_param, - :<%= resource %> => Factory.attributes_for(:<%= resource %>) - end - - should_set_the_flash_to /updated/i - should_redirect_to('<%= resources %> index') { <%= resources %>_path } - end - -<% end -%> -<% if actions.include?("destroy") -%> - context 'given a <%= resource %>' do - setup { @<%= resource %> = Factory(:<%= resource %>) } - - context 'DELETE to destroy' do - setup { delete :destroy, :id => @<%= resource %>.to_param } - - should_destroy :<%= resource %> - should_set_the_flash_to /deleted/i - should_redirect_to('<%= resources %> index') { <%= resources %>_path } - end - end - -<% end -%> -end - diff --git a/vendor/plugins/coulda/generators/feature/feature_generator.rb b/vendor/plugins/coulda/generators/feature/feature_generator.rb deleted file mode 100644 index da28bd1..0000000 --- a/vendor/plugins/coulda/generators/feature/feature_generator.rb +++ /dev/null @@ -1,32 +0,0 @@ -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") - -class FeatureGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - m.directory 'features' - m.directory 'features/step_definitions' - m.directory 'features/support' - - path = File.join('features', "#{resources}.feature") - m.template 'feature.feature', path - - path = File.join('features', 'step_definitions', "#{resources}_steps.rb") - m.template 'step_definition.rb', path - - path = File.join('features', 'support', "paths.rb") - m.insert_cucumber_path path, insertable_path - end - end - - def insertable_path - if %w(new create).any? { |action| actions.include?(action) } - " when /the new #{resource} page/i\n" << - " new_#{resource}_path\n" - elsif %w(edit update).any? { |action| actions.include?(action) } - " when /the edit \"([^\\\"]*)\" #{resource} page/i do |name|\n" << - " post = #{resource_class}.find_by_name(name)\n" - " edit_#{resource}_path(#{resource})" - end - end -end - diff --git a/vendor/plugins/coulda/generators/feature/templates/feature.feature b/vendor/plugins/coulda/generators/feature/templates/feature.feature deleted file mode 100644 index 5d6b1f5..0000000 --- a/vendor/plugins/coulda/generators/feature/templates/feature.feature +++ /dev/null @@ -1,11 +0,0 @@ -<% if %w(new create).any? { |action| actions.include?(action) } -%> - Scenario: Create a new <%= resource %> - Given I am on the new <%= resource %> page - When I create a <%= resource %> named "A new <%= resource %>" - Then I should see "A new <%= resource %>" -<% elsif %w(edit update).any? { |action| actions.include?(action) } -%> - Scenario: Update a <%= resource %> - Given I am on the edit "An existing <%= resource %>" <%= resource %> page - When I update the <%= resource %> - Then I should see "<%= resource_class %> updated" -<% end -%> diff --git a/vendor/plugins/coulda/generators/feature/templates/step_definition.rb b/vendor/plugins/coulda/generators/feature/templates/step_definition.rb deleted file mode 100644 index 78572d3..0000000 --- a/vendor/plugins/coulda/generators/feature/templates/step_definition.rb +++ /dev/null @@ -1,12 +0,0 @@ -<% if %w(new create).any? { |action| actions.include?(action) } -%> -When /^I create a <%= resource %> named "([^\"]*)"$/ do |name| - fills_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 - click_button 'Update' -end -<% end -%> - diff --git a/vendor/plugins/coulda/generators/helper/helper_generator.rb b/vendor/plugins/coulda/generators/helper/helper_generator.rb deleted file mode 100644 index 2eb4f83..0000000 --- a/vendor/plugins/coulda/generators/helper/helper_generator.rb +++ /dev/null @@ -1,25 +0,0 @@ -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") - -class HelperGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions "#{class_name}Helper", "#{class_name}HelperTest" - - # Helper and test directories. - m.directory File.join('app/helpers', class_path) - m.directory File.join('test/unit/helpers', class_path) - - # Helper module and test. - m.template 'helper.rb', - File.join('app/helpers', - class_path, - "#{file_name}_helper.rb") - - m.template 'helper_test.rb', - File.join('test/unit/helpers', - class_path, - "#{file_name}_helper_test.rb") - end - end -end diff --git a/vendor/plugins/coulda/generators/helper/templates/helper.rb b/vendor/plugins/coulda/generators/helper/templates/helper.rb deleted file mode 100644 index 3fe2ecd..0000000 --- a/vendor/plugins/coulda/generators/helper/templates/helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module <%= class_name %>Helper -end diff --git a/vendor/plugins/coulda/generators/helper/templates/helper_test.rb b/vendor/plugins/coulda/generators/helper/templates/helper_test.rb deleted file mode 100644 index 591e409..0000000 --- a/vendor/plugins/coulda/generators/helper/templates/helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class <%= class_name %>HelperTest < ActionView::TestCase -end diff --git a/vendor/plugins/coulda/generators/model/model_generator.rb b/vendor/plugins/coulda/generators/model/model_generator.rb deleted file mode 100644 index 9a3aa57..0000000 --- a/vendor/plugins/coulda/generators/model/model_generator.rb +++ /dev/null @@ -1,81 +0,0 @@ -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") - -class ModelGenerator < Rails::Generator::NamedBase - default_options :skip_timestamps => false, - :skip_migration => false, - :skip_factories => false - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name, "#{class_name}Test" - - # Model, test, and factories directories. - m.directory File.join('app/models', class_path) - m.directory File.join('test/unit', class_path) - m.directory File.join('test/factories', class_path) - - # Model class, unit test, and factories. - m.template 'model.rb', File.join('app/models', class_path, - "#{file_name}.rb") - m.template 'unit_test.rb', File.join('test/unit', class_path, - "#{file_name}_test.rb") - - m.template 'factory.rb', File.join('test/factories', "#{file_name}.rb") - - unless options[:skip_migration] - m.migration_template 'migration.rb', 'db/migrate', :assigns => { - :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" - }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" - end - end - end - - def factory_line(attribute, file_name) - if attribute.reference? - "#{file_name}.association(:#{attribute.name})" - else - "#{file_name}.#{attribute.name} #{attribute.default_for_factory}" - end - end - - protected - - def banner - "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]" - end - - def add_options!(opt) - opt.separator '' - opt.separator 'Options:' - opt.on("--skip-timestamps", - "Don't add timestamps to the migration file for this model") { |v| - options[:skip_timestamps] = v - } - opt.on("--skip-migration", - "Don't generate a migration file for this model") { |v| - options[:skip_migration] = v - } - end -end - -module Rails - module Generator - class GeneratedAttribute - def default_for_factory - @default ||= case type - when :integer then "{ 1 }" - when :float then "{ 1.5 }" - when :decimal then "{ 9.99 }" - when :datetime, :timestamp, :time then "{ Time.now.to_s(:db) }" - when :date then "{ Date.today.to_s(:db) }" - when :string then "{ 'string' }" - when :text then "{ 'text' }" - when :boolean then "{ false }" - else - "" - end - end - end - end -end diff --git a/vendor/plugins/coulda/generators/model/templates/factory.rb b/vendor/plugins/coulda/generators/model/templates/factory.rb deleted file mode 100644 index 1bc9bba..0000000 --- a/vendor/plugins/coulda/generators/model/templates/factory.rb +++ /dev/null @@ -1,5 +0,0 @@ -Factory.define :<%= file_name %> do |<%= file_name %>| -<% attributes.each do |attribute| -%> - <%= factory_line(attribute, file_name) %> -<% end -%> -end diff --git a/vendor/plugins/coulda/generators/model/templates/migration.rb b/vendor/plugins/coulda/generators/model/templates/migration.rb deleted file mode 100644 index 2530587..0000000 --- a/vendor/plugins/coulda/generators/model/templates/migration.rb +++ /dev/null @@ -1,32 +0,0 @@ -class <%= migration_name %> < ActiveRecord::Migration - def self.up - create_table :<%= table_name %> do |table| -<% attributes.each do |attribute| -%> -<% if attribute.type == :paperclip -%> - table.string :<%= attribute.name %>_file_name, :default => "" - table.string :<%= attribute.name %>_content_type, :default => "" - table.integer :<%= attribute.name %>_file_size - table.datetime :<%= attribute.name %>_updated_at -<% elsif attribute.type == :string -%> - table.string :<%= attribute.name %>, :default => "" -<% else -%> - table.<%= attribute.type %> :<%= attribute.name %> -<% end -%> -<% end -%> -<% unless options[:skip_timestamps] -%> - table.timestamps -<% end -%> - end - -<% attributes.select(&:reference?).each do |attribute| -%> - add_index :<%= table_name %>, :<%= attribute.name %>_id -<% end -%> - end - - def self.down -<% attributes.select(&:reference?).each do |attribute| -%> - remove_index :<%= table_name %>, :<%= attribute.name %>_id -<% end -%> - drop_table :<%= table_name %> - end -end diff --git a/vendor/plugins/coulda/generators/model/templates/model.rb b/vendor/plugins/coulda/generators/model/templates/model.rb deleted file mode 100644 index 8ba98a8..0000000 --- a/vendor/plugins/coulda/generators/model/templates/model.rb +++ /dev/null @@ -1,8 +0,0 @@ -class <%= class_name %> < ActiveRecord::Base -<% attributes.select(&:reference?).each do |each| -%> - belongs_to :<%= each.name %> -<% end -%> -<% attributes.select { |each| each.type == :paperclip }.each do |each| -%> - has_attached_file :<%= each.name %> -<% end -%> -end diff --git a/vendor/plugins/coulda/generators/model/templates/unit_test.rb b/vendor/plugins/coulda/generators/model/templates/unit_test.rb deleted file mode 100644 index 9021608..0000000 --- a/vendor/plugins/coulda/generators/model/templates/unit_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActiveSupport::TestCase - should "be valid with factory" do - assert_valid Factory.build(:<%= file_name -%>) - end -<% attributes.each do |attribute| -%> -<% if attribute.reference? -%> - should_belong_to :<%= attribute.name %> - should_have_db_index :<%= attribute.name %>_id -<% end -%> -<% if attribute.type == :paperclip -%> - should_have_attached_file :<%= attribute.name %> -<% end -%> -<% end -%> -end diff --git a/vendor/plugins/coulda/generators/support/generator_helper.rb b/vendor/plugins/coulda/generators/support/generator_helper.rb deleted file mode 100644 index 1419516..0000000 --- a/vendor/plugins/coulda/generators/support/generator_helper.rb +++ /dev/null @@ -1,43 +0,0 @@ -require File.join(File.dirname(__FILE__), "insert_commands") - -module Coulda - module GeneratorHelper - REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed", - "encrypted_password", "salt", "token", "token_expires_at"] - - def resource - file_name.singularize - end - - def resources - file_name.pluralize - end - - def resource_class - class_name.singularize - end - - def columns_for_form - resource_class.constantize.content_columns. - collect { |column| [column.name, column.type] }. - delete_if { |column| remove_column?(column.first) } - end - - def active_record_defined? - models = Dir.glob(File.join( RAILS_ROOT, 'app', 'models', '*.rb')). - collect { |path| path[/.+\/(.+).rb/,1] }. - collect {|model| model.classify } - models.include?(resource_class) - end - - def remove_column?(column) - REMOVABLE_COLUMNS.include?(column) || - !(column =~ /_id$/).nil? - end - end -end - -class Rails::Generator::NamedBase - include Coulda::GeneratorHelper -end - diff --git a/vendor/plugins/coulda/generators/support/insert_commands.rb b/vendor/plugins/coulda/generators/support/insert_commands.rb deleted file mode 100644 index ce4edc0..0000000 --- a/vendor/plugins/coulda/generators/support/insert_commands.rb +++ /dev/null @@ -1,53 +0,0 @@ -# Pinched some from http://github.com/ryanb/nifty-generators - -Rails::Generator::Commands::Base.class_eval do - def file_contains?(relative_destination, line) - File.read(destination_path(relative_destination)).include?(line) - end -end - -Rails::Generator::Commands::Create.class_eval do - def insert_into(file, line) - logger.insert "#{line} into #{file}" - unless file_contains?(file, line) - gsub_file file, /^(class|module|#{Coulda::Insertable.routes}) .+$/ do |match| - "#{match}\n #{line}" - end - end - end - - def insert_cucumber_path(file, line) - logger.insert "#{line} into #{file}" - unless file_contains?(file, line) - gsub_file file, /#{Coulda::Insertable.cucumber_paths}/ do |match| - "#{match}\n#{line}" - end - end - end -end - -Rails::Generator::Commands::Destroy.class_eval do - def insert_into(file, line) - logger.remove "#{line} from #{file}" - gsub_file file, "\n #{line}", '' - end -end - -Rails::Generator::Commands::List.class_eval do - def insert_into(file, line) - logger.insert "#{line} into #{file}" - end -end - -module Coulda - module Insertable - def self.routes - "ActionController::Routing::Routes.draw" - end - - def self.cucumber_paths - "case page_name\n" - end - end -end - diff --git a/vendor/plugins/coulda/generators/view/templates/view_new.html.erb b/vendor/plugins/coulda/generators/view/templates/view_new.html.erb deleted file mode 100644 index 6174b80..0000000 --- a/vendor/plugins/coulda/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/coulda/generators/view/templates/view_show.html.erb b/vendor/plugins/coulda/generators/view/templates/view_show.html.erb deleted file mode 100644 index 71375ad..0000000 --- a/vendor/plugins/coulda/generators/view/templates/view_show.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -

<%= resource %>

- -<%%= link_to 'Edit', edit_<%= resource %>_path(@<%= resource %>) %> - diff --git a/vendor/plugins/coulda/generators/view/view_generator.rb b/vendor/plugins/coulda/generators/view/view_generator.rb deleted file mode 100644 index a87426a..0000000 --- a/vendor/plugins/coulda/generators/view/view_generator.rb +++ /dev/null @@ -1,14 +0,0 @@ -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper") - -class ViewGenerator < Rails::Generator::NamedBase - 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 - end - end - end -end -- libgit2 0.21.2