Created
November 18, 2013 09:37
-
-
Save rauxalach/7525222 to your computer and use it in GitHub Desktop.
Rails Callback Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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