{"action":"created","comment":{"url":"https://api.github.com/repos/sul-dlss/argo/pulls/comments/54620992","id":54620992,"diff_hunk":"@@ -0,0 +1,121 @@\n+require 'spec_helper'\n+require 'cancan/matchers'\n+\n+describe Ability do\n+  let(:subject) { described_class.new(user) }\n+  let(:user) { mock_user }\n+  let(:item) { Dor::Item.new(pid: 'x') }\n+\n+  context 'as an administrator' do\n+    let(:user) { mock_user(is_admin?: true)}\n+\n+    it { should be_able_to(:manage, :everything) }\n+  end\n+\n+  context 'as a manager' do\n+    let(:user) { mock_user(is_manager?: true)}\n+\n+    it { should_not be_able_to(:manage, :everything) }\n+    it { should be_able_to(:manage_item, item) }\n+    it { should be_able_to(:manage_content, item) }\n+    it { should be_able_to(:manage_desc_metadata, item) }\n+    it { should be_able_to(:create, Dor::AdminPolicyObject) }\n+  end\n+\n+  context 'as a viewer' do\n+    let(:user) { mock_user(is_viewer?: true)}\n+\n+    it { should_not be_able_to(:manage_item, item) }\n+    it { should_not be_able_to(:manage_content, item) }\n+    it { should_not be_able_to(:manage_desc_metadata, item) }\n+    it { should be_able_to(:view_item, item) }\n+    it { should be_able_to(:view_metadata, item) }\n+    it { should be_able_to(:view_content, item) }\n+  end\n+\n+  context 'for items without an APO' do\n+    it { should_not be_able_to(:manage_item, item) }\n+    it { should_not be_able_to(:manage_content, item) }\n+    it { should_not be_able_to(:manage_desc_metadata, item) }\n+    it { should_not be_able_to(:view_item, item) }\n+    it { should_not be_able_to(:view_content, item) }\n+    it { should_not be_able_to(:view_metadata, item) }\n+  end\n+\n+  context 'from an APO' do\n+    let(:item) { Dor::AdminPolicyObject.new(pid: 'apo') }\n+\n+    context 'for a managed item' do\n+      before { allow(item).to receive(:can_manage_item?).and_return(true) }\n+      it { should be_able_to(:manage_item, item) }\n+    end\n+\n+    context 'for a viewable item' do\n+      before { allow(item).to receive(:can_view_item?).and_return(true) }\n+      it { should be_able_to(:view_item, item) }\n+    end\n+  end\n+\n+  context 'with roles assigned by an APO' do\n+    let(:apo) { double(Dor::AdminPolicyObject, pid: 'apo')}\n+    let(:random_item) { Dor::Item.new(pid: 'x') }\n+\n+    before do\n+      allow(item).to receive(:admin_policy_object).and_return(apo)","path":"spec/models/ability_spec.rb","position":null,"original_position":64,"commit_id":"2dfd2002db724ead587bc351aa3af35af64ccd08","original_commit_id":"195dd74d2dcd866ef400d48d04113d0ad3f89244","user":{"login":"cbeer","id":111218,"avatar_url":"https://avatars.githubusercontent.com/u/111218?v=3","gravatar_id":"","url":"https://api.github.com/users/cbeer","html_url":"https://github.com/cbeer","followers_url":"https://api.github.com/users/cbeer/followers","following_url":"https://api.github.com/users/cbeer/following{/other_user}","gists_url":"https://api.github.com/users/cbeer/gists{/gist_id}","starred_url":"https://api.github.com/users/cbeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbeer/subscriptions","organizations_url":"https://api.github.com/users/cbeer/orgs","repos_url":"https://api.github.com/users/cbeer/repos","events_url":"https://api.github.com/users/cbeer/events{/privacy}","received_events_url":"https://api.github.com/users/cbeer/received_events","type":"User","site_admin":false},"body":"Ok, the code now explicitly covers 3 different scenarios:\r\n\r\n- [x] an item with an APO where the user is in an appropriate role\r\n- [x] an item with an APO where the user is not in appropriate role\r\n- [x] an item doesn't have an APO","created_at":"2016-03-01T19:28:42Z","updated_at":"2016-03-01T19:28:42Z","html_url":"https://github.com/sul-dlss/argo/pull/596#discussion_r54620992","pull_request_url":"https://api.github.com/repos/sul-dlss/argo/pulls/596","_links":{"self":{"href":"https://api.github.com/repos/sul-dlss/argo/pulls/comments/54620992"},"html":{"href":"https://github.com/sul-dlss/argo/pull/596#discussion_r54620992"},"pull_request":{"href":"https://api.github.com/repos/sul-dlss/argo/pulls/596"}}},"pull_request":{"url":"https://api.github.com/repos/sul-dlss/argo/pulls/596","id":60888840,"html_url":"https://github.com/sul-dlss/argo/pull/596","diff_url":"https://github.com/sul-dlss/argo/pull/596.diff","patch_url":"https://github.com/sul-dlss/argo/pull/596.patch","issue_url":"https://api.github.com/repos/sul-dlss/argo/issues/596","number":596,"state":"open","locked":false,"title":"Shameless green for cancan authorization","user":{"login":"cbeer","id":111218,"avatar_url":"https://avatars.githubusercontent.com/u/111218?v=3","gravatar_id":"","url":"https://api.github.com/users/cbeer","html_url":"https://github.com/cbeer","followers_url":"https://api.github.com/users/cbeer/followers","following_url":"https://api.github.com/users/cbeer/following{/other_user}","gists_url":"https://api.github.com/users/cbeer/gists{/gist_id}","starred_url":"https://api.github.com/users/cbeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbeer/subscriptions","organizations_url":"https://api.github.com/users/cbeer/orgs","repos_url":"https://api.github.com/users/cbeer/repos","events_url":"https://api.github.com/users/cbeer/events{/privacy}","received_events_url":"https://api.github.com/users/cbeer/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-26T19:13:01Z","updated_at":"2016-03-01T19:28:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51258f99a403ed86ad5d1b325b337825f8c46f59","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sul-dlss/argo/pulls/596/commits","review_comments_url":"https://api.github.com/repos/sul-dlss/argo/pulls/596/comments","review_comment_url":"https://api.github.com/repos/sul-dlss/argo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sul-dlss/argo/issues/596/comments","statuses_url":"https://api.github.com/repos/sul-dlss/argo/statuses/2dfd2002db724ead587bc351aa3af35af64ccd08","head":{"label":"sul-dlss:cancancan","ref":"cancancan","sha":"2dfd2002db724ead587bc351aa3af35af64ccd08","user":{"login":"sul-dlss","id":230583,"avatar_url":"https://avatars.githubusercontent.com/u/230583?v=3","gravatar_id":"","url":"https://api.github.com/users/sul-dlss","html_url":"https://github.com/sul-dlss","followers_url":"https://api.github.com/users/sul-dlss/followers","following_url":"https://api.github.com/users/sul-dlss/following{/other_user}","gists_url":"https://api.github.com/users/sul-dlss/gists{/gist_id}","starred_url":"https://api.github.com/users/sul-dlss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sul-dlss/subscriptions","organizations_url":"https://api.github.com/users/sul-dlss/orgs","repos_url":"https://api.github.com/users/sul-dlss/repos","events_url":"https://api.github.com/users/sul-dlss/events{/privacy}","received_events_url":"https://api.github.com/users/sul-dlss/received_events","type":"Organization","site_admin":false},"repo":{"id":4989164,"name":"argo","full_name":"sul-dlss/argo","owner":{"login":"sul-dlss","id":230583,"avatar_url":"https://avatars.githubusercontent.com/u/230583?v=3","gravatar_id":"","url":"https://api.github.com/users/sul-dlss","html_url":"https://github.com/sul-dlss","followers_url":"https://api.github.com/users/sul-dlss/followers","following_url":"https://api.github.com/users/sul-dlss/following{/other_user}","gists_url":"https://api.github.com/users/sul-dlss/gists{/gist_id}","starred_url":"https://api.github.com/users/sul-dlss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sul-dlss/subscriptions","organizations_url":"https://api.github.com/users/sul-dlss/orgs","repos_url":"https://api.github.com/users/sul-dlss/repos","events_url":"https://api.github.com/users/sul-dlss/events{/privacy}","received_events_url":"https://api.github.com/users/sul-dlss/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sul-dlss/argo","description":"The administrative discovery interface for Stanford's Digital Object Registry","fork":false,"url":"https://api.github.com/repos/sul-dlss/argo","forks_url":"https://api.github.com/repos/sul-dlss/argo/forks","keys_url":"https://api.github.com/repos/sul-dlss/argo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sul-dlss/argo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sul-dlss/argo/teams","hooks_url":"https://api.github.com/repos/sul-dlss/argo/hooks","issue_events_url":"https://api.github.com/repos/sul-dlss/argo/issues/events{/number}","events_url":"https://api.github.com/repos/sul-dlss/argo/events","assignees_url":"https://api.github.com/repos/sul-dlss/argo/assignees{/user}","branches_url":"https://api.github.com/repos/sul-dlss/argo/branches{/branch}","tags_url":"https://api.github.com/repos/sul-dlss/argo/tags","blobs_url":"https://api.github.com/repos/sul-dlss/argo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sul-dlss/argo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sul-dlss/argo/git/refs{/sha}","trees_url":"https://api.github.com/repos/sul-dlss/argo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sul-dlss/argo/statuses/{sha}","languages_url":"https://api.github.com/repos/sul-dlss/argo/languages","stargazers_url":"https://api.github.com/repos/sul-dlss/argo/stargazers","contributors_url":"https://api.github.com/repos/sul-dlss/argo/contributors","subscribers_url":"https://api.github.com/repos/sul-dlss/argo/subscribers","subscription_url":"https://api.github.com/repos/sul-dlss/argo/subscription","commits_url":"https://api.github.com/repos/sul-dlss/argo/commits{/sha}","git_commits_url":"https://api.github.com/repos/sul-dlss/argo/git/commits{/sha}","comments_url":"https://api.github.com/repos/sul-dlss/argo/comments{/number}","issue_comment_url":"https://api.github.com/repos/sul-dlss/argo/issues/comments{/number}","contents_url":"https://api.github.com/repos/sul-dlss/argo/contents/{+path}","compare_url":"https://api.github.com/repos/sul-dlss/argo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sul-dlss/argo/merges","archive_url":"https://api.github.com/repos/sul-dlss/argo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sul-dlss/argo/downloads","issues_url":"https://api.github.com/repos/sul-dlss/argo/issues{/number}","pulls_url":"https://api.github.com/repos/sul-dlss/argo/pulls{/number}","milestones_url":"https://api.github.com/repos/sul-dlss/argo/milestones{/number}","notifications_url":"https://api.github.com/repos/sul-dlss/argo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sul-dlss/argo/labels{/name}","releases_url":"https://api.github.com/repos/sul-dlss/argo/releases{/id}","deployments_url":"https://api.github.com/repos/sul-dlss/argo/deployments","created_at":"2012-07-11T13:15:05Z","updated_at":"2016-01-12T22:48:20Z","pushed_at":"2016-03-01T19:27:45Z","git_url":"git://github.com/sul-dlss/argo.git","ssh_url":"git@github.com:sul-dlss/argo.git","clone_url":"https://github.com/sul-dlss/argo.git","svn_url":"https://github.com/sul-dlss/argo","homepage":null,"size":30024,"stargazers_count":12,"watchers_count":12,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":107,"forks":1,"open_issues":107,"watchers":12,"default_branch":"master"}},"base":{"label":"sul-dlss:master","ref":"master","sha":"7099c61bbb74a3503d4093d5c1c690feef9fd830","user":{"login":"sul-dlss","id":230583,"avatar_url":"https://avatars.githubusercontent.com/u/230583?v=3","gravatar_id":"","url":"https://api.github.com/users/sul-dlss","html_url":"https://github.com/sul-dlss","followers_url":"https://api.github.com/users/sul-dlss/followers","following_url":"https://api.github.com/users/sul-dlss/following{/other_user}","gists_url":"https://api.github.com/users/sul-dlss/gists{/gist_id}","starred_url":"https://api.github.com/users/sul-dlss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sul-dlss/subscriptions","organizations_url":"https://api.github.com/users/sul-dlss/orgs","repos_url":"https://api.github.com/users/sul-dlss/repos","events_url":"https://api.github.com/users/sul-dlss/events{/privacy}","received_events_url":"https://api.github.com/users/sul-dlss/received_events","type":"Organization","site_admin":false},"repo":{"id":4989164,"name":"argo","full_name":"sul-dlss/argo","owner":{"login":"sul-dlss","id":230583,"avatar_url":"https://avatars.githubusercontent.com/u/230583?v=3","gravatar_id":"","url":"https://api.github.com/users/sul-dlss","html_url":"https://github.com/sul-dlss","followers_url":"https://api.github.com/users/sul-dlss/followers","following_url":"https://api.github.com/users/sul-dlss/following{/other_user}","gists_url":"https://api.github.com/users/sul-dlss/gists{/gist_id}","starred_url":"https://api.github.com/users/sul-dlss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sul-dlss/subscriptions","organizations_url":"https://api.github.com/users/sul-dlss/orgs","repos_url":"https://api.github.com/users/sul-dlss/repos","events_url":"https://api.github.com/users/sul-dlss/events{/privacy}","received_events_url":"https://api.github.com/users/sul-dlss/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sul-dlss/argo","description":"The administrative discovery interface for Stanford's Digital Object Registry","fork":false,"url":"https://api.github.com/repos/sul-dlss/argo","forks_url":"https://api.github.com/repos/sul-dlss/argo/forks","keys_url":"https://api.github.com/repos/sul-dlss/argo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sul-dlss/argo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sul-dlss/argo/teams","hooks_url":"https://api.github.com/repos/sul-dlss/argo/hooks","issue_events_url":"https://api.github.com/repos/sul-dlss/argo/issues/events{/number}","events_url":"https://api.github.com/repos/sul-dlss/argo/events","assignees_url":"https://api.github.com/repos/sul-dlss/argo/assignees{/user}","branches_url":"https://api.github.com/repos/sul-dlss/argo/branches{/branch}","tags_url":"https://api.github.com/repos/sul-dlss/argo/tags","blobs_url":"https://api.github.com/repos/sul-dlss/argo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sul-dlss/argo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sul-dlss/argo/git/refs{/sha}","trees_url":"https://api.github.com/repos/sul-dlss/argo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sul-dlss/argo/statuses/{sha}","languages_url":"https://api.github.com/repos/sul-dlss/argo/languages","stargazers_url":"https://api.github.com/repos/sul-dlss/argo/stargazers","contributors_url":"https://api.github.com/repos/sul-dlss/argo/contributors","subscribers_url":"https://api.github.com/repos/sul-dlss/argo/subscribers","subscription_url":"https://api.github.com/repos/sul-dlss/argo/subscription","commits_url":"https://api.github.com/repos/sul-dlss/argo/commits{/sha}","git_commits_url":"https://api.github.com/repos/sul-dlss/argo/git/commits{/sha}","comments_url":"https://api.github.com/repos/sul-dlss/argo/comments{/number}","issue_comment_url":"https://api.github.com/repos/sul-dlss/argo/issues/comments{/number}","contents_url":"https://api.github.com/repos/sul-dlss/argo/contents/{+path}","compare_url":"https://api.github.com/repos/sul-dlss/argo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sul-dlss/argo/merges","archive_url":"https://api.github.com/repos/sul-dlss/argo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sul-dlss/argo/downloads","issues_url":"https://api.github.com/repos/sul-dlss/argo/issues{/number}","pulls_url":"https://api.github.com/repos/sul-dlss/argo/pulls{/number}","milestones_url":"https://api.github.com/repos/sul-dlss/argo/milestones{/number}","notifications_url":"https://api.github.com/repos/sul-dlss/argo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sul-dlss/argo/labels{/name}","releases_url":"https://api.github.com/repos/sul-dlss/argo/releases{/id}","deployments_url":"https://api.github.com/repos/sul-dlss/argo/deployments","created_at":"2012-07-11T13:15:05Z","updated_at":"2016-01-12T22:48:20Z","pushed_at":"2016-03-01T19:27:45Z","git_url":"git://github.com/sul-dlss/argo.git","ssh_url":"git@github.com:sul-dlss/argo.git","clone_url":"https://github.com/sul-dlss/argo.git","svn_url":"https://github.com/sul-dlss/argo","homepage":null,"size":30024,"stargazers_count":12,"watchers_count":12,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":107,"forks":1,"open_issues":107,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sul-dlss/argo/pulls/596"},"html":{"href":"https://github.com/sul-dlss/argo/pull/596"},"issue":{"href":"https://api.github.com/repos/sul-dlss/argo/issues/596"},"comments":{"href":"https://api.github.com/repos/sul-dlss/argo/issues/596/comments"},"review_comments":{"href":"https://api.github.com/repos/sul-dlss/argo/pulls/596/comments"},"review_comment":{"href":"https://api.github.com/repos/sul-dlss/argo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sul-dlss/argo/pulls/596/commits"},"statuses":{"href":"https://api.github.com/repos/sul-dlss/argo/statuses/2dfd2002db724ead587bc351aa3af35af64ccd08"}}}}