Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuncheng/ce84f94d9f8dca5a4cd1ed3e91f723f2 to your computer and use it in GitHub Desktop.
Save xuncheng/ce84f94d9f8dca5a4cd1ed3e91f723f2 to your computer and use it in GitHub Desktop.
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
#
# rspec-rails: https://github.com/rspec/rspec-rails
# Shoulda-matchers: https://github.com/thoughtbot/shoulda-matchers
# shoulda-callback-matchers: https://github.com/beatrichartz/shoulda-callback-matchers
# factory_girl_rails: https://github.com/thoughtbot/factory_girl_rails
require 'spec_helper'
RSpec.describe Model do
context "associations" do
it { is_expected.to belong_to(:user) }
end
context "validations" do
it { is_expected.to validate_presence_of(:user_id) }
end
context "callbacks" do
it { is_expected.to callback(:generate_slug).before(:create) }
end
context "norton counters" do
it { is_expected.to respond_to(:submissions_count) }
end
context "norton timestamps" do
it { is_expected.to respond_to(:info_updated_at) }
end
describe ".class_methods" do
it "..." do
# ...
end
end
describe "#instance_methods" do
it "..." do
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment