Skip to content

Commit

Permalink
First commit about rebuild token policy
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira authored and Dany Marcoux committed Apr 26, 2021
1 parent f0d4feb commit 1d97e4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/api/spec/factories/tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
factory :rss_token, class: 'Token::Rss' do
type { 'Token::Rss' }
end
factory :rebuild_token, class: 'Token::Rebuild' do
type { 'Token::Rebuild' }
user
package
trait :with_package_from_association_or_param do
package_from_association_or_params { package }
end
end
end
end
19 changes: 19 additions & 0 deletions src/api/spec/policies/token/rebuild_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'

RSpec.describe Token::RebuildPolicy, vcr: true do
let!(:user) { create(:confirmed_user, login: 'foo') }
let!(:project) { create(:project, maintainer: user) }
let!(:package) { create(:package, project: project) }
let!(:other_user) { build(:confirmed_user, login: 'bar') }
let!(:rebuild_token) { create(:rebuild_token, :with_package_from_association_or_param, user: user, package: package) }
let!(:other_user_rebuild_token) { create(:rebuild_token, :with_package_from_association_or_param, user: other_user) }

subject { described_class }

describe '#create' do
permissions :create? do
it { expect(subject).to permit(user, rebuild_token) }
it { expect(subject).not_to permit(other_user, other_user_rebuild_token) }
end
end
end

0 comments on commit 1d97e4a

Please sign in to comment.