{"action":"created","comment":{"url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments/55381287","id":55381287,"diff_hunk":"@@ -0,0 +1,75 @@\n+shared_examples \"select for incomplete_project\" do\n+  let(:args) { opts }\n+  let(:selector) { Subjects::PostgresqlSelection.new(workflow, user, args) }\n+\n+  let(:sms_scope) do\n+    if ss_id = args[:subject_set_id]\n+      SetMemberSubject.where(subject_set_id: ss_id)\n+    else\n+      SetMemberSubject.all\n+    end\n+  end\n+\n+  let(:unseen_count) do\n+    scoped_seen_count = if ss_id = args[:subject_set_id]\n+                          group_sms = SetMemberSubject.where(subject_set_id: ss_id)\n+                          group_sms.where(subject_id: uss.subject_ids).count\n+                        else\n+                          seen_count\n+                        end\n+    sms_scope.count - scoped_seen_count\n+  end\n+\n+  context \"when a user has only seen a few subjects\" do\n+    let(:seen_count) { 5 }\n+    let(:limit) { nil }\n+    let(:args) { opts.merge(limit: limit) }\n+    let!(:uss) do\n+      subject_ids = sms_scope.sample(seen_count).map(&:subject_id)\n+      create(:user_seen_subject, user: user, subject_ids: subject_ids, workflow: workflow)\n+    end\n+\n+    context \"with a limit of 1\" do\n+      let(:limit) { 1 }\n+\n+      it 'should return an unseen subject' do\n+        selected = selector.select.first\n+        expect(uss.subject_ids).to_not include(selected)\n+      end\n+    end\n+\n+    context \"with a limit of 10\" do\n+      let(:limit) { 10 }\n+\n+      it 'should no have duplicates' do\n+        result = selector.select\n+        expect(result).to match_array(result.to_a.uniq)\n+      end\n+    end\n+\n+    # Account for the loop cut off limit constructing the random sample\n+    it 'should always return an approximate sample of subjects up to the unseen limit' do\n+      unseen_count.times do |n|\n+        limit = n+1\n+        results_size = Subjects::PostgresqlSelection.new(workflow, user, (args || {}).merge(limit: limit)).select.length","path":"spec/support/shared_examples_for_postgresql_selection.rb","position":54,"original_position":54,"commit_id":"5dd58154d73af8dab4974cd751dfba78870e7e74","original_commit_id":"922ac6e42a7785bea516228e56d2ad591f4da2ef","user":{"login":"camallen","id":295329,"avatar_url":"https://avatars.githubusercontent.com/u/295329?v=3","gravatar_id":"","url":"https://api.github.com/users/camallen","html_url":"https://github.com/camallen","followers_url":"https://api.github.com/users/camallen/followers","following_url":"https://api.github.com/users/camallen/following{/other_user}","gists_url":"https://api.github.com/users/camallen/gists{/gist_id}","starred_url":"https://api.github.com/users/camallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camallen/subscriptions","organizations_url":"https://api.github.com/users/camallen/orgs","repos_url":"https://api.github.com/users/camallen/repos","events_url":"https://api.github.com/users/camallen/events{/privacy}","received_events_url":"https://api.github.com/users/camallen/received_events","type":"User","site_admin":false},"body":"can't see why these are using select.length i think it might have been to workaround count errors which should be fixed by something like .count(:all), i think we should change it.","created_at":"2016-03-08T16:08:15Z","updated_at":"2016-03-08T16:08:15Z","html_url":"https://github.com/zooniverse/Panoptes/pull/1706#discussion_r55381287","pull_request_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706","_links":{"self":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments/55381287"},"html":{"href":"https://github.com/zooniverse/Panoptes/pull/1706#discussion_r55381287"},"pull_request":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706"}}},"pull_request":{"url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706","id":61745816,"html_url":"https://github.com/zooniverse/Panoptes/pull/1706","diff_url":"https://github.com/zooniverse/Panoptes/pull/1706.diff","patch_url":"https://github.com/zooniverse/Panoptes/pull/1706.patch","issue_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/1706","number":1706,"state":"open","locked":false,"title":"Clean up PostgresqlSelection","user":{"login":"marten","id":277,"avatar_url":"https://avatars.githubusercontent.com/u/277?v=3","gravatar_id":"","url":"https://api.github.com/users/marten","html_url":"https://github.com/marten","followers_url":"https://api.github.com/users/marten/followers","following_url":"https://api.github.com/users/marten/following{/other_user}","gists_url":"https://api.github.com/users/marten/gists{/gist_id}","starred_url":"https://api.github.com/users/marten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marten/subscriptions","organizations_url":"https://api.github.com/users/marten/orgs","repos_url":"https://api.github.com/users/marten/repos","events_url":"https://api.github.com/users/marten/events{/privacy}","received_events_url":"https://api.github.com/users/marten/received_events","type":"User","site_admin":false},"body":"Started with removal of those `before(:all)` statements, then to keep stuff at least somewhat speedy I'm splitting up some stuff so tests can be more focussed. Not perfect yet, but time to merge this before it gets out of hand :P\r\n\r\n- [x] Figure out why this spec keeps randomly failing --> Doesn't want to fail locally :(\r\n\r\n```\r\n  1) Subjects::PostgresqlSelection selection #select grouped selection behaves like select for incomplete_project when a user has only seen a few subjects with a limit of 1 should return an unseen subject\r\n     Failure/Error: expect(uss.subject_ids).to_not include(subject.select.first)\r\n       expected [417, 430, 419, 427, 410] not to include 427\r\n     Shared Example Group: \"select for incomplete_project\" called from ./spec/lib/subjects/postgresql_selection_spec.rb:52\r\n     # ./spec/support/shared_examples_for_postgresql_selection.rb:36:in `block (4 levels) in <top (required)>'\r\n```","created_at":"2016-03-04T17:42:52Z","updated_at":"2016-03-08T16:08:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9c7a924c278aae101dbe83437ccd3a685c71b985","assignee":{"login":"camallen","id":295329,"avatar_url":"https://avatars.githubusercontent.com/u/295329?v=3","gravatar_id":"","url":"https://api.github.com/users/camallen","html_url":"https://github.com/camallen","followers_url":"https://api.github.com/users/camallen/followers","following_url":"https://api.github.com/users/camallen/following{/other_user}","gists_url":"https://api.github.com/users/camallen/gists{/gist_id}","starred_url":"https://api.github.com/users/camallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camallen/subscriptions","organizations_url":"https://api.github.com/users/camallen/orgs","repos_url":"https://api.github.com/users/camallen/repos","events_url":"https://api.github.com/users/camallen/events{/privacy}","received_events_url":"https://api.github.com/users/camallen/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706/commits","review_comments_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706/comments","review_comment_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/1706/comments","statuses_url":"https://api.github.com/repos/zooniverse/Panoptes/statuses/5dd58154d73af8dab4974cd751dfba78870e7e74","head":{"label":"marten:fix-pgselectionspec","ref":"fix-pgselectionspec","sha":"5dd58154d73af8dab4974cd751dfba78870e7e74","user":{"login":"marten","id":277,"avatar_url":"https://avatars.githubusercontent.com/u/277?v=3","gravatar_id":"","url":"https://api.github.com/users/marten","html_url":"https://github.com/marten","followers_url":"https://api.github.com/users/marten/followers","following_url":"https://api.github.com/users/marten/following{/other_user}","gists_url":"https://api.github.com/users/marten/gists{/gist_id}","starred_url":"https://api.github.com/users/marten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marten/subscriptions","organizations_url":"https://api.github.com/users/marten/orgs","repos_url":"https://api.github.com/users/marten/repos","events_url":"https://api.github.com/users/marten/events{/privacy}","received_events_url":"https://api.github.com/users/marten/received_events","type":"User","site_admin":false},"repo":{"id":37596587,"name":"Panoptes","full_name":"marten/Panoptes","owner":{"login":"marten","id":277,"avatar_url":"https://avatars.githubusercontent.com/u/277?v=3","gravatar_id":"","url":"https://api.github.com/users/marten","html_url":"https://github.com/marten","followers_url":"https://api.github.com/users/marten/followers","following_url":"https://api.github.com/users/marten/following{/other_user}","gists_url":"https://api.github.com/users/marten/gists{/gist_id}","starred_url":"https://api.github.com/users/marten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marten/subscriptions","organizations_url":"https://api.github.com/users/marten/orgs","repos_url":"https://api.github.com/users/marten/repos","events_url":"https://api.github.com/users/marten/events{/privacy}","received_events_url":"https://api.github.com/users/marten/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/marten/Panoptes","description":"It sees everything","fork":true,"url":"https://api.github.com/repos/marten/Panoptes","forks_url":"https://api.github.com/repos/marten/Panoptes/forks","keys_url":"https://api.github.com/repos/marten/Panoptes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marten/Panoptes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marten/Panoptes/teams","hooks_url":"https://api.github.com/repos/marten/Panoptes/hooks","issue_events_url":"https://api.github.com/repos/marten/Panoptes/issues/events{/number}","events_url":"https://api.github.com/repos/marten/Panoptes/events","assignees_url":"https://api.github.com/repos/marten/Panoptes/assignees{/user}","branches_url":"https://api.github.com/repos/marten/Panoptes/branches{/branch}","tags_url":"https://api.github.com/repos/marten/Panoptes/tags","blobs_url":"https://api.github.com/repos/marten/Panoptes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marten/Panoptes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marten/Panoptes/git/refs{/sha}","trees_url":"https://api.github.com/repos/marten/Panoptes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marten/Panoptes/statuses/{sha}","languages_url":"https://api.github.com/repos/marten/Panoptes/languages","stargazers_url":"https://api.github.com/repos/marten/Panoptes/stargazers","contributors_url":"https://api.github.com/repos/marten/Panoptes/contributors","subscribers_url":"https://api.github.com/repos/marten/Panoptes/subscribers","subscription_url":"https://api.github.com/repos/marten/Panoptes/subscription","commits_url":"https://api.github.com/repos/marten/Panoptes/commits{/sha}","git_commits_url":"https://api.github.com/repos/marten/Panoptes/git/commits{/sha}","comments_url":"https://api.github.com/repos/marten/Panoptes/comments{/number}","issue_comment_url":"https://api.github.com/repos/marten/Panoptes/issues/comments{/number}","contents_url":"https://api.github.com/repos/marten/Panoptes/contents/{+path}","compare_url":"https://api.github.com/repos/marten/Panoptes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marten/Panoptes/merges","archive_url":"https://api.github.com/repos/marten/Panoptes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marten/Panoptes/downloads","issues_url":"https://api.github.com/repos/marten/Panoptes/issues{/number}","pulls_url":"https://api.github.com/repos/marten/Panoptes/pulls{/number}","milestones_url":"https://api.github.com/repos/marten/Panoptes/milestones{/number}","notifications_url":"https://api.github.com/repos/marten/Panoptes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marten/Panoptes/labels{/name}","releases_url":"https://api.github.com/repos/marten/Panoptes/releases{/id}","deployments_url":"https://api.github.com/repos/marten/Panoptes/deployments","created_at":"2015-06-17T13:29:32Z","updated_at":"2015-10-15T12:46:49Z","pushed_at":"2016-03-08T13:54:29Z","git_url":"git://github.com/marten/Panoptes.git","ssh_url":"git@github.com:marten/Panoptes.git","clone_url":"https://github.com/marten/Panoptes.git","svn_url":"https://github.com/marten/Panoptes","homepage":"","size":5195,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"zooniverse:master","ref":"master","sha":"659a462571e493841af2f89786bcaefdbc30d8db","user":{"login":"zooniverse","id":106856,"avatar_url":"https://avatars.githubusercontent.com/u/106856?v=3","gravatar_id":"","url":"https://api.github.com/users/zooniverse","html_url":"https://github.com/zooniverse","followers_url":"https://api.github.com/users/zooniverse/followers","following_url":"https://api.github.com/users/zooniverse/following{/other_user}","gists_url":"https://api.github.com/users/zooniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/zooniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooniverse/subscriptions","organizations_url":"https://api.github.com/users/zooniverse/orgs","repos_url":"https://api.github.com/users/zooniverse/repos","events_url":"https://api.github.com/users/zooniverse/events{/privacy}","received_events_url":"https://api.github.com/users/zooniverse/received_events","type":"Organization","site_admin":false},"repo":{"id":19036577,"name":"Panoptes","full_name":"zooniverse/Panoptes","owner":{"login":"zooniverse","id":106856,"avatar_url":"https://avatars.githubusercontent.com/u/106856?v=3","gravatar_id":"","url":"https://api.github.com/users/zooniverse","html_url":"https://github.com/zooniverse","followers_url":"https://api.github.com/users/zooniverse/followers","following_url":"https://api.github.com/users/zooniverse/following{/other_user}","gists_url":"https://api.github.com/users/zooniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/zooniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooniverse/subscriptions","organizations_url":"https://api.github.com/users/zooniverse/orgs","repos_url":"https://api.github.com/users/zooniverse/repos","events_url":"https://api.github.com/users/zooniverse/events{/privacy}","received_events_url":"https://api.github.com/users/zooniverse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zooniverse/Panoptes","description":"It sees everything","fork":false,"url":"https://api.github.com/repos/zooniverse/Panoptes","forks_url":"https://api.github.com/repos/zooniverse/Panoptes/forks","keys_url":"https://api.github.com/repos/zooniverse/Panoptes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zooniverse/Panoptes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zooniverse/Panoptes/teams","hooks_url":"https://api.github.com/repos/zooniverse/Panoptes/hooks","issue_events_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/events{/number}","events_url":"https://api.github.com/repos/zooniverse/Panoptes/events","assignees_url":"https://api.github.com/repos/zooniverse/Panoptes/assignees{/user}","branches_url":"https://api.github.com/repos/zooniverse/Panoptes/branches{/branch}","tags_url":"https://api.github.com/repos/zooniverse/Panoptes/tags","blobs_url":"https://api.github.com/repos/zooniverse/Panoptes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zooniverse/Panoptes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zooniverse/Panoptes/git/refs{/sha}","trees_url":"https://api.github.com/repos/zooniverse/Panoptes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zooniverse/Panoptes/statuses/{sha}","languages_url":"https://api.github.com/repos/zooniverse/Panoptes/languages","stargazers_url":"https://api.github.com/repos/zooniverse/Panoptes/stargazers","contributors_url":"https://api.github.com/repos/zooniverse/Panoptes/contributors","subscribers_url":"https://api.github.com/repos/zooniverse/Panoptes/subscribers","subscription_url":"https://api.github.com/repos/zooniverse/Panoptes/subscription","commits_url":"https://api.github.com/repos/zooniverse/Panoptes/commits{/sha}","git_commits_url":"https://api.github.com/repos/zooniverse/Panoptes/git/commits{/sha}","comments_url":"https://api.github.com/repos/zooniverse/Panoptes/comments{/number}","issue_comment_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/comments{/number}","contents_url":"https://api.github.com/repos/zooniverse/Panoptes/contents/{+path}","compare_url":"https://api.github.com/repos/zooniverse/Panoptes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zooniverse/Panoptes/merges","archive_url":"https://api.github.com/repos/zooniverse/Panoptes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zooniverse/Panoptes/downloads","issues_url":"https://api.github.com/repos/zooniverse/Panoptes/issues{/number}","pulls_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls{/number}","milestones_url":"https://api.github.com/repos/zooniverse/Panoptes/milestones{/number}","notifications_url":"https://api.github.com/repos/zooniverse/Panoptes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zooniverse/Panoptes/labels{/name}","releases_url":"https://api.github.com/repos/zooniverse/Panoptes/releases{/id}","deployments_url":"https://api.github.com/repos/zooniverse/Panoptes/deployments","created_at":"2014-04-22T16:16:02Z","updated_at":"2016-03-03T09:43:59Z","pushed_at":"2016-03-08T14:27:38Z","git_url":"git://github.com/zooniverse/Panoptes.git","ssh_url":"git@github.com:zooniverse/Panoptes.git","clone_url":"https://github.com/zooniverse/Panoptes.git","svn_url":"https://github.com/zooniverse/Panoptes","homepage":"","size":5432,"stargazers_count":42,"watchers_count":42,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":20,"mirror_url":null,"open_issues_count":101,"forks":20,"open_issues":101,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706"},"html":{"href":"https://github.com/zooniverse/Panoptes/pull/1706"},"issue":{"href":"https://api.github.com/repos/zooniverse/Panoptes/issues/1706"},"comments":{"href":"https://api.github.com/repos/zooniverse/Panoptes/issues/1706/comments"},"review_comments":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706/comments"},"review_comment":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/1706/commits"},"statuses":{"href":"https://api.github.com/repos/zooniverse/Panoptes/statuses/5dd58154d73af8dab4974cd751dfba78870e7e74"}}}}