Commit 7e706658a2e7c56e334953107703db6000b5e048
1 parent
e9f589a5
Exists in
colab
and in
4 other branches
Full tet coverage for BaseConfigurationsController
Showing
1 changed file
with
41 additions
and
9 deletions
Show diff stats
spec/controllers/base_metric_configurations_controller_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | +class CleanInheritsFromBaseConfigurationsController < BaseConfigurationsController | |
| 4 | + def metric_configuration; super; end | |
| 5 | + def update_metric_configuration (new_metric_configuration); super; end | |
| 6 | +end | |
| 7 | + | |
| 3 | 8 | class InheritsFromBaseConfigurationsController < BaseConfigurationsController |
| 4 | - | |
| 5 | 9 | def new |
| 6 | 10 | render :nothing => true |
| 7 | 11 | super |
| ... | ... | @@ -13,9 +17,9 @@ class InheritsFromBaseConfigurationsController < BaseConfigurationsController |
| 13 | 17 | end |
| 14 | 18 | |
| 15 | 19 | def show |
| 16 | - render :nothing => true | |
| 17 | 20 | update_metric_configuration(@metric_configuration) |
| 18 | 21 | super |
| 22 | + render :nothing => true | |
| 19 | 23 | end |
| 20 | 24 | |
| 21 | 25 | def metric_configuration |
| ... | ... | @@ -112,16 +116,44 @@ describe InheritsFromBaseConfigurationsController do |
| 112 | 116 | let(:reading_group) { FactoryGirl.build(:reading_group) } |
| 113 | 117 | let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } |
| 114 | 118 | |
| 115 | - before :each do | |
| 116 | - ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).returns(reading_group) | |
| 117 | - MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | |
| 118 | - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([mezuro_range]) | |
| 119 | + context 'with a valid metric_configuration' do | |
| 120 | + before :each do | |
| 121 | + ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).returns(reading_group) | |
| 122 | + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | |
| 123 | + MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([mezuro_range]) | |
| 119 | 124 | |
| 120 | - get :show, mezuro_configuration_id: metric_configuration.configuration_id.to_s, id: metric_configuration.id | |
| 125 | + get :show, mezuro_configuration_id: metric_configuration.configuration_id.to_s, id: metric_configuration.id | |
| 126 | + end | |
| 127 | + | |
| 128 | + it { subject.mezuro_ranges.should_not be_nil} | |
| 129 | + it { subject.reading_group.should_not be_nil } | |
| 121 | 130 | end |
| 122 | 131 | |
| 123 | - it { subject.mezuro_ranges.should_not be_nil} | |
| 124 | - it { subject.reading_group.should_not be_nil } | |
| 132 | + context 'with a invalid metric_configuration' do | |
| 133 | + before :each do | |
| 134 | + subject.expects(:metric_configuration).returns(false) | |
| 135 | + end | |
| 136 | + | |
| 137 | + it 'should raise a NotImplementedError' do | |
| 138 | + expect { subject.show }.to raise_error(NotImplementedError) | |
| 139 | + end | |
| 140 | + end | |
| 125 | 141 | end |
| 126 | 142 | |
| 143 | + | |
| 144 | + context 'with a inheritance without overrides methods' do | |
| 145 | + subject { CleanInheritsFromBaseConfigurationsController.new } | |
| 146 | + | |
| 147 | + describe 'metric_configuration' do | |
| 148 | + it 'should raise a NotImplementedError' do | |
| 149 | + expect { subject.metric_configuration }.to raise_error(NotImplementedError) | |
| 150 | + end | |
| 151 | + end | |
| 152 | + | |
| 153 | + describe 'update_metric_configuration' do | |
| 154 | + it 'should raise a NotImplementedError' do | |
| 155 | + expect { subject.update_metric_configuration(nil) }.to raise_error(NotImplementedError) | |
| 156 | + end | |
| 157 | + end | |
| 158 | + end | |
| 127 | 159 | end | ... | ... |