Skip to content

Commit

Permalink
Add controller tests for save_new action
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira committed Aug 22, 2018
1 parent 571dcf1 commit af23a9e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/api/config/routes.rb
Expand Up @@ -245,7 +245,7 @@ def self.public_or_about_path?(request)
get 'project/subprojects/:project' => :subprojects, constraints: cons, as: 'project_subprojects'
get 'project/attributes/:project', to: redirect('/attribs/%{project}'), constraints: cons
post 'project/new_incident' => :new_incident
get 'project/new_package/:project' => :new_package, constraints: cons
get 'project/new_package/:project' => :new_package, constraints: cons, as: 'project_new_package'
get 'project/new_package_branch/:project' => :new_package_branch, constraints: cons
get 'project/incident_request_dialog' => :incident_request_dialog
post 'project/new_incident_request' => :new_incident_request
Expand Down
40 changes: 40 additions & 0 deletions src/api/spec/controllers/webui/package_controller_spec.rb
@@ -1,5 +1,6 @@
require 'webmock/rspec'
require 'rails_helper'

# WARNING: If you change owner tests make sure you uncomment this line
# and start a test backend. Some of the Owner methods
# require real backend answers for projects/packages.
Expand Down Expand Up @@ -1635,4 +1636,43 @@ def do_request(params)
it { is_expected.to render_template('webui/package/_rpmlint_log') }
end
end

describe 'POST #save_new' do
let(:package_name) { 'new-package' }
let(:my_user) { user }

before do
login(my_user)
post :save_new, params: { project: source_project, name: package_name,
title: 'package foo',
description: 'awesome package foo' }
end

context 'valid package name' do
it { expect(response).to redirect_to(package_show_path(source_project, package_name)) }
it { expect(flash[:notice]).to eq("Package 'new-package' was created successfully") }
end

context 'invalid package name' do
let(:package_name) { 'A' * 250 }

it { expect(response).to redirect_to(project_new_package_path(source_project)) }
it { expect(flash[:error]).to match("Invalid package name:\s.*") }
end

context 'package already exist' do
let(:package_name) { package.name }

it { expect(response).to redirect_to(project_new_package_path(source_project)) }
it { expect(flash[:error]).to start_with("Package '#{package.name}' already exists in project") }
end

context 'not allowed to create package in' do
let(:package_name) { 'foo' }
let(:my_user) { create(:confirmed_user, login: 'another_user') }

it { expect(response).to redirect_to(project_new_package_path(source_project)) }
it { expect(flash[:error]).to eq("You can't create packages in #{source_project.name}") }
end
end
end

0 comments on commit af23a9e

Please sign in to comment.