projects_helper_spec.rb
2.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'rails_helper'
describe ProjectsHelper, :type => :helper do
describe 'project_owner?' do
before :each do
@subject = FactoryGirl.build(:project_with_id)
end
context 'returns false if not logged in' do
before :each do
helper.expects(:user_signed_in?).returns(false)
end
it { expect(helper.project_owner?(@subject.id)).to be_falsey }
end
context 'returns false if is not the owner' do
before :each do
helper.expects(:user_signed_in?).returns(true)
helper.expects(:current_user).returns(FactoryGirl.build(:user))
@attributes = []
@attributes.expects(:find_by_project_id).with(@subject.id).returns(nil)
User.any_instance.expects(:project_attributes).returns(@attributes)
end
it { expect(helper.project_owner?(@subject.id)).to be_falsey }
end
context 'returns true if user is the project owner' do
before :each do
helper.expects(:user_signed_in?).returns(true)
helper.expects(:current_user).returns(FactoryGirl.build(:user))
@project_attributes = FactoryGirl.build(:project_attributes)
@attributes = []
@attributes.expects(:find_by_project_id).with(@subject.id).returns(@project_attributes)
User.any_instance.expects(:project_attributes).returns(@attributes)
end
it { expect(helper.project_owner?(@subject.id)).to be_truthy }
end
end
describe 'project_image_html' do
let(:project) { FactoryGirl.build(:project) }
let(:project_attributes) { FactoryGirl.build(:project_attributes, :with_image) }
context 'when the project has an image' do
before :each do
project.expects(:attributes).twice.returns(project_attributes)
end
it 'is expected to return an image tag with the project attribute URL' do
expect(helper.project_image_html(project)).to include("<img")
expect(helper.project_image_html(project)).to include(project_attributes.image_url)
end
end
context 'when the project does not have an image' do
before :each do
project_attributes.image_url = ""
project.expects(:attributes).twice.returns(project_attributes)
end
it 'is expected to return a default image icon with a message' do
expect(helper.project_image_html(project)).to include("<i class")
expect(helper.project_image_html(project)).to include(I18n.t('no_image_available'))
end
end
end
end