Skip to content

Commit

Permalink
Updated policy tests to use apply instead of calling authorization me…
Browse files Browse the repository at this point in the history
…thod directly which fixed the previous error of undefined method details
  • Loading branch information
deepsidhu85 committed Jan 6, 2025
1 parent defe844 commit ea98b5a
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 98 deletions.
7 changes: 0 additions & 7 deletions app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ class ApplicationPolicy < ActionPolicy::Base
# record.user_id == user.id
# end
#

# attr_accessor :details

# def initialize(record = nil, **params)
# super
# @details ||= {}
# end
end
12 changes: 6 additions & 6 deletions test/policies/graphql_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ def setup
end

test '#query? when token has api scope' do
assert @policy_with_api_scope_token.query?
assert @policy_with_api_scope_token.apply(:query?)
end

test '#mutate? when token has api scope' do
assert @policy_with_api_scope_token.mutate?
assert @policy_with_api_scope_token.apply(:mutate?)
end

test '#query? when token has read api scope' do
assert @policy_with_read_api_scope_token.query?
assert @policy_with_read_api_scope_token.apply(:query?)
end

test '#mutate? when token has read api scope' do
assert_not @policy_with_read_api_scope_token.mutate?
assert_not @policy_with_read_api_scope_token.apply(:mutate?)
end

test '#query? when nil token' do
assert @policy_without_token.query?
assert @policy_without_token.apply(:query?)
end

test '#mutate? when nil token' do
assert @policy_without_token.mutate?
assert @policy_without_token.apply(:mutate?)
end
end
44 changes: 22 additions & 22 deletions test/policies/group_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,91 @@ def setup
end

test '#read?' do
assert @policy.read?
assert @policy.apply(:read?)
end

test '#new?' do
assert @policy.new?
assert @policy.apply(:new?)
end

test '#edit?' do
assert @policy.edit?
assert @policy.apply(:edit?)
end

test '#create?' do
assert @policy.create?
assert @policy.apply(:create?)
end

test '#update?' do
assert @policy.update?
assert @policy.apply(:update?)
end

test '#destroy?' do
assert @policy.destroy?
assert @policy.apply(:destroy?)
end

test '#create_subgroup?' do
assert @policy.create_subgroup?
assert @policy.apply(:create_subgroup?)
end

test '#transfer?' do
assert @policy.transfer?
assert @policy.apply(:transfer?)
end

test '#transfer_into_namespace?' do
assert @policy.transfer_into_namespace?
assert @policy.apply(:transfer_into_namespace?)
end

test '#create_member?' do
assert @policy.create_member?
assert @policy.apply(:create_member?)
end

test '#update_member?' do
assert @policy.update_member?
assert @policy.apply(:update_member?)
end

test '#destroy_member?' do
assert @policy.destroy_member?
assert @policy.apply(:destroy_member?)
end

test '#member_listing?' do
assert @policy.member_listing?
assert @policy.apply(:member_listing?)
end

test '#sample_listing?' do
assert @policy.sample_listing?
assert @policy.apply(:sample_listing?)
end

test '#link_namespace_with_group?' do
assert @policy.link_namespace_with_group?
assert @policy.apply(:link_namespace_with_group?)
end

test '#unlink_namespace_with_group?' do
assert @policy.unlink_namespace_with_group?
assert @policy.apply(:unlink_namespace_with_group?)
end

test '#update_namespace_with_group_link?' do
assert @policy.update_namespace_with_group_link?
assert @policy.apply(:update_namespace_with_group_link?)
end

test '#submit_workflow?' do
assert @policy.submit_workflow?
assert @policy.apply(:submit_workflow?)
end

test '#update_sample_metadata?' do
assert @policy.update_sample_metadata?
assert @policy.apply(:update_sample_metadata?)
end

test '#view_attachments?' do
assert @policy.view_attachments?
assert @policy.apply(:view_attachments?)
end

test '#create_attachment?' do
assert @policy.create_attachment?
assert @policy.apply(:create_attachment?)
end

test '#destroy_attachment?' do
assert @policy.destroy_attachment?
assert @policy.apply(:destroy_attachment?)
end

test 'scope' do
Expand Down
28 changes: 14 additions & 14 deletions test/policies/namespaces/project_namespace_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,59 @@ def setup
end

test '#update?' do
assert @policy.update?
assert @policy.apply(:update?)
end

test '#create_member?' do
assert @policy.create_member?
assert @policy.apply(:create_member?)
end

test '#update_member?' do
assert @policy.update_member?
assert @policy.apply(:update_member?)
end

test '#destroy_member?' do
assert @policy.destroy_member?
assert @policy.apply(:destroy_member?)
end

