Add projects_include? method to GeoNode

parent ac37879f
......@@ -108,6 +108,12 @@ class GeoNode < ActiveRecord::Base
end
end
def projects_include?(project_id)
return true if restricted_project_ids.nil?
restricted_project_ids.include?(project_id)
end
def restricted_project_ids
return unless namespaces.presence
......
......@@ -317,6 +317,32 @@ describe GeoNode, type: :model do
end
end
describe '#projects_include?' do
let(:unsynced_project) { create(:project) }
it 'returns true without namespace restrictions' do
expect(node.projects_include?(unsynced_project.id)).to eq true
end
context 'with namespace restrictions' do
let(:synced_group) { create(:group) }
before do
node.update_attribute(:namespaces, [synced_group])
end
it 'returns true when project belongs to one of the namespaces' do
project_in_synced_group = create(:project, group: synced_group)
expect(node.projects_include?(project_in_synced_group.id)).to eq true
end
it 'returns false when project does not belong to one of the namespaces' do
expect(node.projects_include?(unsynced_project.id)).to eq false
end
end
end
describe '#restricted_project_ids' do
context 'without namespace restriction' do
it 'returns nil' 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