$ rails g model User
belongs_to
has_one
RSpec::Matchers.define(:be_same_file_as) do |exected_file_path| | |
match do |actual_file_path| | |
expect(md5_hash(actual_file_path)).to eq(md5_hash(expected_file_path)) | |
end | |
def md5_hash(file_path) | |
Digest::MD5.hexdigest(File.read(file_path)) | |
end | |
end |
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.
#!/bin/env ruby | |
# lazy hack from Robert Klemme | |
module Memory | |
# sizes are guessed, I was too lazy to look | |
# them up and then they are also platform | |
# dependent | |
REF_SIZE = 4 # ? | |
OBJ_OVERHEAD = 4 # ? |
RSpec::Matchers.define :have_meta do |name, expected| | |
match do |actual| | |
has_css?("meta[name='#{name}'][content='#{expected}']") | |
end | |
failure_message_for_should do |actual| | |
actual = first("meta[name='#{name}']") | |
if actual | |
"expected that meta #{name} would have content='#{expected}' but was '#{actual[:content]}'" | |
else |
module Mongoid | |
# Helps to override find method in an embedded document. | |
# Usage : | |
# - add to your model "include Mongoid::EmbeddedFindable" | |
# - override find method with: | |
# def self.find(id) | |
# find_through(Book, 'chapter', id) | |
# end | |
module EmbeddedFindable |
# Thanks to http://makandracards.com/makandra/1431-resque-+-god-+-capistrano for an idea and v2 version. | |
namespace :god do | |
def god_is_running | |
capture(:bundle, "exec god status > /dev/null 2>&1 || echo 'god not running'") != 'god not running' | |
end | |
# Must be executed within SSHKit context | |
def config_file | |
"#{release_path}/config/god.rb" |
# Change YOUR_TOKEN to your prerender token | |
# Change example.com (server_name) to your website url | |
# Change /path/to/your/root to the correct value | |
server { | |
listen 80; | |
server_name example.com; | |
root /path/to/your/root; | |
index index.html; |
# Requires Capistrano 3.2 or later | |
namespace :deploy do | |
after :finishing, :tag_and_push_tag do | |
on roles(:app) do | |
within release_path do | |
set(:current_revision, capture(:cat, 'REVISION')) | |
# release path may be resolved already or not | |
resolved_release_path = capture(:pwd, "-P") |
These are my notes basically. At first i created this gist just as a reminder for myself. But feel free to use this for your project as a starting point. If you have questions you can find me on twitter @thomasf https://twitter.com/thomasf This is how i used it on a Debian Wheezy testing (https://www.debian.org/releases/testing/)
Discuss, ask questions, etc. here https://news.ycombinator.com/item?id=7445545