Skip to content

Commit

Permalink
add validation for username and fullname presence
Browse files Browse the repository at this point in the history
  • Loading branch information
acushlakoncept committed Aug 25, 2020
1 parent 264d416 commit 7327527
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--require spec_helper
--format documentation
8 changes: 6 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class User < ApplicationRecord
validates :username, presence: true, length: { minimum: 3, maximum: 10 }
validates :fullname, presence: true, length: { minimum: 3, maximum: 20 }
validates :username, presence: true, length: { minimum: 3, maximum: 10,
too_long: 'Maximum allowed username is 10 characters.'
too_short: 'Minimum allowed characters for username is 3' }
validates :fullname, presence: true, length: { minimum: 6, maximum: 20,
too_long: 'Maximum allowed fullname is 20 characters.'
too_short: 'Minimum allowed characters for fullname is 6'}
end
6 changes: 5 additions & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'rails_helper'

RSpec.describe User, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
it { should validate_presence_of(:username) }
it { should validate_presence_of(:fullname) }



end

0 comments on commit 7327527

Please sign in to comment.