summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-06 15:58:28 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-11 11:39:04 -0300
commit95a5cc9285a8583988ece697ebdb948730b5db55 (patch)
treee27fd2d1c13d5643d01852932160b6c4550bd9e1
parentfb5a4202062d07d2dbca544f4cfb475a65411716 (diff)
downloadgitlab-ce-95a5cc9285a8583988ece697ebdb948730b5db55.tar.gz
Restrict the number of permitted boards per project to one
-rw-r--r--app/models/project.rb7
-rw-r--r--spec/models/project_spec.rb9
2 files changed, 15 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 795a456b094..30db7ed50b3 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -16,6 +16,7 @@ class Project < ActiveRecord::Base
extend Gitlab::ConfigHelper
+ NUMBER_OF_PERMITTED_BOARDS = 1
UNKNOWN_IMPORT_URL = 'http://unknown.git'
cache_markdown_field :description, pipeline: :description
@@ -65,7 +66,7 @@ class Project < ActiveRecord::Base
belongs_to :namespace
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event', foreign_key: 'project_id'
- has_many :boards, dependent: :destroy
+ has_many :boards, before_add: :validate_board_limit, dependent: :destroy
# Project services
has_many :services
@@ -1338,4 +1339,8 @@ class Project < ActiveRecord::Base
shared_projects.any?
end
+
+ def validate_board_limit(board)
+ raise StandardError, 'Number of permitted boards exceeded' if boards.size >= NUMBER_OF_PERMITTED_BOARDS
+ end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 3748b1c7f5f..1b13f1be477 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -94,6 +94,15 @@ describe Project, models: true do
end
end
end
+
+ describe '#boards' do
+ it 'raises an error when attempting to add more than one board to the project' do
+ subject.boards.build
+
+ expect { subject.boards.build }.to raise_error(StandardError, 'Number of permitted boards exceeded')
+ expect(subject.boards.size).to eq 1
+ end
+ end
end
describe 'modules' do