$ rails g model User
belongs_to
has_one
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
# Usage: | |
# git log | ruby git_commit_parser.rb | |
# https://gist.github.com/881641 | |
# By: Jason Amster | |
# [email protected] | |
require 'rubygems' | |
require 'pp' | |
logs = STDIN.read | |
logs = logs.split("commit ") |
require 'rubygems' | |
require 'yaml' | |
# A demonstration of YAML anchors, references and handling of nested values | |
# For more info, see: | |
# http://atechie.net/2009/07/merging-hashes-in-yaml-conf-files/ | |
stooges = YAML::load( File.read('stooges.yml') ) | |
# => { | |
# "default" => { |
set :test_log, "logs/capistrano.test.log" | |
namespace :deploy do | |
before 'deploy:update_code' do | |
puts "--> Running tests, please wait ..." | |
unless system "bundle exec rake > #{test_log} 2>&1" #' > /dev/null' | |
puts "--> Tests failed. Run `cat #{test_log}` to see what went wrong." | |
exit | |
else | |
puts "--> Tests passed" |
cribbed from http://pastebin.com/xgzeAmBn
Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.
by Jonathan Rochkind, http://bibwild.wordpress.com
Capistrano automates pushing out a new version of your application to a deployment location.
I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".
Startup | |
======= | |
run pig locally: | |
$ magicpig -x local script.pig # doesn't work | |
expand pig macros: | |
$ magicpig -dryrun script.pig | |
Commands | |
======== |
"For comprehension" is a another syntaxe to use map
, flatMap
and withFilter
(or filter) methods.
yield
keyword is used to aggregate values in the resulting structure.
This composition can be used on any type implementing this methods, like List
, Option
, Future
...
def truncate_table table_name | |
config = Rails.configuration.database_configuration | |
connection = ActiveRecord::Base.connection | |
connection.disable_referential_integrity do | |
next if connection.select_value("SELECT count(*) FROM #{table_name}") == 0 | |
case config[Rails.env]["adapter"] | |
when "mysql", "mysql2", "postgresql" | |
connection.execute("TRUNCATE #{table_name}") | |
when "sqlite", "sqlite3" | |
connection.execute("DELETE FROM #{table_name}") |