Namespace can have only one chat team

This commit is contained in:
Z.J. van de Weg 2017-03-07 15:20:22 +01:00
parent df55d35ffd
commit 7fb2d94e56
3 changed files with 15 additions and 0 deletions

View file

@ -1,5 +1,6 @@
class ChatTeam < ActiveRecord::Base class ChatTeam < ActiveRecord::Base
validates :team_id, presence: true validates :team_id, presence: true
validates :namespace, uniqueness: true
belongs_to :namespace belongs_to :namespace
end end

View file

@ -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

View file

@ -1,9 +1,14 @@
require 'spec_helper' require 'spec_helper'
describe ChatTeam, type: :model do describe ChatTeam, type: :model do
subject { create(:chat_team) }
# Associations # Associations
it { is_expected.to belong_to(:namespace) } it { is_expected.to belong_to(:namespace) }
# Validations
it { is_expected.to validate_uniqueness_of(:namespace) }
# Fields # Fields
it { is_expected.to respond_to(:name) } it { is_expected.to respond_to(:name) }
it { is_expected.to respond_to(:team_id) } it { is_expected.to respond_to(:team_id) }