-
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.
- Loading branch information
Showing
3 changed files
with
94 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
require 'rails_helper' | ||
require 'faker' | ||
|
||
RSpec.describe Cloth, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
before(:each) do | ||
@joy = User.create!(name: Faker::Name.unique.name, | ||
email: Faker::Internet.email, | ||
password: 'joy123', password_confirmation: 'joy123') | ||
|
||
@group = Group.create!(name: 'Tops', icon: 'some icon', user: @joy) | ||
end | ||
|
||
subject { Cloth.new(name: 'Shirt', amount: 25, user: @joy, group: @group) } | ||
|
||
before { subject.save } | ||
|
||
describe 'Check validity of Cloths' do | ||
it 'should check validity of name' do | ||
subject.name = nil | ||
expect(subject).to_not be_valid | ||
end | ||
|
||
it 'should check validity of amount' do | ||
subject.amount = nil | ||
expect(subject).to_not be_valid | ||
end | ||
|
||
it 'should check validity to be saved' do | ||
expect(subject).to be_valid | ||
end | ||
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,30 @@ | ||
require 'rails_helper' | ||
require 'faker' | ||
|
||
RSpec.describe Group, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
before(:each) do | ||
@joy = User.create!(name: Faker::Name.unique.name, | ||
email: Faker::Internet.email, | ||
password: 'joy123', password_confirmation: 'joy123') | ||
end | ||
|
||
subject { Group.new(name: 'Tops', icon: 'some icon', user: @joy) } | ||
|
||
before { subject.save } | ||
|
||
describe 'Check validity of Model' do | ||
it 'should check validity of name' do | ||
subject.name = nil | ||
expect(subject).to_not be_valid | ||
end | ||
|
||
it 'should check validity of icon' do | ||
subject.icon = nil | ||
expect(subject).to_not be_valid | ||
end | ||
|
||
it 'should check validity to be saved' do | ||
expect(subject).to be_valid | ||
end | ||
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,44 @@ | ||
require 'rails_helper' | ||
require 'faker' | ||
require 'shoulda/matchers' | ||
|
||
RSpec.describe User, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
describe 'Check user validity' do | ||
subject do | ||
User.new(name: Faker::Name.unique.name, | ||
email: Faker::Internet.email, | ||
password: 'joy123', password_confirmation: 'joy123') | ||
end | ||
|
||
it 'should be valid with correct attributes' do | ||
expect(subject).to be_valid | ||
end | ||
|
||
it 'should not be valid without a name' do | ||
subject.name = nil | ||
expect(subject).to_not be_valid | ||
end | ||
|
||
it 'should not be valid without an email' do | ||
subject.email = nil | ||
expect(subject).to_not be_valid | ||
end | ||
end | ||
|
||
context 'associations' do | ||
it { should have_many(:clothes).dependent(:destroy).class_name('Cloth').with_foreign_key(:user_id) } | ||
it { should have_many(:groups).dependent(:destroy).class_name('Group').with_foreign_key(:user_id) } | ||
end | ||
|
||
context 'validations' do | ||
it { should validate_presence_of(:email) } | ||
it { should validate_uniqueness_of(:email).case_insensitive } | ||
it { should validate_presence_of(:password) } | ||
it { should validate_length_of(:password).is_at_least(6) } | ||
it { should validate_confirmation_of(:password) } | ||
end | ||
|
||
context 'devise modules' do | ||
it { should validate_presence_of(:password_confirmation) } | ||
end | ||
end |