-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model class specs #8
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Timecop here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ale tutaj nie potrzeba Timecop :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A, no to olej :)