project_spec.rb
1.29 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'
describe Project, :type => :model do
describe 'methods' do
describe 'latest' do
let!(:project) { FactoryGirl.build(:project_with_id, id: 1) }
let!(:another_project) { FactoryGirl.build(:another_project, id: 2) }
let!(:project_attributes) { FactoryGirl.build(:project_attributes) }
before :each do
project.expects(:attributes).returns(project_attributes)
another_project.expects(:attributes).returns(project_attributes)
Project.expects(:all).returns([project, another_project])
end
it 'should return the two projects ordered' do
expect(Project.latest(2)).to eq([another_project, project])
end
context 'when no parameter is passed' do
it 'should return just the most recent project' do
expect(Project.latest).to eq([another_project])
end
end
end
describe 'attributes' do
subject { FactoryGirl.build(:project_with_id) }
let!(:project_attributes) { FactoryGirl.build(:project_attributes) }
before :each do
ProjectAttributes.expects(:find_by_project_id).returns(project_attributes)
end
it 'is expected to return the project attributes' do
expect(subject.attributes).to eq(project_attributes)
end
end
end
end