Commit 8c803107cd3f13f592a775a4fccd1eded2f9c4a4

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent c150494b

WIP: Fixing reading acceptance tests

Fixed kalibro_configurations factory
features/step_definitions/configuration_steps.rb
... ... @@ -7,15 +7,15 @@ Given(/^I am at the New Configuration page$/) do
7 7 end
8 8  
9 9 Given(/^I have a configuration named "(.*?)"$/) do |name|
10   - @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, {id: nil, name: name})
  10 + @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, {name: name})
11 11 end
12 12  
13 13 Given(/^I have a sample configuration$/) do
14   - @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, {id: nil})
  14 + @kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
15 15 end
16 16  
17 17 Given(/^I own a sample configuration$/) do
18   - @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, {id: nil})
  18 + @kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
19 19 FactoryGirl.create(:kalibro_configuration_ownership, {id: nil, user_id: @user.id, kalibro_configuration_id: @kalibro_configuration.id})
20 20 end
21 21  
... ... @@ -28,7 +28,7 @@ Given(/^I am at the sample configuration edit page$/) do
28 28 end
29 29  
30 30 Given(/^I own a configuration named "(.*?)"$/) do |name|
31   - @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, {id: nil, name: name})
  31 + @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, {name: name})
32 32 FactoryGirl.create(:kalibro_configuration_ownership, {id: nil, user_id: @user.id, kalibro_configuration_id: @kalibro_configuration.id})
33 33 end
34 34  
... ... @@ -49,7 +49,7 @@ Then(/^I should be in the All configurations page$/) do
49 49 end
50 50  
51 51 Then(/^the sample configuration should not be there$/) do
52   - expect { KalibroConfiguration.find(@kalibro_configuration.id) }.to raise_error
  52 + expect { KalibroConfiguration.find(@kalibro_configuration.id) }.to raise_error
53 53 end
54 54  
55 55 Then(/^the sample configuration should be there$/) do
... ...
features/step_definitions/repository_steps.rb
1 1 Given(/^I have a sample configuration with native metrics but without ranges$/) do
2 2 reading_group = FactoryGirl.create(:reading_group)
3 3 reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id})
4   - @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, id: nil)
  4 + @kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
5 5 metric_configuration = FactoryGirl.create(:metric_configuration,
6 6 {metric: FactoryGirl.build(:loc),
7 7 reading_group_id: reading_group.id,
... ... @@ -16,7 +16,7 @@ Given(/^I have a sample configuration with native metrics$/) do
16 16 KalibroClient::Processor::MetricCollector.find('Analizo').supported_metrics.select { |x| not x.persisted? }.save
17 17  
18 18  
19   - @kalibro_configuration = FactoryGirl.create(:kalibro_configuration, id: nil)
  19 + @kalibro_configuration = FactoryGirl.create(:kalibro_configuration)
20 20 metric_configuration = FactoryGirl.create(:metric_configuration,
21 21 {metric: FactoryGirl.build(:loc),
22 22 reading_group_id: reading_group.id,
... ...
spec/controllers/base_metric_configurations_controller_spec.rb
... ... @@ -41,7 +41,7 @@ end
41 41  
42 42  
43 43 describe InheritsFromBaseMetricConfigurationsController, :type => :controller do
44   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
  44 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
45 45  
46 46 before do
47 47 Rails.application.routes.draw do
... ...
spec/controllers/compound_metric_configurations_controller_spec.rb
1 1 require 'rails_helper'
2 2  
3 3 describe CompoundMetricConfigurationsController, :type => :controller do
4   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
  4 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
5 5  
6 6 describe 'new' do
7 7 before :each do
... ...
spec/controllers/concerns/ownership_authentication_spec.rb
... ... @@ -65,7 +65,7 @@ describe OwnershipAuthentication, type: :controller do
65 65 end
66 66  
67 67 describe 'kalibro_configuration_owner?' do
68   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
  68 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
69 69  
70 70 context 'Not KalibroConfigurationsController nor MetricConfigurationsController nor CompoundMetricConfigurationsController' do
71 71 let!(:projects_controller) { ProjectsController.new }
... ...
spec/controllers/kalibro_configurations_controller_spec.rb 0 → 100644
... ... @@ -0,0 +1,270 @@
  1 +require 'rails_helper'
  2 +
  3 +describe KalibroConfigurationsController, :type => :controller do
  4 +
  5 + describe 'new' do
  6 + before :each do
  7 + sign_in FactoryGirl.create(:user)
  8 + get :new
  9 + end
  10 +
  11 + it { is_expected.to respond_with(:success) }
  12 + it { is_expected.to render_template(:new) }
  13 + end
  14 +
  15 + describe 'create' do
  16 + before do
  17 + sign_in FactoryGirl.create(:user)
  18 + end
  19 +
  20 + context 'with valid fields' do
  21 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
  22 + let(:subject_params) { kalibro_configuration.to_hash }
  23 +
  24 + before :each do
  25 + KalibroConfiguration.any_instance.expects(:save).returns(true)
  26 + end
  27 +
  28 + context 'rendering the show' do
  29 + before :each do
  30 + post :create, :kalibro_configuration => subject_params
  31 + end
  32 +
  33 + it 'should redirect to the show view' do
  34 + expect(response).to redirect_to kalibro_configuration_path(kalibro_configuration.id)
  35 + end
  36 + end
  37 +
  38 + context 'without rendering the show view' do
  39 + before :each do
  40 + post :create, :kalibro_configuration => subject_params
  41 + end
  42 +
  43 + it { is_expected.to respond_with(:redirect) }
  44 + end
  45 + end
  46 +
  47 + context 'with an invalid field' do
  48 + before :each do
  49 + @subject = FactoryGirl.build(:kalibro_configuration_with_id)
  50 + @subject_params = @subject.to_hash
  51 +
  52 + KalibroConfiguration.expects(:new).at_least_once.with(@subject_params).returns(@subject)
  53 + KalibroConfiguration.any_instance.expects(:save).returns(false)
  54 +
  55 + post :create, :kalibro_configuration => @subject_params
  56 + end
  57 +
  58 + it { is_expected.to render_template(:new) }
  59 + end
  60 + end
  61 +
  62 + describe 'show' do
  63 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
  64 + let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
  65 +
  66 + before :each do
  67 + kalibro_configuration.expects(:metric_configurations).returns(metric_configuration)
  68 + subject.expects(:find_resource).with(KalibroConfiguration, kalibro_configuration.id).returns(kalibro_configuration)
  69 +
  70 + get :show, :id => kalibro_configuration.id
  71 + end
  72 +
  73 + it { is_expected.to render_template(:show) }
  74 +
  75 + after :each do
  76 + Rails.cache.clear
  77 + end
  78 + end
  79 +
  80 + describe 'destroy' do
  81 + before do
  82 + @subject = FactoryGirl.build(:kalibro_configuration_with_id)
  83 + end
  84 +
  85 + context 'with an User logged in' do
  86 + before do
  87 + sign_in FactoryGirl.create(:user)
  88 + @ownership = FactoryGirl.build(:kalibro_configuration_ownership)
  89 + @ownerships = []
  90 + end
  91 +
  92 + context 'when the user owns the kalibro_configuration' do
  93 + before :each do
  94 + @ownership.expects(:destroy)
  95 + @subject.expects(:destroy)
  96 +
  97 + #Those two mocks looks the same but they are necessary since params[:id] is a String and @configuration.id is an Integer :(
  98 + @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(@ownership)
  99 + @ownerships.expects(:find_by_kalibro_configuration_id).with(@subject.id).returns(@ownership)
  100 +
  101 + User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
  102 +
  103 + subject.expects(:find_resource).with(KalibroConfiguration, @subject.id).returns(@subject)
  104 + delete :destroy, :id => @subject.id
  105 + end
  106 +
  107 + it 'should redirect to the kalibro_configurations page' do
  108 + expect(response).to redirect_to kalibro_configurations_url
  109 + end
  110 +
  111 + it { is_expected.to respond_with(:redirect) }
  112 + end
  113 +
  114 + context "when the user doesn't own the kalibro_configuration" do
  115 + before :each do
  116 + @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(nil)
  117 + User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
  118 +
  119 + delete :destroy, :id => @subject.id
  120 + end
  121 +
  122 + it { is_expected.to redirect_to(kalibro_configurations_path(@subject.id)) }
  123 + end
  124 + end
  125 +
  126 + context 'with no User logged in' do
  127 + before :each do
  128 + delete :destroy, :id => @subject.id
  129 + end
  130 +
  131 + it { is_expected.to redirect_to new_user_session_path }
  132 + end
  133 + end
  134 +
  135 + describe 'index' do
  136 + before :each do
  137 + @subject = FactoryGirl.build(:kalibro_configuration_with_id)
  138 + KalibroConfiguration.expects(:all).returns([@subject])
  139 + get :index
  140 + end
  141 +
  142 + it { is_expected.to render_template(:index) }
  143 + end
  144 +
  145 + describe 'edit' do
  146 + before do
  147 + @subject = FactoryGirl.build(:kalibro_configuration_with_id)
  148 + end
  149 +
  150 + context 'with an User logged in' do
  151 + before do
  152 + @user = FactoryGirl.create(:user)
  153 + @ownership = FactoryGirl.build(:kalibro_configuration_ownership)
  154 + @ownerships = []
  155 +
  156 + User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
  157 +
  158 + sign_in @user
  159 + end
  160 +
  161 + context 'when the user owns the kalibro_configuration' do
  162 + before :each do
  163 + subject.expects(:find_resource).with(KalibroConfiguration, @subject.id).returns(@subject)
  164 + @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(@ownership)
  165 +
  166 + get :edit, :id => @subject.id
  167 + end
  168 +
  169 + it { is_expected.to render_template(:edit) }
  170 +
  171 + it 'should assign to @kalibro_configuration the @subject' do
  172 + expect(assigns(:kalibro_configuration)).to eq(@subject)
  173 + end
  174 + end
  175 +
  176 + context 'when the user does not own the kalibro_configuration' do
  177 + before do
  178 + @subject = FactoryGirl.build(:another_kalibro_configuration_with_id)
  179 + @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(nil)
  180 +
  181 + get :edit, :id => @subject.id
  182 + end
  183 +
  184 + it { is_expected.to redirect_to(kalibro_configurations_path(@subject.id)) }
  185 + it { is_expected.to set_the_flash[:notice].to("You're not allowed to do this operation") }
  186 + end
  187 + end
  188 +
  189 + context 'with no user logged in' do
  190 + before :each do
  191 + get :edit, :id => @subject.id
  192 + end
  193 +
  194 + it { is_expected.to redirect_to new_user_session_path }
  195 + end
  196 + end
  197 +
  198 + describe 'update' do
  199 + let(:kalibro_configuration) {FactoryGirl.build(:kalibro_configuration_with_id)}
  200 + let(:kalibro_configuration_params) { kalibro_configuration.to_hash }
  201 +
  202 + context 'when the user is logged in' do
  203 + before do
  204 + sign_in FactoryGirl.create(:user)
  205 + end
  206 +
  207 + context 'when user owns the kalibro_configuration' do
  208 + before do
  209 + @ownership = FactoryGirl.build(:kalibro_configuration_ownership)
  210 + @ownerships = []
  211 +
  212 + @ownerships.expects(:find_by_kalibro_configuration_id).with("#{kalibro_configuration.id}").returns(@ownership)
  213 + User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
  214 + end
  215 +
  216 + context 'with valid fields' do
  217 + before :each do
  218 + subject.expects(:find_resource).with(KalibroConfiguration, kalibro_configuration.id).returns(kalibro_configuration)
  219 + KalibroConfiguration.any_instance.expects(:update).with(kalibro_configuration_params).returns(true)
  220 + end
  221 +
  222 + context 'rendering the show' do
  223 + before :each do
  224 + post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
  225 + end
  226 +
  227 + it 'should redirect to the show view' do
  228 + expect(response).to redirect_to kalibro_configuration_path(kalibro_configuration.id)
  229 + end
  230 + end
  231 +
  232 + context 'without rendering the show view' do
  233 + before :each do
  234 + post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
  235 + end
  236 +
  237 + it { is_expected.to respond_with(:redirect) }
  238 + end
  239 + end
  240 +
  241 + context 'with an invalid field' do
  242 + before :each do
  243 + subject.expects(:find_resource).with(KalibroConfiguration, kalibro_configuration.id).returns(kalibro_configuration)
  244 + KalibroConfiguration.any_instance.expects(:update).with(kalibro_configuration_params).returns(false)
  245 +
  246 + post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
  247 + end
  248 +
  249 + it { is_expected.to render_template(:edit) }
  250 + end
  251 + end
  252 +
  253 + context 'when the user does not own the kalibro_configuration' do
  254 + before :each do
  255 + post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
  256 + end
  257 +
  258 + it { is_expected.to redirect_to kalibro_configurations_path(kalibro_configuration.id) }
  259 + end
  260 + end
  261 +
  262 + context 'with no user logged in' do
  263 + before :each do
  264 + post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
  265 + end
  266 +
  267 + it { is_expected.to redirect_to new_user_session_path }
  268 + end
  269 + end
  270 +end
... ...
spec/controllers/metric_configurations_controller_spec.rb
1 1 require 'rails_helper'
2 2  
3 3 describe MetricConfigurationsController, :type => :controller do
4   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
  4 + let!(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
5 5 describe 'choose_metric' do
6 6 let(:metric_collector) { FactoryGirl.build(:metric_collector) }
7 7 before :each do
... ... @@ -53,7 +53,6 @@ describe MetricConfigurationsController, :type => :controller do
53 53 describe 'create' do
54 54 let!(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
55 55 let(:metric_configuration_params) { metric_configuration.to_hash }
56   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
57 56 let(:metric_collector) { FactoryGirl.build(:metric_collector) }
58 57  
59 58 before do
... ...
spec/controllers/mezuro_configurations_controller_spec.rb
... ... @@ -1,270 +0,0 @@
1   -require 'rails_helper'
2   -
3   -describe KalibroConfigurationsController, :type => :controller do
4   -
5   - describe 'new' do
6   - before :each do
7   - sign_in FactoryGirl.create(:user)
8   - get :new
9   - end
10   -
11   - it { is_expected.to respond_with(:success) }
12   - it { is_expected.to render_template(:new) }
13   - end
14   -
15   - describe 'create' do
16   - before do
17   - sign_in FactoryGirl.create(:user)
18   - end
19   -
20   - context 'with valid fields' do
21   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
22   - let(:subject_params) { Hash[FactoryGirl.attributes_for(:kalibro_configuration).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
23   -
24   - before :each do
25   - KalibroConfiguration.any_instance.expects(:save).returns(true)
26   - end
27   -
28   - context 'rendering the show' do
29   - before :each do
30   - post :create, :kalibro_configuration => subject_params
31   - end
32   -
33   - it 'should redirect to the show view' do
34   - expect(response).to redirect_to kalibro_configuration_path(kalibro_configuration.id)
35   - end
36   - end
37   -
38   - context 'without rendering the show view' do
39   - before :each do
40   - post :create, :kalibro_configuration => subject_params
41   - end
42   -
43   - it { is_expected.to respond_with(:redirect) }
44   - end
45   - end
46   -
47   - context 'with an invalid field' do
48   - before :each do
49   - @subject = FactoryGirl.build(:kalibro_configuration)
50   - @subject_params = Hash[FactoryGirl.attributes_for(:kalibro_configuration).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
51   -
52   - KalibroConfiguration.expects(:new).at_least_once.with(@subject_params).returns(@subject)
53   - KalibroConfiguration.any_instance.expects(:save).returns(false)
54   -
55   - post :create, :kalibro_configuration => @subject_params
56   - end
57   -
58   - it { is_expected.to render_template(:new) }
59   - end
60   - end
61   -
62   - describe 'show' do
63   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
64   - let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
65   -
66   - before :each do
67   - kalibro_configuration.expects(:metric_configurations).returns(metric_configuration)
68   - subject.expects(:find_resource).with(KalibroConfiguration, kalibro_configuration.id).returns(kalibro_configuration)
69   -
70   - get :show, :id => kalibro_configuration.id
71   - end
72   -
73   - it { is_expected.to render_template(:show) }
74   -
75   - after :each do
76   - Rails.cache.clear
77   - end
78   - end
79   -
80   - describe 'destroy' do
81   - before do
82   - @subject = FactoryGirl.build(:kalibro_configuration)
83   - end
84   -
85   - context 'with an User logged in' do
86   - before do
87   - sign_in FactoryGirl.create(:user)
88   - @ownership = FactoryGirl.build(:kalibro_configuration_ownership)
89   - @ownerships = []
90   - end
91   -
92   - context 'when the user owns the kalibro_configuration' do
93   - before :each do
94   - @ownership.expects(:destroy)
95   - @subject.expects(:destroy)
96   -
97   - #Those two mocks looks the same but they are necessary since params[:id] is a String and @configuration.id is an Integer :(
98   - @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(@ownership)
99   - @ownerships.expects(:find_by_kalibro_configuration_id).with(@subject.id).returns(@ownership)
100   -
101   - User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
102   -
103   - subject.expects(:find_resource).with(KalibroConfiguration, @subject.id).returns(@subject)
104   - delete :destroy, :id => @subject.id
105   - end
106   -
107   - it 'should redirect to the kalibro_configurations page' do
108   - expect(response).to redirect_to kalibro_configurations_url
109   - end
110   -
111   - it { is_expected.to respond_with(:redirect) }
112   - end
113   -
114   - context "when the user doesn't own the kalibro_configuration" do
115   - before :each do
116   - @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(nil)
117   - User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
118   -
119   - delete :destroy, :id => @subject.id
120   - end
121   -
122   - it { is_expected.to redirect_to(kalibro_configurations_path(@subject.id)) }
123   - end
124   - end
125   -
126   - context 'with no User logged in' do
127   - before :each do
128   - delete :destroy, :id => @subject.id
129   - end
130   -
131   - it { is_expected.to redirect_to new_user_session_path }
132   - end
133   - end
134   -
135   - describe 'index' do
136   - before :each do
137   - @subject = FactoryGirl.build(:kalibro_configuration)
138   - KalibroConfiguration.expects(:all).returns([@subject])
139   - get :index
140   - end
141   -
142   - it { is_expected.to render_template(:index) }
143   - end
144   -
145   - describe 'edit' do
146   - before do
147   - @subject = FactoryGirl.build(:kalibro_configuration)
148   - end
149   -
150   - context 'with an User logged in' do
151   - before do
152   - @user = FactoryGirl.create(:user)
153   - @ownership = FactoryGirl.build(:kalibro_configuration_ownership)
154   - @ownerships = []
155   -
156   - User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
157   -
158   - sign_in @user
159   - end
160   -
161   - context 'when the user owns the kalibro_configuration' do
162   - before :each do
163   - subject.expects(:find_resource).with(KalibroConfiguration, @subject.id).returns(@subject)
164   - @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(@ownership)
165   -
166   - get :edit, :id => @subject.id
167   - end
168   -
169   - it { is_expected.to render_template(:edit) }
170   -
171   - it 'should assign to @kalibro_configuration the @subject' do
172   - expect(assigns(:kalibro_configuration)).to eq(@subject)
173   - end
174   - end
175   -
176   - context 'when the user does not own the kalibro_configuration' do
177   - before do
178   - @subject = FactoryGirl.build(:another_kalibro_configuration)
179   - @ownerships.expects(:find_by_kalibro_configuration_id).with("#{@subject.id}").returns(nil)
180   -
181   - get :edit, :id => @subject.id
182   - end
183   -
184   - it { is_expected.to redirect_to(kalibro_configurations_path(@subject.id)) }
185   - it { is_expected.to set_the_flash[:notice].to("You're not allowed to do this operation") }
186   - end
187   - end
188   -
189   - context 'with no user logged in' do
190   - before :each do
191   - get :edit, :id => @subject.id
192   - end
193   -
194   - it { is_expected.to redirect_to new_user_session_path }
195   - end
196   - end
197   -
198   - describe 'update' do
199   - let(:kalibro_configuration) {FactoryGirl.build(:kalibro_configuration)}
200   - let(:kalibro_configuration_params) {Hash[FactoryGirl.attributes_for(:kalibro_configuration).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers
201   -
202   - context 'when the user is logged in' do
203   - before do
204   - sign_in FactoryGirl.create(:user)
205   - end
206   -
207   - context 'when user owns the kalibro_configuration' do
208   - before do
209   - @ownership = FactoryGirl.build(:kalibro_configuration_ownership)
210   - @ownerships = []
211   -
212   - @ownerships.expects(:find_by_kalibro_configuration_id).with("#{kalibro_configuration.id}").returns(@ownership)
213   - User.any_instance.expects(:kalibro_configuration_ownerships).at_least_once.returns(@ownerships)
214   - end
215   -
216   - context 'with valid fields' do
217   - before :each do
218   - subject.expects(:find_resource).with(KalibroConfiguration, kalibro_configuration.id).returns(kalibro_configuration)
219   - KalibroConfiguration.any_instance.expects(:update).with(kalibro_configuration_params).returns(true)
220   - end
221   -
222   - context 'rendering the show' do
223   - before :each do
224   - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
225   - end
226   -
227   - it 'should redirect to the show view' do
228   - expect(response).to redirect_to kalibro_configuration_path(kalibro_configuration.id)
229   - end
230   - end
231   -
232   - context 'without rendering the show view' do
233   - before :each do
234   - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
235   - end
236   -
237   - it { is_expected.to respond_with(:redirect) }
238   - end
239   - end
240   -
241   - context 'with an invalid field' do
242   - before :each do
243   - subject.expects(:find_resource).with(KalibroConfiguration, kalibro_configuration.id).returns(kalibro_configuration)
244   - KalibroConfiguration.any_instance.expects(:update).with(kalibro_configuration_params).returns(false)
245   -
246   - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
247   - end
248   -
249   - it { is_expected.to render_template(:edit) }
250   - end
251   - end
252   -
253   - context 'when the user does not own the kalibro_configuration' do
254   - before :each do
255   - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
256   - end
257   -
258   - it { is_expected.to redirect_to kalibro_configurations_path(kalibro_configuration.id) }
259   - end
260   - end
261   -
262   - context 'with no user logged in' do
263   - before :each do
264   - post :update, :id => kalibro_configuration.id, :kalibro_configuration => kalibro_configuration_params
265   - end
266   -
267   - it { is_expected.to redirect_to new_user_session_path }
268   - end
269   - end
270   -end
spec/controllers/mezuro_ranges_controller_spec.rb
... ... @@ -5,7 +5,7 @@ describe MezuroRangesController, :type => :controller do
5 5 let(:metric_configuration) { FactoryGirl.build(:metric_configuration_with_id) }
6 6  
7 7 describe 'new' do
8   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
  8 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
9 9  
10 10 before :each do
11 11 sign_in FactoryGirl.create(:user)
... ... @@ -35,7 +35,7 @@ describe MezuroRangesController, :type => :controller do
35 35  
36 36 describe 'create' do
37 37 let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers
38   - let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration) }
  38 + let(:kalibro_configuration) { FactoryGirl.build(:kalibro_configuration_with_id) }
39 39  
40 40 before do
41 41 sign_in FactoryGirl.create(:user)
... ...
spec/controllers/repositories_controller_spec.rb
... ... @@ -93,7 +93,7 @@ describe RepositoriesController, :type => :controller do
93 93 before :each do
94 94 processing = FactoryGirl.build(:processing)
95 95  
96   - KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration))
  96 + KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration_with_id))
97 97 subject.expects(:find_resource).with(Repository, repository.id).returns(repository)
98 98  
99 99 get :show, id: repository.id.to_s, project_id: project.id.to_s
... ... @@ -107,7 +107,7 @@ describe RepositoriesController, :type => :controller do
107 107 before :each do
108 108 processing = FactoryGirl.build(:processing)
109 109  
110   - KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration))
  110 + KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration_with_id))
111 111 subject.expects(:find_resource).with(Repository, repository.id).returns(repository)
112 112  
113 113 get :show, id: repository.id.to_s, project_id: project.id.to_s
... ... @@ -331,7 +331,7 @@ describe RepositoriesController, :type => :controller do
331 331 subject.expects(:repository_owner?).returns true
332 332 repository.expects(:process)
333 333 Repository.expects(:find).at_least_once.with(repository.id).returns(repository)
334   - KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration))
  334 + KalibroConfiguration.expects(:find).with(repository.id).returns(FactoryGirl.build(:kalibro_configuration_with_id))
335 335 get :process_repository, project_id: project.id.to_s, id: repository.id
336 336 end
337 337 it { is_expected.to redirect_to(project_repository_path(repository.project_id, repository.id)) }
... ...
spec/factories/kalibro_configurations.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 + FactoryGirl.define do
  2 + factory :kalibro_configuration, class: KalibroConfiguration do
  3 + name "Java"
  4 + description "Code metrics for Java."
  5 +
  6 + trait :with_id do
  7 + id 1
  8 + end
  9 +
  10 + factory :kalibro_configuration_with_id, traits: [:with_id]
  11 + end
  12 +
  13 + factory :another_kalibro_configuration, class: KalibroConfiguration do
  14 + name "Perl"
  15 + description "Code metrics for Perl."
  16 +
  17 + trait :with_id do
  18 + id 12
  19 + end
  20 +
  21 + factory :another_kalibro_configuration_with_id, traits: [:with_id]
  22 + end
  23 +end
... ...
spec/factories/mezuro_configurations.rb
... ... @@ -1,13 +0,0 @@
1   - FactoryGirl.define do
2   - factory :kalibro_configuration, class: KalibroConfiguration do
3   - id 1
4   - name "Java"
5   - description "Code metrics for Java."
6   - end
7   -
8   - factory :another_kalibro_configuration, class: KalibroConfiguration do
9   - id 12
10   - name "Perl"
11   - description "Code metrics for Perl."
12   - end
13   -end
spec/helpers/mezuro_configurations_helper_spec.rb
... ... @@ -3,7 +3,7 @@ require 'rails_helper'
3 3 describe KalibroConfigurationsHelper, :type => :helper do
4 4 describe 'kalibro_configuration_owner?' do
5 5 before :each do
6   - @subject = FactoryGirl.build(:kalibro_configuration)
  6 + @subject = FactoryGirl.build(:kalibro_configuration_with_id)
7 7 end
8 8  
9 9 context 'returns false if not logged in' do
... ...