Commit 97887b40760bc3da1f584f0f56562d9ab589b6fd
Committed by
Diego Camarinha
1 parent
16bb89f4
Exists in
colab
and in
4 other branches
RepositoriesController create and update, when called with invalid fields, loadi…
…ng the kalibro configurations list Before they were not loaded leading to a exception when redering the edit view again.
Showing
3 changed files
with
14 additions
and
2 deletions
Show diff stats
app/controllers/repositories_controller.rb
... | ... | @@ -99,6 +99,9 @@ private |
99 | 99 | def failed_action(format, destiny_action) |
100 | 100 | @project_id = params[:project_id] |
101 | 101 | @repository_types = Repository.repository_types |
102 | + @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf| | |
103 | + [conf.name, conf.id] | |
104 | + } | |
102 | 105 | |
103 | 106 | format.html { render action: destiny_action } |
104 | 107 | format.json { render json: @repository.errors, status: :unprocessable_entity } | ... | ... |
features/step_definitions/repository_steps.rb
... | ... | @@ -13,6 +13,8 @@ Given(/^I have a sample configuration with native metrics$/) do |
13 | 13 | reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id}) |
14 | 14 | |
15 | 15 | @kalibro_configuration = FactoryGirl.create(:kalibro_configuration) |
16 | + FactoryGirl.create(:kalibro_configuration_attributes, {id: nil, user_id: nil, kalibro_configuration_id: @kalibro_configuration.id}) | |
17 | + | |
16 | 18 | metric_configuration = FactoryGirl.create(:metric_configuration, |
17 | 19 | {metric: FactoryGirl.build(:loc), |
18 | 20 | reading_group_id: reading_group.id, | ... | ... |
spec/controllers/repositories_controller_spec.rb
... | ... | @@ -44,11 +44,13 @@ describe RepositoriesController, :type => :controller do |
44 | 44 | end |
45 | 45 | |
46 | 46 | describe 'create' do |
47 | + let!(:kalibro_configurations) { [FactoryGirl.build(:kalibro_configuration)] } | |
48 | + let!(:user) { FactoryGirl.create(:user) } | |
47 | 49 | let (:repository) { FactoryGirl.build(:repository, project_id: project.id) } |
48 | 50 | let(:repository_params) { FactoryGirl.build(:repository).to_hash } |
49 | 51 | |
50 | 52 | before do |
51 | - sign_in FactoryGirl.create(:user) | |
53 | + sign_in user | |
52 | 54 | end |
53 | 55 | |
54 | 56 | context 'when the current user owns the project' do |
... | ... | @@ -69,6 +71,7 @@ describe RepositoriesController, :type => :controller do |
69 | 71 | |
70 | 72 | context 'with an invalid field' do |
71 | 73 | before :each do |
74 | + KalibroConfiguration.expects(:public_or_owned_by_user).with(user).returns(kalibro_configurations) | |
72 | 75 | Repository.any_instance.expects(:save).returns(false) |
73 | 76 | Repository.expects(:repository_types).returns([]) |
74 | 77 | |
... | ... | @@ -199,12 +202,15 @@ describe RepositoriesController, :type => :controller do |
199 | 202 | end |
200 | 203 | |
201 | 204 | describe 'update' do |
205 | + let(:kalibro_configurations) { [FactoryGirl.build(:kalibro_configuration)] } | |
202 | 206 | let(:repository) { FactoryGirl.build(:repository) } |
203 | 207 | let(:repository_params) { Hash[FactoryGirl.attributes_for(:repository).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 |
204 | 208 | |
205 | 209 | context 'when the user is logged in' do |
210 | + let!(:user) { FactoryGirl.create(:user) } | |
211 | + | |
206 | 212 | before do |
207 | - sign_in FactoryGirl.create(:user) | |
213 | + sign_in user | |
208 | 214 | end |
209 | 215 | |
210 | 216 | context 'when user owns the repository' do |
... | ... | @@ -226,6 +232,7 @@ describe RepositoriesController, :type => :controller do |
226 | 232 | |
227 | 233 | context 'with an invalid field' do |
228 | 234 | before :each do |
235 | + KalibroConfiguration.expects(:public_or_owned_by_user).with(user).returns(kalibro_configurations) | |
229 | 236 | Repository.expects(:find).at_least_once.with(repository.id).returns(repository) |
230 | 237 | Repository.any_instance.expects(:update).with(repository_params).returns(false) |
231 | 238 | Repository.expects(:repository_types).returns([]) | ... | ... |