mezuro_configurations_helper_spec.rb
3.49 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
75
76
require 'rails_helper'
describe MezuroConfigurationsHelper, :type => :helper do
describe 'mezuro_configuration_owner?' do
before :each do
@subject = FactoryGirl.build(:mezuro_configuration)
end
context 'returns false if not logged in' do
before :each do
helper.expects(:user_signed_in?).returns(false)
end
it { expect(helper.mezuro_configuration_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))
@ownerships = []
@ownerships.expects(:find_by_mezuro_configuration_id).with(@subject.id).returns(nil)
User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships)
end
it { expect(helper.mezuro_configuration_owner?(@subject.id)).to be_falsey }
end
context 'returns true if user is the mezuro_configuration owner' do
before :each do
helper.expects(:user_signed_in?).returns(true)
helper.expects(:current_user).returns(FactoryGirl.build(:user))
@ownership = FactoryGirl.build(:mezuro_configuration_ownership)
@ownerships = []
@ownerships.expects(:find_by_mezuro_configuration_id).with(@subject.id).returns(@ownership)
User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships)
end
it { expect(helper.mezuro_configuration_owner?(@subject.id)).to be_truthy }
end
end
describe 'link to edit form' do
context 'when the metric is native' do
let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
let(:response_link) {"<a class=\"btn btn-info\" href=\"/mezuro_configurations/#{metric_configuration.configuration_id}/metric_configurations/#{metric_configuration.id}/edit\">Edit</a>"}
it { expect(helper.link_to_edit_form(metric_configuration, metric_configuration.configuration_id)).to eq(response_link) }
end
context 'when the metric is compound' do
let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) }
let(:response_link) {"<a class=\"btn btn-info\" href=\"/mezuro_configurations/#{compound_metric_configuration.configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}/edit\">Edit</a>"}
it { expect(helper.link_to_edit_form(compound_metric_configuration, compound_metric_configuration.configuration_id)).to eq(response_link) }
end
end
describe 'link to show page' do
context 'when the metric is native' do
let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
let(:response_link) {"<a class=\"btn btn-info\" href=\"/mezuro_configurations/#{metric_configuration.configuration_id}/metric_configurations/#{metric_configuration.id}\">Show</a>"}
it { expect(helper.link_to_show_page(metric_configuration, metric_configuration.configuration_id)).to eq(response_link) }
end
context 'when the metric is compound' do
let(:compound_metric_configuration) { FactoryGirl.build(:compound_metric_configuration) }
let(:response_link) {"<a class=\"btn btn-info\" href=\"/mezuro_configurations/#{compound_metric_configuration.configuration_id}/compound_metric_configurations/#{compound_metric_configuration.id}\">Show</a>"}
it { expect(helper.link_to_show_page(compound_metric_configuration, compound_metric_configuration.configuration_id)).to eq(response_link) }
end
end
end