diff --git a/spec/models/cloth_spec.rb b/spec/models/cloth_spec.rb index 43b3c62..f4eb9d8 100644 --- a/spec/models/cloth_spec.rb +++ b/spec/models/cloth_spec.rb @@ -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 diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index be100cf..69a6ce5 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 47a31bb..f8a7a18 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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