metamaps--metamaps/spec/models/synapse_spec.rb

42 lines
1.8 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2015-12-16 14:19:58 +00:00
RSpec.describe Synapse, type: :model do
2015-12-18 01:26:15 +00:00
it { is_expected.to belong_to :user }
it { is_expected.to belong_to :topic1 }
it { is_expected.to belong_to :topic2 }
it { is_expected.to have_many :maps }
it { is_expected.to have_many :mappings }
2015-12-18 01:28:20 +00:00
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-20 13:55:10 +00:00
it { is_expected.to validate_length_of(:desc).is_at_least(0) } # TODO don't allow nil
2015-12-18 01:35:56 +00:00
2015-12-18 01:26:15 +00:00
context 'permissions' do
let(:owner) { create :user }
let(:other_user) { create :user }
let(:synapse) { create :synapse, user: owner, permission: :commons }
let(:private_synapse) { create :synapse, user: owner, permission: :private }
let(:public_synapse) { create :synapse, user: owner, permission: :public }
it 'prevents deletion by non-owner' do
expect(synapse.authorize_to_delete(other_user)).to eq false
expect(synapse.authorize_to_delete(owner)).to eq synapse
end
it 'prevents visibility if private' do
expect(synapse.authorize_to_show(other_user)).to eq synapse
expect(synapse.authorize_to_show(owner)).to eq synapse
expect(private_synapse.authorize_to_show(owner)).to eq private_synapse
2015-12-18 01:26:15 +00:00
expect(private_synapse.authorize_to_show(other_user)).to eq false
end
it 'only allows editing if commons or owned' do
expect(synapse.authorize_to_edit(other_user)).to eq synapse
expect(synapse.authorize_to_edit(owner)).to eq synapse
2015-12-18 01:26:15 +00:00
expect(private_synapse.authorize_to_edit(other_user)).to eq false
expect(private_synapse.authorize_to_edit(owner)).to eq private_synapse
2015-12-18 01:26:15 +00:00
expect(public_synapse.authorize_to_edit(other_user)).to eq false
expect(public_synapse.authorize_to_edit(owner)).to eq public_synapse
2015-12-18 01:26:15 +00:00
end
end
end