2015-10-12 03:37:44 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2015-12-16 14:19:58 +00:00
|
|
|
RSpec.describe Map, type: :model do
|
2015-12-17 01:16:02 +00:00
|
|
|
it { is_expected.to belong_to :user }
|
|
|
|
it { is_expected.to validate_presence_of :name }
|
|
|
|
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 01:44:48 +00:00
|
|
|
|
|
|
|
context 'permissions' do
|
|
|
|
let(:owner) { create :user }
|
|
|
|
let(:other_user) { create :user }
|
|
|
|
let(:map) { create :map, user: owner, permission: :commons }
|
2015-12-17 15:20:53 +00:00
|
|
|
let(:private_map) { create :map, user: owner, permission: :private }
|
|
|
|
let(:public_map) { create :map, user: owner, permission: :public }
|
2015-12-17 01:44:48 +00:00
|
|
|
|
|
|
|
it 'prevents deletion by non-owner' do
|
|
|
|
expect(map.authorize_to_delete(other_user)).to eq false
|
|
|
|
expect(map.authorize_to_delete(owner)).to eq map
|
|
|
|
end
|
2015-12-17 15:20:53 +00:00
|
|
|
|
|
|
|
it 'prevents visibility if private' do
|
2015-12-18 01:33:16 +00:00
|
|
|
expect(map.authorize_to_show(other_user)).to eq map
|
|
|
|
expect(map.authorize_to_show(owner)).to eq map
|
|
|
|
expect(private_map.authorize_to_show(owner)).to eq private_map
|
2015-12-17 15:20:53 +00:00
|
|
|
expect(private_map.authorize_to_show(other_user)).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only allows editing if commons or owned' do
|
2015-12-18 01:33:16 +00:00
|
|
|
expect(map.authorize_to_edit(other_user)).to eq map
|
|
|
|
expect(map.authorize_to_edit(owner)).to eq map
|
2015-12-17 15:20:53 +00:00
|
|
|
expect(private_map.authorize_to_edit(other_user)).to eq false
|
2015-12-18 01:33:16 +00:00
|
|
|
expect(private_map.authorize_to_edit(owner)).to eq private_map
|
2015-12-17 15:20:53 +00:00
|
|
|
expect(public_map.authorize_to_edit(other_user)).to eq false
|
2015-12-18 01:33:16 +00:00
|
|
|
expect(public_map.authorize_to_edit(owner)).to eq public_map
|
2015-12-17 15:20:53 +00:00
|
|
|
end
|
2015-12-17 01:44:48 +00:00
|
|
|
end
|
2015-10-12 03:37:44 +00:00
|
|
|
end
|
2015-12-17 01:16:02 +00:00
|
|
|
|