Commit 1d5e39e0218802b4ac45453c1b0a385b8f7c2a21

Authored by Dan Croak
1 parent 867da600

replacing coulda with blitz

Showing 75 changed files with 1417 additions and 1361 deletions   Show diff stats
README.markdown
... ... @@ -21,7 +21,7 @@ This will create a Rails 2.3.2 app with Heroku-recommended code:
21 21 * Clearance for authentication
22 22 * Cucumber, Shoulda, Factory Girl, & Mocha for testing
23 23 * Evergreen for CSS framework
24   -* Coulda for features, model, controller, & helper generators
  24 +* Blitz for features, model, controller, & helper generators
25 25  
26 26 If you don't have all the necessary gems, they will be installed.
27 27  
... ...
doc/README_FOR_TEMPLATE
... ... @@ -57,7 +57,7 @@ For exception notification:
57 57  
58 58 For models, controllers, helpers, & features generators:
59 59  
60   - coulda
  60 + blitz
61 61  
62 62 For rake tasks:
63 63  
... ... @@ -89,7 +89,7 @@ Two time formats are available by default, :short_date and :long_date. Add other
89 89 Testing
90 90 -------
91 91  
92   -Testing is done utilizing Test::Unit, Shoulda, factory_girl, and mocha.
  92 +Testing is done utilizing Cucumber, Test::Unit, Shoulda, Factory Girl, and Mocha.
93 93  
94 94 Shoulda is a pragmatic testing framework for TDD built on top of Test::Unit.
95 95  
... ... @@ -121,8 +121,8 @@ It imports the Stylus framework:
121 121  
122 122 @import url("framework/reset.css");
123 123 @import url("framework/typography.css");
124   - @import url("framework/layout.css");
125   - @import url("framework/forms.css");
  124 + @import url("framework/grid.css");
  125 + @import url("framework/spacing.css");
126 126  
127 127 Add another import for your own styles, by convention named after your app.
128 128  
... ...
vendor/plugins/blitz/CHANGELOG.textile 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +h1. March 8, 2009
  2 +
  3 +* Updated functional tests to use shoulda 2.10 should_redirect_to block syntax
  4 +
  5 +h1. March 7, 2009
  6 +
  7 +* Added Paperclip option to model generator
  8 +* Removed comments on model per complaints by thoughtbot
  9 +
