-
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.
Merge pull request #8 from elpassion/feature-model-specs
Model class specs
- Loading branch information
Showing
3 changed files
with
127 additions
and
1 deletion.
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,68 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Desk, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
let(:desk) { build(:desk) } | ||
let(:user) { build(:user) } | ||
|
||
it 'factory is valid' do | ||
expect(desk).to be_valid | ||
end | ||
|
||
describe 'owner' do | ||
it 'is required' do | ||
desk.owner = nil | ||
expect(desk).not_to be_valid | ||
end | ||
end | ||
|
||
describe 'finish_date' do | ||
it 'is presence' do | ||
desk.finish_at = nil | ||
expect(desk).not_to be_valid | ||
end | ||
|
||
it 'finish date has to be after start date' do | ||
desk.finish_at = 1.day.ago(desk.start_at) | ||
expect(desk).not_to be_valid | ||
end | ||
|
||
it 'finish date cannot be in the past' do | ||
desk.finish_at = 1.hour.ago(DateTime.current) | ||
expect(desk).not_to be_valid | ||
end | ||
end | ||
|
||
describe 'start_date' do | ||
it 'is presence' do | ||
desk.start_at = nil | ||
expect(desk).not_to be_valid | ||
end | ||
end | ||
|
||
describe 'owner' do | ||
let(:idea) { | ||
build(:idea, owner: user, desk: desk) | ||
} | ||
|
||
before do | ||
desk.save | ||
idea.save | ||
end | ||
|
||
it 'has only one idea by specific user in desk' do | ||
user.save | ||
|
||
second_idea = Idea.create(owner: user, desk: desk, name: 'New user idea') | ||
second_idea.save | ||
|
||
expect { second_idea.save }.not_to change { desk.ideas.count } | ||
expect(desk.ideas.first.name).to eq idea.name | ||
expect(second_idea.errors).to include(:user) | ||
end | ||
|
||
it 'has multiple idea by different user in single' do | ||
expect { create(:idea, desk: desk, name: 'First idea') | ||
create(:idea, desk: desk, name: 'Other idea') }.to change { desk.ideas.count }.by(2) | ||
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Idea, type: :model do | ||
|
||
it 'factory is valid' do | ||
expect(build(:idea)).to be_valid | ||
end | ||
|
||
describe 'owner' do | ||
it 'is assigned to user' do | ||
expect(build(:idea, owner: nil)).not_to be_valid | ||
end | ||
end | ||
|
||
describe 'assignation to desk' do | ||
it 'is assigned to desk' do | ||
expect(build(:idea, desk: nil)).not_to be_valid | ||
end | ||
end | ||
|
||
describe 'name' do | ||
it 'is required' do | ||
expect(build(:idea, name: nil)).not_to be_valid | ||
end | ||
end | ||
|
||
describe 'if time is up to add new idea' do | ||
xit 'will not add idea to an expired desk' do | ||
Timecop.freeze(2015, 10, 1, 11, 0) | ||
finish_time = DateTime.new(2015, 10, 1, 14, 0) | ||
desk = build(:desk, finish_at: finish_time) | ||
expect(build(:idea, desk: desk)).not_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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe User, type: :model do | ||
|
||
let (:owner) { create(:user) } | ||
|
||
let (:other_user) { create(:user) } | ||
|
||
let (:user_with_empty_date_of_birth) { build(:user, date_of_birth: nil)} | ||
|
||
it 'factory is valid' do | ||
expect(build(:user)).to be_valid | ||
end | ||
|
||
it 'assigns desks to user' do | ||
expect { create(:desk, owner: owner) | ||
create(:desk, owner: owner) | ||
create(:desk, owner: other_user) | ||
}.to change { owner.desks.count }.by(2) | ||
end | ||
|
||
describe 'date_of_birth' do | ||
it 'is required' do | ||
expect(user_with_empty_date_of_birth).to_not be_valid | ||
expect(user_with_empty_date_of_birth.errors[:date_of_birth]).to_not be_empty | ||
end | ||
end | ||
end |