Created
February 3, 2025 22:34
-
-
Save mabsboza/3ec2b3c4a8bd75c351599c6b1d2bc883 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class User < ApplicationRecord | |
validates :name, presence: true, length: { maximum: 50 } | |
validates :email, presence: true, length: { maximum: 255 } | |
end | |
# spec/models/user_spec.rb | |
require 'rails_helper' | |
RSpec.describe User, type: :model do | |
it "es válido con un nombre y un email" do | |
user = User.new(name: "Juan", email: "[email protected]") | |
expect(user).to be_valid | |
end | |
it "no es válido sin un nombre" do | |
user = User.new(name: nil, email: "[email protected]") | |
expect(user).not_to be_valid | |
end | |
it "no es válido si el nombre es demasiado largo" do | |
user = User.new(name: "a" * 51, email: "[email protected]") | |
expect(user).not_to be_valid | |
end | |
it "no es válido sin un email" do | |
user = User.new(name: "Juan", email: nil) | |
expect(user).not_to be_valid | |
end | |
it "no es válido si el email es demasiado largo" do | |
user = User.new(name: "Juan", email: "a" * 256) | |
expect(user).not_to be_valid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment