Commit 8c64ffc8af338a0f632e5422e10fdc73492ffafe
1 parent
2f185be5
Exists in
colab
and in
4 other branches
Coverup all metric_con finding branches on Base
We were not testing the case when the returned metric_configuration was from a different KalibroConfiguration. This prevents different ownership MetricConfiguration editions and false positives for ownership_authentication helper. Signed off by: Heitor Reis <marcheing@gmail.com>
Showing
1 changed file
with
33 additions
and
12 deletions
Show diff stats
spec/controllers/metric_configurations_controller_spec.rb
@@ -105,29 +105,50 @@ describe MetricConfigurationsController, :type => :controller do | @@ -105,29 +105,50 @@ describe MetricConfigurationsController, :type => :controller do | ||
105 | let(:kalibro_range) { FactoryGirl.build(:kalibro_range) } | 105 | let(:kalibro_range) { FactoryGirl.build(:kalibro_range) } |
106 | 106 | ||
107 | before :each do | 107 | before :each do |
108 | - KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns kalibro_configuration | ||
109 | - MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) | 108 | + KalibroConfiguration.expects(:find).with(kalibro_configuration.id).returns kalibro_configuration |
110 | end | 109 | end |
111 | 110 | ||
112 | - context 'with valid parameters' do | 111 | + context 'with a valid metric configuration instance' do |
113 | before :each do | 112 | before :each do |
114 | - ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).returns(reading_group) | ||
115 | - metric_configuration.expects(:kalibro_ranges).returns([kalibro_range]) | 113 | + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) |
114 | + end | ||
115 | + | ||
116 | + context 'with valid parameters' do | ||
117 | + before :each do | ||
118 | + ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).returns(reading_group) | ||
119 | + metric_configuration.expects(:kalibro_ranges).returns([kalibro_range]) | ||
120 | + | ||
121 | + get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | ||
122 | + end | ||
116 | 123 | ||
117 | - get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | 124 | + it { is_expected.to render_template(:show) } |
118 | end | 125 | end |
119 | 126 | ||
120 | - it { is_expected.to render_template(:show) } | 127 | + context 'with invalid parameters' do |
128 | + before :each do | ||
129 | + ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).raises(KalibroClient::Errors::RecordNotFound) | ||
130 | + | ||
131 | + get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | ||
132 | + end | ||
133 | + | ||
134 | + it { is_expected.to redirect_to(kalibro_configuration_path(kalibro_configuration.id)) } | ||
135 | + end | ||
121 | end | 136 | end |
122 | 137 | ||
123 | - context 'with invalid parameters' do | ||
124 | - before :each do | ||
125 | - ReadingGroup.expects(:find).with(metric_configuration.reading_group_id).raises(KalibroClient::Errors::RecordNotFound) | 138 | + context 'with an invalid metric configuration instance' do |
139 | + let!(:invalid_metric_configuration) { FactoryGirl.build(:metric_configuration, reading_group_id: reading_group.id, kalibro_configuration_id: metric_configuration.kalibro_configuration_id + 1) } | ||
126 | 140 | ||
127 | - get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | 141 | + before :each do |
142 | + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(invalid_metric_configuration) | ||
128 | end | 143 | end |
129 | 144 | ||
130 | - it { is_expected.to redirect_to(kalibro_configuration_path(kalibro_configuration.id)) } | 145 | + context 'with valid parameters' do |
146 | + before :each do | ||
147 | + get :show, kalibro_configuration_id: metric_configuration.kalibro_configuration_id.to_s, id: metric_configuration.id | ||
148 | + end | ||
149 | + | ||
150 | + it { is_expected.to respond_with(:not_found) } | ||
151 | + end | ||
131 | end | 152 | end |
132 | end | 153 | end |
133 | 154 |