... ...
vendor/plugins/blitz/README.textile 0 → 100644
... ... @@ -0,0 +1,174 @@
  1 +h1. Blitz generators
  2 +
  3 +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.
  4 +
  5 +h2. Generated code may contain
  6 +
  7 +* "Cucumber":http://github.com/aslakhellesoy/cucumber
  8 +* "Shoulda":http://github.com/thoughtbot/shoulda
  9 +* "Factory Girl":http://github.com/thoughtbot/factory_girl
  10 +* "Mocha":http://github.com/jferris/mocha
  11 +
  12 +h2. Installation
  13 +
  14 + $ script/plugin install git://github.com/dancroak/blitz.git
  15 +
  16 +h2. Feature generator
  17 +
  18 + $ script/generate feature Posts new create
  19 +
  20 +generates...
  21 +
  22 +<pre><code> Scenario: Create a new post
  23 + Given I am on the new post page
  24 + When I create a 'post' named 'A new post'
  25 + Then I should see 'A new post'</code></pre>
  26 +
  27 +Now run it:
  28 +
  29 + $ cucumber features/posts.feature
  30 +
  31 +The failure will be:
  32 +
  33 + undefined method `new_post_path'
  34 +
  35 +To get past this error, we'll create just the route we need:
  36 +
  37 + map.resources :posts, :only => [:new]
  38 +
  39 +Running the test again, we have a new failure:
  40 +
  41 + uninitialized constant PostsController
  42 +
  43 +h2. Controller test generator
  44 +
  45 +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.
  46 +
  47 + $ script/generate controller_test Posts new create
  48 +
  49 +h2. Controller generator
  50 +
  51 + $ script/generate controller Posts new create
  52 +
  53 +generates...
  54 +
  55 +
  56 +h2. Model generator
  57 +
  58 + $ script/generate model User
  59 +
  60 +* factory (Factory Girl)
  61 +* unit test (Shoulda)
  62 +* migration
  63 +* model
  64 +
  65 +h2. Helper generator
  66 +
  67 + $ script/generate helper Navigation
  68 +
  69 +* empty helper test file
  70 +* empty helper module
  71 +
  72 +h2. View generator
  73 +
  74 + $ script/generate view Posts new
  75 +
  76 +h2. Model generator: belongs_to
  77 +
  78 + $ script/generate model post user:belongs_to
  79 +
  80 +generates...
  81 +
  82 +<pre><code>class CreatePosts < ActiveRecord::Migration
  83 + def self.up
  84 + create_table :posts do |t|
  85 + t.belongs_to :user
  86 + t.timestamps
  87 + end
  88 +
  89 + add_index :posts, :user_id
  90 + end
  91 +
  92 + def self.down
  93 + remove_index :posts, :user_id
  94 + drop_table :posts
  95 + end
  96 +end
  97 +
  98 +class Post < ActiveRecord::Base
  99 + belongs_to :user
  100 +end
  101 +
  102 +class PostTest < ActiveSupport::TestCase
  103 + should_belong_to :user
  104 + should_have_index :user_id
  105 +end
  106 +
  107 +Factory.define :post do |post|
  108 + post.association(:user)
  109 +end</code></pre>
  110 +
  111 +h2. Model generator: paperclip
  112 +
  113 + $ script/generate model design image:paperclip
  114 +
  115 +* all the necessary columns in the migration
  116 +* "has_attached_file" in the model
  117 +* "should_have_attached_file" in unit test
  118 +
  119 +<pre><code>class CreateDesigns < ActiveRecord::Migration
  120 + def self.up
  121 + create_table :designs do |t|
  122 + t.string :image_file_name
  123 + t.string :image_content_type
  124 + t.integer :image_file_size
  125 + t.datetime :image_updated_at
  126 + t.timestamps
  127 + end
  128 + end
  129 +
  130 + def self.down
  131 + drop_table :designs
  132 + end
  133 +end
  134 +
  135 +class Design < ActiveRecord::Base
  136 + has_attached_file :image
  137 +end
  138 +
  139 +class DesignTest < ActiveSupport::TestCase
  140 + should "be valid with factory" do
  141 + assert_valid Factory.build(:design)
  142 + end
  143 + should_have_attached_file :image
  144 +end</code></pre>
  145 +
  146 +h2. Attribution
  147 +
  148 +"Dan Croak":http://github.com/dancroak and "Mike Breen":http://github.com/hardbap
  149 +
  150 +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
  151 +
  152 +h2. License
  153 +
  154 +The MIT License
  155 +
  156 +Copyright (c) 2008, 2009 Dan Croak
  157 +
  158 +Permission is hereby granted, free of charge, to any person obtaining a copy
  159 +of this software and associated documentation files (the "Software"), to deal
  160 +in the Software without restriction, including without limitation the rights
  161 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  162 +copies of the Software, and to permit persons to whom the Software is
  163 +furnished to do so, subject to the following conditions:
  164 +
  165 +The above copyright notice and this permission notice shall be included in
  166 +all copies or substantial portions of the Software.
  167 +
  168 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  169 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  170 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  171 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  172 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  173 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  174 +THE SOFTWARE.
... ...
vendor/plugins/blitz/Rakefile 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require 'rake'
  2 +require 'rake/testtask'
  3 +
  4 +require 'cucumber/rake/task'
  5 +Cucumber::Rake::Task.new(:features) do |features|
  6 + features.cucumber_opts = "features --format progress"
  7 +end
  8 +
  9 +task :default => [:features]
  10 +
... ...
vendor/plugins/blitz/features/controller_generator.feature 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +Feature: Rails controller generator
  2 + In order to better do Test-Driven Development with Rails
  3 + As a user
  4 + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
  5 +
  6 + Scenario: Controller generator for index action
  7 + Given a Rails app
  8 + And the coulda plugin is installed
  9 + When I generate a "Posts" controller with "index" action
  10 + And an empty "index" controller action for "posts" should be generated
  11 +
  12 + Scenario: Controller generator for new action
  13 + Given a Rails app
  14 + And the coulda plugin is installed
  15 + When I generate a "Posts" controller with "new" action
  16 + And a "new" controller action for "posts" should be generated
  17 +
  18 + Scenario: Controller generator for create action
  19 + Given a Rails app
  20 + And the coulda plugin is installed
  21 + When I generate a "Posts" controller with "create" action
  22 + And a "create" controller action for "posts" should be generated
  23 +
  24 + Scenario: Controller generator for create action when Cucumber is installed
  25 + Given a Rails app with Cucumber
  26 + And the coulda plugin is installed
  27 + When I generate a "Posts" controller with "create" action
  28 + And a "create" controller action for "posts" should be generated
  29 +
  30 + Scenario: Controller generator for show action
  31 + Given a Rails app
  32 + And the coulda plugin is installed
  33 + When I generate a "Posts" controller with "show" action
  34 + And a "show" controller action for "posts" should be generated
  35 +
  36 + Scenario: Controller generator for edit action
  37 + Given a Rails app
  38 + And the coulda plugin is installed
  39 + When I generate a "Posts" controller with "edit" action
  40 + And a "edit" controller action for "posts" should be generated
  41 +
  42 + Scenario: Controller generator for update action
  43 + Given a Rails app
  44 + And the coulda plugin is installed
  45 + When I generate a "Posts" controller with "update" action
  46 + And a "update" controller action for "posts" should be generated
  47 +
  48 + Scenario: Controller generator for destroy action
  49 + Given a Rails app
  50 + And the coulda plugin is installed
  51 + When I generate a "Posts" controller with "destroy" action
  52 + And a "destroy" controller action for "posts" should be generated
  53 +
... ...
vendor/plugins/blitz/features/feature_generator.feature 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +Feature: Rails controller generator
  2 + In order to better do Test-Driven Development with Rails
  3 + As a user
  4 + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
  5 +
  6 + Scenario: Feature generator for new action
  7 + Given a Rails app with Cucumber
  8 + And the coulda plugin is installed
  9 + When I generate a "new" feature for "Posts"
  10 + Then a "posts" feature for the "create" scenario should be generated
  11 + And a "create posts" step definition should be generated
  12 + And a new post page path should be generated
  13 +
  14 + Scenario: Feature generator for create action same as new
  15 + Given a Rails app with Cucumber
  16 + And the coulda plugin is installed
  17 + When I generate a "create" feature for "Posts"
  18 + Then a "posts" feature for the "create" scenario should be generated
  19 + And a "create posts" step definition should be generated
  20 + And a new post page path should be generated
  21 +
  22 + Scenario: Feature generator for edit action
  23 + Given a Rails app with Cucumber
  24 + And the coulda plugin is installed
  25 + When I generate a "edit" feature for "Posts"
  26 + Then a "posts" feature for the "edit" scenario should be generated
  27 + And a "update posts" step definition should be generated
  28 + And a edit post page path should be generated
  29 +
  30 + Scenario: Feature generator for update action same as edit
  31 + Given a Rails app with Cucumber
  32 + And the coulda plugin is installed
  33 + When I generate a "update" feature for "Posts"
  34 + Then a "posts" feature for the "update" scenario should be generated
  35 + And a "update posts" step definition should be generated
  36 + And a edit post page path should be generated
  37 +
... ...
vendor/plugins/blitz/features/functional_test_generator.feature 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +Feature: Rails controller generator
  2 + In order to better do Test-Driven Development with Rails
  3 + As a user
  4 + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
  5 +
  6 + Scenario: Functional test generator for index action
  7 + Given a Rails app
  8 + And the coulda plugin is installed
  9 + When I generate a "Posts" functional test with "index" action
  10 + Then a standard "index" functional test for "posts" should be generated
  11 +
  12 + Scenario: Functional test generator for new action
  13 + Given a Rails app
  14 + And the coulda plugin is installed
  15 + When I generate a "Posts" functional test with "new" action
  16 + Then a standard "new" functional test for "posts" should be generated
  17 +
  18 + Scenario: Functional test generator for create action
  19 + Given a Rails app
  20 + And the coulda plugin is installed
  21 + When I generate a "Posts" functional test with "create" action
  22 + Then a standard "create" functional test for "posts" should be generated
  23 +
  24 + Scenario: Functional test generator for create action when Cucumber is installed
  25 + Given a Rails app with Cucumber
  26 + And the coulda plugin is installed
  27 + When I generate a "Posts" functional test with "create" action
  28 + Then a standard "create" functional test for "posts" should be generated
  29 +
  30 + Scenario: Functional test generator for show action
  31 + Given a Rails app
  32 + And the coulda plugin is installed
  33 + When I generate a "Posts" functional test with "show" action
  34 + Then a standard "show" functional test for "posts" should be generated
  35 +
  36 + Scenario: Functional test generator for edit action
  37 + Given a Rails app
  38 + And the coulda plugin is installed
  39 + When I generate a "Posts" functional test with "edit" action
  40 + Then a standard "edit" functional test for "posts" should be generated
  41 +
  42 + Scenario: Functional test generator for update action
  43 + Given a Rails app
  44 + And the coulda plugin is installed
  45 + When I generate a "Posts" functional test with "update" action
  46 + Then a standard "update" functional test for "posts" should be generated
  47 +
  48 + Scenario: Functional test generator for destroy action
  49 + Given a Rails app
  50 + And the coulda plugin is installed
  51 + When I generate a "Posts" functional test with "destroy" action
  52 + Then a standard "destroy" functional test for "posts" should be generated
  53 +
... ...
vendor/plugins/blitz/features/helper_generator.feature 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +Feature: Rails helper generator
  2 + In order to better do Test-Driven Development with Rails
  3 + As a user
  4 + I want to generate just the module and test I need.
  5 +
  6 + Scenario: Helper
  7 + Given a Rails app
  8 + And the coulda plugin is installed
  9 + When I generate a helper named "Navigation"
  10 + Then a helper should be generated for "Navigation"
  11 + And a helper test should be generated for "Navigation"
  12 +
... ...
vendor/plugins/blitz/features/model_generator.feature 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +Feature: Rails model generator
  2 + In order to better do Test-Driven Development with Rails
  3 + As a user
  4 + I want to generate a Factory definition and Shoulda tests.
  5 +
  6 + Scenario: Model generator without attributes
  7 + Given a Rails app
  8 + And the coulda plugin is installed
  9 + When I generate a model named "User"
  10 + Then a factory should be generated for "User"
  11 + And a unit test should be generated for "User"
  12 +
  13 + Scenario: Model generator with attributes
  14 + Given a Rails app
  15 + And the coulda plugin is installed
  16 + When I generate a model "User" with a string "email"
  17 + Then a factory for "User" should have an "email" string
  18 + And a unit test should be generated for "User"
  19 +
  20 + Scenario: Model generator with association
  21 + Given a Rails app
  22 + And the coulda plugin is installed
  23 + When I generate a model "Post" that belongs to a "User"
  24 + Then a factory for "Post" should have an association to "User"
  25 + And the "Post" unit test should have "should_belong_to :user" macro
  26 + And the "Post" unit test should have "should_have_db_index :user_id" macro
  27 + And the "posts" table should have db index on "user_id"
  28 + And the "Post" model should have "belongs_to :user" macro
  29 +
  30 + Scenario: Model generator with Paperclip
  31 + Given a Rails app
  32 + And the coulda plugin is installed
  33 + When I generate a model "Design" with file "Image"
  34 + Then the "Design" model should have "has_attached_file :image" macro
  35 + And the "Design" unit test should have "should_have_attached_file :image" macro
  36 + And the "designs" table should have paperclip columns for "image"
  37 +
... ...
vendor/plugins/blitz/features/step_definitions/controller_steps.rb 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, action|
  2 + system "cd #{@rails_root} && " <<
  3 + "script/generate controller #{controller} #{action} && " <<
  4 + "cd .."
  5 +end
  6 +
  7 +Then /^a "new" controller action for "posts" should be generated$/ do
  8 + assert_generated_file("app/controllers/posts_controller.rb") do
  9 + " def new\n" <<
  10 + " @post = Post.new\n" <<
  11 + " end"
  12 + end
  13 +end
  14 +
  15 +Then /^a "create" controller action for "posts" should be generated$/ do
  16 + assert_generated_file("app/controllers/posts_controller.rb") do
  17 + " def create\n" <<
  18 + " @post = Post.new(params[:post])\n" <<
  19 + " @post.save\n" <<
  20 + " flash[:success] = 'Post created.'\n" <<
  21 + " redirect_to posts_path\n" <<
  22 + " end"
  23 + end
  24 +end
  25 +
  26 +Then /^a "show" controller action for "posts" should be generated$/ do
  27 + assert_generated_file("app/controllers/posts_controller.rb") do
  28 + " def show\n" <<
  29 + " @post = Post.find(params[:id])\n" <<
  30 + " end"
  31 + end
  32 +end
  33 +
  34 +Then /^a "edit" controller action for "posts" should be generated$/ do
  35 + assert_generated_file("app/controllers/posts_controller.rb") do
  36 + " def edit\n" <<
  37 + " @post = Post.find(params[:id])\n" <<
  38 + " end"
  39 + end
  40 +end
  41 +
  42 +Then /^a "update" controller action for "posts" should be generated$/ do
  43 + assert_generated_file("app/controllers/posts_controller.rb") do
  44 + " def update\n" <<
  45 + " @post = Post.find(params[:id])\n" <<
  46 + " @post.update_attributes(params[:post])\n" <<
  47 + " flash[:success] = 'Post updated.'\n" <<
  48 + " redirect_to posts_path\n" <<
  49 + " end"
  50 + end
  51 +end
  52 +
  53 +Then /^a "destroy" controller action for "posts" should be generated$/ do
  54 + assert_generated_file("app/controllers/posts_controller.rb") do
  55 + " def destroy\n" <<
  56 + " @post = Post.find(params[:id])\n" <<
  57 + " @post.destroy\n" <<
  58 + " flash[:success] = 'Post deleted.'\n" <<
  59 + " redirect_to posts_path\n" <<
  60 + " end"
  61 + end
  62 +end
  63 +
  64 +Then /^only a "([^\"]*)" action for RESTful "([^\"]*)" route should be generated$/ do |action, resource|
  65 + assert_generated_route_for resource, action
  66 +end
  67 +
... ...
vendor/plugins/blitz/features/step_definitions/cucumber_steps.rb 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +Given /^a Rails app with Cucumber$/ do
  2 + system "rails rails_root"
  3 + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root")
  4 + require 'cucumber'
  5 + system "cd #{@rails_root} && ruby script/generate cucumber"
  6 +end
  7 +
  8 +When /^I generate a "([^\"]*)" feature for "([^\"]*)"$/ do |feature, resource|
  9 + system "cd #{@rails_root} && " <<
  10 + "script/generate feature #{resource} #{feature} && " <<
  11 + "cd .."
  12 +end
  13 +
  14 +Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action|
  15 + if %w(new create).include?(action)
  16 + assert_generated_file("features/posts.feature") do
  17 + " Scenario: Create a new post\n" <<
  18 + " Given I am on the new post page\n" <<
  19 + " When I create a post named \"A new post\"\n" <<
  20 + " Then I should see \"A new post\""
  21 + end
  22 + elsif %w(edit update).include?(action)
  23 + assert_generated_file("features/posts.feature") do
  24 + " Scenario: Update a post\n" <<
  25 + " Given I am on the edit \"An existing post\" post page\n" <<
  26 + " When I update the post\n" <<
  27 + " Then I should see \"Post updated\""
  28 + end
  29 + end
  30 +end
  31 +
  32 +Then /^a "create posts" step definition should be generated$/ do
  33 + assert_generated_file("features/step_definitions/posts_steps.rb") do
  34 + "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" <<
  35 + " fills_in :name, :with => name\n" <<
  36 + " click_button 'Create'\n"
  37 + "end"
  38 + end
  39 +end
  40 +
  41 +Then /^a new post page path should be generated$/ do
  42 + assert_generated_file("features/support/paths.rb") do
  43 + " when /the new post page/i\n" <<
  44 + " new_post_path"
  45 + end
  46 +end
  47 +
  48 +Then /^a "update posts" step definition should be generated$/ do
  49 + assert_generated_file("features/step_definitions/posts_steps.rb") do
  50 + "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" <<
  51 + " fills_in :name, :with => name\n" <<
  52 + " click_button 'Update'\n"
  53 + "end"
  54 + end
  55 +end
  56 +
  57 +Then /^a edit post page path should be generated$/ do
  58 + assert_generated_file("features/support/paths.rb") do
  59 + " when /the edit \"([^\\\"]*)\" post page/i do |name|\n" <<
  60 + " post = Post.find_by_name(name)\n"
  61 + " edit_post_path(post)"
  62 + end
  63 +end
  64 +
... ...
vendor/plugins/blitz/features/step_definitions/functional_test_steps.rb 0 → 100644
... ... @@ -0,0 +1,101 @@
  1 +When /^I generate a "(.*)" functional test with "(.*)" action$/ do |controller, action|
  2 + system "cd #{@rails_root} && " <<
  3 + "script/generate functional_test #{controller} #{action} && " <<
  4 + "cd .."
  5 +end
  6 +
  7 +Then /^a standard "index" functional test for "posts" should be generated$/ do
  8 + assert_generated_file("test/functional/posts_controller_test.rb") do
  9 + " context 'GET to index' do\n" <<
  10 + " setup { get :index }\n\n" <<
  11 + " should_render_template :index\n" <<
  12 + " should_respond_with :success\n" <<
  13 + " end"
  14 + end
  15 +end
  16 +
  17 +Then /^an empty "index" controller action for "posts" should be generated$/ do
  18 + assert_generated_file("app/controllers/posts_controller.rb") do
  19 + " def index\n" <<
  20 + " end"
  21 + end
  22 +end
  23 +
  24 +Then /^a standard "new" functional test for "posts" should be generated$/ do
  25 + assert_generated_file("test/functional/posts_controller_test.rb") do
  26 + " context 'GET to new' do\n" <<
  27 + " setup { get :new }\n\n" <<
  28 + " should_assign_to :post\n" <<
  29 + " should_render_template :new\n" <<
  30 + " should_respond_with :success\n" <<
  31 + " end"
  32 + end
  33 +end
  34 +
  35 +Then /^a standard "create" functional test for "posts" should be generated$/ do
  36 + assert_generated_file("test/functional/posts_controller_test.rb") do
  37 + " context 'POST to create with valid parameters' do\n" <<
  38 + " setup do\n" <<
  39 + " post :create, :post => Factory.attributes_for(:post)\n" <<
  40 + " end\n\n" <<
  41 + " should_set_the_flash_to /created/i\n" <<
  42 + " should_redirect_to('posts index') { posts_path }\n" <<
  43 + " end"
  44 + end
  45 +end
  46 +
  47 +Then /^a standard "show" functional test for "posts" should be generated$/ do
  48 + assert_generated_file("test/functional/posts_controller_test.rb") do
  49 + " context 'GET to show for existing post' do\n" <<
  50 + " setup do\n" <<
  51 + " @post = Factory(:post)\n" <<
  52 + " get :show, :id => @post.to_param\n" <<
  53 + " end\n\n" <<
  54 + " should_assign_to :post, :equals => '@post'\n" <<
  55 + " should_render_template :show\n" <<
  56 + " should_respond_with :success\n" <<
  57 + " end"
  58 + end
  59 +end
  60 +
  61 +Then /^a standard "edit" functional test for "posts" should be generated$/ do
  62 + assert_generated_file("test/functional/posts_controller_test.rb") do
  63 + " context 'GET to edit for existing post' do\n" <<
  64 + " setup do\n" <<
  65 + " @post = Factory(:post)\n" <<
  66 + " get :edit, :id => @post.to_param\n" <<
  67 + " end\n\n" <<
  68 + " should_assign_to :post, :equals => '@post'\n" <<
  69 + " should_render_template :edit\n" <<
  70 + " should_respond_with :success\n" <<
  71 + " end"
  72 + end
  73 +end
  74 +
  75 +Then /^a standard "update" functional test for "posts" should be generated$/ do
  76 + assert_generated_file("test/functional/posts_controller_test.rb") do
  77 + " context 'PUT to update for existing post' do\n" <<
  78 + " setup do\n" <<
  79 + " @post = Factory(:post)\n" <<
  80 + " put :update, :id => @post.to_param,\n" <<
  81 + " :post => Factory.attributes_for(:post)\n" <<
  82 + " end\n\n" <<
  83 + " should_set_the_flash_to /updated/i\n" <<
  84 + " should_redirect_to('posts index') { posts_path }\n" <<
  85 + " end"
  86 + end
  87 +end
  88 +
  89 +Then /^a standard "destroy" functional test for "posts" should be generated$/ do
  90 + assert_generated_file("test/functional/posts_controller_test.rb") do
  91 + " context 'given a post' do\n" <<
  92 + " setup { @post = Factory(:post) }\n\n" <<
  93 + " context 'DELETE to destroy' do\n" <<
  94 + " setup { delete :destroy, :id => @post.to_param }\n\n" <<
  95 + " should_set_the_flash_to /deleted/i\n" <<
  96 + " should_redirect_to('posts index') { posts_path }\n" <<
  97 + " end\n" <<
  98 + " end"
  99 + end
  100 +end
  101 +
... ...
vendor/plugins/blitz/features/step_definitions/generator_steps.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +Given 'a Rails app' do
  2 + system "rails rails_root"
  3 + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root")
  4 +end
  5 +
  6 +Given /^the coulda plugin is installed$/ do
  7 + plugin_dir = File.join(@rails_root, "vendor", "plugins")
  8 + target = File.join(File.dirname(__FILE__), "..", "..", "generators")
  9 + FileUtils.mkdir_p "#{plugin_dir}/coulda"
  10 + system "cp -r #{target} #{plugin_dir}/coulda"
  11 +end
  12 +
  13 +After do
  14 + FileUtils.rm_rf @rails_root if @rails_root
  15 +end
  16 +
... ...
vendor/plugins/blitz/features/step_definitions/helper_steps.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +When /^I generate a helper named "(.*)"$/ do |name|
  2 + system "cd #{@rails_root} && " <<
  3 + "script/generate helper #{name} && " <<
  4 + "cd .."
  5 +end
  6 +
  7 +Then /^a helper should be generated for "(.*)"$/ do |name|
  8 + assert_generated_file("app/helpers/#{name}_helper.rb")
  9 +end
  10 +
  11 +Then /^a helper test should be generated for "(.*)"$/ do |name|
  12 + assert_generated_file("test/unit/helpers/#{name}_helper_test.rb")
  13 +end
  14 +
... ...
vendor/plugins/blitz/features/step_definitions/migration_steps.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table|
  2 + assert_generated_migration(table) do
  3 + " add_column :#{table}, :#{attr}_file_name, :string, :default => \"\"\n" <<
  4 + " add_column :#{table}, :#{attr}_content_type, :string, :default => \"\"\n" <<
  5 + " add_column :#{table}, :#{attr}_file_size, :integer, :default => \"\"\n" <<
  6 + " add_column :#{table}, :#{attr}_updated_at, :datetime, :default => \"\""
  7 + end
  8 + assert_generated_migration(table) do
  9 + " remove_column :#{table}, :#{attr}_file_name\n" <<
  10 + " remove_column :#{table}, :#{attr}_content_type\n" <<
  11 + " remove_column :#{table}, :#{attr}_file_size\n" <<
  12 + " remove_column :#{table}, :#{attr}_updated_at"
  13 + end
  14 +end
  15 +
  16 +Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key|
  17 + assert_generated_migration(table) do
  18 + "add_index :#{table}, :#{foreign_key}"
  19 + end
  20 +end
  21 +
  22 +Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr|
  23 + assert_generated_migration(table) do
  24 + " table.string :#{attr}_file_name, :default => \"\"\n" <<
  25 + " table.string :#{attr}_content_type, :default => \"\"\n" <<
  26 + " table.integer :#{attr}_file_size\n" <<
  27 + " table.datetime :#{attr}_updated_at"
  28 + end
  29 +end
  30 +
... ...
vendor/plugins/blitz/features/step_definitions/model_steps.rb 0 → 100644
... ... @@ -0,0 +1,89 @@
  1 +# GENERATION
  2 +
  3 +When /^I generate a model named "(.*)"$/ do |model|
  4 + system "cd #{@rails_root} && " <<
  5 + "script/generate model #{model} && " <<
  6 + "cd .."
  7 +end
  8 +
  9 +When /^I generate a model "(.*)" with a (.*) "(.*)"$/ do |model, attr_type, attr_name|
  10 + system "cd #{@rails_root} && " <<
  11 + "script/generate model #{model} #{attr_name}:#{attr_type} && " <<
  12 + "cd .."
  13 +end
  14 +
  15 +When /^I generate a model "(.*)" that belongs to a "(.*)"$/ do |model, association|
  16 + association.downcase!
  17 + system "cd #{@rails_root} && " <<
  18 + "script/generate model #{model} #{association}:belongs_to && " <<
  19 + "cd .."
  20 +end
  21 +
  22 +When /^I generate a model "(.*)" with file "(.*)"$/ do |model, file|
  23 + file.downcase!
  24 + system "cd #{@rails_root} && " <<
  25 + "script/generate model #{model} #{file}:paperclip && " <<
  26 + "cd .."
  27 +end
  28 +
  29 +When /^I generate a Post model with title, body, and User$/ do
  30 + system "cd #{@rails_root} && " <<
  31 + "script/generate model Post title:string body:text user:belongs_to && " <<
  32 + "rake db:migrate " <<
  33 + "cd .."
  34 +end
  35 +
  36 +# MODEL
  37 +
  38 +Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro|
  39 + model.downcase!
  40 + assert_generated_file("app/models/#{model}.rb") do
  41 + macro
  42 + end
  43 +end
  44 +
  45 +# FACTORY
  46 +
  47 +Then /^a factory should be generated for "(.*)"$/ do |model|
  48 + model.downcase!
  49 + assert_generated_file("test/factories/#{model}.rb") do
  50 + "Factory.define :#{model.downcase} do |#{model.downcase}|\n" <<
  51 + "end\n"
  52 + end
  53 +end
  54 +
  55 +Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type|
  56 + model.downcase!
  57 + assert_generated_file("test/factories/#{model}.rb") do
  58 + "Factory.define :#{model} do |#{model}|\n" <<
  59 + " #{model}.#{attr_name} { '#{attr_type}' }\n" <<
  60 + "end\n"
  61 + end
  62 +end
  63 +
  64 +Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model|
  65 + model.downcase!
  66 + associated_model.downcase!
  67 + assert_generated_file("test/factories/#{model}.rb") do
  68 + "Factory.define :#{model} do |#{model}|\n" <<
  69 + " #{model}.association(:#{associated_model})\n" <<
  70 + "end\n"
  71 + end
  72 +end
  73 +
  74 +# UNIT TEST
  75 +
  76 +Then /^a unit test should be generated for "(.*)"$/ do |model|
  77 + model.downcase!
  78 + assert_generated_file("test/unit/#{model}_test.rb") do
  79 + "assert_valid Factory.build(:#{model})"
  80 + end
  81 +end
  82 +
  83 +Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro|
  84 + model.downcase!
  85 + assert_generated_file("test/unit/#{model}_test.rb") do
  86 + macro
  87 + end
  88 +end
  89 +
... ...
vendor/plugins/blitz/features/step_definitions/view_steps.rb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource|
  2 + system "cd #{@rails_root} && " <<
  3 + "script/generate view #{resource} #{view} && " <<
  4 + "cd .."
  5 +end
  6 +
  7 +When /^a SemiFormal "new" view for "posts" should be generated$/ do
  8 + assert_generated_file("app/views/posts/new.html.erb") do
  9 + "<h1>New post</h1>\n\n" <<
  10 + "<% form_for(@post) do |form| %>\n" <<
  11 + " <%= form.error_messages %>\n" <<
  12 + " <fieldset class=\"inputs\">\n" <<
  13 + " </fieldset>\n" <<
  14 + " <fieldset class=\"buttons\">\n" <<
  15 + " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
  16 + " </fieldset>\n" <<
  17 + "<% end %>"
  18 + end
  19 +end
  20 +
  21 +Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do
  22 + assert_generated_file("app/views/posts/new.html.erb") do
  23 + "<h1>New post</h1>\n\n" <<
  24 + "<% form_for(@post) do |form| %>\n" <<
  25 + " <%= form.error_messages %>\n" <<
  26 + " <fieldset class=\"inputs\">\n" <<
  27 + " <%= form.string :title %>\n" <<
  28 + " <%= form.text :body %>\n" <<
  29 + " </fieldset>\n" <<
  30 + " <fieldset class=\"buttons\">\n" <<
  31 + " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
  32 + " </fieldset>\n" <<
  33 + "<% end %>"
  34 + end
  35 +end
  36 +
... ...
vendor/plugins/blitz/features/support/env.rb 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +require 'test/unit'
  2 +
  3 +module Test::Unit::Assertions
  4 +
  5 + def assert_generated_file(path)
  6 + assert_file_exists(path)
  7 + if block_given?
  8 + File.open(File.join(@rails_root, path)) do |file|
  9 + expected = yield
  10 + body = file.read
  11 + assert body.include?(expected),
  12 + "expected #{expected} but was #{body.inspect}"
  13 + end
  14 + end
  15 + end
  16 +
  17 + def assert_file_exists(path)
  18 + file = File.join(@rails_root, path)
  19 +
  20 + assert File.exists?(file), "#{file} expected to exist, but did not"
  21 + assert File.file?(file), "#{file} expected to be a file, but is not"
  22 + end
  23 +
  24 + def assert_generated_views_for(name, *actions)
  25 + actions.each do |action|
  26 + assert_generated_file("app/views/#{name}/#{action}.html.erb") do
  27 + yield if block_given?
  28 + end
  29 + end
  30 + end
  31 +
  32 + def assert_generated_migration(name)
  33 + file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first
  34 + file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb"
  35 + assert_generated_file(file) { "timestamps" }
  36 + assert_generated_file(file) { yield if block_given? }
  37 + end
  38 +
  39 + def assert_generated_route_for(name, *actions)
  40 + routeable_actions = actions.collect { |action| ":#{action}" }.join(", ")
  41 + assert_generated_file("config/routes.rb") do
  42 + " map.resources :#{name.to_s}, :only => [#{routeable_actions}]"
  43 + end
  44 + end
  45 +
  46 + def assert_has_empty_method(body, *methods)
  47 + methods.each do |name|
  48 + assert body.include?(" def #{name}\n end"),
  49 + "should have method #{name} in #{body.inspect}"
  50 + yield(name, $2) if block_given?
  51 + end
  52 + end
  53 +
  54 +end
  55 +
  56 +class BlitzWorld
  57 + include Test::Unit::Assertions
  58 +end
  59 +
  60 +World do
  61 + BlitzWorld.new
  62 +end
  63 +
... ...
vendor/plugins/blitz/features/view_generator.feature 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +Feature: Rails view generator
  2 + In order to do Test-Driven Development with Rails
  3 + As a developer
  4 + I want to generate a view to make a functional test pass
  5 +
  6 + Scenario: View generator for new action
  7 + Given a Rails app
  8 + And the coulda plugin is installed
  9 + When I generate a "new" view for "Posts"
  10 + Then a SemiFormal "new" view for "posts" should be generated
  11 +
  12 + Scenario: View generator for new action
  13 + Given a Rails app
  14 + And the coulda plugin is installed
  15 + When I generate a Post model with title, body, and User
  16 + And I generate a "new" view for "Posts"
  17 + Then a SemiFormal "new" view for "posts" should be generated with fields
  18 +
... ...
vendor/plugins/blitz/generators/controller/controller_generator.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
  2 +
  3 +class ControllerGenerator < Rails::Generator::NamedBase
  4 + def manifest
  5 + record do |m|
  6 + m.class_collisions "#{class_name}Controller"
  7 +
  8 + m.directory File.join('app/controllers', class_path)
  9 +
  10 + m.template 'controller.rb',
  11 + File.join('app/controllers',
  12 + class_path,
  13 + "#{file_name}_controller.rb")
  14 + end
  15 + end
  16 +end
... ...
vendor/plugins/blitz/generators/controller/templates/controller.rb 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +class <%= class_name %>Controller < ApplicationController
  2 +<% if actions.include?("index") -%>
  3 + def index
  4 + end
  5 +
  6 +<% end -%>
  7 +<% if actions.include?("new") -%>
  8 + def new
  9 + @<%= resource %> = <%= resource_class %>.new
  10 + end
  11 +
  12 +<% end -%>
  13 +<% if actions.include?("create") -%>
  14 + def create
  15 + @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>])
  16 + @<%= resource %>.save
  17 + flash[:success] = '<%= resource_class %> created.'
  18 + redirect_to <%= resources %>_path
  19 + end
  20 +
  21 +<% end -%>
  22 +<% if actions.include?("show") -%>
  23 + def show
  24 + @<%= resource %> = <%= resource_class %>.find(params[:id])
  25 + end
  26 +
  27 +<% end -%>
  28 +<% if actions.include?("edit") -%>
  29 + def edit
  30 + @<%= resource %> = <%= resource_class %>.find(params[:id])
  31 + end
  32 +
  33 +<% end -%>
  34 +<% if actions.include?("update") -%>
  35 + def update
  36 + @<%= resource %> = <%= resource_class %>.find(params[:id])
  37 + @<%= resource %>.update_attributes(params[:<%= resource %>])
  38 + flash[:success] = '<%= resource_class %> updated.'
  39 + redirect_to <%= resources %>_path
  40 + end
  41 +
  42 +<% end -%>
  43 +<% if actions.include?("destroy") -%>
  44 + def destroy
  45 + @<%= resource %> = <%= resource_class %>.find(params[:id])
  46 + @<%= resource %>.destroy
  47 + flash[:success] = '<%= resource_class %> deleted.'
  48 + redirect_to <%= resources %>_path
  49 + end
  50 +
  51 +<% end -%>
  52 +end
... ...
vendor/plugins/blitz/generators/feature/feature_generator.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
  2 +
  3 +class FeatureGenerator < Rails::Generator::NamedBase
  4 + def manifest
  5 + record do |m|
  6 + m.directory 'features'
  7 + m.directory 'features/step_definitions'
  8 + m.directory 'features/support'
  9 +
  10 + path = File.join('features', "#{resources}.feature")
  11 + m.template 'feature.feature', path
  12 +
  13 + path = File.join('features', 'step_definitions', "#{resources}_steps.rb")
  14 + m.template 'step_definition.rb', path
  15 +
  16 + path = File.join('features', 'support', "paths.rb")
  17 + m.insert_cucumber_path path, insertable_path
  18 + end
  19 + end
  20 +
  21 + def insertable_path
  22 + if %w(new create).any? { |action| actions.include?(action) }
  23 + " when /the new #{resource} page/i\n" <<
  24 + " new_#{resource}_path\n"
  25 + elsif %w(edit update).any? { |action| actions.include?(action) }
  26 + " when /the edit \"([^\\\"]*)\" #{resource} page/i do |name|\n" <<
  27 + " post = #{resource_class}.find_by_name(name)\n"
  28 + " edit_#{resource}_path(#{resource})"
  29 + end
  30 + end
  31 +end
  32 +
... ...
vendor/plugins/blitz/generators/feature/templates/feature.feature 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<% if %w(new create).any? { |action| actions.include?(action) } -%>
  2 + Scenario: Create a new <%= resource %>
  3 + Given I am on the new <%= resource %> page
  4 + When I create a <%= resource %> named "A new <%= resource %>"
  5 + Then I should see "A new <%= resource %>"
  6 +<% elsif %w(edit update).any? { |action| actions.include?(action) } -%>
  7 + Scenario: Update a <%= resource %>
  8 + Given I am on the edit "An existing <%= resource %>" <%= resource %> page
  9 + When I update the <%= resource %>
  10 + Then I should see "<%= resource_class %> updated"
  11 +<% end -%>
... ...
vendor/plugins/blitz/generators/feature/templates/step_definition.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<% if %w(new create).any? { |action| actions.include?(action) } -%>
  2 +When /^I create a <%= resource %> named "([^\"]*)"$/ do |name|
  3 + fills_in :name, :with => name
  4 + click_button 'Create'
  5 +end
  6 +<% elsif %w(edit update).any? { |action| actions.include?(action) } -%>
  7 +When /^I update a post named "([^\"]*)"$/ do |name|
  8 + fills_in :name, :with => name
  9 + click_button 'Update'
  10 +end
  11 +<% end -%>
  12 +
... ...
vendor/plugins/blitz/generators/functional_test/functional_test_generator.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
  2 +
  3 +class FunctionalTestGenerator < Rails::Generator::NamedBase
  4 + def manifest
  5 + record do |m|
  6 + m.class_collisions "#{class_name}ControllerTest"
  7 +
  8 + m.directory File.join('test/functional', class_path)
  9 +
  10 + m.template 'functional_test.rb',
  11 + File.join('test/functional',
  12 + class_path,
  13 + "#{file_name}_controller_test.rb")
  14 + end
  15 + end
  16 +end
  17 +
... ...
vendor/plugins/blitz/generators/functional_test/templates/functional_test.rb 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +require 'test_helper'
  2 +
  3 +class <%= class_name %>ControllerTest < ActionController::TestCase
  4 +<% if actions.include?("index") -%>
  5 + context 'GET to index' do
  6 + setup { get :index }
  7 +
  8 + should_render_template :index
  9 + should_respond_with :success
  10 + end
  11 +
  12 +<% end -%>
  13 +<% if actions.include?("new") -%>
  14 + context 'GET to new' do
  15 + setup { get :new }
  16 +
  17 + should_assign_to :<%= resource %>
  18 + should_render_template :new
  19 + should_respond_with :success
  20 + end
  21 +
  22 +<% end -%>
  23 +<% if actions.include?("create") -%>
  24 + context 'POST to create with valid parameters' do
  25 + setup do
  26 + post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>)
  27 + end
  28 +
  29 + should_set_the_flash_to /created/i
  30 + should_redirect_to('<%= resources %> index') { <%= resources %>_path }
  31 + end
  32 +
  33 +<% end -%>
  34 +<% if actions.include?("show") -%>
  35 + context 'GET to show for existing <%= resource %>' do
  36 + setup do
  37 + @<%= resource %> = Factory(:<%= resource %>)
  38 + get :show, :id => @<%= resource %>.to_param
  39 + end
  40 +
  41 + should_assign_to :<%= resource %>, :equals => '@<%= resource %>'
  42 + should_render_template :show
  43 + should_respond_with :success
  44 + end
  45 +
  46 +<% end -%>
  47 +<% if actions.include?("edit") -%>
  48 + context 'GET to edit for existing <%= resource %>' do
  49 + setup do
  50 + @<%= resource %> = Factory(:<%= resource %>)
  51 + get :edit, :id => @<%= resource %>.to_param
  52 + end
  53 +
  54 + should_assign_to :<%= resource %>, :equals => '@<%= resource %>'
  55 + should_render_template :edit
  56 + should_respond_with :success
  57 + end
  58 +
  59 +<% end -%>
  60 +<% if actions.include?("update") -%>
  61 + context 'PUT to update for existing <%= resource %>' do
  62 + setup do
  63 + @<%= resource %> = Factory(:<%= resource %>)
  64 + put :update, :id => @<%= resource %>.to_param,
  65 + :<%= resource %> => Factory.attributes_for(:<%= resource %>)
  66 + end
  67 +
  68 + should_set_the_flash_to /updated/i
  69 + should_redirect_to('<%= resources %> index') { <%= resources %>_path }
  70 + end
  71 +
  72 +<% end -%>
  73 +<% if actions.include?("destroy") -%>
  74 + context 'given a <%= resource %>' do
  75 + setup { @<%= resource %> = Factory(:<%= resource %>) }
  76 +
  77 + context 'DELETE to destroy' do
  78 + setup { delete :destroy, :id => @<%= resource %>.to_param }
  79 +
  80 + should_set_the_flash_to /deleted/i
  81 + should_redirect_to('<%= resources %> index') { <%= resources %>_path }
  82 + end
  83 + end
  84 +
  85 +<% end -%>
  86 +end
  87 +
... ...
vendor/plugins/blitz/generators/helper/helper_generator.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
  2 +
  3 +class HelperGenerator < Rails::Generator::NamedBase
  4 + def manifest
  5 + record do |m|
  6 + # Check for class naming collisions.
  7 + m.class_collisions "#{class_name}Helper", "#{class_name}HelperTest"
  8 +
  9 + # Helper and test directories.
  10 + m.directory File.join('app/helpers', class_path)
  11 + m.directory File.join('test/unit/helpers', class_path)
  12 +
  13 + # Helper module and test.
  14 + m.template 'helper.rb',
  15 + File.join('app/helpers',
  16 + class_path,
  17 + "#{file_name}_helper.rb")
  18 +
  19 + m.template 'helper_test.rb',
  20 + File.join('test/unit/helpers',
  21 + class_path,
  22 + "#{file_name}_helper_test.rb")
  23 + end
  24 + end
  25 +end
... ...
vendor/plugins/blitz/generators/helper/templates/helper.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +module <%= class_name %>Helper
  2 +end
... ...
vendor/plugins/blitz/generators/helper/templates/helper_test.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +require 'test_helper'
  2 +
  3 +class <%= class_name %>HelperTest < ActionView::TestCase
  4 +end
... ...
vendor/plugins/blitz/generators/model/model_generator.rb 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
  2 +
  3 +class ModelGenerator < Rails::Generator::NamedBase
  4 + default_options :skip_timestamps => false,
  5 + :skip_migration => false,
  6 + :skip_factories => false
  7 +
  8 + def manifest
  9 + record do |m|
  10 + # Check for class naming collisions.
  11 + m.class_collisions class_name, "#{class_name}Test"
  12 +
  13 + # Model, test, and factories directories.
  14 + m.directory File.join('app/models', class_path)
  15 + m.directory File.join('test/unit', class_path)
  16 + m.directory File.join('test/factories', class_path)
  17 +
  18 + # Model class, unit test, and factories.
  19 + m.template 'model.rb', File.join('app/models', class_path,
  20 + "#{file_name}.rb")
  21 + m.template 'unit_test.rb', File.join('test/unit', class_path,
  22 + "#{file_name}_test.rb")
  23 +
  24 + m.template 'factory.rb', File.join('test/factories', "#{file_name}.rb")
  25 +
  26 + unless options[:skip_migration]
  27 + m.migration_template 'migration.rb', 'db/migrate', :assigns => {
  28 + :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
  29 + }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
  30 + end
  31 + end
  32 + end
  33 +
  34 + def factory_line(attribute, file_name)
  35 + if attribute.reference?
  36 + "#{file_name}.association(:#{attribute.name})"
  37 + else
  38 + "#{file_name}.#{attribute.name} #{attribute.default_for_factory}"
  39 + end
  40 + end
  41 +
  42 + protected
  43 +
  44 + def banner
  45 + "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
  46 + end
  47 +
  48 + def add_options!(opt)
  49 + opt.separator ''
  50 + opt.separator 'Options:'
  51 + opt.on("--skip-timestamps",
  52 + "Don't add timestamps to the migration file for this model") { |v|
  53 + options[:skip_timestamps] = v
  54 + }
  55 + opt.on("--skip-migration",
  56 + "Don't generate a migration file for this model") { |v|
  57 + options[:skip_migration] = v
  58 + }
  59 + end
  60 +end
  61 +
  62 +module Rails
  63 + module Generator
  64 + class GeneratedAttribute
  65 + def default_for_factory
  66 + @default ||= case type
  67 + when :integer then "{ 1 }"
  68 + when :float then "{ 1.5 }"
  69 + when :decimal then "{ 9.99 }"
  70 + when :datetime, :timestamp, :time then "{ Time.now.to_s(:db) }"
  71 + when :date then "{ Date.today.to_s(:db) }"
  72 + when :string then "{ 'string' }"
  73 + when :text then "{ 'text' }"
  74 + when :boolean then "{ false }"
  75 + else
  76 + ""
  77 + end
  78 + end
  79 + end
  80 + end
  81 +end
... ...
vendor/plugins/blitz/generators/model/templates/factory.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +Factory.define :<%= file_name %> do |<%= file_name %>|
  2 +<% attributes.each do |attribute| -%>
  3 + <%= factory_line(attribute, file_name) %>
  4 +<% end -%>
  5 +end
... ...
vendor/plugins/blitz/generators/model/templates/migration.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +class <%= migration_name %> < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :<%= table_name %> do |table|
  4 +<% attributes.each do |attribute| -%>
  5 +<% if attribute.type == :paperclip -%>
  6 + table.string :<%= attribute.name %>_file_name, :default => ""
  7 + table.string :<%= attribute.name %>_content_type, :default => ""
  8 + table.integer :<%= attribute.name %>_file_size
  9 + table.datetime :<%= attribute.name %>_updated_at
  10 +<% elsif attribute.type == :string -%>
  11 + table.string :<%= attribute.name %>, :default => ""
  12 +<% else -%>
  13 + table.<%= attribute.type %> :<%= attribute.name %>
  14 +<% end -%>
  15 +<% end -%>
  16 +<% unless options[:skip_timestamps] -%>
  17 + table.timestamps
  18 +<% end -%>
  19 + end
  20 +
  21 +<% attributes.select(&:reference?).each do |attribute| -%>
  22 + add_index :<%= table_name %>, :<%= attribute.name %>_id
  23 +<% end -%>
  24 + end
  25 +
  26 + def self.down
  27 +<% attributes.select(&:reference?).each do |attribute| -%>
  28 + remove_index :<%= table_name %>, :<%= attribute.name %>_id
  29 +<% end -%>
  30 + drop_table :<%= table_name %>
  31 + end
  32 +end
... ...
vendor/plugins/blitz/generators/model/templates/model.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +class <%= class_name %> < ActiveRecord::Base
  2 +<% attributes.select(&:reference?).each do |each| -%>
  3 + belongs_to :<%= each.name %>
  4 +<% end -%>
  5 +<% attributes.select { |each| each.type == :paperclip }.each do |each| -%>
  6 + has_attached_file :<%= each.name %>
  7 +<% end -%>
  8 +end
... ...
vendor/plugins/blitz/generators/model/templates/unit_test.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +require 'test_helper'
  2 +
  3 +class <%= class_name %>Test < ActiveSupport::TestCase
  4 + should "be valid with factory" do
  5 + assert_valid Factory.build(:<%= file_name -%>)
  6 + end
  7 +<% attributes.each do |attribute| -%>
  8 +<% if attribute.reference? -%>
  9 + should_belong_to :<%= attribute.name %>
  10 + should_have_db_index :<%= attribute.name %>_id
  11 +<% end -%>
  12 +<% if attribute.type == :paperclip -%>
  13 + should_have_attached_file :<%= attribute.name %>
  14 +<% end -%>
  15 +<% end -%>
  16 +end
... ...
vendor/plugins/blitz/generators/support/generator_helper.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +require File.join(File.dirname(__FILE__), "insert_commands")
  2 +
  3 +module Blitz
  4 + module GeneratorHelper
  5 + REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed",
  6 + "encrypted_password", "salt", "token", "token_expires_at"]
  7 +
  8 + def resource
  9 + file_name.singularize
  10 + end
  11 +
  12 + def resources
  13 + file_name.pluralize
  14 + end
  15 +
  16 + def resource_class
  17 + class_name.singularize
  18 + end
  19 +
  20 + def columns_for_form
  21 + resource_class.constantize.content_columns.
  22 + collect { |column| [column.name, column.type] }.
  23 + delete_if { |column| remove_column?(column.first) }
  24 + end
  25 +
  26 + def active_record_defined?
  27 + models = Dir.glob(File.join( RAILS_ROOT, 'app', 'models', '*.rb')).
  28 + collect { |path| path[/.+\/(.+).rb/,1] }.
  29 + collect {|model| model.classify }
  30 + models.include?(resource_class)
  31 + end
  32 +
  33 + def remove_column?(column)
  34 + REMOVABLE_COLUMNS.include?(column) ||
  35 + !(column =~ /_id$/).nil?
  36 + end
  37 + end
  38 +end
  39 +
  40 +class Rails::Generator::NamedBase
  41 + include Blitz::GeneratorHelper
  42 +end
  43 +
... ...
vendor/plugins/blitz/generators/support/insert_commands.rb 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +# Pinched some from http://github.com/ryanb/nifty-generators
  2 +
  3 +Rails::Generator::Commands::Base.class_eval do
  4 + def file_contains?(relative_destination, line)
  5 + File.read(destination_path(relative_destination)).include?(line)
  6 + end
  7 +end
  8 +
  9 +Rails::Generator::Commands::Create.class_eval do
  10 + def insert_into(file, line)
  11 + logger.insert "#{line} into #{file}"
  12 + unless file_contains?(file, line)
  13 + gsub_file file, /^(class|module|#{Blitz::Insertable.routes}) .+$/ do |match|
  14 + "#{match}\n #{line}"
  15 + end
  16 + end
  17 + end
  18 +
  19 + def insert_cucumber_path(file, line)
  20 + logger.insert "#{line} into #{file}"
  21 + unless file_contains?(file, line)
  22 + gsub_file file, /#{Blitz::Insertable.cucumber_paths}/ do |match|
  23 + "#{match}\n#{line}"
  24 + end
  25 + end
  26 + end
  27 +end
  28 +
  29 +Rails::Generator::Commands::Destroy.class_eval do
  30 + def insert_into(file, line)
  31 + logger.remove "#{line} from #{file}"
  32 + gsub_file file, "\n #{line}", ''
  33 + end
  34 +end
  35 +
  36 +Rails::Generator::Commands::List.class_eval do
  37 + def insert_into(file, line)
  38 + logger.insert "#{line} into #{file}"
  39 + end
  40 +end
  41 +
  42 +module Blitz
  43 + module Insertable
  44 + def self.routes
  45 + "ActionController::Routing::Routes.draw"
  46 + end
  47 +
  48 + def self.cucumber_paths
  49 + "case page_name\n"
  50 + end
  51 + end
  52 +end
  53 +
... ...
vendor/plugins/blitz/generators/view/templates/view_new.html.erb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<h1>New <%= resource %></h1>
  2 +
  3 +<%% form_for(@<%= resource %>) do |form| %>
  4 + <%%= form.error_messages %>
  5 + <fieldset class="inputs">
  6 +<% if active_record_defined? -%>
  7 +<% columns_for_form.each do |attribute_name, attribute_type| -%>
  8 + <%%= form.<%= attribute_type %> :<%= attribute_name %> %>
  9 +<% end -%>
  10 +<% end -%>
  11 + </fieldset>
  12 + <fieldset class="buttons">
  13 + <%%= form.submit 'Create', :disable_with => 'Please wait...' %>
  14 + </fieldset>
  15 +<%% end %>
... ...
vendor/plugins/blitz/generators/view/templates/view_show.html.erb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +<h1><%= resource %></h1>
  2 +
  3 +<%%= link_to 'Edit', edit_<%= resource %>_path(@<%= resource %>) %>
  4 +
... ...
vendor/plugins/blitz/generators/view/view_generator.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
  2 +
  3 +class ViewGenerator < Rails::Generator::NamedBase
  4 + def manifest
  5 + record do |m|
  6 + m.directory File.join('app/views', class_path, file_name)
  7 +
  8 + if actions.include?("new")
  9 + path = File.join('app/views', class_path, file_name, "new.html.erb")
  10 + m.template 'view_new.html.erb', path
  11 + end
  12 + end
  13 + end
  14 +end
... ...
vendor/plugins/coulda/CHANGELOG.textile
... ... @@ -1,9 +0,0 @@
1   -h1. March 8, 2009
2   -
3   -* Updated functional tests to use shoulda 2.10 should_redirect_to block syntax
4   -
5   -h1. March 7, 2009
6   -
7   -* Added Paperclip option to model generator
8   -* Removed comments on model per complaints by thoughtbot
9   -
vendor/plugins/coulda/README.textile
... ... @@ -1,174 +0,0 @@
1   -h1. Coulda generators
2   -
3   -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.
4   -
5   -h2. Requirements
6   -
7   -* "Cucumber":http://github.com/aslakhellesoy/cucumber
8   -* "Shoulda":http://github.com/thoughtbot/shoulda
9   -* "Factory Girl":http://github.com/thoughtbot/factory_girl
10   -* "Mocha":http://github.com/jferris/mocha
11   -
12   -h2. Installation
13   -
14   - $ script/plugin install git://github.com/dancroak/coulda.git
15   -
16   -h2. Feature generator
17   -
18   - $ script/generate feature Posts new create
19   -
20   -generates...
21   -
22   -<pre><code> Scenario: Create a new post
23   - Given I am on the new post page
24   - When I create a 'post' named 'A new post'
25   - Then I should see 'A new post'</code></pre>
26   -
27   -Now run it:
28   -
29   - $ cucumber features/posts.feature
30   -
31   -The failure will be:
32   -
33   - undefined method `new_post_path'
34   -
35   -To get past this error, we'll create just the route we need:
36   -
37   - map.resources :posts, :only => [:new]
38   -
39   -Running the test again, we have a new failure:
40   -
41   - uninitialized constant PostsController
42   -
43   -h2. Controller test generator
44   -
45   -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.
46   -
47   - $ script/generate controller_test Posts new create
48   -
49   -h2. Controller generator
50   -
51   - $ script/generate controller Posts new create
52   -
53   -generates...
54   -
55   -
56   -h2. Model generator
57   -
58   - $ script/generate model User
59   -
60   -* factory (Factory Girl)
61   -* unit test (Shoulda)
62   -* migration
63   -* model
64   -
65   -h2. Helper generator
66   -
67   - $ script/generate helper Navigation
68   -
69   -* empty helper test file
70   -* empty helper module
71   -
72   -h2. View generator
73   -
74   - $ script/generate view Posts new
75   -
76   -h2. Model generator: belongs_to
77   -
78   - $ script/generate model post user:belongs_to
79   -
80   -generates...
81   -
82   -<pre><code>class CreatePosts < ActiveRecord::Migration
83   - def self.up
84   - create_table :posts do |t|
85   - t.belongs_to :user
86   - t.timestamps
87   - end
88   -
89   - add_index :posts, :user_id
90   - end
91   -
92   - def self.down
93   - remove_index :posts, :user_id
94   - drop_table :posts
95   - end
96   -end
97   -
98   -class Post < ActiveRecord::Base
99   - belongs_to :user
100   -end
101   -
102   -class PostTest < ActiveSupport::TestCase
103   - should_belong_to :user
104   - should_have_index :user_id
105   -end
106   -
107   -Factory.define :post do |post|
108   - post.association(:user)
109   -end</code></pre>
110   -
111   -h2. Model generator: paperclip
112   -
113   - $ script/generate model design image:paperclip
114   -
115   -* all the necessary columns in the migration
116   -* "has_attached_file" in the model
117   -* "should_have_attached_file" in unit test
118   -
119   -<pre><code>class CreateDesigns < ActiveRecord::Migration
120   - def self.up
121   - create_table :designs do |t|
122   - t.string :image_file_name
123   - t.string :image_content_type
124   - t.integer :image_file_size
125   - t.datetime :image_updated_at
126   - t.timestamps
127   - end
128   - end
129   -
130   - def self.down
131   - drop_table :designs
132   - end
133   -end
134   -
135   -class Design < ActiveRecord::Base
136   - has_attached_file :image
137   -end
138   -
139   -class DesignTest < ActiveSupport::TestCase
140   - should "be valid with factory" do
141   - assert_valid Factory.build(:design)
142   - end
143   - should_have_attached_file :image
144   -end</code></pre>
145   -
146   -h2. Attribution
147   -
148   -"Mike Breen":http://github.com/hardbap and "Dan Croak":http://github.com/dancroak
149   -
150   -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
151   -
152   -h2. License
153   -
154   -The MIT License
155   -
156   -Copyright (c) 2008, 2009 Mike Breen
157   -
158   -Permission is hereby granted, free of charge, to any person obtaining a copy
159   -of this software and associated documentation files (the "Software"), to deal
160   -in the Software without restriction, including without limitation the rights
161   -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
162   -copies of the Software, and to permit persons to whom the Software is
163   -furnished to do so, subject to the following conditions:
164   -
165   -The above copyright notice and this permission notice shall be included in
166   -all copies or substantial portions of the Software.
167   -
168   -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169   -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
170   -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
171   -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
172   -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
173   -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
174   -THE SOFTWARE.
vendor/plugins/coulda/Rakefile
... ... @@ -1,10 +0,0 @@
1   -require 'rake'
2   -require 'rake/testtask'
3   -
4   -require 'cucumber/rake/task'
5   -Cucumber::Rake::Task.new(:features) do |features|
6   - features.cucumber_opts = "features --format progress"
7   -end
8   -
9   -task :default => [:features]
10   -
vendor/plugins/coulda/features/controller_generator.feature
... ... @@ -1,61 +0,0 @@
1   -Feature: Rails controller generator
2   - In order to better do Test-Driven Development with Rails
3   - As a user
4   - I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
5   -
6   - Scenario: Controller generator for index action
7   - Given a Rails app
8   - And the coulda plugin is installed
9   - When I generate a "Posts" controller with "index" action
10   - Then a standard "index" functional test for "posts" should be generated
11   - And an empty "index" controller action for "posts" should be generated
12   -
13   - Scenario: Controller generator for new action
14   - Given a Rails app
15   - And the coulda plugin is installed
16   - When I generate a "Posts" controller with "new" action
17   - Then a standard "new" functional test for "posts" should be generated
18   - And a "new" controller action for "posts" should be generated
19   -
20   - Scenario: Controller generator for create action
21   - Given a Rails app
22   - And the coulda plugin is installed
23   - When I generate a "Posts" controller with "create" action
24   - Then a standard "create" functional test for "posts" should be generated
25   - And a "create" controller action for "posts" should be generated
26   -
27   - Scenario: Controller generator for create action when Cucumber is installed
28   - Given a Rails app with Cucumber
29   - And the coulda plugin is installed
30   - When I generate a "Posts" controller with "create" action
31   - Then a standard "create" functional test for "posts" should be generated
32   - And a "create" controller action for "posts" should be generated
33   -
34   - Scenario: Controller generator for show action
35   - Given a Rails app
36   - And the coulda plugin is installed
37   - When I generate a "Posts" controller with "show" action
38   - Then a standard "show" functional test for "posts" should be generated
39   - And a "show" controller action for "posts" should be generated
40   -
41   - Scenario: Controller generator for edit action
42   - Given a Rails app
43   - And the coulda plugin is installed
44   - When I generate a "Posts" controller with "edit" action
45   - Then a standard "edit" functional test for "posts" should be generated
46   - And a "edit" controller action for "posts" should be generated
47   -
48   - Scenario: Controller generator for update action
49   - Given a Rails app
50   - And the coulda plugin is installed
51   - When I generate a "Posts" controller with "update" action
52   - Then a standard "update" functional test for "posts" should be generated
53   - And a "update" controller action for "posts" should be generated
54   -
55   - Scenario: Controller generator for destroy action
56   - Given a Rails app
57   - And the coulda plugin is installed
58   - When I generate a "Posts" controller with "destroy" action
59   - Then a standard "destroy" functional test for "posts" should be generated
60   - And a "destroy" controller action for "posts" should be generated
61   -
vendor/plugins/coulda/features/feature_generator.feature
... ... @@ -1,37 +0,0 @@
1   -Feature: Rails controller generator
2   - In order to better do Test-Driven Development with Rails
3   - As a user
4   - I want to generate Shoulda & Factory Girl tests for only RESTful actions I need.
5   -
6   - Scenario: Feature generator for new action
7   - Given a Rails app with Cucumber
8   - And the coulda plugin is installed
9   - When I generate a "new" feature for "Posts"
10   - Then a "posts" feature for the "create" scenario should be generated
11   - And a "create posts" step definition should be generated
12   - And a new post page path should be generated
13   -
14   - Scenario: Feature generator for create action same as new
15   - Given a Rails app with Cucumber
16   - And the coulda plugin is installed
17   - When I generate a "create" feature for "Posts"
18   - Then a "posts" feature for the "create" scenario should be generated
19   - And a "create posts" step definition should be generated
20   - And a new post page path should be generated
21   -
22   - Scenario: Feature generator for edit action
23   - Given a Rails app with Cucumber
24   - And the coulda plugin is installed
25   - When I generate a "edit" feature for "Posts"
26   - Then a "posts" feature for the "edit" scenario should be generated
27   - And a "update posts" step definition should be generated
28   - And a edit post page path should be generated
29   -
30   - Scenario: Feature generator for update action same as edit
31   - Given a Rails app with Cucumber
32   - And the coulda plugin is installed
33   - When I generate a "update" feature for "Posts"
34   - Then a "posts" feature for the "update" scenario should be generated
35   - And a "update posts" step definition should be generated
36   - And a edit post page path should be generated
37   -
vendor/plugins/coulda/features/helper_generator.feature
... ... @@ -1,12 +0,0 @@
1   -Feature: Rails helper generator
2   - In order to better do Test-Driven Development with Rails
3   - As a user
4   - I want to generate just the module and test I need.
5   -
6   - Scenario: Helper
7   - Given a Rails app
8   - And the coulda plugin is installed
9   - When I generate a helper named "Navigation"
10   - Then a helper should be generated for "Navigation"
11   - And a helper test should be generated for "Navigation"
12   -
vendor/plugins/coulda/features/model_generator.feature
... ... @@ -1,37 +0,0 @@
1   -Feature: Rails model generator
2   - In order to better do Test-Driven Development with Rails
3   - As a user
4   - I want to generate a Factory definition and Shoulda tests.
5   -
6   - Scenario: Model generator without attributes
7   - Given a Rails app
8   - And the coulda plugin is installed
9   - When I generate a model named "User"
10   - Then a factory should be generated for "User"
11   - And a unit test should be generated for "User"
12   -
13   - Scenario: Model generator with attributes
14   - Given a Rails app
15   - And the coulda plugin is installed
16   - When I generate a model "User" with a string "email"
17   - Then a factory for "User" should have an "email" string
18   - And a unit test should be generated for "User"
19   -
20   - Scenario: Model generator with association
21   - Given a Rails app
22   - And the coulda plugin is installed
23   - When I generate a model "Post" that belongs to a "User"
24   - Then a factory for "Post" should have an association to "User"
25   - And the "Post" unit test should have "should_belong_to :user" macro
26   - And the "Post" unit test should have "should_have_db_index :user_id" macro
27   - And the "posts" table should have db index on "user_id"
28   - And the "Post" model should have "belongs_to :user" macro
29   -
30   - Scenario: Model generator with Paperclip
31   - Given a Rails app
32   - And the coulda plugin is installed
33   - When I generate a model "Design" with file "Image"
34   - Then the "Design" model should have "has_attached_file :image" macro
35   - And the "Design" unit test should have "should_have_attached_file :image" macro
36   - And the "designs" table should have paperclip columns for "image"
37   -
vendor/plugins/coulda/features/step_definitions/controller_steps.rb
... ... @@ -1,163 +0,0 @@
1   -When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, action|
2   - system "cd #{@rails_root} && " <<
3   - "script/generate controller #{controller} #{action} && " <<
4   - "cd .."
5   -end
6   -
7   -Then /^a standard "index" functional test for "posts" should be generated$/ do
8   - assert_generated_file("test/functional/posts_controller_test.rb") do
9   - " context 'GET to index' do\n" <<
10   - " setup { get :index }\n\n" <<
11   - " should_render_template :index\n" <<
12   - " should_respond_with :success\n" <<
13   - " end"
14   - end
15   -end
16   -
17   -Then /^an empty "index" controller action for "posts" should be generated$/ do
18   - assert_generated_file("app/controllers/posts_controller.rb") do
19   - " def index\n" <<
20   - " end"
21   - end
22   -end
23   -
24   -Then /^a standard "new" functional test for "posts" should be generated$/ do
25   - assert_generated_file("test/functional/posts_controller_test.rb") do
26   - " context 'GET to new' do\n" <<
27   - " setup { get :new }\n\n" <<
28   - " should_assign_to :post\n" <<
29   - " should_render_template :new\n" <<
30   - " should_respond_with :success\n" <<
31   - " end"
32   - end
33   -end
34   -
35   -Then /^a standard "create" functional test for "posts" should be generated$/ do
36   - assert_generated_file("test/functional/posts_controller_test.rb") do
37   - " context 'POST to create with valid parameters' do\n" <<
38   - " setup do\n" <<
39   - " post :create, :post => Factory.attributes_for(:post)\n" <<
40   - " end\n\n" <<
41   - " should_set_the_flash_to /created/i\n" <<
42   - " should_redirect_to('posts index') { posts_path }\n" <<
43   - " end"
44   - end
45   -end
46   -
47   -Then /^a standard "show" functional test for "posts" should be generated$/ do
48   - assert_generated_file("test/functional/posts_controller_test.rb") do
49   - " context 'GET to show for existing post' do\n" <<
50   - " setup do\n" <<
51   - " @post = Factory(:post)\n" <<
52   - " get :show, :id => @post.to_param\n" <<
53   - " end\n\n" <<
54   - " should_assign_to :post, :equals => '@post'\n" <<
55   - " should_render_template :show\n" <<
56   - " should_respond_with :success\n" <<
57   - " end"
58   - end
59   -end
60   -
61   -Then /^a standard "edit" functional test for "posts" should be generated$/ do
62   - assert_generated_file("test/functional/posts_controller_test.rb") do
63   - " context 'GET to edit for existing post' do\n" <<
64   - " setup do\n" <<
65   - " @post = Factory(:post)\n" <<
66   - " get :edit, :id => @post.to_param\n" <<
67   - " end\n\n" <<
68   - " should_assign_to :post, :equals => '@post'\n" <<
69   - " should_render_template :edit\n" <<
70   - " should_respond_with :success\n" <<
71   - " end"
72   - end
73   -end
74   -
75   -Then /^a standard "update" functional test for "posts" should be generated$/ do
76   - assert_generated_file("test/functional/posts_controller_test.rb") do
77   - " context 'PUT to update for existing post' do\n" <<
78   - " setup do\n" <<
79   - " @post = Factory(:post)\n" <<
80   - " put :update, :id => @post.to_param,\n" <<
81   - " :post => Factory.attributes_for(:post)\n" <<
82   - " end\n\n" <<
83   - " should_set_the_flash_to /updated/i\n" <<
84   - " should_redirect_to('posts index') { posts_path }\n" <<
85   - " end"
86   - end
87   -end
88   -
89   -Then /^a standard "destroy" functional test for "posts" should be generated$/ do
90   - assert_generated_file("test/functional/posts_controller_test.rb") do
91   - " context 'given a post' do\n" <<
92   - " setup { @post = Factory(:post) }\n\n" <<
93   - " context 'DELETE to destroy' do\n" <<
94   - " setup { delete :destroy, :id => @post.to_param }\n\n" <<
95   - " should_destroy :post\n" <<
96   - " should_set_the_flash_to /deleted/i\n" <<
97   - " should_redirect_to('posts index') { posts_path }\n" <<
98   - " end\n" <<
99   - " end"
100   - end
101   -end
102   -
103   -Then /^a "new" controller action for "posts" should be generated$/ do
104   - assert_generated_file("app/controllers/posts_controller.rb") do
105   - " def new\n" <<
106   - " @post = Post.new\n" <<
107   - " end"
108   - end
109   -end
110   -
111   -Then /^a "create" controller action for "posts" should be generated$/ do
112   - assert_generated_file("app/controllers/posts_controller.rb") do
113   - " def create\n" <<
114   - " @post = Post.new(params[:post])\n" <<
115   - " @post.save\n" <<
116   - " flash[:success] = 'Post created.'\n" <<
117   - " redirect_to posts_path\n" <<
118   - " end"
119   - end
120   -end
121   -
122   -Then /^a "show" controller action for "posts" should be generated$/ do
123   - assert_generated_file("app/controllers/posts_controller.rb") do
124   - " def show\n" <<
125   - " @post = Post.find(params[:id])\n" <<
126   - " end"
127   - end
128   -end
129   -
130   -Then /^a "edit" controller action for "posts" should be generated$/ do
131   - assert_generated_file("app/controllers/posts_controller.rb") do
132   - " def edit\n" <<
133   - " @post = Post.find(params[:id])\n" <<
134   - " end"
135   - end
136   -end
137   -
138   -Then /^a "update" controller action for "posts" should be generated$/ do
139   - assert_generated_file("app/controllers/posts_controller.rb") do
140   - " def update\n" <<
141   - " @post = Post.find(params[:id])\n" <<
142   - " @post.update_attributes(params[:post])\n" <<
143   - " flash[:success] = 'Post updated.'\n" <<
144   - " redirect_to posts_path\n" <<
145   - " end"
146   - end
147   -end
148   -
149   -Then /^a "destroy" controller action for "posts" should be generated$/ do
150   - assert_generated_file("app/controllers/posts_controller.rb") do
151   - " def destroy\n" <<
152   - " @post = Post.find(params[:id])\n" <<
153   - " @post.destroy\n" <<
154   - " flash[:success] = 'Post deleted.'\n" <<
155   - " redirect_to posts_path\n" <<
156   - " end"
157   - end
158   -end
159   -
160   -Then /^only a "([^\"]*)" action for RESTful "([^\"]*)" route should be generated$/ do |action, resource|
161   - assert_generated_route_for resource, action
162   -end
163   -
vendor/plugins/coulda/features/step_definitions/cucumber_steps.rb
... ... @@ -1,64 +0,0 @@
1   -Given /^a Rails app with Cucumber$/ do
2   - system "rails rails_root"
3   - @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root")
4   - require 'cucumber'
5   - system "cd #{@rails_root} && ruby script/generate cucumber"
6   -end
7   -
8   -When /^I generate a "([^\"]*)" feature for "([^\"]*)"$/ do |feature, resource|
9   - system "cd #{@rails_root} && " <<
10   - "script/generate feature #{resource} #{feature} && " <<
11   - "cd .."
12   -end
13   -
14   -Then /^a "posts" feature for the "([^\"]*)" scenario should be generated$/ do |action|
15   - if %w(new create).include?(action)
16   - assert_generated_file("features/posts.feature") do
17   - " Scenario: Create a new post\n" <<
18   - " Given I am on the new post page\n" <<
19   - " When I create a post named \"A new post\"\n" <<
20   - " Then I should see \"A new post\""
21   - end
22   - elsif %w(edit update).include?(action)
23   - assert_generated_file("features/posts.feature") do
24   - " Scenario: Update a post\n" <<
25   - " Given I am on the edit \"An existing post\" post page\n" <<
26   - " When I update the post\n" <<
27   - " Then I should see \"Post updated\""
28   - end
29   - end
30   -end
31   -
32   -Then /^a "create posts" step definition should be generated$/ do
33   - assert_generated_file("features/step_definitions/posts_steps.rb") do
34   - "When /^I create a post named \"([^\\\"]*)\"$/ do |name|\n" <<
35   - " fills_in :name, :with => name\n" <<
36   - " click_button 'Create'\n"
37   - "end"
38   - end
39   -end
40   -
41   -Then /^a new post page path should be generated$/ do
42   - assert_generated_file("features/support/paths.rb") do
43   - " when /the new post page/i\n" <<
44   - " new_post_path"
45   - end
46   -end
47   -
48   -Then /^a "update posts" step definition should be generated$/ do
49   - assert_generated_file("features/step_definitions/posts_steps.rb") do
50   - "When /^I update a post named \"([^\\\"]*)\"$/ do |name|\n" <<
51   - " fills_in :name, :with => name\n" <<
52   - " click_button 'Update'\n"
53   - "end"
54   - end
55   -end
56   -
57   -Then /^a edit post page path should be generated$/ do
58   - assert_generated_file("features/support/paths.rb") do
59   - " when /the edit \"([^\\\"]*)\" post page/i do |name|\n" <<
60   - " post = Post.find_by_name(name)\n"
61   - " edit_post_path(post)"
62   - end
63   -end
64   -
vendor/plugins/coulda/features/step_definitions/generator_steps.rb
... ... @@ -1,16 +0,0 @@
1   -Given 'a Rails app' do
2   - system "rails rails_root"
3   - @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root")
4   -end
5   -
6   -Given /^the coulda plugin is installed$/ do
7   - plugin_dir = File.join(@rails_root, "vendor", "plugins")
8   - target = File.join(File.dirname(__FILE__), "..", "..", "generators")
9   - FileUtils.mkdir_p "#{plugin_dir}/coulda"
10   - system "cp -r #{target} #{plugin_dir}/coulda"
11   -end
12   -
13   -After do
14   - FileUtils.rm_rf @rails_root if @rails_root
15   -end
16   -
vendor/plugins/coulda/features/step_definitions/helper_steps.rb
... ... @@ -1,14 +0,0 @@
1   -When /^I generate a helper named "(.*)"$/ do |name|
2   - system "cd #{@rails_root} && " <<
3   - "script/generate helper #{name} && " <<
4   - "cd .."
5   -end
6   -
7   -Then /^a helper should be generated for "(.*)"$/ do |name|
8   - assert_generated_file("app/helpers/#{name}_helper.rb")
9   -end
10   -
11   -Then /^a helper test should be generated for "(.*)"$/ do |name|
12   - assert_generated_file("test/unit/helpers/#{name}_helper_test.rb")
13   -end
14   -
vendor/plugins/coulda/features/step_definitions/migration_steps.rb
... ... @@ -1,30 +0,0 @@
1   -Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table|
2   - assert_generated_migration(table) do
3   - " add_column :#{table}, :#{attr}_file_name, :string, :default => \"\"\n" <<
4   - " add_column :#{table}, :#{attr}_content_type, :string, :default => \"\"\n" <<
5   - " add_column :#{table}, :#{attr}_file_size, :integer, :default => \"\"\n" <<
6   - " add_column :#{table}, :#{attr}_updated_at, :datetime, :default => \"\""
7   - end
8   - assert_generated_migration(table) do
9   - " remove_column :#{table}, :#{attr}_file_name\n" <<
10   - " remove_column :#{table}, :#{attr}_content_type\n" <<
11   - " remove_column :#{table}, :#{attr}_file_size\n" <<
12   - " remove_column :#{table}, :#{attr}_updated_at"
13   - end
14   -end
15   -
16   -Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key|
17   - assert_generated_migration(table) do
18   - "add_index :#{table}, :#{foreign_key}"
19   - end
20   -end
21   -
22   -Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr|
23   - assert_generated_migration(table) do
24   - " table.string :#{attr}_file_name, :default => \"\"\n" <<
25   - " table.string :#{attr}_content_type, :default => \"\"\n" <<
26   - " table.integer :#{attr}_file_size\n" <<
27   - " table.datetime :#{attr}_updated_at"
28   - end
29   -end
30   -
vendor/plugins/coulda/features/step_definitions/model_steps.rb
... ... @@ -1,89 +0,0 @@
1   -# GENERATION
2   -
3   -When /^I generate a model named "(.*)"$/ do |model|
4   - system "cd #{@rails_root} && " <<
5   - "script/generate model #{model} && " <<
6   - "cd .."
7   -end
8   -
9   -When /^I generate a model "(.*)" with a (.*) "(.*)"$/ do |model, attr_type, attr_name|
10   - system "cd #{@rails_root} && " <<
11   - "script/generate model #{model} #{attr_name}:#{attr_type} && " <<
12   - "cd .."
13   -end
14   -
15   -When /^I generate a model "(.*)" that belongs to a "(.*)"$/ do |model, association|
16   - association.downcase!
17   - system "cd #{@rails_root} && " <<
18   - "script/generate model #{model} #{association}:belongs_to && " <<
19   - "cd .."
20   -end
21   -
22   -When /^I generate a model "(.*)" with file "(.*)"$/ do |model, file|
23   - file.downcase!
24   - system "cd #{@rails_root} && " <<
25   - "script/generate model #{model} #{file}:paperclip && " <<
26   - "cd .."
27   -end
28   -
29   -When /^I generate a Post model with title, body, and User$/ do
30   - system "cd #{@rails_root} && " <<
31   - "script/generate model Post title:string body:text user:belongs_to && " <<
32   - "rake db:migrate " <<
33   - "cd .."
34   -end
35   -
36   -# MODEL
37   -
38   -Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro|
39   - model.downcase!
40   - assert_generated_file("app/models/#{model}.rb") do
41   - macro
42   - end
43   -end
44   -
45   -# FACTORY
46   -
47   -Then /^a factory should be generated for "(.*)"$/ do |model|
48   - model.downcase!
49   - assert_generated_file("test/factories/#{model}.rb") do
50   - "Factory.define :#{model.downcase} do |#{model.downcase}|\n" <<
51   - "end\n"
52   - end
53   -end
54   -
55   -Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type|
56   - model.downcase!
57   - assert_generated_file("test/factories/#{model}.rb") do
58   - "Factory.define :#{model} do |#{model}|\n" <<
59   - " #{model}.#{attr_name} { '#{attr_type}' }\n" <<
60   - "end\n"
61   - end
62   -end
63   -
64   -Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model|
65   - model.downcase!
66   - associated_model.downcase!
67   - assert_generated_file("test/factories/#{model}.rb") do
68   - "Factory.define :#{model} do |#{model}|\n" <<
69   - " #{model}.association(:#{associated_model})\n" <<
70   - "end\n"
71   - end
72   -end
73   -
74   -# UNIT TEST
75   -
76   -Then /^a unit test should be generated for "(.*)"$/ do |model|
77   - model.downcase!
78   - assert_generated_file("test/unit/#{model}_test.rb") do
79   - "assert_valid Factory.build(:#{model})"
80   - end
81   -end
82   -
83   -Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro|
84   - model.downcase!
85   - assert_generated_file("test/unit/#{model}_test.rb") do
86   - macro
87   - end
88   -end
89   -
vendor/plugins/coulda/features/step_definitions/view_steps.rb
... ... @@ -1,36 +0,0 @@
1   -When /^I generate a "([^\"]*)" view for "([^\"]*)"$/ do |view, resource|
2   - system "cd #{@rails_root} && " <<
3   - "script/generate view #{resource} #{view} && " <<
4   - "cd .."
5   -end
6   -
7   -When /^a SemiFormal "new" view for "posts" should be generated$/ do
8   - assert_generated_file("app/views/posts/new.html.erb") do
9   - "<h1>New post</h1>\n\n" <<
10   - "<% form_for(@post) do |form| %>\n" <<
11   - " <%= form.error_messages %>\n" <<
12   - " <fieldset class=\"inputs\">\n" <<
13   - " </fieldset>\n" <<
14   - " <fieldset class=\"buttons\">\n" <<
15   - " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
16   - " </fieldset>\n" <<
17   - "<% end %>"
18   - end
19   -end
20   -
21   -Then /^a SemiFormal "new" view for "posts" should be generated with fields$/ do
22   - assert_generated_file("app/views/posts/new.html.erb") do
23   - "<h1>New post</h1>\n\n" <<
24   - "<% form_for(@post) do |form| %>\n" <<
25   - " <%= form.error_messages %>\n" <<
26   - " <fieldset class=\"inputs\">\n" <<
27   - " <%= form.string :title %>\n" <<
28   - " <%= form.text :body %>\n" <<
29   - " </fieldset>\n" <<
30   - " <fieldset class=\"buttons\">\n" <<
31   - " <%= form.submit 'Create', :disable_with => 'Please wait...' %>\n" <<
32   - " </fieldset>\n" <<
33   - "<% end %>"
34   - end
35   -end
36   -
vendor/plugins/coulda/features/support/env.rb
... ... @@ -1,63 +0,0 @@
1   -require 'test/unit'
2   -
3   -module Test::Unit::Assertions
4   -
5   - def assert_generated_file(path)
6   - assert_file_exists(path)
7   - if block_given?
8   - File.open(File.join(@rails_root, path)) do |file|
9   - expected = yield
10   - body = file.read
11   - assert body.include?(expected),
12   - "expected #{expected} but was #{body.inspect}"
13   - end
14   - end
15   - end
16   -
17   - def assert_file_exists(path)
18   - file = File.join(@rails_root, path)
19   -
20   - assert File.exists?(file), "#{file} expected to exist, but did not"
21   - assert File.file?(file), "#{file} expected to be a file, but is not"
22   - end
23   -
24   - def assert_generated_views_for(name, *actions)
25   - actions.each do |action|
26   - assert_generated_file("app/views/#{name}/#{action}.html.erb") do
27   - yield if block_given?
28   - end
29   - end
30   - end
31   -
32   - def assert_generated_migration(name)
33   - file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first
34   - file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb"
35   - assert_generated_file(file) { "timestamps" }
36   - assert_generated_file(file) { yield if block_given? }
37   - end
38   -
39   - def assert_generated_route_for(name, *actions)
40   - routeable_actions = actions.collect { |action| ":#{action}" }.join(", ")
41   - assert_generated_file("config/routes.rb") do
42   - " map.resources :#{name.to_s}, :only => [#{routeable_actions}]"
43   - end
44   - end
45   -
46   - def assert_has_empty_method(body, *methods)
47   - methods.each do |name|
48   - assert body.include?(" def #{name}\n end"),
49   - "should have method #{name} in #{body.inspect}"
50   - yield(name, $2) if block_given?
51   - end
52   - end
53   -
54   -end
55   -
56   -class CouldaWorld
57   - include Test::Unit::Assertions
58   -end
59   -
60   -World do
61   - CouldaWorld.new
62   -end
63   -
vendor/plugins/coulda/features/view_generator.feature
... ... @@ -1,18 +0,0 @@
1   -Feature: Rails view generator
2   - In order to do Test-Driven Development with Rails
3   - As a developer
4   - I want to generate a view to make a functional test pass
5   -
6   - Scenario: View generator for new action
7   - Given a Rails app
8   - And the coulda plugin is installed
9   - When I generate a "new" view for "Posts"
10   - Then a SemiFormal "new" view for "posts" should be generated
11   -
12   - Scenario: View generator for new action
13   - Given a Rails app
14   - And the coulda plugin is installed
15   - When I generate a Post model with title, body, and User
16   - And I generate a "new" view for "Posts"
17   - Then a SemiFormal "new" view for "posts" should be generated with fields
18   -
vendor/plugins/coulda/generators/controller/controller_generator.rb
... ... @@ -1,26 +0,0 @@
1   -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
2   -
3   -class ControllerGenerator < Rails::Generator::NamedBase
4   - def manifest
5   - record do |m|
6   - m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest"
7   -
8   - m.directory File.join('app/controllers', class_path)
9   - m.directory File.join('test/functional', class_path)
10   -
11   - m.template 'controller.rb',
12   - File.join('app/controllers',
13   - class_path,
14   - "#{file_name}_controller.rb")
15   -
16   - m.template 'functional_test.rb',
17   - File.join('test/functional',
18   - class_path,
19   - "#{file_name}_controller_test.rb")
20   - end
21   - end
22   -
23   - def routeable_actions
24   - actions.collect { |action| ":#{action}" }.join(", ")
25   - end
26   -end
vendor/plugins/coulda/generators/controller/templates/controller.rb
... ... @@ -1,52 +0,0 @@
1   -class <%= class_name %>Controller < ApplicationController
2   -<% if actions.include?("index") -%>
3   - def index
4   - end
5   -
6   -<% end -%>
7   -<% if actions.include?("new") -%>
8   - def new
9   - @<%= resource %> = <%= resource_class %>.new
10   - end
11   -
12   -<% end -%>
13   -<% if actions.include?("create") -%>
14   - def create
15   - @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>])
16   - @<%= resource %>.save
17   - flash[:success] = '<%= resource_class %> created.'
18   - redirect_to <%= resources %>_path
19   - end
20   -
21   -<% end -%>
22   -<% if actions.include?("show") -%>
23   - def show
24   - @<%= resource %> = <%= resource_class %>.find(params[:id])
25   - end
26   -
27   -<% end -%>
28   -<% if actions.include?("edit") -%>
29   - def edit
30   - @<%= resource %> = <%= resource_class %>.find(params[:id])
31   - end
32   -
33   -<% end -%>
34   -<% if actions.include?("update") -%>
35   - def update
36   - @<%= resource %> = <%= resource_class %>.find(params[:id])
37   - @<%= resource %>.update_attributes(params[:<%= resource %>])
38   - flash[:success] = '<%= resource_class %> updated.'
39   - redirect_to <%= resources %>_path
40   - end
41   -
42   -<% end -%>
43   -<% if actions.include?("destroy") -%>
44   - def destroy
45   - @<%= resource %> = <%= resource_class %>.find(params[:id])
46   - @<%= resource %>.destroy
47   - flash[:success] = '<%= resource_class %> deleted.'
48   - redirect_to <%= resources %>_path
49   - end
50   -
51   -<% end -%>
52   -end
vendor/plugins/coulda/generators/controller/templates/functional_test.rb
... ... @@ -1,88 +0,0 @@
1   -require 'test_helper'
2   -
3   -class <%= class_name %>ControllerTest < ActionController::TestCase
4   -<% if actions.include?("index") -%>
5   - context 'GET to index' do
6   - setup { get :index }
7   -
8   - should_render_template :index
9   - should_respond_with :success
10   - end
11   -
12   -<% end -%>
13   -<% if actions.include?("new") -%>
14   - context 'GET to new' do
15   - setup { get :new }
16   -
17   - should_assign_to :<%= resource %>
18   - should_render_template :new
19   - should_respond_with :success
20   - end
21   -
22   -<% end -%>
23   -<% if actions.include?("create") -%>
24   - context 'POST to create with valid parameters' do
25   - setup do
26   - post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>)
27   - end
28   -
29   - should_set_the_flash_to /created/i
30   - should_redirect_to('<%= resources %> index') { <%= resources %>_path }
31   - end
32   -
33   -<% end -%>
34   -<% if actions.include?("show") -%>
35   - context 'GET to show for existing <%= resource %>' do
36   - setup do
37   - @<%= resource %> = Factory(:<%= resource %>)
38   - get :show, :id => @<%= resource %>.to_param
39   - end
40   -
41   - should_assign_to :<%= resource %>, :equals => '@<%= resource %>'
42   - should_render_template :show
43   - should_respond_with :success
44   - end
45   -
46   -<% end -%>
47   -<% if actions.include?("edit") -%>
48   - context 'GET to edit for existing <%= resource %>' do
49   - setup do
50   - @<%= resource %> = Factory(:<%= resource %>)
51   - get :edit, :id => @<%= resource %>.to_param
52   - end
53   -
54   - should_assign_to :<%= resource %>, :equals => '@<%= resource %>'
55   - should_render_template :edit
56   - should_respond_with :success
57   - end
58   -
59   -<% end -%>
60   -<% if actions.include?("update") -%>
61   - context 'PUT to update for existing <%= resource %>' do
62   - setup do
63   - @<%= resource %> = Factory(:<%= resource %>)
64   - put :update, :id => @<%= resource %>.to_param,
65   - :<%= resource %> => Factory.attributes_for(:<%= resource %>)
66   - end
67   -
68   - should_set_the_flash_to /updated/i
69   - should_redirect_to('<%= resources %> index') { <%= resources %>_path }
70   - end
71   -
72   -<% end -%>
73   -<% if actions.include?("destroy") -%>
74   - context 'given a <%= resource %>' do
75   - setup { @<%= resource %> = Factory(:<%= resource %>) }
76   -
77   - context 'DELETE to destroy' do
78   - setup { delete :destroy, :id => @<%= resource %>.to_param }
79   -
80   - should_destroy :<%= resource %>
81   - should_set_the_flash_to /deleted/i
82   - should_redirect_to('<%= resources %> index') { <%= resources %>_path }
83   - end
84   - end
85   -
86   -<% end -%>
87   -end
88   -
vendor/plugins/coulda/generators/feature/feature_generator.rb
... ... @@ -1,32 +0,0 @@
1   -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
2   -
3   -class FeatureGenerator < Rails::Generator::NamedBase
4   - def manifest
5   - record do |m|
6   - m.directory 'features'
7   - m.directory 'features/step_definitions'
8   - m.directory 'features/support'
9   -
10   - path = File.join('features', "#{resources}.feature")
11   - m.template 'feature.feature', path
12   -
13   - path = File.join('features', 'step_definitions', "#{resources}_steps.rb")
14   - m.template 'step_definition.rb', path
15   -
16   - path = File.join('features', 'support', "paths.rb")
17   - m.insert_cucumber_path path, insertable_path
18   - end
19   - end
20   -
21   - def insertable_path
22   - if %w(new create).any? { |action| actions.include?(action) }
23   - " when /the new #{resource} page/i\n" <<
24   - " new_#{resource}_path\n"
25   - elsif %w(edit update).any? { |action| actions.include?(action) }
26   - " when /the edit \"([^\\\"]*)\" #{resource} page/i do |name|\n" <<
27   - " post = #{resource_class}.find_by_name(name)\n"
28   - " edit_#{resource}_path(#{resource})"
29   - end
30   - end
31   -end
32   -
vendor/plugins/coulda/generators/feature/templates/feature.feature
... ... @@ -1,11 +0,0 @@
1   -<% if %w(new create).any? { |action| actions.include?(action) } -%>
2   - Scenario: Create a new <%= resource %>
3   - Given I am on the new <%= resource %> page
4   - When I create a <%= resource %> named "A new <%= resource %>"
5   - Then I should see "A new <%= resource %>"
6   -<% elsif %w(edit update).any? { |action| actions.include?(action) } -%>
7   - Scenario: Update a <%= resource %>
8   - Given I am on the edit "An existing <%= resource %>" <%= resource %> page
9   - When I update the <%= resource %>
10   - Then I should see "<%= resource_class %> updated"
11   -<% end -%>
vendor/plugins/coulda/generators/feature/templates/step_definition.rb
... ... @@ -1,12 +0,0 @@
1   -<% if %w(new create).any? { |action| actions.include?(action) } -%>
2   -When /^I create a <%= resource %> named "([^\"]*)"$/ do |name|
3   - fills_in :name, :with => name
4   - click_button 'Create'
5   -end
6   -<% elsif %w(edit update).any? { |action| actions.include?(action) } -%>
7   -When /^I update a post named "([^\"]*)"$/ do |name|
8   - fills_in :name, :with => name
9   - click_button 'Update'
10   -end
11   -<% end -%>
12   -
vendor/plugins/coulda/generators/helper/helper_generator.rb
... ... @@ -1,25 +0,0 @@
1   -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
2   -
3   -class HelperGenerator < Rails::Generator::NamedBase
4   - def manifest
5   - record do |m|
6   - # Check for class naming collisions.
7   - m.class_collisions "#{class_name}Helper", "#{class_name}HelperTest"
8   -
9   - # Helper and test directories.
10   - m.directory File.join('app/helpers', class_path)
11   - m.directory File.join('test/unit/helpers', class_path)
12   -
13   - # Helper module and test.
14   - m.template 'helper.rb',
15   - File.join('app/helpers',
16   - class_path,
17   - "#{file_name}_helper.rb")
18   -
19   - m.template 'helper_test.rb',
20   - File.join('test/unit/helpers',
21   - class_path,
22   - "#{file_name}_helper_test.rb")
23   - end
24   - end
25   -end
vendor/plugins/coulda/generators/helper/templates/helper.rb
... ... @@ -1,2 +0,0 @@
1   -module <%= class_name %>Helper
2   -end
vendor/plugins/coulda/generators/helper/templates/helper_test.rb
... ... @@ -1,4 +0,0 @@
1   -require 'test_helper'
2   -
3   -class <%= class_name %>HelperTest < ActionView::TestCase
4   -end
vendor/plugins/coulda/generators/model/model_generator.rb
... ... @@ -1,81 +0,0 @@
1   -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
2   -
3   -class ModelGenerator < Rails::Generator::NamedBase
4   - default_options :skip_timestamps => false,
5   - :skip_migration => false,
6   - :skip_factories => false
7   -
8   - def manifest
9   - record do |m|
10   - # Check for class naming collisions.
11   - m.class_collisions class_name, "#{class_name}Test"
12   -
13   - # Model, test, and factories directories.
14   - m.directory File.join('app/models', class_path)
15   - m.directory File.join('test/unit', class_path)
16   - m.directory File.join('test/factories', class_path)
17   -
18   - # Model class, unit test, and factories.
19   - m.template 'model.rb', File.join('app/models', class_path,
20   - "#{file_name}.rb")
21   - m.template 'unit_test.rb', File.join('test/unit', class_path,
22   - "#{file_name}_test.rb")
23   -
24   - m.template 'factory.rb', File.join('test/factories', "#{file_name}.rb")
25   -
26   - unless options[:skip_migration]
27   - m.migration_template 'migration.rb', 'db/migrate', :assigns => {
28   - :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
29   - }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
30   - end
31   - end
32   - end
33   -
34   - def factory_line(attribute, file_name)
35   - if attribute.reference?
36   - "#{file_name}.association(:#{attribute.name})"
37   - else
38   - "#{file_name}.#{attribute.name} #{attribute.default_for_factory}"
39   - end
40   - end
41   -
42   - protected
43   -
44   - def banner
45   - "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
46   - end
47   -
48   - def add_options!(opt)
49   - opt.separator ''
50   - opt.separator 'Options:'
51   - opt.on("--skip-timestamps",
52   - "Don't add timestamps to the migration file for this model") { |v|
53   - options[:skip_timestamps] = v
54   - }
55   - opt.on("--skip-migration",
56   - "Don't generate a migration file for this model") { |v|
57   - options[:skip_migration] = v
58   - }
59   - end
60   -end
61   -
62   -module Rails
63   - module Generator
64   - class GeneratedAttribute
65   - def default_for_factory
66   - @default ||= case type
67   - when :integer then "{ 1 }"
68   - when :float then "{ 1.5 }"
69   - when :decimal then "{ 9.99 }"
70   - when :datetime, :timestamp, :time then "{ Time.now.to_s(:db) }"
71   - when :date then "{ Date.today.to_s(:db) }"
72   - when :string then "{ 'string' }"
73   - when :text then "{ 'text' }"
74   - when :boolean then "{ false }"
75   - else
76   - ""
77   - end
78   - end
79   - end
80   - end
81   -end
vendor/plugins/coulda/generators/model/templates/factory.rb
... ... @@ -1,5 +0,0 @@
1   -Factory.define :<%= file_name %> do |<%= file_name %>|
2   -<% attributes.each do |attribute| -%>
3   - <%= factory_line(attribute, file_name) %>
4   -<% end -%>
5   -end
vendor/plugins/coulda/generators/model/templates/migration.rb
... ... @@ -1,32 +0,0 @@
1   -class <%= migration_name %> < ActiveRecord::Migration
2   - def self.up
3   - create_table :<%= table_name %> do |table|
4   -<% attributes.each do |attribute| -%>
5   -<% if attribute.type == :paperclip -%>
6   - table.string :<%= attribute.name %>_file_name, :default => ""
7   - table.string :<%= attribute.name %>_content_type, :default => ""
8   - table.integer :<%= attribute.name %>_file_size
9   - table.datetime :<%= attribute.name %>_updated_at
10   -<% elsif attribute.type == :string -%>
11   - table.string :<%= attribute.name %>, :default => ""
12   -<% else -%>
13   - table.<%= attribute.type %> :<%= attribute.name %>
14   -<% end -%>
15   -<% end -%>
16   -<% unless options[:skip_timestamps] -%>
17   - table.timestamps
18   -<% end -%>
19   - end
20   -
21   -<% attributes.select(&:reference?).each do |attribute| -%>
22   - add_index :<%= table_name %>, :<%= attribute.name %>_id
23   -<% end -%>
24   - end
25   -
26   - def self.down
27   -<% attributes.select(&:reference?).each do |attribute| -%>
28   - remove_index :<%= table_name %>, :<%= attribute.name %>_id
29   -<% end -%>
30   - drop_table :<%= table_name %>
31   - end
32   -end
vendor/plugins/coulda/generators/model/templates/model.rb
... ... @@ -1,8 +0,0 @@
1   -class <%= class_name %> < ActiveRecord::Base
2   -<% attributes.select(&:reference?).each do |each| -%>
3   - belongs_to :<%= each.name %>
4   -<% end -%>
5   -<% attributes.select { |each| each.type == :paperclip }.each do |each| -%>
6   - has_attached_file :<%= each.name %>
7   -<% end -%>
8   -end
vendor/plugins/coulda/generators/model/templates/unit_test.rb
... ... @@ -1,16 +0,0 @@
1   -require 'test_helper'
2   -
3   -class <%= class_name %>Test < ActiveSupport::TestCase
4   - should "be valid with factory" do
5   - assert_valid Factory.build(:<%= file_name -%>)
6   - end
7   -<% attributes.each do |attribute| -%>
8   -<% if attribute.reference? -%>
9   - should_belong_to :<%= attribute.name %>
10   - should_have_db_index :<%= attribute.name %>_id
11   -<% end -%>
12   -<% if attribute.type == :paperclip -%>
13   - should_have_attached_file :<%= attribute.name %>
14   -<% end -%>
15   -<% end -%>
16   -end
vendor/plugins/coulda/generators/support/generator_helper.rb
... ... @@ -1,43 +0,0 @@
1   -require File.join(File.dirname(__FILE__), "insert_commands")
2   -
3   -module Coulda
4   - module GeneratorHelper
5   - REMOVABLE_COLUMNS = ["created_at", "updated_at", "email_confirmed",
6   - "encrypted_password", "salt", "token", "token_expires_at"]
7   -
8   - def resource
9   - file_name.singularize
10   - end
11   -
12   - def resources
13   - file_name.pluralize
14   - end
15   -
16   - def resource_class
17   - class_name.singularize
18   - end
19   -
20   - def columns_for_form
21   - resource_class.constantize.content_columns.
22   - collect { |column| [column.name, column.type] }.
23   - delete_if { |column| remove_column?(column.first) }
24   - end
25   -
26   - def active_record_defined?
27   - models = Dir.glob(File.join( RAILS_ROOT, 'app', 'models', '*.rb')).
28   - collect { |path| path[/.+\/(.+).rb/,1] }.
29   - collect {|model| model.classify }
30   - models.include?(resource_class)
31   - end
32   -
33   - def remove_column?(column)
34   - REMOVABLE_COLUMNS.include?(column) ||
35   - !(column =~ /_id$/).nil?
36   - end
37   - end
38   -end
39   -
40   -class Rails::Generator::NamedBase
41   - include Coulda::GeneratorHelper
42   -end
43   -
vendor/plugins/coulda/generators/support/insert_commands.rb
... ... @@ -1,53 +0,0 @@
1   -# Pinched some from http://github.com/ryanb/nifty-generators
2   -
3   -Rails::Generator::Commands::Base.class_eval do
4   - def file_contains?(relative_destination, line)
5   - File.read(destination_path(relative_destination)).include?(line)
6   - end
7   -end
8   -
9   -Rails::Generator::Commands::Create.class_eval do
10   - def insert_into(file, line)
11   - logger.insert "#{line} into #{file}"
12   - unless file_contains?(file, line)
13   - gsub_file file, /^(class|module|#{Coulda::Insertable.routes}) .+$/ do |match|
14   - "#{match}\n #{line}"
15   - end
16   - end
17   - end
18   -
19   - def insert_cucumber_path(file, line)
20   - logger.insert "#{line} into #{file}"
21   - unless file_contains?(file, line)
22   - gsub_file file, /#{Coulda::Insertable.cucumber_paths}/ do |match|
23   - "#{match}\n#{line}"
24   - end
25   - end
26   - end
27   -end
28   -
29   -Rails::Generator::Commands::Destroy.class_eval do
30   - def insert_into(file, line)
31   - logger.remove "#{line} from #{file}"
32   - gsub_file file, "\n #{line}", ''
33   - end
34   -end
35   -
36   -Rails::Generator::Commands::List.class_eval do
37   - def insert_into(file, line)
38   - logger.insert "#{line} into #{file}"
39   - end
40   -end
41   -
42   -module Coulda
43   - module Insertable
44   - def self.routes
45   - "ActionController::Routing::Routes.draw"
46   - end
47   -
48   - def self.cucumber_paths
49   - "case page_name\n"
50   - end
51   - end
52   -end
53   -
vendor/plugins/coulda/generators/view/templates/view_new.html.erb
... ... @@ -1,15 +0,0 @@
1   -<h1>New <%= resource %></h1>
2   -
3   -<%% form_for(@<%= resource %>) do |form| %>
4   - <%%= form.error_messages %>
5   - <fieldset class="inputs">
6   -<% if active_record_defined? -%>
7   -<% columns_for_form.each do |attribute_name, attribute_type| -%>
8   - <%%= form.<%= attribute_type %> :<%= attribute_name %> %>
9   -<% end -%>
10   -<% end -%>
11   - </fieldset>
12   - <fieldset class="buttons">
13   - <%%= form.submit 'Create', :disable_with => 'Please wait...' %>
14   - </fieldset>
15   -<%% end %>
vendor/plugins/coulda/generators/view/templates/view_show.html.erb
... ... @@ -1,4 +0,0 @@
1   -<h1><%= resource %></h1>
2   -
3   -<%%= link_to 'Edit', edit_<%= resource %>_path(@<%= resource %>) %>
4   -
vendor/plugins/coulda/generators/view/view_generator.rb
... ... @@ -1,14 +0,0 @@
1   -require File.join(File.dirname(__FILE__), "..", "support", "generator_helper")
2   -
3   -class ViewGenerator < Rails::Generator::NamedBase
4   - def manifest
5   - record do |m|
6   - m.directory File.join('app/views', class_path, file_name)
7   -
8   - if actions.include?("new")
9   - path = File.join('app/views', class_path, file_name, "new.html.erb")
10   - m.template 'view_new.html.erb', path
11   - end
12   - end
13   - end
14   -end