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,6 +99,9 @@ private | ||
99 | def failed_action(format, destiny_action) | 99 | def failed_action(format, destiny_action) |
100 | @project_id = params[:project_id] | 100 | @project_id = params[:project_id] |
101 | @repository_types = Repository.repository_types | 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 | format.html { render action: destiny_action } | 106 | format.html { render action: destiny_action } |
104 | format.json { render json: @repository.errors, status: :unprocessable_entity } | 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,6 +13,8 @@ Given(/^I have a sample configuration with native metrics$/) do | ||
13 | reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id}) | 13 | reading = FactoryGirl.create(:reading, {reading_group_id: reading_group.id}) |
14 | 14 | ||
15 | @kalibro_configuration = FactoryGirl.create(:kalibro_configuration) | 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 | metric_configuration = FactoryGirl.create(:metric_configuration, | 18 | metric_configuration = FactoryGirl.create(:metric_configuration, |
17 | {metric: FactoryGirl.build(:loc), | 19 | {metric: FactoryGirl.build(:loc), |
18 | reading_group_id: reading_group.id, | 20 | reading_group_id: reading_group.id, |
spec/controllers/repositories_controller_spec.rb
@@ -44,11 +44,13 @@ describe RepositoriesController, :type => :controller do | @@ -44,11 +44,13 @@ describe RepositoriesController, :type => :controller do | ||
44 | end | 44 | end |
45 | 45 | ||
46 | describe 'create' do | 46 | describe 'create' do |
47 | + let!(:kalibro_configurations) { [FactoryGirl.build(:kalibro_configuration)] } | ||
48 | + let!(:user) { FactoryGirl.create(:user) } | ||
47 | let (:repository) { FactoryGirl.build(:repository, project_id: project.id) } | 49 | let (:repository) { FactoryGirl.build(:repository, project_id: project.id) } |
48 | let(:repository_params) { FactoryGirl.build(:repository).to_hash } | 50 | let(:repository_params) { FactoryGirl.build(:repository).to_hash } |
49 | 51 | ||
50 | before do | 52 | before do |
51 | - sign_in FactoryGirl.create(:user) | 53 | + sign_in user |
52 | end | 54 | end |
53 | 55 | ||
54 | context 'when the current user owns the project' do | 56 | context 'when the current user owns the project' do |
@@ -69,6 +71,7 @@ describe RepositoriesController, :type => :controller do | @@ -69,6 +71,7 @@ describe RepositoriesController, :type => :controller do | ||
69 | 71 | ||
70 | context 'with an invalid field' do | 72 | context 'with an invalid field' do |
71 | before :each do | 73 | before :each do |
74 | + KalibroConfiguration.expects(:public_or_owned_by_user).with(user).returns(kalibro_configurations) | ||
72 | Repository.any_instance.expects(:save).returns(false) | 75 | Repository.any_instance.expects(:save).returns(false) |
73 | Repository.expects(:repository_types).returns([]) | 76 | Repository.expects(:repository_types).returns([]) |
74 | 77 | ||
@@ -199,12 +202,15 @@ describe RepositoriesController, :type => :controller do | @@ -199,12 +202,15 @@ describe RepositoriesController, :type => :controller do | ||
199 | end | 202 | end |
200 | 203 | ||
201 | describe 'update' do | 204 | describe 'update' do |
205 | + let(:kalibro_configurations) { [FactoryGirl.build(:kalibro_configuration)] } | ||
202 | let(:repository) { FactoryGirl.build(:repository) } | 206 | let(:repository) { FactoryGirl.build(:repository) } |
203 | 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 | 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 | context 'when the user is logged in' do | 209 | context 'when the user is logged in' do |
210 | + let!(:user) { FactoryGirl.create(:user) } | ||
211 | + | ||
206 | before do | 212 | before do |
207 | - sign_in FactoryGirl.create(:user) | 213 | + sign_in user |
208 | end | 214 | end |
209 | 215 | ||
210 | context 'when user owns the repository' do | 216 | context 'when user owns the repository' do |
@@ -226,6 +232,7 @@ describe RepositoriesController, :type => :controller do | @@ -226,6 +232,7 @@ describe RepositoriesController, :type => :controller do | ||
226 | 232 | ||
227 | context 'with an invalid field' do | 233 | context 'with an invalid field' do |
228 | before :each do | 234 | before :each do |
235 | + KalibroConfiguration.expects(:public_or_owned_by_user).with(user).returns(kalibro_configurations) | ||
229 | Repository.expects(:find).at_least_once.with(repository.id).returns(repository) | 236 | Repository.expects(:find).at_least_once.with(repository.id).returns(repository) |
230 | Repository.any_instance.expects(:update).with(repository_params).returns(false) | 237 | Repository.any_instance.expects(:update).with(repository_params).returns(false) |
231 | Repository.expects(:repository_types).returns([]) | 238 | Repository.expects(:repository_types).returns([]) |