test '#member_listing?' do
assert @policy.member_listing?
assert @policy.apply(:member_listing?)
end

test '#link_namespace_with_group?' do
assert @policy.link_namespace_with_group?
assert @policy.apply(:link_namespace_with_group?)
end

test '#unlink_namespace_with_group?' do
assert @policy.unlink_namespace_with_group?
assert @policy.apply(:unlink_namespace_with_group?)
end

test '#update_namespace_with_group_link?' do
assert @policy.update_namespace_with_group_link?
assert @policy.apply(:update_namespace_with_group_link?)
end

test '#create_automated_workflow_executions?' do
assert @policy.create_automated_workflow_executions?
assert @policy.apply(:create_automated_workflow_executions?)
end

test '#destroy_automated_workflow_executions?' do
assert @policy.destroy_automated_workflow_executions?
assert @policy.apply(:destroy_automated_workflow_executions?)
end

test '#update_automated_workflow_executions?' do
assert @policy.update_automated_workflow_executions?
assert @policy.apply(:update_automated_workflow_executions?)
end

test '#view_automated_workflow_executions?' do
assert @policy.view_automated_workflow_executions?
assert @policy.apply(:view_automated_workflow_executions?)
end

test '#view_workflow_executions?' do
assert @policy.view_automated_workflow_executions?
assert @policy.apply(:view_automated_workflow_executions?)
end

test '#update_sample_metadata?' do
assert @policy.update_sample_metadata?
assert @policy.apply(:update_sample_metadata?)
end
end
end
4 changes: 2 additions & 2 deletions test/policies/namespaces/user_namespace_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def setup
end

test '#create?' do
assert @policy.create?
assert @policy.apply(:create?)
end

test '#transfer_into_namespace?' do
assert @policy.transfer_into_namespace?
assert @policy.apply(:transfer_into_namespace?)
end
end
end
42 changes: 21 additions & 21 deletions test/policies/project_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,86 +11,86 @@ def setup
end

test '#read?' do
assert @policy.read?
assert @policy.apply(:read?)
end

test '#edit?' do
assert @policy.edit?
assert @policy.apply(:edit?)
end

test '#new?' do
assert @policy.new?
assert @policy.apply(:new?)
end

test '#update?' do
assert @policy.update?
assert @policy.apply(:update?)
end

test '#activity?' do
assert @policy.activity?
assert @policy.apply(:activity?)
end

test '#destroy?' do
assert @policy.destroy?
assert @policy.apply(:destroy?)
end

test '#transfer?' do
assert @policy.transfer?
assert @policy.apply(:transfer?)
end

test '#sample_listing?' do
assert @policy.sample_listing?
assert @policy.apply(:sample_listing?)
end

test '#create_sample?' do
assert @policy.create_sample?
assert @policy.apply(:create_sample?)
end

test '#update_sample?' do
assert @policy.update_sample?
assert @policy.apply(:update_sample?)
end

test '#transfer_sample?' do
assert @policy.transfer_sample?
assert @policy.apply(:transfer_sample?)
end

test '#destroy_sample?' do
assert @policy.destroy_sample?
assert @policy.apply(:destroy_sample?)
end

test '#read_sample?' do
assert @policy.destroy_sample?
assert @policy.apply(:read_sample?)
end

test '#transfer_sample_into_project?' do
assert @policy.transfer_sample_into_project?
assert @policy.apply(:transfer_sample_into_project?)
end

test '#clone_sample?' do
assert @policy.clone_sample?
assert @policy.apply(:clone_sample?)
end

test '#clone_sample_into_project?' do
assert @policy.clone_sample_into_project?
assert @policy.apply(:clone_sample_into_project?)
end
test '#export_data?' do
assert @policy.export_data?
assert @policy.apply(:export_data?)
end

test '#submit_workflow?' do
assert @policy.submit_workflow?
assert @policy.apply(:submit_workflow?)
end

test '#view_attachments?' do
assert @policy.view_attachments?
assert @policy.apply(:view_attachments?)
end

test '#create_attachment?' do
assert @policy.create_attachment?
assert @policy.apply(:create_attachment?)
end

test '#destroy_attachment?' do
assert @policy.destroy_attachment?
assert @policy.apply(:destroy_attachment?)
end

test 'scope' do
Expand Down
2 changes: 1 addition & 1 deletion test/policies/sample_policy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def setup
end

test '#destroy_attachment?' do
assert @policy.destroy_attachment?
assert @policy.apply(:destroy_attachment?)
end

test 'scope' do
Expand Down
Loading

0 comments on commit ea98b5a

Please sign in to comment.