repository_attributes_spec.rb
1.36 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
43
44
45
46
47
require 'rails_helper'
RSpec.describe RepositoryAttributes, type: :model do
context 'validations' do
it { is_expected.to validate_presence_of(:repository_id) }
it { is_expected.to validate_presence_of(:user) }
end
describe 'associations' do
it { is_expected.to belong_to(:user) }
end
describe 'methods' do
describe 'repository' do
subject { FactoryGirl.build(:repository_attributes, repository: nil) }
let(:repository) { FactoryGirl.build(:repository) }
before :each do
Repository.expects(:find).with(subject.repository_id).returns(repository)
end
it 'should return the repository' do
expect(subject.repository).to eq(repository)
end
end
describe 'repository=' do
subject { FactoryGirl.build(:repository_attributes) }
let(:repository) { FactoryGirl.build(:repository) }
context 'when the repository is not nil' do
it "should set the repository and it's ID correctly" do
subject.repository = repository
expect(subject.repository).to eq(repository)
expect(subject.repository_id).to eq(repository.id)
end
end
context 'when the repository is nil' do
it "should unset the repository id" do
subject.repository = nil
expect(subject.repository_id).to be_nil
end
end
end
end
end