Commit 3d724355f53a7970ed6aff507608ce2ee49fd966
Committed by
Rafael Manzo
1 parent
82bc8ca4
Exists in
colab
and in
4 other branches
Remove BaseMetricConfigurationsController unit test
All of it's code is covered by the concrete class tests, and the abstract class tests were nothing like real usage, and will be made totally obsolete with the refactor. Signed off by: Daniel Miranda <danielkza2@gmail.com>
Showing
1 changed file
with
0 additions
and
157 deletions
Show diff stats
spec/controllers/base_metric_configurations_controller_spec.rb
... | ... | @@ -1,157 +0,0 @@ |
1 | -require 'rails_helper' | |
2 | - | |
3 | -class CleanInheritsFromBaseMetricConfigurationsController < BaseMetricConfigurationsController | |
4 | - def metric_configuration; super; end | |
5 | - def update_metric_configuration (new_metric_configuration); super; end | |
6 | -end | |
7 | - | |
8 | -class InheritsFromBaseMetricConfigurationsController < BaseMetricConfigurationsController | |
9 | - def new | |
10 | - render :nothing => true | |
11 | - super | |
12 | - end | |
13 | - | |
14 | - def create | |
15 | - render :nothing => true | |
16 | - super | |
17 | - end | |
18 | - | |
19 | - def show | |
20 | - update_metric_configuration(@metric_configuration) | |
21 | - super | |
22 | - render :nothing => true | |
23 | - end | |
24 | - | |
25 | - def metric_configuration | |
26 | - @metric_configuration | |
27 | - end | |
28 | - | |
29 | - def update_metric_configuration (new_metric_configuration) | |
30 | - @metric_configuration = new_metric_configuration | |
31 | - end | |
32 | - | |
33 | - def kalibro_ranges | |
34 | - @kalibro_ranges | |
35 | - end | |
36 | - | |
37 | - def reading_group | |
38 | - @reading_group | |
39 | - end | |
40 | -end | |
41 | - | |
42 | - | |
43 | -describe InheritsFromBaseMetricConfigurationsController, :type => :controller do | |
44 | - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration, :with_id) } | |
45 | - | |
46 | - before do | |
47 | - Rails.application.routes.draw do | |
48 | - resources :kalibro_configurations do | |
49 | - match '/metric_configurations/choose_metric' => 'metric_configurations#choose_metric', as: :choose_metric, :via => [:get] | |
50 | - resources :inherits_from_base_metric_configurations do | |
51 | - match '/metric_configurations/new' => 'metric_configurations#new', as: :new_metric_configuration, :via => [:post] | |
52 | - match '/metric_configurations/:id' => 'metric_configurations#update', as: :metric_configuration_update, :via => [:put] | |
53 | - end | |
54 | - end | |
55 | - end | |
56 | - end | |
57 | - | |
58 | - after do | |
59 | - Rails.application.reload_routes! | |
60 | - end | |
61 | - | |
62 | - describe 'new' do | |
63 | - before :each do | |
64 | - sign_in FactoryGirl.create(:user) | |
65 | - end | |
66 | - | |
67 | - context 'when the current user owns the kalibro configuration' do | |
68 | - let!(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } | |
69 | - before :each do | |
70 | - subject.expects(:kalibro_configuration_owner?).returns true | |
71 | - get :new, kalibro_configuration_id: kalibro_configuration.id | |
72 | - end | |
73 | - | |
74 | - it { expect(metric_configuration).not_to be_nil } | |
75 | - it { is_expected.to respond_with(:success) } | |
76 | - end | |
77 | - | |
78 | - context "when the current user doesn't own the kalibro configuration" do | |
79 | - before :each do | |
80 | - get :new, kalibro_configuration_id: kalibro_configuration.id | |
81 | - end | |
82 | - | |
83 | - it { is_expected.to redirect_to(kalibro_configurations_url(id: kalibro_configuration.id)) } | |
84 | - it { is_expected.to respond_with(:redirect) } | |
85 | - end | |
86 | - end | |
87 | - | |
88 | - describe 'create' do | |
89 | - let!(:metric_configuration_params) { FactoryGirl.build(:metric_configuration, metric: FactoryGirl.build(:metric)).to_hash } | |
90 | - let(:metric_collector) { FactoryGirl.build(:metric_collector) } | |
91 | - | |
92 | - before :each do | |
93 | - sign_in FactoryGirl.create(:user) | |
94 | - end | |
95 | - | |
96 | - context 'when the current user owns the kalibro configuration' do | |
97 | - before :each do | |
98 | - subject.expects(:kalibro_configuration_owner?).returns true | |
99 | - end | |
100 | - | |
101 | - context 'with valid fields' do | |
102 | - before :each do | |
103 | - post :create, kalibro_configuration_id: kalibro_configuration.id, metric_configuration: metric_configuration_params, metric_collector_name: metric_collector.name | |
104 | - end | |
105 | - | |
106 | - it { expect(subject.metric_configuration).not_to be_nil } | |
107 | - it { is_expected.to respond_with(:success) } | |
108 | - end | |
109 | - end | |
110 | - end | |
111 | - | |
112 | - describe 'show' do | |
113 | - let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) } | |
114 | - let(:reading_group) { FactoryGirl.build(:reading_group, :with_id) } | |
115 | - let(:kalibro_range) { FactoryGirl.build(:kalibro_range) } | |
116 | - | |
117 | - context 'with a valid metric_configuration' do | |
118 | - before :each do | |
119 | - ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).returns(reading_group) | |
120 | - MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | |
121 | - metric_configuration.expects(:kalibro_ranges).returns([kalibro_range]) | |
122 | - | |
123 | - get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | |
124 | - end | |
125 | - | |
126 | - it { expect(subject.kalibro_ranges).not_to be_nil} | |
127 | - it { expect(subject.reading_group).not_to be_nil } | |
128 | - end | |
129 | - | |
130 | - context 'with a invalid metric_configuration' do | |
131 | - before :each do | |
132 | - subject.expects(:metric_configuration).returns(false) | |
133 | - end | |
134 | - | |
135 | - it 'should raise a NotImplementedError' do | |
136 | - expect { subject.show }.to raise_error(NotImplementedError) | |
137 | - end | |
138 | - end | |
139 | - end | |
140 | - | |
141 | - | |
142 | - context 'with a inheritance without overrides methods' do | |
143 | - subject { CleanInheritsFromBaseMetricConfigurationsController.new } | |
144 | - | |
145 | - describe 'metric_configuration' do | |
146 | - it 'should raise a NotImplementedError' do | |
147 | - expect { subject.metric_configuration }.to raise_error(NotImplementedError) | |
148 | - end | |
149 | - end | |
150 | - | |
151 | - describe 'update_metric_configuration' do | |
152 | - it 'should raise a NotImplementedError' do | |
153 | - expect { subject.update_metric_configuration(nil) }.to raise_error(NotImplementedError) | |
154 | - end | |
155 | - end | |
156 | - end | |
157 | -end |