summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2017-03-07 17:25:42 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2017-03-07 17:25:42 +0000
commit80898d91ecc8106c3c7f21da27a8daf8f00a3cbf (patch)
treeea05624ccb6cf9fd19941f89a9c3d8cd28f563ef
parent08223299eaf876d361149ff527ca7c2c2a501a58 (diff)
parent7fb2d94e56e2e74ec00a5c221d9aaa494222a573 (diff)
downloadgitlab-ce-80898d91ecc8106c3c7f21da27a8daf8f00a3cbf.tar.gz
Merge branch 'zj-chat-teams-unique' into 'master'
Namespace can have only one chat team See merge request !9769
-rw-r--r--app/models/chat_team.rb1
-rw-r--r--spec/factories/chat_teams.rb9
-rw-r--r--spec/models/chat_team_spec.rb5
3 files changed, 15 insertions, 0 deletions
diff --git a/app/models/chat_team.rb b/app/models/chat_team.rb
index 7952141a0d6..c52b6f15913 100644
--- a/app/models/chat_team.rb
+++ b/app/models/chat_team.rb
@@ -1,5 +1,6 @@
class ChatTeam < ActiveRecord::Base
validates :team_id, presence: true
+ validates :namespace, uniqueness: true
belongs_to :namespace
end
diff --git a/spec/factories/chat_teams.rb b/spec/factories/chat_teams.rb
new file mode 100644
index 00000000000..82f44fa3d15
--- /dev/null
+++ b/spec/factories/chat_teams.rb
@@ -0,0 +1,9 @@
+FactoryGirl.define do
+ factory :chat_team, class: ChatTeam do
+ sequence :team_id do |n|
+ "abcdefghijklm#{n}"
+ end
+
+ namespace factory: :group
+ end
+end
diff --git a/spec/models/chat_team_spec.rb b/spec/models/chat_team_spec.rb
index 1aab161ec13..5283561a83f 100644
--- a/spec/models/chat_team_spec.rb
+++ b/spec/models/chat_team_spec.rb
@@ -1,9 +1,14 @@
require 'spec_helper'
describe ChatTeam, type: :model do
+ subject { create(:chat_team) }
+
# Associations
it { is_expected.to belong_to(:namespace) }
+ # Validations
+ it { is_expected.to validate_uniqueness_of(:namespace) }
+
# Fields
it { is_expected.to respond_to(:name) }
it { is_expected.to respond_to(:team_id) }