summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-20 14:15:39 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-20 14:15:39 -0200
commitfab393984a4685164886c974747d312da21e1798 (patch)
treecb728cccdabf6ff6045877eea377e7d88fe8002d
parent3c5b94740b7b0193cfd0929484f60f321b3bf0b6 (diff)
downloadgitlab-ce-fab393984a4685164886c974747d312da21e1798.tar.gz
[ci skip] Add a comment explaining validate_board_limit callbackfix/validate-board-limit
Callback associations are not common to see around. We want to make clear that the `before_add` callback uses the number before the addition, in this particular case 1.
-rw-r--r--app/models/project.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 6685baab699..af117f0acb0 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1339,6 +1339,13 @@ class Project < ActiveRecord::Base
shared_projects.any?
end
+ # Similar to the normal callbacks that hook into the life cycle of an
+ # Active Record object, you can also define callbacks that get triggered
+ # when you add an object to an association collection. If any of these
+ # callbacks throw an exception, the object will not be added to the
+ # collection. Before you add a new board to the boards collection if you
+ # already have 1, 2, or n it will fail, but it if you have 0 that is lower
+ # than the number of permitted boards per project it won't fail.
def validate_board_limit(board)
raise BoardLimitExceeded, 'Number of permitted boards exceeded' if boards.size >= NUMBER_OF_PERMITTED_BOARDS
end