callback methos rspecs in ruby on rails
Add gem 'shoulda-callback-matchers'
In app/models/user.rb
class User < ActiveRecord::Base
after_create :create_usersetting
before_destroy :delete_user_information
end
In spec/models/user_spec.rb
require "rails_helper"
require 'factory_girl_rails'
describe User do
before(:each) do
@user = User.create(:email=>"example@gmail.com",:password=>"1234578")
end
it "should trigger create_usersetting on after create" do
should callback(:create_usersetting).after(:create)
end
it "should trigger delete_user_information on before destroy" do
is_expected.to callback(:delete_user_information).before(:destroy)
end
end
In app/models/user.rb
class User < ActiveRecord::Base
after_create :create_usersetting
before_destroy :delete_user_information
end
In spec/models/user_spec.rb
require "rails_helper"
require 'factory_girl_rails'
describe User do
before(:each) do
@user = User.create(:email=>"example@gmail.com",:password=>"1234578")
end
it "should trigger create_usersetting on after create" do
should callback(:create_usersetting).after(:create)
end
it "should trigger delete_user_information on before destroy" do
is_expected.to callback(:delete_user_information).before(:destroy)
end
end
Comments
Post a Comment