Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails template for starting apps
def remote_file(path)
run "wget http://static.railstips.org/template/#{path} -qO- > #{path}"
end
def uncomment_line(file, line)
gsub_file file, /#\s*#{Regexp.escape(line)}/, line
end
def append_to_class(file, contents)
log file, contents
gsub_file file, /^end$/, "#{contents}\nend"
end
app_domain = ask('What is the eventual domain for this app?')
rake "db:drop", :env => :development
rake "db:drop", :env => :test
rake "db:create", :env => :development
rake "db:create", :env => :test
run "echo TODO > README"
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/robots.txt"
run "rm public/javascripts/controls.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/prototype.js"
gem "thoughtbot-clearance", :lib => 'clearance', :source => 'http://gems.github.com'
gem 'mislav-will_paginate', :lib => 'will_paginate', :source => 'http://gems.github.com'
gem 'RedCloth', :lib => 'redcloth'
gem 'gravatar'
generate('clearance')
generate('migration', 'add_display_name_and_bio_and_url_and_admin_to_users display_name:string url:string bio:text admin:boolean')
generate('controller', 'home index')
route("map.root :controller => 'home'")
# Add some test gems
environment %q(config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => "http://gems.github.com"), :env => :test
environment %q(config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => "http://gems.github.com"), :env => :test
environment %q(config.gem 'thoughtbot-quietbacktrace', :lib => 'quietbacktrace', :source => "http://gems.github.com"), :env => :test
environment %q(config.gem 'mocha'), :env => :test
# Tell paperclip where to find my imagemagick install
environment %q(Paperclip.options[:image_magick_path] = "/opt/local/bin"), :env => :development
# Add HOST to environments for clearance
environment %q(HOST = 'localhost'), :env => :development
environment %q(HOST = 'localhost'), :env => :test
environment %Q(HOST = '#{app_domain}), :env => :production
environment %Q(DO_NOT_REPLY = "do-not-reply@#{app_domain}")
plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
plugin 'user_stamp', :git => 'git://github.com/jnunemaker/user_stamp.git'
plugin 'common_helpers', :git => 'git://github.com/jnunemaker/common_helpers.git'
plugin 'acts_as_enumeration', :git => 'git://github.com/pluginaweek/acts_as_enumeration.git'
# Filter parameter logging
uncomment_line File.join('app', 'controllers', 'application_controller.rb'),
'filter_parameter_logging :password, :password_confirmation'
remote_file "app/helpers/application_helper.rb"
remote_file "app/views/layouts/application.html.erb"
remote_file "app/views/passwords/new.html.erb"
remote_file "app/views/passwords/edit.html.erb"
remote_file "app/views/sessions/new.html.erb"
remote_file "app/views/users/_form.html.erb"
remote_file "app/views/users/new.html.erb"
remote_file "app/views/users/edit.html.erb"
remote_file "public/javascripts/application.js"
remote_file "public/stylesheets/common.css"
remote_file "public/javascripts/jquery.cookie.js"
remote_file "public/javascripts/jquery.form.js"
remote_file "public/javascripts/jquery.js"
run "cp config/database.yml config/database.yml.sample"
file ".gitignore", <<-END
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
END
file 'public/stylesheets/application.css', ''
rake "db:migrate"
rake "db:test:prepare"
run 'annotate'
append_to_class File.join('app', 'models', 'user.rb'), %q(
attr_accessible :display_name, :bio, :url
validates_presence_of :display_name
validates_uniqueness_of :display_name, :case_sensitive => false
validates_length_of :display_name, :within => 1..100
def url=(new_url)
write_attribute :url, new_url.gsub(/^http\:(\/){0,}/i, '')
end
def full_url
"http://#{url}" if url.present?
end
def gravatar_url(options={})
@gravatar ||= Gravatar.new(email, {:size => 50}.merge(options)).to_s
end)
append_to_class File.join('test', 'unit', 'user_test.rb'), %q(
should_validate_presence_of :display_name
should_validate_uniqueness_of :display_name, :case_sensitive => false
should_ensure_length_in_range :display_name, 1..100
should_allow_mass_assignment_of :display_name
should_allow_mass_assignment_of :email
should_allow_mass_assignment_of :bio
should_allow_mass_assignment_of :url
should_not_allow_mass_assignment_of :admin
should "ensure url does not have http://" do
User.new(:url => 'foobar.com').url.should == 'foobar.com'
User.new(:url => 'http:foobar.com').url.should == 'foobar.com'
User.new(:url => 'http:/foobar.com').url.should == 'foobar.com'
User.new(:url => 'http://foobar.com').url.should == 'foobar.com'
User.new(:url => 'http:///foobar.com').url.should == 'foobar.com'
end
should "have full url" do
User.new(:url => 'foobar.com').full_url.should == 'http://foobar.com'
User.new.full_url.should be(nil)
end
should "have a gravatar_url" do
user = Factory(:user, :email => 'nunemaker@gmail.com')
user.gravatar_url.should include('http://gravatar.com/avatar.php?gravatar_id=')
end)
git :init
git :add => "."
git :commit => "-a -m 'Initial commit'"
#!/bin/bash
rm -rf testapp && rails testapp -m template.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.