Skip to content

Instantly share code, notes, and snippets.

@bbugh
bbugh / gist:4657749
Created January 28, 2013 18:14
Using traits in FactoryGirl to do things like add tags to models, or unassociated data that multiple models would share.

Using traits in FactoryGirl for things like tags on other models, and so forth.

FactoryGirl.define do
  factory :post do
    title 'New post'
  end

  trait :with_comments do
 after :create do |post|
@bbugh
bbugh / gist:3909614
Created October 18, 2012 02:52
Ruby 1.9 passing arguments to define_method blocks
@bbugh
bbugh / gist:3907096
Created October 17, 2012 18:06
Drop and recreate test database

I would recommend dropping your test database, then re-create it and migrate:

bundle exec rake db:drop RAILS_ENV=test
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test

Shorter:

@bbugh
bbugh / gist:3882746
Created October 13, 2012 01:04
Accessing alert box in JavaScript with Capybara/rails/rspec
//Get a reference to the alert using the following:
alert = page.driver.browser.switch_to.alert
// and then hit OK with
page.driver.browser.switch_to.alert.accept
// or dismiss it with
@bbugh
bbugh / gist:3880669
Created October 12, 2012 18:22
Displaying unpushed changes on branches in git
@bbugh
bbugh / gist:3842793
Created October 5, 2012 22:21
Automatically stripping/highlighting trailing whitespace in VIM
" Two best solutions from the discussion here http://stackoverflow.com/questions/356126/how-can-you-automatically-remove-trailing-whitespace-in-vim
" Automatically strip white space on save in VIM.
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun