Add GeoNodeGroupLink model

parent e781857d
......@@ -5,6 +5,9 @@ class GeoNode < ActiveRecord::Base
belongs_to :oauth_application, class_name: 'Doorkeeper::Application', dependent: :destroy # rubocop: disable Cop/ActiveRecordDependent
belongs_to :system_hook, dependent: :destroy # rubocop: disable Cop/ActiveRecordDependent
has_many :geo_node_group_links
has_many :groups, through: :geo_node_group_links
default_values schema: lambda { Gitlab.config.gitlab.protocol },
host: lambda { Gitlab.config.gitlab.host },
port: lambda { Gitlab.config.gitlab.port },
......
class GeoNodeGroupLink < ActiveRecord::Base
belongs_to :geo_node
belongs_to :group
validates :geo_node_id, :group_id, presence: true
validates :group_id, uniqueness: { scope: [:geo_node_id] }
end
FactoryGirl.define do
factory :geo_node_group_link do
geo_node
group
end
end
require 'spec_helper'
describe GeoNodeGroupLink, models: true do
describe 'relationships' do
it { is_expected.to belong_to(:geo_node) }
it { is_expected.to belong_to(:group) }
end
describe 'validations' do
let!(:geo_node_group_link) { create(:geo_node_group_link) }
it { is_expected.to validate_presence_of(:geo_node_id) }
it { is_expected.to validate_presence_of(:group_id) }
it { is_expected.to validate_uniqueness_of(:group_id).scoped_to(:geo_node_id) }
end
end
......@@ -14,6 +14,9 @@ describe GeoNode, type: :model do
context 'associations' do
it { is_expected.to belong_to(:geo_node_key).dependent(:destroy) }
it { is_expected.to belong_to(:oauth_application).dependent(:destroy) }
it { is_expected.to have_many(:geo_node_group_links) }
it { is_expected.to have_many(:groups).through(:geo_node_group_links) }
end
context 'default values' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment