Skip to content

Instantly share code, notes, and snippets.

@peterberkenbosch
Created May 14, 2009 14:45
Show Gist options
  • Save peterberkenbosch/111688 to your computer and use it in GitHub Desktop.
Save peterberkenbosch/111688 to your computer and use it in GitHub Desktop.
# Link to local copy of edge rails
#inside('vendor') { run 'ln -s ~/dev/rails rails' }
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm public/images/rails.png"
run "rm -f public/javascripts/*"
# Download JQuery
#run "curl -s -L http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js > public/javascripts/jquery.js"
#run "curl -s -L http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js > public/javascripts/jquery.form.js"
# Set up git repository
git :init
# Copy database.yml for distribution use
run "cp config/database.yml config/database.yml.example"
# Set up .gitignore files
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore}
file '.gitignore', <<-END
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
END
#Install the plugins
plugin 'shoulda', :git => 'git://github.com/thoughtbot/shoulda.git', :submodule => true
plugin 'factory_girl_on_rails', :git => 'git://github.com/technicalpickles/factory_girl_on_rails.git', :submodule => true
plugin 'hoptoad_notifier', :git => 'git://github.com/thoughtbot/hoptoad_notifier.git', :submodule => true
plugin 'jrails', :svn => 'http://ennerchi.googlecode.com/svn/trunk/plugins/jrails'
plugin 'shoulda_generator', :git => 'git://github.com/technicalpickles/shoulda_generator.git', :submodule => true
# Install all gems
gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => 'http://gems.github.com'
rake('gems:install', :sudo => true)
# Initialize submodules
git :submodule => "init"
# Set up session store initializer
initializer 'session_store.rb', <<-END
ActionController::Base.session = { :session_key => '_#{(1..6).map { |x| (65 + rand(26)).chr }.join}_session', :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}' }
ActionController::Base.session_store = :active_record_store
END
rake('db:sessions:create')
rake('db:migrate')
initializer 'mocks.rb',
%q{# Rails 2 doesn't like mocks
# This callback will run before every request to a mock in development mode,
# or before the first server request in production.
Rails.configuration.to_prepare do
Dir[File.join(RAILS_ROOT, 'test', 'mocks', RAILS_ENV, '*.rb')].each do |f|
load f
end
end
}
initializer 'hoptoad.rb',
%q{HoptoadNotifier.configure do |config|
config.api_key = 'HOPTOAD-KEY'
end
}
file 'test/shoulda_macros/forms.rb',
%q{class Test::Unit::TestCase
def self.should_have_form(opts)
model = self.name.gsub(/ControllerTest$/, '').singularize.downcase
model = model[model.rindex('::')+2..model.size] if model.include?('::')
http_method, hidden_http_method = form_http_method opts[:method]
should "have a #{model} form" do
assert_select "form[action=?][method=#{http_method}]", eval(opts[:action]) do
if hidden_http_method
assert_select "input[type=hidden][name=_method][value=#{hidden_http_method}]"
end
opts[:fields].each do |attribute, type|
attribute = attribute.is_a?(Symbol) ? "#{model}[#{attribute.to_s}]" : attribute
assert_select "input[type=#{type.to_s}][name=?]", attribute
end
assert_select "input[type=submit]"
end
end
end
def self.form_http_method(http_method)
http_method = http_method.nil? ? 'post' : http_method.to_s
if http_method == "post" || http_method == "get"
return http_method, nil
else
return "post", http_method
end
end
end
}
file 'test/shoulda_macros/pagination.rb',
%q{class Test::Unit::TestCase
# Example:
# context "a GET to index logged in as admin" do
# setup do
# login_as_admin
# get :index
# end
# should_paginate_collection :users
# should_display_pagination
# end
def self.should_paginate_collection(collection_name)
should "paginate #{collection_name}" do
assert collection = assigns(collection_name),
"Controller isn't assigning to @#{collection_name.to_s}."
assert_kind_of WillPaginate::Collection, collection,
"@#{collection_name.to_s} isn't a WillPaginate collection."
end
end
def self.should_display_pagination
should "display pagination" do
assert_select "div.pagination", { :minimum => 1 },
"View isn't displaying pagination. Add <%= will_paginate @collection %>."
end
end
# Example:
# context "a GET to index not logged in as admin" do
# setup { get :index }
# should_not_paginate_collection :users
# should_not_display_pagination
# end
def self.should_not_paginate_collection(collection_name)
should "not paginate #{collection_name}" do
assert collection = assigns(collection_name),
"Controller isn't assigning to @#{collection_name.to_s}."
assert_not_equal WillPaginate::Collection, collection.class,
"@#{collection_name.to_s} is a WillPaginate collection."
end
end
def self.should_not_display_pagination
should "not display pagination" do
assert_select "div.pagination", { :count => 0 },
"View is displaying pagination. Check your logic."
end
end
end
}
file 'test/test_helper.rb',
%q{ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'action_view/test_case'
class Test::Unit::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
self.backtrace_silencers << :rails_vendor
self.backtrace_filters << :rails_root
end
class ActionView::TestCase
# Enable UrlWriter when testing helpers
include ActionController::UrlWriter
# Default host for helper tests
default_url_options[:host] = HOST
end
}
# Commit all work so far to the repository
git :add => '.'
git :commit => "-a -m 'Initial commit'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment