update map spec - add authorize_to_delete. TODO: add other map authorize specs
This commit is contained in:
parent
9e4a7b821f
commit
d5f66487b7
3 changed files with 13 additions and 2 deletions
|
@ -14,7 +14,6 @@ class Map < ActiveRecord::Base
|
|||
},
|
||||
:default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png'
|
||||
validates :name, presence: true
|
||||
validates :arranged, presence: true
|
||||
validates :arranged, inclusion: { in: [true, false] }
|
||||
validates :permission, presence: true
|
||||
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
|
||||
|
|
|
@ -2,6 +2,7 @@ FactoryGirl.define do
|
|||
factory :map do
|
||||
name { random_string(10) }
|
||||
permission :commons
|
||||
arranged { false }
|
||||
user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,8 +4,19 @@ RSpec.describe Map, type: :model do
|
|||
# TODO: what is it important to be sure about when working with a Map?
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
it { is_expected.to validate_presence_of :arranged }
|
||||
it { is_expected.to validate_presence_of :permission }
|
||||
it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) }
|
||||
it { is_expected.to validate_inclusion_of(:arranged).in_array [true, false] }
|
||||
|
||||
context 'permissions' do
|
||||
let(:owner) { create :user }
|
||||
let(:other_user) { create :user }
|
||||
let(:map) { create :map, user: owner, permission: :commons }
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue