hotspot_metric_configuration_controller_spec.rb
2.16 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
require 'rails_helper'
describe HotspotMetricConfigurationsController, :type => :controller do
let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration, :with_id) }
describe 'create' do
let!(:metric_configuration) { FactoryGirl.build(:hotspot_metric_configuration) }
let(:metric_configuration_params) { metric_configuration.to_hash }
let(:metric_collector) { FactoryGirl.build(:metric_collector) }
before do
sign_in FactoryGirl.create(:user)
end
context 'when the current user owns the metric configuration' do
before :each do
KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns kalibro_configuration
subject.expects(:kalibro_configuration_owner?).returns true
end
context 'with valid fields' do
before :each do
MetricConfiguration.any_instance.expects(:save).returns(true)
KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find_by_name).with(metric_collector.name).returns(metric_collector)
metric_collector.expects(:find_metric_by_code).with(metric_configuration.metric.code).returns(metric_configuration.metric)
post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_code: metric_configuration.metric.code
end
it { is_expected.to respond_with(:redirect) }
end
context 'with invalid fields' do
before :each do
MetricConfiguration.any_instance.expects(:save).returns(false)
KalibroClient::Entities::Processor::MetricCollectorDetails.expects(:find_by_name).with(metric_collector.name).returns(metric_collector)
metric_collector.expects(:find_metric_by_code).with(metric_configuration.metric.code).returns(metric_configuration.metric)
post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name, metric_code: metric_configuration.metric.code
end
it { is_expected.to respond_with(:redirect) }
end
end
end
end