github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dancroak / blitz

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 81
    • 6
  • Source
  • Commits
  • Network (6)
  • Issues (8)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • master ✓
    • rails3
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Fine-grained Rails generators for Outside-In Development. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

rolling back MySQL-specific migration generator change 
dancroak (author)
Sun Dec 27 13:47:20 -0800 2009
commit  82117ff99b6a28e5bb5e34d3aec71b4afd8911e9
tree    c6176ab34f0b041c67564a94dcbee6193be9014e
parent  3566b9323f9a7e88ea4ad0774b3f49a5ecce0220
blitz /
name age
history
message
file .gitignore Sun Mar 01 16:12:16 -0800 2009 cleaning up stories, steps, helper assertions [dancroak]
file CHANGELOG.textile Sat Mar 07 23:30:38 -0800 2009 adding last change and next change to CHANGELOG... [dancroak]
file README.textile Sun Dec 27 13:46:59 -0800 2009 changing controller generator to be simpler, no... [dancroak]
file Rakefile Sat Jun 13 13:45:26 -0700 2009 [#1] replace should_change in #create action te... [dancroak]
directory features/ Sun Dec 27 13:47:20 -0800 2009 rolling back MySQL-specific migration generator... [dancroak]
directory generators/ Sun Dec 27 13:47:20 -0800 2009 rolling back MySQL-specific migration generator... [dancroak]
README.textile

Blitz generators

A Rails plugin for feature, view, controller, model, & helper generators. It is meant to be used as part of an “Outside-In” Test-Driven Development cycle.

Generated code may contain

  • Cucumber
  • Shoulda
  • Factory Girl
  • Mocha
  • Formtastic

Installation

$ script/plugin install git://github.com/dancroak/blitz.git

Feature generator

$ script/generate feature Posts new create

generates…

  Scenario: Create a new post
    Given I am on the new post page
    When I create a 'post' named 'A new post'
    Then I should see 'A new post'

Now run it:

$ cucumber features/posts.feature

The failure will be:

undefined method `new_post_path’

To get past this error, we’ll create just the route we need:

map.resources :posts, :only => [:new]

Running the test again, we have a new failure:

uninitialized constant PostsController

Controller test generator

We’ve reached a point in our Outside-In cycle where we want to spiral down into a tighter feedback loop to unit test the non-existant controller.

$ script/generate controller_test Posts new create

Controller generator

$ script/generate controller Posts new create

generates…

class PostsController < ApplicationController def new end def create end end

Model generator

$ script/generate model User
  • factory (Factory Girl)
  • unit test (Shoulda)
  • migration
  • model

Helper generator

$ script/generate helper Navigation
  • empty helper test file
  • empty helper module

View generator

$ script/generate view Posts new

generates a Formtastic view which reflects on your current schema…

<h1>New post</h1>

<% semantic_form_for(@post) do |form| %>
  <% form.inputs do %>
    <%= form.input :title %>
    <%= form.input :body %>
    <%= form.input :user %>
  <% end %>
  <% form.buttons do %>
    <%= form.commit_button 'Create',
          :button_html => { :disable_with => 'Please wait...' } %>
  <% end %>
<% end %>

If no ActiveRecord is defined named Post, it will generate…

<h1>New post</h1>

<% semantic_form_for(@post) do |form| %>
  <% form.inputs %>
  <% form.buttons do %>
    <%= form.commit_button 'Create',
          :button_html => { :disable_with => 'Please wait...' } %>
  <% end %>
<% end %>

Model generator: belongs_to

$ script/generate model post user:belongs_to

generates…

class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.belongs_to :user
      t.timestamps
    end

    add_index :posts, :user_id
  end

  def self.down
    remove_index :posts, :user_id
    drop_table :posts
  end
end

class Post < ActiveRecord::Base
  belongs_to :user
end

class PostTest < ActiveSupport::TestCase
  should_belong_to :user
  should_have_index :user_id
end

Factory.define :post do |post|
  post.association(:user)
end

Model generator: paperclip

$ script/generate model design image:paperclip
  • all the necessary columns in the migration
  • “has_attached_file” in the model
  • “should_have_attached_file” in unit test
class CreateDesigns < ActiveRecord::Migration
  def self.up
    create_table :designs do |t|
      t.string :image_file_name
      t.string :image_content_type
      t.integer :image_file_size
      t.datetime :image_updated_at
      t.timestamps
    end
  end

  def self.down
    drop_table :designs
  end
end

class Design < ActiveRecord::Base
  has_attached_file :image
end

class DesignTest < ActiveSupport::TestCase
  should "be valid with factory" do
    assert_valid Factory.build(:design)
  end
  should_have_attached_file :image
end

Attribution

Dan Croak and Mike Breen

Inspired by shoulda_generator, model_generator_with_factories, and nifty_generators

License

The MIT License

Copyright © 2008, 2009 Dan Croak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server