project_attributes_spec.rb
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rails_helper'
RSpec.describe ProjectAttributes, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:user) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:user) }
end
describe 'methods' do
let(:project) { FactoryGirl.build(:project_with_id) }
describe 'project' do
subject { FactoryGirl.build(:project_attributes, :bare, project_id: project.id) }
before :each do
Project.expects(:find).with(subject.project_id).returns(project)
end
it 'should return the project' do
expect(subject.project).to eq(project)
end
end
describe 'project=' do
subject { FactoryGirl.build(:project_attributes, :bare) }
before do
subject.project = project
end
it 'is expected to set the project' do
expect(subject.project).to eq project
end
it 'is expected to set the project_id' do
expect(subject.project_id).to eq project.id
end
end
end
end