2015-10-12 03:37:44 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
RSpec.describe Topic, type: :model do
|
2015-12-17 15:45:38 +00:00
|
|
|
it { is_expected.to belong_to :user }
|
|
|
|
it { is_expected.to belong_to :metacode }
|
|
|
|
it { is_expected.to have_many :maps }
|
2015-12-18 01:26:07 +00:00
|
|
|
it { is_expected.to have_many :mappings }
|
|
|
|
it { is_expected.to validate_presence_of :permission }
|
|
|
|
it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) }
|
2015-12-17 15:45:38 +00:00
|
|
|
|
|
|
|
context 'has_viewable_synapses function' do
|
|
|
|
let (:user) { create(:user) }
|
|
|
|
let (:other_user) { create(:user) }
|
|
|
|
|
|
|
|
context 'topic with no synapses' do
|
|
|
|
let (:topic) { create(:topic) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(topic.has_viewable_synapses(user)).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'topic with one unpermitted synapse' do
|
2015-12-20 14:18:40 +00:00
|
|
|
let (:synapse) { create(:synapse, permission: :private, user: other_user) }
|
|
|
|
let (:topic) { create(:topic, synapses1: [synapse]) }
|
2015-12-17 15:45:38 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(topic.has_viewable_synapses(user)).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'topic with one permitted synapse' do
|
2015-12-20 14:18:40 +00:00
|
|
|
let (:synapse) { create(:synapse, permission: :private, user: user) }
|
|
|
|
let(:topic) { create(:topic, synapses1: [synapse]) }
|
2015-12-17 15:45:38 +00:00
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(topic.has_viewable_synapses(user)).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'topic with one unpermitted, one permitted synapse' do
|
2015-12-20 14:18:40 +00:00
|
|
|
let (:synapse1) { create(:synapse, permission: :private, user: other_user) }
|
|
|
|
let (:synapse2) { create(:synapse, permission: :private, user: user) }
|
|
|
|
let (:topic) { create(:topic, synapses1: [synapse1, synapse2]) }
|
2015-12-17 15:45:38 +00:00
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(topic.synapses.count).to eq 2
|
|
|
|
expect(topic.has_viewable_synapses(user)).to eq true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-12 03:37:44 +00:00
|
|
|
end
|