Skip to content

Commit

Permalink
Simplify specs
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Donisa <daniel.donisa@suse.com>
Co-authored-by: Eduardo Navarro <enavarro@suse.com>
  • Loading branch information
3 people committed Jun 14, 2022
1 parent 2ec7487 commit c2efd1a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 207 deletions.

This file was deleted.

This file was deleted.

36 changes: 0 additions & 36 deletions src/api/spec/models/token/workflow_spec.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
require 'rails_helper'

RSpec.describe Token::Workflow do
describe '#workflow_token_users' do
let(:token_user) { create(:confirmed_user) }

context 'asking for workflow tokens' do
let(:workflow_token) { create(:workflow_token, user: token_user) }

before { token_user.shared_workflow_tokens << workflow_token }

it 'returns the users whom I shared the token' do
expect(workflow_token.users_shared_among).to include(token_user)
end
end

context 'trying to use rss tokens' do
let(:rss_token) { create(:rss_token, user: token_user) }

it 'returns nothing' do
expect { token_user.shared_workflow_tokens << rss_token }.to raise_error(ActiveRecord::AssociationTypeMismatch)
end
end
end

describe '#workflow_token_groups' do
let(:token_group) { create(:group) }

context 'asking for workflow tokens' do
let(:workflow_token) { create(:workflow_token) }

before { token_group.shared_workflow_tokens << workflow_token }

it 'returns the groups whom I shared the token' do
expect(workflow_token.groups_shared_among).to include(token_group)
end
end
end

describe '#call' do
let(:token_user) { create(:confirmed_user, :with_home, login: 'Iggy') }
let(:workflow_token) { create(:workflow_token, user: token_user) }
Expand Down
16 changes: 16 additions & 0 deletions src/api/spec/policies/token/workflow_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
it { is_expected.to permit(user, user_token) }
end

context 'when the user belongs to a group which owns the token' do
let(:group_token) { create(:workflow_token, user: user) }

before { group.shared_workflow_tokens << group_token }

it { is_expected.to permit(other_user, group_token) }
end

context 'when the user is not the owner of the token' do
context 'and the token has not been shared with that user' do
it { is_expected.not_to permit(other_user, user_token) }
Expand Down Expand Up @@ -70,6 +78,14 @@
it { is_expected.to permit(user, user_token) }
end

context 'when the user belongs to a group which owns the token' do
let(:group_token) { create(:workflow_token, user: user) }

before { group.shared_workflow_tokens << group_token }

it { is_expected.to permit(other_user, group_token) }
end

context 'when the user does not own the token' do
it { is_expected.not_to(permit(other_user, user_token)) }
end
Expand Down

0 comments on commit c2efd1a

Please sign in to comment.