Created
November 15, 2018 19:40
-
-
Save ysnerdem/6f9416f7ff18fdcf7b021978ec5fd299 to your computer and use it in GitHub Desktop.
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
one: | |
name: MyString | |
email: MyString | |
two: | |
name: MyString | |
email: MyString | |
valid: | |
name: ysn | |
email: ysn@kobiks.com | |
old: | |
name: Old | |
email: old@example.com | |
created_at: <%= 2.weeks.ago %> |
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
#app/models/user.rb | |
class User < ApplicationRecord | |
scope :recent, -> { where('created_at > ?', 1.week.ago) } | |
has_many :posts | |
validates :name, :email, presence: true | |
end |
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
#test/models/user_test.rb | |
require 'test_helper' | |
class UserTest < ActiveSupport::TestCase | |
def setup | |
@user = users(:valid) | |
end | |
test 'valid user' do | |
assert @user.valid? | |
end | |
test 'invalid without name' do | |
@user.name = nil | |
refute @user.valid? | |
assert_not_nil @user.errors[:name] | |
end | |
test 'invalid without email' do | |
@user.email = nil | |
refute @user.valid? | |
assert_not_nil @user.errors[:email] | |
end | |
test '#posts' do | |
assert_equal 2, @user.posts.size | |
end | |
test '#recent' do | |
assert_includes User.recent, users(:valid) | |
refute_includes User.recent, users(:old) | |
end | |
end |
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
one: | |
name: MyString | |
email: MyString | |
two: | |
name: MyString | |
email: MyString | |
valid: | |
name: ysn | |
email: ysn@kobiks.com | |
old: | |
name: Old | |
email: old@example.com | |
created_at: <%= 2.weeks.ago %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment