Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add specs for validation errors

Aaron Contreras2fa42de400e8
diff --git a/modules/boards/app/contracts/boards/create_contract.rb b/modules/boards/app/contracts/boards/create_contract.rb
index 26dbbe25bd3..9e5f1b7d95a 100644
--- a/modules/boards/app/contracts/boards/create_contract.rb
+++ b/modules/boards/app/contracts/boards/create_contract.rb
@@ -2,5 +2,13 @@
module Boards
class CreateContract < ::Grids::CreateContract
+ private
+
+ def validate_allowed
+ unless edit_allowed?
+ # "project" is what is exposed to the user in the global form, not "scope"
+ errors.add(:project, :blank)
+ end
+ end
end
end
diff --git a/modules/boards/app/services/boards/base_create_service.rb b/modules/boards/app/services/boards/base_create_service.rb
index 94e81fd3f2b..26ec585049e 100644
--- a/modules/boards/app/services/boards/base_create_service.rb
+++ b/modules/boards/app/services/boards/base_create_service.rb
@@ -5,8 +5,11 @@ module Boards
protected
def instance(attributes)
- factory_attributes = attributes.merge(scope: scope(attributes))
- super(factory_attributes)
+ Boards::Grid.new(
+ row_count: row_count_for_board,
+ column_count: column_count_for_board,
+ project: attributes[:project]
+ )
end
def before_perform(params, _service_result)
@@ -14,15 +17,11 @@ module Boards
create_query_result = create_query(params)
- return result if create_query_result.failure?
+ return create_query_result if create_query_result.failure?
super(params.merge(query_id: create_query_result.result.id), create_query_result)
end
- def scope(params)
- Rails.application.routes.url_helpers.project_work_package_boards_path(params[:project])
- end
-
def set_attributes_params(params)
{}.tap do |grid_params|
grid_params[:name] = params[:name]
@@ -50,7 +49,7 @@ module Boards
def create_query_params(params)
{
- project_id: params[:project].id,
+ project: params[:project],
name: query_name(params),
filters: query_filters(params)
}
@@ -71,12 +70,16 @@ module Boards
end
end
- def column_count_for_grid(_params)
- 4
- end
-
def options_for_widgets(params)
raise 'Define the options for the grid widgets'
end
+
+ def row_count_for_board
+ 1
+ end
+
+ def column_count_for_board
+ 4
+ end
end
end
diff --git a/modules/boards/spec/features/boards_global_create_spec.rb b/modules/boards/spec/features/boards_global_create_spec.rb
index dad5abfbe3b..80bdbc6b138 100644
--- a/modules/boards/spec/features/boards_global_create_spec.rb
+++ b/modules/boards/spec/features/boards_global_create_spec.rb
@@ -144,5 +144,50 @@ RSpec.describe 'Boards',
end
end
end
+
+ context 'when missing a required field' do
+ describe 'title' do
+ before do
+ wait_for_reload # Halt until the project autocompleter is ready
+
+ new_board_page.set_project(project)
+ new_board_page.click_on_submit
+ end
+
+ it 'renders a required attribute validation error' do
+ expect(Boards::Grid.all).to be_empty
+
+ # Required HTML attribute just warns
+ expect(page).to have_current_path(new_work_package_board_path)
+ end
+ end
+
+ describe 'project_id' do
+ before do
+ new_board_page.set_title("Batman's Itinerary")
+ new_board_page.click_on_submit
+
+ wait_for_reload
+ end
+
+ it 'renders a required attribute validation error' do
+ expect(Boards::Grid.all).to be_empty
+
+ expect(page).to have_text("Project can't be blank.")
+ end
+ end
+ end
+
+ describe 'cancel button' do
+ context "when it's clicked" do
+ before do
+ new_board_page.click_on_cancel_button
+ end
+
+ it 'navigates back to the global index page' do
+ expect(page).to have_current_path(boards_all_path)
+ end
+ end
+ end
end
end
diff --git a/modules/boards/spec/features/support/board_global_create_page.rb b/modules/boards/spec/features/support/board_global_create_page.rb
index ffe90bf2f92..db2b9a697c5 100644
--- a/modules/boards/spec/features/support/board_global_create_page.rb
+++ b/modules/boards/spec/features/support/board_global_create_page.rb
@@ -36,5 +36,9 @@ module Pages
def click_on_submit
click_on 'Create'
end
+
+ def click_on_cancel_button
+ click_on 'Cancel'
+ end
end
end