Skip to content

Commit

Permalink
[frontend] Include request action validations to bs request validations
Browse files Browse the repository at this point in the history
Before it wasn't possible to see why a bs request action was causing a
bs request to fail. All a user would see was 'Validation failed: Bs
request actions is invalid'.
Now the validation message would include details of the failed request
action.

This allows users to see why a request failed, eg. when forwarding a
request (related to #3730).
  • Loading branch information
bgeuken committed Apr 18, 2018
1 parent cb599c1 commit e570752
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class SaveError < APIException
validate :check_creator, on: [:create, :save!]
validates :comment, length: { maximum: 65_535 }
validates :description, length: { maximum: 65_535 }
validates_associated :bs_request_actions, message: ->(_, record) { record[:value].map { |r| r.errors.full_messages }.flatten.to_sentence }

after_update :send_state_change
after_commit :update_cache
Expand Down
5 changes: 4 additions & 1 deletion src/api/spec/controllers/webui/package_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@
post :submit_request, params: { project: source_project, package: package, targetproject: target_project, sourceupdate: 'invalid' }
end

it { expect(flash[:error]).to eq('Unable to submit: Validation failed: Bs request actions is invalid') }
it do
expect(flash[:error]).to eq('Unable to submit: Validation failed: Bs request actions is invalid, ' \
'Bs request actions Sourceupdate is not included in the list')
end
it { expect(response).to redirect_to(package_show_path(project: source_project, package: package)) }
it { expect(BsRequestActionSubmit.where(target_project: target_project.name, target_package: package.name)).not_to exist }
end
Expand Down
14 changes: 14 additions & 0 deletions src/api/spec/models/bs_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
source_package: source_package.name)
end

context 'validations' do
let(:bs_request) { create(:bs_request) }
let(:bs_request_action) { create(:bs_request_action, bs_request: bs_request) }

it 'includes validation errors of associated bs_request_actions' do
# rubocop:disable Rails/SkipsModelValidations
bs_request_action.update_attribute(:sourceupdate, 'foo')
# rubocop:enable Rails/SkipsModelValidations
expect { bs_request.reload.save! }.to raise_error(
ActiveRecord::RecordInvalid, 'Validation failed: Bs request actions Sourceupdate is not included in the list'
)
end
end

context '.new_from_xml' do
let(:user) { create(:user) }
let(:review_request) do
Expand Down

0 comments on commit e570752

Please sign in to comment.