Skip to content

Instantly share code, notes, and snippets.

@rauxalach
Created November 18, 2013 09:37
Show Gist options
  • Save rauxalach/7525222 to your computer and use it in GitHub Desktop.
Save rauxalach/7525222 to your computer and use it in GitHub Desktop.
Rails Callback Test
rails g model ABC status:string
rake db:migrate
class Abc < ActiveRecord::Base
before_create :set_status
private
def set_status
status = 'Test'
end
end
#Console test
rails c
a = Abc.create
a.status
#Test file using rspec
describe ABC do
describe '.before_update' do
let(:abc) { Abc.create }
it 'sets initialize status to Test' do
abc.status.should == 'Test'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment