2019-10-17 11:06:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe TodoPolicy do
|
2019-10-17 11:06:17 -04:00
|
|
|
let_it_be(:author) { create(:user) }
|
|
|
|
|
|
|
|
let_it_be(:user1) { create(:user) }
|
|
|
|
let_it_be(:user2) { create(:user) }
|
|
|
|
let_it_be(:user3) { create(:user) }
|
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
let_it_be(:todo1) { create(:todo, author: author, user: user1, issue: issue) }
|
|
|
|
let_it_be(:todo2) { create(:todo, author: author, user: user2, issue: issue) }
|
2019-10-17 11:06:17 -04:00
|
|
|
let_it_be(:todo3) { create(:todo, author: author, user: user2) }
|
2021-08-03 17:09:39 -04:00
|
|
|
let_it_be(:todo4) { create(:todo, author: author, user: user3, issue: issue) }
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
def permissions(user, todo)
|
|
|
|
described_class.new(user, todo)
|
|
|
|
end
|
|
|
|
|
2021-08-03 17:09:39 -04:00
|
|
|
before_all do
|
|
|
|
project.add_developer(user1)
|
|
|
|
project.add_developer(user2)
|
|
|
|
end
|
|
|
|
|
2019-10-17 11:06:17 -04:00
|
|
|
describe 'own_todo' do
|
2021-08-03 17:09:39 -04:00
|
|
|
it 'allows owners to access their own todos if they can read todo target' do
|
2019-10-17 11:06:17 -04:00
|
|
|
[
|
|
|
|
[user1, todo1],
|
2021-08-03 17:09:39 -04:00
|
|
|
[user2, todo2]
|
2019-10-17 11:06:17 -04:00
|
|
|
].each do |user, todo|
|
|
|
|
expect(permissions(user, todo)).to be_allowed(:read_todo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow users to access todos of other users' do
|
|
|
|
[
|
|
|
|
[user1, todo2],
|
|
|
|
[user1, todo3],
|
|
|
|
[user2, todo1],
|
|
|
|
[user2, todo4],
|
|
|
|
[user3, todo1],
|
|
|
|
[user3, todo2],
|
2021-08-03 17:09:39 -04:00
|
|
|
[user3, todo3],
|
|
|
|
[user2, todo3],
|
|
|
|
[user3, todo4]
|
2019-10-17 11:06:17 -04:00
|
|
|
].each do |user, todo|
|
|
|
|
expect(permissions(user, todo)).to be_disallowed(:read_todo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|