Skip to content

Commit

Permalink
[webui] Remove unused exception handling
Browse files Browse the repository at this point in the history
UnknownObjectError is not raised by any of the methods called in the
controller. This exception can occure only when calling update_from_xml.
But this method is wrapped within a transaction, which will catch the
exception.

This commit removes the unused rescue and adds a test for calling
save_meta with invalid devel projects.
We also update the xml parser code to throw a more explicit error
message.
  • Loading branch information
bgeuken committed Oct 2, 2017
1 parent b2b81f2 commit 066d9c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,6 @@ def save_meta

rescue Suse::ValidationError => exception
errors << exception.message
rescue Project::UnknownObjectError => exception
errors << "Project with name '#{exception.message}' not found"
end

if errors.empty?
Expand Down
6 changes: 5 additions & 1 deletion src/api/app/models/project/update_from_xml_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def parse_develproject(xmlhash)
if devel
prj_name = devel['project']
if prj_name
develprj = Project.get_by_name(prj_name)
begin
develprj = Project.get_by_name(prj_name)
rescue UnknownObjectError => e
raise UnknownObjectError, "Project with name '#{e.message}' not found"
end
unless develprj
raise SaveError, "value of develproject has to be a existing project (project '#{prj_name}' does not exist)"
end
Expand Down
10 changes: 10 additions & 0 deletions src/api/spec/controllers/webui/project_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,16 @@
it { expect(response).to have_http_status(400) }
end

context 'with an invalid devel project' do
before do
post :save_meta, params: { project: user.home_project,
meta: '<project name="home:tom"><title/><description/><devel project="non-existant"/></project>' }, xhr: true
end

it { expect(flash.now[:error]).to eq("Project with name 'non-existant' not found") }
it { expect(response).to have_http_status(400) }
end

context 'with a valid meta' do
before do
post :save_meta, params: { project: user.home_project, meta: '<project name="home:tom"><title/><description/></project>' }, xhr: true
Expand Down

0 comments on commit 066d9c5

Please sign in to comment.