-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented User Model validation and tested in user_spec.rb, the tes…
…ts using users factory
- Loading branch information
Kornelije Sajler
committed
Nov 5, 2012
1 parent
2c239f5
commit f2edd55
Showing
3 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Read about factories at https://github.com/thoughtbot/factory_girl | ||
|
||
FactoryGirl.define do | ||
factory :user do | ||
email "MyString" | ||
password_digest "MyString" | ||
email 'xajler@gmail.com' | ||
password 'x1234567' | ||
password_digest 'x1234567' | ||
full_name 'Kornelije Sajler' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,57 @@ | ||
require 'spec_helper' | ||
|
||
describe User do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
let :user do | ||
build :user | ||
end | ||
|
||
subject do | ||
user | ||
end | ||
|
||
context 'is invalid' do | ||
it 'when required #email is not given' do | ||
user.email = '' | ||
should_not be_valid | ||
end | ||
|
||
it 'when required #password is not given' do | ||
user.password = '' | ||
should_not be_valid | ||
end | ||
|
||
it 'when required #full_name is not given' do | ||
user.full_name = '' | ||
should_not be_valid | ||
end | ||
|
||
it 'when #email is not unique' do | ||
user.save | ||
user1 = build :user | ||
user1.save | ||
|
||
user1.should_not be_valid | ||
user1.errors.full_messages[0].should match 'Email has already been taken' | ||
end | ||
|
||
it 'when #email format is not valid' do | ||
user.email = 'invalid mail' | ||
should_not be_valid | ||
end | ||
|
||
it 'when #password is not at least 8 characters' do | ||
user.password = 'abc123' | ||
should_not be_valid | ||
end | ||
end | ||
|
||
it '#email must not ever change after it is created' do | ||
user.save | ||
user.update_attributes email: 'ksajler@gmail.com' | ||
user.reload.email.should match 'xajler@gmail.com' | ||
end | ||
|
||
it 'is valid' do | ||
should be_valid | ||
end | ||
end |