Last active
          August 29, 2015 14:23 
        
      - 
      
 - 
        
Save jesuslerma/9c9fc3708c678e370313 to your computer and use it in GitHub Desktop.  
    solution
  
        
  
    
      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
    
  
  
    
  | require 'rails_helper' | |
| RSpec.describe User, type: :model do | |
| let(:user) {FactoryGirl.create :user} | |
| subject { user } | |
| context "attributes" do | |
| it { is_expected.to respond_to(:username) } | |
| it { is_expected.to respond_to(:full_name) } | |
| it { is_expected.to respond_to(:bio) } | |
| end | |
| context "validations" do | |
| it { is_expected.to validate_presence_of(:username) } | |
| it { is_expected.to validate_presence_of(:full_name) } | |
| it { is_expected.to validate_length_of(:bio).is_at_most(300) } | |
| it { is_expected.to allow_value('Jesuslerma3').for(:username) } | |
| it { is_expected.to_not allow_value('jesuslerma').for(:username) } | |
| it { is_expected.to validate_uniqueness_of(:username)} | |
| end | |
| end | 
  
    
      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 < ActiveRecord::Base | |
| # Include default devise modules. Others available are: | |
| # :confirmable, :lockable, :timeoutable and :omniauthable | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :validatable | |
| validates :username, :full_name, presence: true | |
| validates :bio, length: { maximum: 300 } | |
| validates :username, format: { | |
| with: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/, | |
| multiline: true, | |
| message: "Only allow username with at least 1 number and 1 upcase letter" | |
| } | |
| validates :username, uniqueness: true | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment