{"action":"created","comment":{"url":"https://api.github.com/repos/mavenlink/brainstem/pulls/comments/33820841","id":33820841,"diff_hunk":"@@ -404,41 +404,73 @@ def workspace.synthetic_id\n     end\n \n     describe \"preloading\" do\n-      it \"preloads associations when they are full model-level associations\" do\n-        mock(Brainstem::Presenter).ar_preload(anything, anything) do |models, args|\n-          expect(args).to eq %w[tasks user]\n+\n+      #\n+      # We have three strategies for introspecting what the AR Preloader\n+      # receives:\n+      #\n+      # 1. Actually looking at what AR receives.\n+      #\n+      #    This is sub-optimal because AR works differently between versions\n+      #    3 and 4, so introspecting is difficult.\n+      #\n+      # 2. Looking at what the proc that encapsulates the AR methods is\n+      #    called with.\n+      #\n+      #    This is difficult to do because we don't control the instantiation\n+      #    of the Preloader, which makes injecting this hard.\n+      #\n+      # 3. Intercept the instantiating parent function and append the\n+      #    inspectable proc.\n+      #\n+      #    This is probably the grossest of all the above options, and I\n+      #    suspect it's the greatest indication that we're testing\n+      #    inappropriately here -- a fact that I think bears weight given\n+      #    we're making unit-level assertions in an integration spec.\n+      #    However, there's also some value in asserting that these are\n+      #    passed through without digging into Rails internals. However,\n+      #    further 'purity' improvements could be made by introspecting on\n+      #    AR's actual data structures.\n+      #\n+      #    That's about three shades on the side of overkill, though.\n+      #\n+      def preloader_should_receive(hsh)","path":"spec/brainstem/presenter_spec.rb","position":37,"original_position":37,"commit_id":"1061782536331edeafc325fae6b20bf1a38e9d7c","original_commit_id":"bd8fa387a25392a62d808c8f0bbb93497d9cf59f","user":{"login":"robyurkowski","id":230379,"avatar_url":"https://avatars.githubusercontent.com/u/230379?v=3","gravatar_id":"","url":"https://api.github.com/users/robyurkowski","html_url":"https://github.com/robyurkowski","followers_url":"https://api.github.com/users/robyurkowski/followers","following_url":"https://api.github.com/users/robyurkowski/following{/other_user}","gists_url":"https://api.github.com/users/robyurkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/robyurkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robyurkowski/subscriptions","organizations_url":"https://api.github.com/users/robyurkowski/orgs","repos_url":"https://api.github.com/users/robyurkowski/repos","events_url":"https://api.github.com/users/robyurkowski/events{/privacy}","received_events_url":"https://api.github.com/users/robyurkowski/received_events","type":"User","site_admin":false},"body":"I've moved `ar_preload` into the Preloader as the presenter shouldn't care about the actual method of preloading. \r\n\r\nInside `Preloader`, it's appropriate to inject a method or a proc as a collaborator because it should be insulated from the actual implementation within ActiveRecord—or, put another way, what the preloader needs is to send a message to ActiveRecord, but just *which* message is actually an implementation detail of AR and should be injected as a dependency. \r\n\r\nWe could move the `ar_preload` method entirely within the Preloader, but that closely binds Preloader to AR. In some situations (testing being the biggest example), we want to inject a different collaborator that handles the way that preloading is done. ","created_at":"2015-07-02T20:44:36Z","updated_at":"2015-07-02T20:44:36Z","html_url":"https://github.com/mavenlink/brainstem/pull/57#discussion_r33820841","pull_request_url":"https://api.github.com/repos/mavenlink/brainstem/pulls/57","_links":{"self":{"href":"https://api.github.com/repos/mavenlink/brainstem/pulls/comments/33820841"},"html":{"href":"https://github.com/mavenlink/brainstem/pull/57#discussion_r33820841"},"pull_request":{"href":"https://api.github.com/repos/mavenlink/brainstem/pulls/57"}}},"pull_request":{"url":"https://api.github.com/repos/mavenlink/brainstem/pulls/57","id":38153408,"html_url":"https://github.com/mavenlink/brainstem/pull/57","diff_url":"https://github.com/mavenlink/brainstem/pull/57.diff","patch_url":"https://github.com/mavenlink/brainstem/pull/57.patch","issue_url":"https://api.github.com/repos/mavenlink/brainstem/issues/57","number":57,"state":"open","locked":false,"title":"Refactor presenter preload","user":{"login":"robyurkowski","id":230379,"avatar_url":"https://avatars.githubusercontent.com/u/230379?v=3","gravatar_id":"","url":"https://api.github.com/users/robyurkowski","html_url":"https://github.com/robyurkowski","followers_url":"https://api.github.com/users/robyurkowski/followers","following_url":"https://api.github.com/users/robyurkowski/following{/other_user}","gists_url":"https://api.github.com/users/robyurkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/robyurkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robyurkowski/subscriptions","organizations_url":"https://api.github.com/users/robyurkowski/orgs","repos_url":"https://api.github.com/users/robyurkowski/repos","events_url":"https://api.github.com/users/robyurkowski/events{/privacy}","received_events_url":"https://api.github.com/users/robyurkowski/received_events","type":"User","site_admin":false},"body":"I need to add one more fix here before this is merged (missing a test for when there are no valid preloads), but I think this is a reasonable attempt at removing some of the complexity of the presenter into an appropriate collaborator.","created_at":"2015-06-19T22:22:47Z","updated_at":"2015-07-02T20:44:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a520b126ba2a6eb9b9ba78f190e2c7dd77108f3a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mavenlink/brainstem/pulls/57/commits","review_comments_url":"https://api.github.com/repos/mavenlink/brainstem/pulls/57/comments","review_comment_url":"https://api.github.com/repos/mavenlink/brainstem/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mavenlink/brainstem/issues/57/comments","statuses_url":"https://api.github.com/repos/mavenlink/brainstem/statuses/1061782536331edeafc325fae6b20bf1a38e9d7c","head":{"label":"robyurkowski:refactor_presenter_preload","ref":"refactor_presenter_preload","sha":"1061782536331edeafc325fae6b20bf1a38e9d7c","user":{"login":"robyurkowski","id":230379,"avatar_url":"https://avatars.githubusercontent.com/u/230379?v=3","gravatar_id":"","url":"https://api.github.com/users/robyurkowski","html_url":"https://github.com/robyurkowski","followers_url":"https://api.github.com/users/robyurkowski/followers","following_url":"https://api.github.com/users/robyurkowski/following{/other_user}","gists_url":"https://api.github.com/users/robyurkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/robyurkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robyurkowski/subscriptions","organizations_url":"https://api.github.com/users/robyurkowski/orgs","repos_url":"https://api.github.com/users/robyurkowski/repos","events_url":"https://api.github.com/users/robyurkowski/events{/privacy}","received_events_url":"https://api.github.com/users/robyurkowski/received_events","type":"User","site_admin":false},"repo":{"id":37748316,"name":"brainstem","full_name":"robyurkowski/brainstem","owner":{"login":"robyurkowski","id":230379,"avatar_url":"https://avatars.githubusercontent.com/u/230379?v=3","gravatar_id":"","url":"https://api.github.com/users/robyurkowski","html_url":"https://github.com/robyurkowski","followers_url":"https://api.github.com/users/robyurkowski/followers","following_url":"https://api.github.com/users/robyurkowski/following{/other_user}","gists_url":"https://api.github.com/users/robyurkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/robyurkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robyurkowski/subscriptions","organizations_url":"https://api.github.com/users/robyurkowski/orgs","repos_url":"https://api.github.com/users/robyurkowski/repos","events_url":"https://api.github.com/users/robyurkowski/events{/privacy}","received_events_url":"https://api.github.com/users/robyurkowski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robyurkowski/brainstem","description":"The Brainstem gem provides a framework for converting ActiveRecord objects into a great JSON API. Brainstem Presenters allow easy application of user-requested sorts, filters, and association loads, allowing for simpler implementations, fewer requests, and smaller responses.","fork":true,"url":"https://api.github.com/repos/robyurkowski/brainstem","forks_url":"https://api.github.com/repos/robyurkowski/brainstem/forks","keys_url":"https://api.github.com/repos/robyurkowski/brainstem/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robyurkowski/brainstem/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robyurkowski/brainstem/teams","hooks_url":"https://api.github.com/repos/robyurkowski/brainstem/hooks","issue_events_url":"https://api.github.com/repos/robyurkowski/brainstem/issues/events{/number}","events_url":"https://api.github.com/repos/robyurkowski/brainstem/events","assignees_url":"https://api.github.com/repos/robyurkowski/brainstem/assignees{/user}","branches_url":"https://api.github.com/repos/robyurkowski/brainstem/branches{/branch}","tags_url":"https://api.github.com/repos/robyurkowski/brainstem/tags","blobs_url":"https://api.github.com/repos/robyurkowski/brainstem/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robyurkowski/brainstem/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robyurkowski/brainstem/git/refs{/sha}","trees_url":"https://api.github.com/repos/robyurkowski/brainstem/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robyurkowski/brainstem/statuses/{sha}","languages_url":"https://api.github.com/repos/robyurkowski/brainstem/languages","stargazers_url":"https://api.github.com/repos/robyurkowski/brainstem/stargazers","contributors_url":"https://api.github.com/repos/robyurkowski/brainstem/contributors","subscribers_url":"https://api.github.com/repos/robyurkowski/brainstem/subscribers","subscription_url":"https://api.github.com/repos/robyurkowski/brainstem/subscription","commits_url":"https://api.github.com/repos/robyurkowski/brainstem/commits{/sha}","git_commits_url":"https://api.github.com/repos/robyurkowski/brainstem/git/commits{/sha}","comments_url":"https://api.github.com/repos/robyurkowski/brainstem/comments{/number}","issue_comment_url":"https://api.github.com/repos/robyurkowski/brainstem/issues/comments{/number}","contents_url":"https://api.github.com/repos/robyurkowski/brainstem/contents/{+path}","compare_url":"https://api.github.com/repos/robyurkowski/brainstem/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robyurkowski/brainstem/merges","archive_url":"https://api.github.com/repos/robyurkowski/brainstem/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robyurkowski/brainstem/downloads","issues_url":"https://api.github.com/repos/robyurkowski/brainstem/issues{/number}","pulls_url":"https://api.github.com/repos/robyurkowski/brainstem/pulls{/number}","milestones_url":"https://api.github.com/repos/robyurkowski/brainstem/milestones{/number}","notifications_url":"https://api.github.com/repos/robyurkowski/brainstem/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robyurkowski/brainstem/labels{/name}","releases_url":"https://api.github.com/repos/robyurkowski/brainstem/releases{/id}","created_at":"2015-06-19T22:08:43Z","updated_at":"2015-06-19T22:08:43Z","pushed_at":"2015-07-02T20:31:48Z","git_url":"git://github.com/robyurkowski/brainstem.git","ssh_url":"git@github.com:robyurkowski/brainstem.git","clone_url":"https://github.com/robyurkowski/brainstem.git","svn_url":"https://github.com/robyurkowski/brainstem","homepage":"","size":647,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"mavenlink:presenter_dsl","ref":"presenter_dsl","sha":"915491260576852ee7d321feb33eb50801cdaf8c","user":{"login":"mavenlink","id":52609,"avatar_url":"https://avatars.githubusercontent.com/u/52609?v=3","gravatar_id":"","url":"https://api.github.com/users/mavenlink","html_url":"https://github.com/mavenlink","followers_url":"https://api.github.com/users/mavenlink/followers","following_url":"https://api.github.com/users/mavenlink/following{/other_user}","gists_url":"https://api.github.com/users/mavenlink/gists{/gist_id}","starred_url":"https://api.github.com/users/mavenlink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavenlink/subscriptions","organizations_url":"https://api.github.com/users/mavenlink/orgs","repos_url":"https://api.github.com/users/mavenlink/repos","events_url":"https://api.github.com/users/mavenlink/events{/privacy}","received_events_url":"https://api.github.com/users/mavenlink/received_events","type":"Organization","site_admin":false},"repo":{"id":7262746,"name":"brainstem","full_name":"mavenlink/brainstem","owner":{"login":"mavenlink","id":52609,"avatar_url":"https://avatars.githubusercontent.com/u/52609?v=3","gravatar_id":"","url":"https://api.github.com/users/mavenlink","html_url":"https://github.com/mavenlink","followers_url":"https://api.github.com/users/mavenlink/followers","following_url":"https://api.github.com/users/mavenlink/following{/other_user}","gists_url":"https://api.github.com/users/mavenlink/gists{/gist_id}","starred_url":"https://api.github.com/users/mavenlink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mavenlink/subscriptions","organizations_url":"https://api.github.com/users/mavenlink/orgs","repos_url":"https://api.github.com/users/mavenlink/repos","events_url":"https://api.github.com/users/mavenlink/events{/privacy}","received_events_url":"https://api.github.com/users/mavenlink/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mavenlink/brainstem","description":"The Brainstem gem provides a framework for converting ActiveRecord objects into a great JSON API. Brainstem Presenters allow easy application of user-requested sorts, filters, and association loads, allowing for simpler implementations, fewer requests, and smaller responses.","fork":false,"url":"https://api.github.com/repos/mavenlink/brainstem","forks_url":"https://api.github.com/repos/mavenlink/brainstem/forks","keys_url":"https://api.github.com/repos/mavenlink/brainstem/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mavenlink/brainstem/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mavenlink/brainstem/teams","hooks_url":"https://api.github.com/repos/mavenlink/brainstem/hooks","issue_events_url":"https://api.github.com/repos/mavenlink/brainstem/issues/events{/number}","events_url":"https://api.github.com/repos/mavenlink/brainstem/events","assignees_url":"https://api.github.com/repos/mavenlink/brainstem/assignees{/user}","branches_url":"https://api.github.com/repos/mavenlink/brainstem/branches{/branch}","tags_url":"https://api.github.com/repos/mavenlink/brainstem/tags","blobs_url":"https://api.github.com/repos/mavenlink/brainstem/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mavenlink/brainstem/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mavenlink/brainstem/git/refs{/sha}","trees_url":"https://api.github.com/repos/mavenlink/brainstem/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mavenlink/brainstem/statuses/{sha}","languages_url":"https://api.github.com/repos/mavenlink/brainstem/languages","stargazers_url":"https://api.github.com/repos/mavenlink/brainstem/stargazers","contributors_url":"https://api.github.com/repos/mavenlink/brainstem/contributors","subscribers_url":"https://api.github.com/repos/mavenlink/brainstem/subscribers","subscription_url":"https://api.github.com/repos/mavenlink/brainstem/subscription","commits_url":"https://api.github.com/repos/mavenlink/brainstem/commits{/sha}","git_commits_url":"https://api.github.com/repos/mavenlink/brainstem/git/commits{/sha}","comments_url":"https://api.github.com/repos/mavenlink/brainstem/comments{/number}","issue_comment_url":"https://api.github.com/repos/mavenlink/brainstem/issues/comments{/number}","contents_url":"https://api.github.com/repos/mavenlink/brainstem/contents/{+path}","compare_url":"https://api.github.com/repos/mavenlink/brainstem/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mavenlink/brainstem/merges","archive_url":"https://api.github.com/repos/mavenlink/brainstem/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mavenlink/brainstem/downloads","issues_url":"https://api.github.com/repos/mavenlink/brainstem/issues{/number}","pulls_url":"https://api.github.com/repos/mavenlink/brainstem/pulls{/number}","milestones_url":"https://api.github.com/repos/mavenlink/brainstem/milestones{/number}","notifications_url":"https://api.github.com/repos/mavenlink/brainstem/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mavenlink/brainstem/labels{/name}","releases_url":"https://api.github.com/repos/mavenlink/brainstem/releases{/id}","created_at":"2012-12-20T19:06:15Z","updated_at":"2015-06-17T23:43:50Z","pushed_at":"2015-07-02T20:31:48Z","git_url":"git://github.com/mavenlink/brainstem.git","ssh_url":"git@github.com:mavenlink/brainstem.git","clone_url":"https://github.com/mavenlink/brainstem.git","svn_url":"https://github.com/mavenlink/brainstem","homepage":"","size":1322,"stargazers_count":161,"watchers_count":161,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":9,"forks":12,"open_issues":9,"watchers":161,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mavenlink/brainstem/pulls/57"},"html":{"href":"https://github.com/mavenlink/brainstem/pull/57"},"issue":{"href":"https://api.github.com/repos/mavenlink/brainstem/issues/57"},"comments":{"href":"https://api.github.com/repos/mavenlink/brainstem/issues/57/comments"},"review_comments":{"href":"https://api.github.com/repos/mavenlink/brainstem/pulls/57/comments"},"review_comment":{"href":"https://api.github.com/repos/mavenlink/brainstem/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mavenlink/brainstem/pulls/57/commits"},"statuses":{"href":"https://api.github.com/repos/mavenlink/brainstem/statuses/1061782536331edeafc325fae6b20bf1a38e9d7c"}}}}