diff --git a/.gems b/.gems index 4b00b0d..36c7bcb 100644 --- a/.gems +++ b/.gems @@ -1,4 +1,4 @@ thoughtbot-clearance --version '>= 0.6.8' --source gems.github.com -RedCloth --version '= 3.0.4' +RedCloth --version '= 4.1.1' mislav-will_paginate --version '~> 2.3.11' --source gems.github.com diff --git a/config/initializers/mail.rb b/config/initializers/mail.rb index b707b1d..3e3e8f9 100644 --- a/config/initializers/mail.rb +++ b/config/initializers/mail.rb @@ -1,7 +1,13 @@ +config.action_mailer.delivery_method = :smtp + ActionMailer::Base.smtp_settings = { - :address => "smtp.thoughtbot.com", - :port => 25, - :domain => "thoughtbot.com" + :tls => true, + :address => "smtp.gmail.com", + :port => "587", + :domain => "heroku.com", + :authentication => :plain, + :user_name => "YOUREMAIL", + :password => "YOURPASSWORD" } DO_NOT_REPLY = "donotreply@example.com" diff --git a/vendor/plugins/coulda/CHANGELOG.textile b/vendor/plugins/coulda/CHANGELOG.textile new file mode 100644 index 0000000..efe4da3 --- /dev/null +++ b/vendor/plugins/coulda/CHANGELOG.textile @@ -0,0 +1,9 @@ +h1. March 8, 2009 + +* Updated functional tests to use shoulda 2.10 should_redirect_to block syntax + +h1. March 7, 2009 + +* Added Paperclip option to model generator +* Removed comments on model per complaints by thoughtbot + diff --git a/vendor/plugins/coulda/README.textile b/vendor/plugins/coulda/README.textile new file mode 100644 index 0000000..882301c --- /dev/null +++ b/vendor/plugins/coulda/README.textile @@ -0,0 +1,145 @@ +h1. Coulda generators + +A plugin that overrides Rails' model, controller, & helper generators. It also adds a view generator. It uses Shoulda & Factory Girl for tests. + +h2. Requirements + +* "Shoulda":http://github.com/thoughtbot/shoulda +* "Factory Girl":http://github.com/thoughtbot/factory_girl + +h2. Installation + + $ script/plugin install git://github.com/dancroak/coulda.git + +h2. Model generator + + $ script/generate model User + +* factory (Factory Girl) +* unit test (Shoulda) +* migration +* model + +h2. Controller generator + + $ script/generate controller Users new + +* functional test (Shoulda & Factory Girl), only test RESTful new action +* controller, only RESTful new action +* no helper file + +h2. Helper generator + + $ script/generate helper Navigation + +* empty helper test file +* empty helper module + +h2. View generator + + $ script/generate view Posts new + +* We're not sure we like this one yet. Let us know what you think. + +h2. Model generator: belongs_to + + $ script/generate model post user:belongs_to + +* "add_index" in the migration +* "belongs_to" in the model +* "should_belong_to" in unit test +* association in the factory + +
class CreatePosts < ActiveRecord::Migration
+  def self.up
+    create_table :posts do |t|
+      t.belongs_to :user
+      t.timestamps
+    end
+
+    add_index :posts, :user_id
+  end
+
+  def self.down
+    remove_index :posts, :user_id
+    drop_table :posts
+  end
+end
+
+class Post < ActiveRecord::Base
+  belongs_to :user
+end
+
+class PostTest < ActiveSupport::TestCase
+  should_belong_to :user
+  should_have_index :user_id
+end
+
+Factory.define :post do |post|
+  post.association(:user)
+end
+ +h2. Model generator: paperclip + + $ script/generate model design image:paperclip + +* all the necessary columns in the migration +* "has_attached_file" in the model +* "should_have_attached_file" in unit test + +
class CreateDesigns < ActiveRecord::Migration
+  def self.up
+    create_table :designs do |t|
+      t.string :image_file_name
+      t.string :image_content_type
+      t.integer :image_file_size
+      t.datetime :image_updated_at
+      t.timestamps
+    end
+  end
+
+  def self.down
+    drop_table :designs
+  end
+end
+
+class Design < ActiveRecord::Base
+  has_attached_file :image
+end
+
+class DesignTest < ActiveSupport::TestCase
+  should "be valid with factory" do
+    assert_valid Factory.build(:design)
+  end
+  should_have_attached_file :image
+end
+ +h2. Attribution + +"Mike Breen":http://github.com/hardbap and "Dan Croak":http://github.com/dancroak + +Inspired by "shoulda_generator":http://github.com/technicalpickles/shoulda_generator, "model_generator_with_factories":http://github.com/vigetlabs/model_generator_with_factories, and "nifty_generators":http://github.com/ryanb/nifty-generators + +h2. License + +The MIT License + +Copyright (c) 2008, 2009 Mike Breen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/plugins/coulda/Rakefile b/vendor/plugins/coulda/Rakefile new file mode 100644 index 0000000..b521a0a --- /dev/null +++ b/vendor/plugins/coulda/Rakefile @@ -0,0 +1,10 @@ +require 'rake' +require 'rake/testtask' + +require 'cucumber/rake/task' +Cucumber::Rake::Task.new(:features) do |features| + features.cucumber_opts = "features --format progress" +end + +task :default => [:features] + diff --git a/vendor/plugins/coulda/features/controller_generator.feature b/vendor/plugins/coulda/features/controller_generator.feature new file mode 100644 index 0000000..86fe696 --- /dev/null +++ b/vendor/plugins/coulda/features/controller_generator.feature @@ -0,0 +1,61 @@ +Feature: Rails controller generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate Shoulda & Factory Girl tests for only RESTful actions I need. + + Scenario: Controller generator for index action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "index" action + Then a standard "index" functional test for "posts" should be generated + And an empty "index" controller action for "posts" should be generated + And only a "index" action for RESTful "posts" route should be generated + + Scenario: Controller generator for new action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "new" action + Then a standard "new" functional test for "posts" should be generated + And a "new" controller action for "posts" should be generated + And only a "new" action for RESTful "posts" route should be generated + + Scenario: Controller generator for create action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "create" action + Then a standard "create" functional test for "posts" should be generated + And a "create" controller action for "posts" should be generated + And only a "create" action for RESTful "posts" route should be generated + + Scenario: Controller generator for show action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "show" action + Then a standard "show" functional test for "posts" should be generated + And a "show" controller action for "posts" should be generated + And only a "show" action for RESTful "posts" route should be generated + + Scenario: Controller generator for edit action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "edit" action + Then a standard "edit" functional test for "posts" should be generated + And a "edit" controller action for "posts" should be generated + And only a "edit" action for RESTful "posts" route should be generated + + Scenario: Controller generator for update action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "update" action + Then a standard "update" functional test for "posts" should be generated + And a "update" controller action for "posts" should be generated + And only a "update" action for RESTful "posts" route should be generated + + Scenario: Controller generator for destroy action + Given a Rails app + And the coulda plugin is installed + When I generate a "Posts" controller with "destroy" action + Then a standard "destroy" functional test for "posts" should be generated + And a "destroy" controller action for "posts" should be generated + And only a "destroy" action for RESTful "posts" route should be generated + diff --git a/vendor/plugins/coulda/features/helper_generator.feature b/vendor/plugins/coulda/features/helper_generator.feature new file mode 100644 index 0000000..f0e0af7 --- /dev/null +++ b/vendor/plugins/coulda/features/helper_generator.feature @@ -0,0 +1,12 @@ +Feature: Rails helper generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate just the module and test I need. + + Scenario: Helper + Given a Rails app + And the coulda plugin is installed + When I generate a helper named "Navigation" + Then a helper should be generated for "Navigation" + And a helper test should be generated for "Navigation" + diff --git a/vendor/plugins/coulda/features/model_generator.feature b/vendor/plugins/coulda/features/model_generator.feature new file mode 100644 index 0000000..35e4e05 --- /dev/null +++ b/vendor/plugins/coulda/features/model_generator.feature @@ -0,0 +1,37 @@ +Feature: Rails model generator + In order to better do Test-Driven Development with Rails + As a user + I want to generate a Factory definition and Shoulda tests. + + Scenario: Model generator without attributes + Given a Rails app + And the coulda plugin is installed + When I generate a model named "User" + Then a factory should be generated for "User" + And a unit test should be generated for "User" + + Scenario: Model generator with attributes + Given a Rails app + And the coulda plugin is installed + When I generate a model "User" with a string "email" + Then a factory for "User" should have an "email" string + And a unit test should be generated for "User" + + Scenario: Model generator with association + Given a Rails app + And the coulda plugin is installed + When I generate a model "Post" that belongs to a "User" + Then a factory for "Post" should have an association to "User" + And the "Post" unit test should have "should_belong_to :user" macro + And the "Post" unit test should have "should_have_db_index :user_id" macro + And the "posts" table should have db index on "user_id" + And the "Post" model should have "belongs_to :user" macro + + Scenario: Model generator with Paperclip + Given a Rails app + And the coulda plugin is installed + When I generate a model "Design" with file "Image" + Then the "Design" model should have "has_attached_file :image" macro + And the "Design" unit test should have "should_have_attached_file :image" macro + And the "designs" table should have paperclip columns for "image" + diff --git a/vendor/plugins/coulda/features/step_definitions/controller_steps.rb b/vendor/plugins/coulda/features/step_definitions/controller_steps.rb new file mode 100644 index 0000000..be7a321 --- /dev/null +++ b/vendor/plugins/coulda/features/step_definitions/controller_steps.rb @@ -0,0 +1,189 @@ +When /^I generate a "(.*)" controller with "(.*)" action$/ do |controller, action| + system "cd #{@rails_root} && " << + "script/generate controller #{controller} #{action} && " << + "cd .." +end + +Then /^a standard "index" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'GET to index' do\n" << + " setup { get :index }\n\n" << + " should_render_template :index\n" << + " should_respond_with :success\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a standard "new" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'GET to new' do\n" << + " setup { get :new }\n\n" << + " should_assign_to :post\n" << + " should_render_template :new\n" << + " should_respond_with :success\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a standard "create" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'POST to create with valid parameters' do\n" << + " setup do\n" << + " post :create, :post => Factory.attributes_for(:post)\n" << + " end\n\n" << + " should_create :post\n" << + " should_set_the_flash_to /created/i\n" << + " should_redirect_to('posts index') { posts_path }\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a standard "show" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'GET to show for existing post' do\n" << + " setup do\n" << + " @post = Factory(:post)\n" << + " get :show, :id => @post.to_param\n" << + " end\n\n" << + " should_assign_to :post, :equals => '@post'\n" << + " should_render_template :show\n" << + " should_respond_with :success\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a standard "edit" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'GET to edit for existing post' do\n" << + " setup do\n" << + " @post = Factory(:post)\n" << + " get :edit, :id => @post.to_param\n" << + " end\n\n" << + " should_assign_to :post, :equals => '@post'\n" << + " should_render_template :edit\n" << + " should_respond_with :success\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a standard "update" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'PUT to update for existing post' do\n" << + " setup do\n" << + " @post = Factory(:post)\n" << + " put :update, :id => @post.to_param,\n" << + " :post => Factory.attributes_for(:post)\n" << + " end\n\n" << + " should_set_the_flash_to /updated/i\n" << + " should_redirect_to('posts index') { posts_path }\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a standard "destroy" functional test for "posts" should be generated$/ do + assert_generated_functional_test_for("posts") do |body| + expected = " context 'given a post' do\n" << + " setup { @post = Factory(:post) }\n\n" << + " context 'DELETE to destroy' do\n" << + " setup { delete :destroy, :id => @post.to_param }\n\n" << + " should_destroy :post\n" << + " should_set_the_flash_to /deleted/i\n" << + " should_redirect_to('posts index') { posts_path }\n" << + " end\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a "new" controller action for "posts" should be generated$/ do + assert_generated_controller_for("posts") do |body| + expected = " def new\n" << + " @post = Post.new\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a "create" controller action for "posts" should be generated$/ do + assert_generated_controller_for("posts") do |body| + expected = " def create\n" << + " @post = Post.new(params[:post])\n" << + " @post.save\n" << + " flash[:success] = 'Post created.'\n" << + " redirect_to posts_path\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a "show" controller action for "posts" should be generated$/ do + assert_generated_controller_for("posts") do |body| + expected = " def show\n" << + " @post = Post.find(params[:id])\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a "edit" controller action for "posts" should be generated$/ do + assert_generated_controller_for("posts") do |body| + expected = " def edit\n" << + " @post = Post.find(params[:id])\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a "update" controller action for "posts" should be generated$/ do + assert_generated_controller_for("posts") do |body| + expected = " def update\n" << + " @post = Post.find(params[:id])\n" << + " @post.update_attributes(params[:post])\n" << + " flash[:success] = 'Post updated.'\n" << + " redirect_to posts_path\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^a "destroy" controller action for "posts" should be generated$/ do + assert_generated_controller_for("posts") do |body| + expected = " def destroy\n" << + " @post = Post.find(params[:id])\n" << + " @post.destroy\n" << + " flash[:success] = 'Post deleted.'\n" << + " redirect_to posts_path\n" << + " end" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end +end + +Then /^an empty "(.*)" controller action for "(.*)" should be generated$/ do |action, controller| + assert_generated_controller_for(controller) do |body| + assert_has_empty_method(body, action) + end +end + +Then /^only a "([^\"]*)" action for RESTful "([^\"]*)" route should be generated$/ do |action, resource| + assert_generated_route_for resource, action +end + diff --git a/vendor/plugins/coulda/features/step_definitions/generator_steps.rb b/vendor/plugins/coulda/features/step_definitions/generator_steps.rb new file mode 100644 index 0000000..3df26cd --- /dev/null +++ b/vendor/plugins/coulda/features/step_definitions/generator_steps.rb @@ -0,0 +1,16 @@ +Given 'a Rails app' do + system "rails rails_root" + @rails_root = File.join(File.dirname(__FILE__), "..", "..", "rails_root") +end + +Given /^the coulda plugin is installed$/ do + plugin_dir = File.join(@rails_root, "vendor", "plugins") + target = File.join(File.dirname(__FILE__), "..", "..", "generators") + FileUtils.mkdir_p "#{plugin_dir}/coulda" + system "cp -r #{target} #{plugin_dir}/coulda" +end + +After do + FileUtils.rm_rf @rails_root if @rails_root +end + diff --git a/vendor/plugins/coulda/features/step_definitions/helper_steps.rb b/vendor/plugins/coulda/features/step_definitions/helper_steps.rb new file mode 100644 index 0000000..b7f8bcc --- /dev/null +++ b/vendor/plugins/coulda/features/step_definitions/helper_steps.rb @@ -0,0 +1,14 @@ +When /^I generate a helper named "(.*)"$/ do |name| + system "cd #{@rails_root} && " << + "script/generate helper #{name} && " << + "cd .." +end + +Then /^a helper should be generated for "(.*)"$/ do |name| + assert_generated_helper_for(name) +end + +Then /^a helper test should be generated for "(.*)"$/ do |name| + assert_generated_helper_test_for(name) +end + diff --git a/vendor/plugins/coulda/features/step_definitions/migration_steps.rb b/vendor/plugins/coulda/features/step_definitions/migration_steps.rb new file mode 100644 index 0000000..c9a3eeb --- /dev/null +++ b/vendor/plugins/coulda/features/step_definitions/migration_steps.rb @@ -0,0 +1,14 @@ +Then /^the paperclip migration should add "(.*)" columns to the "(.*)"$/ do |attr, table| + up = " add_column :#{table}, :#{attr}_file_name, :string\n" << + " add_column :#{table}, :#{attr}_content_type, :string\n" << + " add_column :#{table}, :#{attr}_file_size, :integer\n" << + " add_column :#{table}, :#{attr}_updated_at, :datetime" + down = " remove_column :#{table}, :#{attr}_file_name\n" << + " remove_column :#{table}, :#{attr}_content_type\n" << + " remove_column :#{table}, :#{attr}_file_size\n" << + " remove_column :#{table}, :#{attr}_updated_at" + assert_generated_migration(table) do |body| + assert body.include?(up), body.inspect + assert body.include?(down), body.inspect + end +end diff --git a/vendor/plugins/coulda/features/step_definitions/model_steps.rb b/vendor/plugins/coulda/features/step_definitions/model_steps.rb new file mode 100644 index 0000000..0a280ff --- /dev/null +++ b/vendor/plugins/coulda/features/step_definitions/model_steps.rb @@ -0,0 +1,122 @@ +# GENERATION + +When /^I generate a model named "(.*)"$/ do |model| + system "cd #{@rails_root} && " << + "script/generate model #{model} && " << + "cd .." +end + +When /^I generate a model "(.*)" with a (.*) "(.*)"$/ do |model, attr_type, attr_name| + system "cd #{@rails_root} && " << + "script/generate model #{model} #{attr_name}:#{attr_type} && " << + "cd .." +end + +When /^I generate a model "(.*)" that belongs to a "(.*)"$/ do |model, association| + association.downcase! + system "cd #{@rails_root} && " << + "script/generate model #{model} #{association}:belongs_to && " << + "cd .." +end + +When /^I generate a model "(.*)" with file "(.*)"$/ do |model, file| + file.downcase! + system "cd #{@rails_root} && " << + "script/generate model #{model} #{file}:paperclip && " << + "cd .." +end + +# MODEL + +Then /^a model with comments should be generated for "(.*)"$/ do |model| + model.downcase! + assert_generated_model_for(model) do |body| + comments = [] + comments << "# includes: mixed in behavior" << + "# properties: attributes, associations" << + "# lifecycle: validations, callbacks" << + "# class methods: self.method, named_scopes" << + "# instance methods" << + "# non-public interface: protected helpers" + comments.each do |comment| + assert body.include?(comment), body.inspect + end + end +end + +Then /^the "(.*)" model should have "(.*)" macro$/ do |model, macro| + model.downcase! + assert_generated_model_for(model) do |body| + assert body.include?(macro), body.inspect + end +end + +# FACTORY + +Then /^a factory should be generated for "(.*)"$/ do |model| + model.downcase! + assert_generated_factory_for(model) do |body| + expected = "Factory.define :#{model.downcase} do |#{model.downcase}|\n" << + "end\n" + assert_equal expected, body + end +end + +Then /^a factory for "(.*)" should have an? "(.*)" (.*)$/ do |model, attr_name, attr_type| + model.downcase! + assert_generated_factory_for(model) do |body| + expected = "Factory.define :#{model} do |#{model}|\n" << + " #{model}.#{attr_name} { '#{attr_type}' }\n" << + "end\n" + assert_equal expected, body + end +end + +Then /^a factory for "(.*)" should have an association to "(.*)"$/ do |model, associated_model| + model.downcase! + associated_model.downcase! + assert_generated_factory_for(model) do |body| + expected = "Factory.define :#{model} do |#{model}|\n" << + " #{model}.association(:#{associated_model})\n" << + "end\n" + assert_equal expected, body + end +end + +# UNIT TEST + +Then /^a unit test should be generated for "(.*)"$/ do |model| + model.downcase! + assert_generated_unit_test_for(model) do |body| + match = "assert_valid Factory.build(:#{model})" + assert body.include?(match), body.inspect + end +end + +Then /^the "(.*)" unit test should have "(.*)" macro$/ do |model, macro| + model.downcase! + assert_generated_unit_test_for(model) do |body| + assert body.include?(macro), body.inspect + end +end + +# MIGRATION + +Then /^the "(.*)" table should have db index on "(.*)"$/ do |table, foreign_key| + assert_generated_migration(table) do |body| + index = "add_index :#{table}, :#{foreign_key}" + assert body.include?(index), body.inspect + end +end + +Then /^the "(.*)" table should have paperclip columns for "(.*)"$/ do |table, attr| + up = " table.string :#{attr}_file_name\n" << + " table.string :#{attr}_content_type\n" << + " table.integer :#{attr}_file_size\n" << + " table.datetime :#{attr}_updated_at" + assert_generated_migration(table) do |body| + assert body.include?(up), body.inspect + end +end + + diff --git a/vendor/plugins/coulda/features/step_definitions/view_steps.rb b/vendor/plugins/coulda/features/step_definitions/view_steps.rb new file mode 100644 index 0000000..24db4c2 --- /dev/null +++ b/vendor/plugins/coulda/features/step_definitions/view_steps.rb @@ -0,0 +1,4 @@ +Then /^an empty "(.*)" view for "(.*)" should be generated$/ do |action, controller| + assert_generated_views_for(controller, action) +end + diff --git a/vendor/plugins/coulda/features/support/env.rb b/vendor/plugins/coulda/features/support/env.rb new file mode 100644 index 0000000..74581c1 --- /dev/null +++ b/vendor/plugins/coulda/features/support/env.rb @@ -0,0 +1,104 @@ +require 'test/unit' + +module Test::Unit::Assertions + + def assert_generated_controller_for(name) + assert_generated_file "app/controllers/#{name}_controller.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_model_for(name) + assert_generated_file "app/models/#{name}.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_helper_for(name) + assert_generated_file "app/helpers/#{name}_helper.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_factory_for(name) + assert_generated_file "test/factories/#{name}.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_functional_test_for(name) + assert_generated_file "test/functional/#{name}_controller_test.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_unit_test_for(name) + assert_generated_file "test/unit/#{name}_test.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_helper_test_for(name) + assert_generated_file "test/unit/helpers/#{name}_helper_test.rb" do |body| + yield body if block_given? + end + end + + def assert_generated_file(path) + assert_file_exists(path) + File.open(File.join(@rails_root, path)) do |file| + yield file.read if block_given? + end + end + + def assert_file_exists(path) + file = File.join(@rails_root, path) + + assert File.exists?(file), "#{file} expected to exist, but did not" + assert File.file?(file), "#{file} expected to be a file, but is not" + end + + def assert_generated_views_for(name, *actions) + actions.each do |action| + assert_generated_file("app/views/#{name}/#{action}.html.erb") do |body| + yield body if block_given? + end + end + end + + def assert_generated_migration(name) + file = Dir.glob("#{@rails_root}/db/migrate/*_#{name}.rb").first + file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s << ".rb" + assert_generated_file file do |body| + assert_match /timestamps/, body, "should have timestamps defined" + yield body if block_given? + end + end + + def assert_generated_route_for(name, *actions) + assert_generated_file("config/routes.rb") do |body| + routeable_actions = actions.collect { |action| ":#{action}" }.join(", ") + expected = " map.resources :#{name.to_s}, :only => [#{routeable_actions}]" + assert body.include?(expected), + "expected #{expected} but was #{body.inspect}" + end + end + + def assert_has_empty_method(body, *methods) + methods.each do |name| + assert body.include?(" def #{name}\n end"), + "should have method #{name} in #{body.inspect}" + yield(name, $2) if block_given? + end + end + +end + +class CouldaWorld + include Test::Unit::Assertions +end + +World do + CouldaWorld.new +end + diff --git a/vendor/plugins/coulda/generators/controller/controller_generator.rb b/vendor/plugins/coulda/generators/controller/controller_generator.rb new file mode 100644 index 0000000..d5be929 --- /dev/null +++ b/vendor/plugins/coulda/generators/controller/controller_generator.rb @@ -0,0 +1,29 @@ +require File.join(File.dirname(__FILE__), "..", "support", "insert_commands") + +class ControllerGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest" + + m.directory File.join('app/controllers', class_path) + m.directory File.join('test/functional', class_path) + + m.template 'controller.rb', + File.join('app/controllers', + class_path, + "#{file_name}_controller.rb") + + m.template 'functional_test.rb', + File.join('test/functional', + class_path, + "#{file_name}_controller_test.rb") + + m.insert_into "config/routes.rb", + "map.resources :#{file_name}, :only => [#{routeable_actions}]" + end + end + + def routeable_actions + actions.collect { |action| ":#{action}" }.join(", ") + end +end diff --git a/vendor/plugins/coulda/generators/controller/templates/controller.rb b/vendor/plugins/coulda/generators/controller/templates/controller.rb new file mode 100644 index 0000000..ea75b75 --- /dev/null +++ b/vendor/plugins/coulda/generators/controller/templates/controller.rb @@ -0,0 +1,56 @@ +class <%= class_name %>Controller < ApplicationController +<% resource = file_name.singularize -%> +<% resources = file_name.pluralize -%> +<% resource_class = class_name.singularize -%> + +<% if actions.include?("index") -%> + def index + end + +<% end -%> +<% if actions.include?("new") -%> + def new + @<%= resource %> = <%= resource_class %>.new + end + +<% end -%> +<% if actions.include?("create") -%> + def create + @<%= resource %> = <%= resource_class %>.new(params[:<%= resource %>]) + @<%= resource %>.save + flash[:success] = '<%= resource_class %> created.' + redirect_to <%= resources %>_path + end + +<% end -%> +<% if actions.include?("show") -%> + def show + @<%= resource %> = <%= resource_class %>.find(params[:id]) + end + +<% end -%> +<% if actions.include?("edit") -%> + def edit + @<%= resource %> = <%= resource_class %>.find(params[:id]) + end + +<% end -%> +<% if actions.include?("update") -%> + def update + @<%= resource %> = <%= resource_class %>.find(params[:id]) + @<%= resource %>.update_attributes(params[:<%= resource %>]) + flash[:success] = '<%= resource_class %> updated.' + redirect_to <%= resources %>_path + end + +<% end -%> +<% if actions.include?("destroy") -%> + def destroy + @<%= resource %> = <%= resource_class %>.find(params[:id]) + @<%= resource %>.destroy + flash[:success] = '<%= resource_class %> deleted.' + redirect_to <%= resources %>_path + end + +<% end -%> +end diff --git a/vendor/plugins/coulda/generators/controller/templates/functional_test.rb b/vendor/plugins/coulda/generators/controller/templates/functional_test.rb new file mode 100644 index 0000000..702bd9f --- /dev/null +++ b/vendor/plugins/coulda/generators/controller/templates/functional_test.rb @@ -0,0 +1,93 @@ +require 'test_helper' + +class <%= class_name %>ControllerTest < ActionController::TestCase +<% resource = file_name.singularize -%> +<% resources = file_name.pluralize -%> +<% resource_class = class_name.singularize -%> + +<% if actions.include?("index") -%> + context 'GET to index' do + setup { get :index } + + should_render_template :index + should_respond_with :success + end + +<% end -%> +<% if actions.include?("new") -%> + context 'GET to new' do + setup { get :new } + + should_assign_to :<%= resource %> + should_render_template :new + should_respond_with :success + end + +<% end -%> +<% if actions.include?("create") -%> + context 'POST to create with valid parameters' do + setup do + post :create, :<%= resource %> => Factory.attributes_for(:<%= resource %>) + end + + should_create :<%= resource %> + should_set_the_flash_to /created/i + should_redirect_to('<%= resources %> index') { <%= resources %>_path } + end + +<% end -%> +<% if actions.include?("show") -%> + context 'GET to show for existing <%= resource %>' do + setup do + @<%= resource %> = Factory(:<%= resource %>) + get :show, :id => @<%= resource %>.to_param + end + + should_assign_to :<%= resource %>, :equals => '@<%= resource %>' + should_render_template :show + should_respond_with :success + end + +<% end -%> +<% if actions.include?("edit") -%> + context 'GET to edit for existing <%= resource %>' do + setup do + @<%= resource %> = Factory(:<%= resource %>) + get :edit, :id => @<%= resource %>.to_param + end + + should_assign_to :<%= resource %>, :equals => '@<%= resource %>' + should_render_template :edit + should_respond_with :success + end + +<% end -%> +<% if actions.include?("update") -%> + context 'PUT to update for existing <%= resource %>' do + setup do + @<%= resource %> = Factory(:<%= resource %>) + put :update, :id => @<%= resource %>.to_param, + :<%= resource %> => Factory.attributes_for(:<%= resource %>) + end + + should_set_the_flash_to /updated/i + should_redirect_to('<%= resources %> index') { <%= resources %>_path } + end + +<% end -%> +<% if actions.include?("destroy") -%> + context 'given a <%= resource %>' do + setup { @<%= resource %> = Factory(:<%= resource %>) } + + context 'DELETE to destroy' do + setup { delete :destroy, :id => @<%= resource %>.to_param } + + should_destroy :<%= resource %> + should_set_the_flash_to /deleted/i + should_redirect_to('<%= resources %> index') { <%= resources %>_path } + end + end + +<% end -%> +end + diff --git a/vendor/plugins/coulda/generators/helper/helper_generator.rb b/vendor/plugins/coulda/generators/helper/helper_generator.rb new file mode 100644 index 0000000..baf1e31 --- /dev/null +++ b/vendor/plugins/coulda/generators/helper/helper_generator.rb @@ -0,0 +1,23 @@ +class HelperGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions "#{class_name}Helper", "#{class_name}HelperTest" + + # Helper and test directories. + m.directory File.join('app/helpers', class_path) + m.directory File.join('test/unit/helpers', class_path) + + # Helper module and test. + m.template 'helper.rb', + File.join('app/helpers', + class_path, + "#{file_name}_helper.rb") + + m.template 'helper_test.rb', + File.join('test/unit/helpers', + class_path, + "#{file_name}_helper_test.rb") + end + end +end diff --git a/vendor/plugins/coulda/generators/helper/templates/helper.rb b/vendor/plugins/coulda/generators/helper/templates/helper.rb new file mode 100644 index 0000000..3fe2ecd --- /dev/null +++ b/vendor/plugins/coulda/generators/helper/templates/helper.rb @@ -0,0 +1,2 @@ +module <%= class_name %>Helper +end diff --git a/vendor/plugins/coulda/generators/helper/templates/helper_test.rb b/vendor/plugins/coulda/generators/helper/templates/helper_test.rb new file mode 100644 index 0000000..591e409 --- /dev/null +++ b/vendor/plugins/coulda/generators/helper/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/vendor/plugins/coulda/generators/model/model_generator.rb b/vendor/plugins/coulda/generators/model/model_generator.rb new file mode 100644 index 0000000..9bef5b9 --- /dev/null +++ b/vendor/plugins/coulda/generators/model/model_generator.rb @@ -0,0 +1,79 @@ +class ModelGenerator < Rails::Generator::NamedBase + default_options :skip_timestamps => false, + :skip_migration => false, + :skip_factories => false + + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_name, "#{class_name}Test" + + # Model, test, and factories directories. + m.directory File.join('app/models', class_path) + m.directory File.join('test/unit', class_path) + m.directory File.join('test/factories', class_path) + + # Model class, unit test, and factories. + m.template 'model.rb', File.join('app/models', class_path, + "#{file_name}.rb") + m.template 'unit_test.rb', File.join('test/unit', class_path, + "#{file_name}_test.rb") + + m.template 'factory.rb', File.join('test/factories', "#{file_name}.rb") + + unless options[:skip_migration] + m.migration_template 'migration.rb', 'db/migrate', :assigns => { + :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" + }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" + end + end + end + + def factory_line(attribute, file_name) + if attribute.reference? + "#{file_name}.association(:#{attribute.name})" + else + "#{file_name}.#{attribute.name} #{attribute.default_for_factory}" + end + end + + protected + + def banner + "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]" + end + + def add_options!(opt) + opt.separator '' + opt.separator 'Options:' + opt.on("--skip-timestamps", + "Don't add timestamps to the migration file for this model") { |v| + options[:skip_timestamps] = v + } + opt.on("--skip-migration", + "Don't generate a migration file for this model") { |v| + options[:skip_migration] = v + } + end +end + +module Rails + module Generator + class GeneratedAttribute + def default_for_factory + @default ||= case type + when :integer then "{ 1 }" + when :float then "{ 1.5 }" + when :decimal then "{ 9.99 }" + when :datetime, :timestamp, :time then "{ Time.now.to_s(:db) }" + when :date then "{ Date.today.to_s(:db) }" + when :string then "{ 'string' }" + when :text then "{ 'text' }" + when :boolean then "{ false }" + else + "" + end + end + end + end +end diff --git a/vendor/plugins/coulda/generators/model/templates/factory.rb b/vendor/plugins/coulda/generators/model/templates/factory.rb new file mode 100644 index 0000000..1bc9bba --- /dev/null +++ b/vendor/plugins/coulda/generators/model/templates/factory.rb @@ -0,0 +1,5 @@ +Factory.define :<%= file_name %> do |<%= file_name %>| +<% attributes.each do |attribute| -%> + <%= factory_line(attribute, file_name) %> +<% end -%> +end diff --git a/vendor/plugins/coulda/generators/model/templates/migration.rb b/vendor/plugins/coulda/generators/model/templates/migration.rb new file mode 100644 index 0000000..a114dca --- /dev/null +++ b/vendor/plugins/coulda/generators/model/templates/migration.rb @@ -0,0 +1,30 @@ +class <%= migration_name %> < ActiveRecord::Migration + def self.up + create_table :<%= table_name %> do |table| +<% attributes.each do |attribute| -%> +<% if attribute.type == :paperclip -%> + table.string :<%= attribute.name %>_file_name + table.string :<%= attribute.name %>_content_type + table.integer :<%= attribute.name %>_file_size + table.datetime :<%= attribute.name %>_updated_at +<% else -%> + table.<%= attribute.type %> :<%= attribute.name %> +<% end -%> +<% end -%> +<% unless options[:skip_timestamps] -%> + table.timestamps +<% end -%> + end + +<% attributes.select(&:reference?).each do |attribute| -%> + add_index :<%= table_name %>, :<%= attribute.name %>_id +<% end -%> + end + + def self.down +<% attributes.select(&:reference?).each do |attribute| -%> + remove_index :<%= table_name %>, :<%= attribute.name %>_id +<% end -%> + drop_table :<%= table_name %> + end +end diff --git a/vendor/plugins/coulda/generators/model/templates/model.rb b/vendor/plugins/coulda/generators/model/templates/model.rb new file mode 100644 index 0000000..8ba98a8 --- /dev/null +++ b/vendor/plugins/coulda/generators/model/templates/model.rb @@ -0,0 +1,8 @@ +class <%= class_name %> < ActiveRecord::Base +<% attributes.select(&:reference?).each do |each| -%> + belongs_to :<%= each.name %> +<% end -%> +<% attributes.select { |each| each.type == :paperclip }.each do |each| -%> + has_attached_file :<%= each.name %> +<% end -%> +end diff --git a/vendor/plugins/coulda/generators/model/templates/unit_test.rb b/vendor/plugins/coulda/generators/model/templates/unit_test.rb new file mode 100644 index 0000000..f8ab510 --- /dev/null +++ b/vendor/plugins/coulda/generators/model/templates/unit_test.rb @@ -0,0 +1,16 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class <%= class_name %>Test < ActiveSupport::TestCase + should "be valid with factory" do + assert_valid Factory.build(:<%= file_name -%>) + end +<% attributes.each do |attribute| -%> +<% if attribute.reference? -%> + should_belong_to :<%= attribute.name %> + should_have_db_index :<%= attribute.name %>_id +<% end -%> +<% if attribute.type == :paperclip -%> + should_have_attached_file :<%= attribute.name %> +<% end -%> +<% end -%> +end diff --git a/vendor/plugins/coulda/generators/support/insert_commands.rb b/vendor/plugins/coulda/generators/support/insert_commands.rb new file mode 100644 index 0000000..eb648e0 --- /dev/null +++ b/vendor/plugins/coulda/generators/support/insert_commands.rb @@ -0,0 +1,35 @@ +# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master + +Rails::Generator::Commands::Base.class_eval do + def file_contains?(relative_destination, line) + File.read(destination_path(relative_destination)).include?(line) + end +end + +Rails::Generator::Commands::Create.class_eval do + def insert_into(file, line) + logger.insert "#{line} into #{file}" + unless options[:pretend] || file_contains?(file, line) + start_of_routes_file = "ActionController::Routing::Routes.draw" + gsub_file file, /^(class|module|#{start_of_routes_file}) .+$/ do |match| + "#{match}\n #{line}" + end + end + end +end + +Rails::Generator::Commands::Destroy.class_eval do + def insert_into(file, line) + logger.remove "#{line} from #{file}" + unless options[:pretend] + gsub_file file, "\n #{line}", '' + end + end +end + +Rails::Generator::Commands::List.class_eval do + def insert_into(file, line) + logger.insert "#{line} into #{file}" + end +end + diff --git a/vendor/plugins/coulda/generators/view/templates/view_new.html.erb b/vendor/plugins/coulda/generators/view/templates/view_new.html.erb new file mode 100644 index 0000000..ec9e61d --- /dev/null +++ b/vendor/plugins/coulda/generators/view/templates/view_new.html.erb @@ -0,0 +1,6 @@ +

New <%= singular_name %>

+ +<%% form_for(@<%= singular_name %>) do |form| %> + <%%= form.error_messages %> + <%%= form.submit "Create", :disable_with => "Please wait..." %> +<%% end %> diff --git a/vendor/plugins/coulda/generators/view/view_generator.rb b/vendor/plugins/coulda/generators/view/view_generator.rb new file mode 100644 index 0000000..ee394ef --- /dev/null +++ b/vendor/plugins/coulda/generators/view/view_generator.rb @@ -0,0 +1,14 @@ +class ViewGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.directory File.join('app/views', class_path, file_name) + + # View template for specified action. + if actions.include?("new") + path = File.join('app/views', class_path, file_name, "new.html.erb") + m.template 'view_new.html.erb', path, + :assigns => { :action => action, :path => path } + end + end + end +end -- libgit2 0.21.2