{"action":"created","comment":{"url":"https://api.github.com/repos/mdumke/myflix/pulls/comments/44232259","id":44232259,"diff_hunk":"@@ -83,6 +83,161 @@\n     end\n   end\n \n+  describe 'PATCH update' do\n+    context 'with authenticated user' do\n+\n+      let(:current_user) { Fabricate(:user) }\n+      let(:video1) { Fabricate(:video) }\n+      let(:video2) { Fabricate(:video) }\n+      let(:item1) { Fabricate(:queue_item, queue_position: -1) }\n+      let(:item2) { Fabricate(:queue_item, queue_position: -1) }\n+\n+      before do\n+        session[:user_id] = current_user.id\n+\n+        item1.update_attributes(user: current_user, video: video1)\n+        item2.update_attributes(user: current_user, video: video2)\n+\n+        item1.rating = 1\n+        item2.rating = 2\n+      end\n+\n+      context 'updating queue positions' do\n+        it 'redirects to my_queue_path for invalid positions' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 1.5, rating: 1}]\n+\n+          expect(response).to redirect_to my_queue_path\n+        end\n+\n+        it 'sets the flash-error for invalid positions' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 1.5, rating: 1}\n+          ]\n+\n+          expect(flash[:error]).not_to be_nil\n+        end\n+\n+        it 'updates positions so that the lowest position is 1' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 2, rating: 1},\n+            {id: item2.id, position: 4, rating: 1}\n+          ]\n+          expect(QueueItem.find(item1.id).queue_position).to eq 1\n+        end\n+\n+        it 'reorders positions so that the lowest position is 1' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 3, rating: 1},\n+            {id: item2.id, position: 2, rating: 1}\n+          ]\n+          expect(QueueItem.find(item2.id).queue_position).to eq 1\n+        end\n+\n+        it 'reorders so that all positions are contiguous' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 3, rating: 1},\n+            {id: item2.id, position: 2, rating: 1}\n+          ]\n+          expect(QueueItem.find(item1.id).queue_position).to eq 2\n+          expect(QueueItem.find(item2.id).queue_position).to eq 1\n+        end\n+\n+        it 'updates all positions in a transaction' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 3, rating: 1},\n+            {id: item2.id, position: 2.5, rating: 1}\n+          ]\n+          expect(QueueItem.find(item1.id).queue_position).to eq -1\n+          expect(QueueItem.find(item2.id).queue_position).to eq -1\n+        end\n+\n+        it 'redirects to my_queue after successful update' do\n+          patch :update_queue, queue: [\n+            {id: item1.id, position: 1, rating: 1},\n+            {id: item2.id, position: 2, rating: 1}\n+          ]\n+          expect(response).to redirect_to my_queue_path\n+        end\n+\n+        it 'does not update queue when position-data is incomplete' do","path":"spec/controllers/queue_items_controller_spec.rb","position":81,"original_position":81,"commit_id":"795ca7ad73f335d9e2b1040abeb501065bfa2edc","original_commit_id":"795ca7ad73f335d9e2b1040abeb501065bfa2edc","user":{"login":"brandoncc","id":543973,"avatar_url":"https://avatars.githubusercontent.com/u/543973?v=3","gravatar_id":"","url":"https://api.github.com/users/brandoncc","html_url":"https://github.com/brandoncc","followers_url":"https://api.github.com/users/brandoncc/followers","following_url":"https://api.github.com/users/brandoncc/following{/other_user}","gists_url":"https://api.github.com/users/brandoncc/gists{/gist_id}","starred_url":"https://api.github.com/users/brandoncc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandoncc/subscriptions","organizations_url":"https://api.github.com/users/brandoncc/orgs","repos_url":"https://api.github.com/users/brandoncc/repos","events_url":"https://api.github.com/users/brandoncc/events{/privacy}","received_events_url":"https://api.github.com/users/brandoncc/received_events","type":"User","site_admin":false},"body":"This spec and the spec on line 146 are basically testing the same thing. You don't need both. I prefer this one over the on line 146.","created_at":"2015-11-08T22:55:41Z","updated_at":"2015-11-08T22:55:41Z","html_url":"https://github.com/mdumke/myflix/pull/3#discussion_r44232259","pull_request_url":"https://api.github.com/repos/mdumke/myflix/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/mdumke/myflix/pulls/comments/44232259"},"html":{"href":"https://github.com/mdumke/myflix/pull/3#discussion_r44232259"},"pull_request":{"href":"https://api.github.com/repos/mdumke/myflix/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/mdumke/myflix/pulls/3","id":50070173,"html_url":"https://github.com/mdumke/myflix/pull/3","diff_url":"https://github.com/mdumke/myflix/pull/3.diff","patch_url":"https://github.com/mdumke/myflix/pull/3.patch","issue_url":"https://api.github.com/repos/mdumke/myflix/issues/3","number":3,"state":"open","locked":false,"title":"Module 3, part 1: Reordering and Rating Videos in MyQueue","user":{"login":"mdumke","id":5279797,"avatar_url":"https://avatars.githubusercontent.com/u/5279797?v=3","gravatar_id":"","url":"https://api.github.com/users/mdumke","html_url":"https://github.com/mdumke","followers_url":"https://api.github.com/users/mdumke/followers","following_url":"https://api.github.com/users/mdumke/following{/other_user}","gists_url":"https://api.github.com/users/mdumke/gists{/gist_id}","starred_url":"https://api.github.com/users/mdumke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdumke/subscriptions","organizations_url":"https://api.github.com/users/mdumke/orgs","repos_url":"https://api.github.com/users/mdumke/repos","events_url":"https://api.github.com/users/mdumke/events{/privacy}","received_events_url":"https://api.github.com/users/mdumke/received_events","type":"User","site_admin":false},"body":"Adds functionality to change the queue-position and rating of videos in the queue.","created_at":"2015-11-08T21:08:34Z","updated_at":"2015-11-08T22:55:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c7de009cdd2534a60cfe37357f0de4150cf7e1d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mdumke/myflix/pulls/3/commits","review_comments_url":"https://api.github.com/repos/mdumke/myflix/pulls/3/comments","review_comment_url":"https://api.github.com/repos/mdumke/myflix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mdumke/myflix/issues/3/comments","statuses_url":"https://api.github.com/repos/mdumke/myflix/statuses/795ca7ad73f335d9e2b1040abeb501065bfa2edc","head":{"label":"mdumke:module_3","ref":"module_3","sha":"795ca7ad73f335d9e2b1040abeb501065bfa2edc","user":{"login":"mdumke","id":5279797,"avatar_url":"https://avatars.githubusercontent.com/u/5279797?v=3","gravatar_id":"","url":"https://api.github.com/users/mdumke","html_url":"https://github.com/mdumke","followers_url":"https://api.github.com/users/mdumke/followers","following_url":"https://api.github.com/users/mdumke/following{/other_user}","gists_url":"https://api.github.com/users/mdumke/gists{/gist_id}","starred_url":"https://api.github.com/users/mdumke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdumke/subscriptions","organizations_url":"https://api.github.com/users/mdumke/orgs","repos_url":"https://api.github.com/users/mdumke/repos","events_url":"https://api.github.com/users/mdumke/events{/privacy}","received_events_url":"https://api.github.com/users/mdumke/received_events","type":"User","site_admin":false},"repo":{"id":44101531,"name":"myflix","full_name":"mdumke/myflix","owner":{"login":"mdumke","id":5279797,"avatar_url":"https://avatars.githubusercontent.com/u/5279797?v=3","gravatar_id":"","url":"https://api.github.com/users/mdumke","html_url":"https://github.com/mdumke","followers_url":"https://api.github.com/users/mdumke/followers","following_url":"https://api.github.com/users/mdumke/following{/other_user}","gists_url":"https://api.github.com/users/mdumke/gists{/gist_id}","starred_url":"https://api.github.com/users/mdumke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdumke/subscriptions","organizations_url":"https://api.github.com/users/mdumke/orgs","repos_url":"https://api.github.com/users/mdumke/repos","events_url":"https://api.github.com/users/mdumke/events{/privacy}","received_events_url":"https://api.github.com/users/mdumke/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mdumke/myflix","description":"Netflix clone built during the tealeaf academy training program","fork":false,"url":"https://api.github.com/repos/mdumke/myflix","forks_url":"https://api.github.com/repos/mdumke/myflix/forks","keys_url":"https://api.github.com/repos/mdumke/myflix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mdumke/myflix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mdumke/myflix/teams","hooks_url":"https://api.github.com/repos/mdumke/myflix/hooks","issue_events_url":"https://api.github.com/repos/mdumke/myflix/issues/events{/number}","events_url":"https://api.github.com/repos/mdumke/myflix/events","assignees_url":"https://api.github.com/repos/mdumke/myflix/assignees{/user}","branches_url":"https://api.github.com/repos/mdumke/myflix/branches{/branch}","tags_url":"https://api.github.com/repos/mdumke/myflix/tags","blobs_url":"https://api.github.com/repos/mdumke/myflix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mdumke/myflix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mdumke/myflix/git/refs{/sha}","trees_url":"https://api.github.com/repos/mdumke/myflix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mdumke/myflix/statuses/{sha}","languages_url":"https://api.github.com/repos/mdumke/myflix/languages","stargazers_url":"https://api.github.com/repos/mdumke/myflix/stargazers","contributors_url":"https://api.github.com/repos/mdumke/myflix/contributors","subscribers_url":"https://api.github.com/repos/mdumke/myflix/subscribers","subscription_url":"https://api.github.com/repos/mdumke/myflix/subscription","commits_url":"https://api.github.com/repos/mdumke/myflix/commits{/sha}","git_commits_url":"https://api.github.com/repos/mdumke/myflix/git/commits{/sha}","comments_url":"https://api.github.com/repos/mdumke/myflix/comments{/number}","issue_comment_url":"https://api.github.com/repos/mdumke/myflix/issues/comments{/number}","contents_url":"https://api.github.com/repos/mdumke/myflix/contents/{+path}","compare_url":"https://api.github.com/repos/mdumke/myflix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mdumke/myflix/merges","archive_url":"https://api.github.com/repos/mdumke/myflix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mdumke/myflix/downloads","issues_url":"https://api.github.com/repos/mdumke/myflix/issues{/number}","pulls_url":"https://api.github.com/repos/mdumke/myflix/pulls{/number}","milestones_url":"https://api.github.com/repos/mdumke/myflix/milestones{/number}","notifications_url":"https://api.github.com/repos/mdumke/myflix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mdumke/myflix/labels{/name}","releases_url":"https://api.github.com/repos/mdumke/myflix/releases{/id}","created_at":"2015-10-12T10:51:35Z","updated_at":"2015-10-18T19:45:17Z","pushed_at":"2015-11-08T21:08:35Z","git_url":"git://github.com/mdumke/myflix.git","ssh_url":"git@github.com:mdumke/myflix.git","clone_url":"https://github.com/mdumke/myflix.git","svn_url":"https://github.com/mdumke/myflix","homepage":"","size":564,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"mdumke:master","ref":"master","sha":"d9cb750f52d3cbea20f093b2489f5cf42c932c0e","user":{"login":"mdumke","id":5279797,"avatar_url":"https://avatars.githubusercontent.com/u/5279797?v=3","gravatar_id":"","url":"https://api.github.com/users/mdumke","html_url":"https://github.com/mdumke","followers_url":"https://api.github.com/users/mdumke/followers","following_url":"https://api.github.com/users/mdumke/following{/other_user}","gists_url":"https://api.github.com/users/mdumke/gists{/gist_id}","starred_url":"https://api.github.com/users/mdumke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdumke/subscriptions","organizations_url":"https://api.github.com/users/mdumke/orgs","repos_url":"https://api.github.com/users/mdumke/repos","events_url":"https://api.github.com/users/mdumke/events{/privacy}","received_events_url":"https://api.github.com/users/mdumke/received_events","type":"User","site_admin":false},"repo":{"id":44101531,"name":"myflix","full_name":"mdumke/myflix","owner":{"login":"mdumke","id":5279797,"avatar_url":"https://avatars.githubusercontent.com/u/5279797?v=3","gravatar_id":"","url":"https://api.github.com/users/mdumke","html_url":"https://github.com/mdumke","followers_url":"https://api.github.com/users/mdumke/followers","following_url":"https://api.github.com/users/mdumke/following{/other_user}","gists_url":"https://api.github.com/users/mdumke/gists{/gist_id}","starred_url":"https://api.github.com/users/mdumke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdumke/subscriptions","organizations_url":"https://api.github.com/users/mdumke/orgs","repos_url":"https://api.github.com/users/mdumke/repos","events_url":"https://api.github.com/users/mdumke/events{/privacy}","received_events_url":"https://api.github.com/users/mdumke/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mdumke/myflix","description":"Netflix clone built during the tealeaf academy training program","fork":false,"url":"https://api.github.com/repos/mdumke/myflix","forks_url":"https://api.github.com/repos/mdumke/myflix/forks","keys_url":"https://api.github.com/repos/mdumke/myflix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mdumke/myflix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mdumke/myflix/teams","hooks_url":"https://api.github.com/repos/mdumke/myflix/hooks","issue_events_url":"https://api.github.com/repos/mdumke/myflix/issues/events{/number}","events_url":"https://api.github.com/repos/mdumke/myflix/events","assignees_url":"https://api.github.com/repos/mdumke/myflix/assignees{/user}","branches_url":"https://api.github.com/repos/mdumke/myflix/branches{/branch}","tags_url":"https://api.github.com/repos/mdumke/myflix/tags","blobs_url":"https://api.github.com/repos/mdumke/myflix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mdumke/myflix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mdumke/myflix/git/refs{/sha}","trees_url":"https://api.github.com/repos/mdumke/myflix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mdumke/myflix/statuses/{sha}","languages_url":"https://api.github.com/repos/mdumke/myflix/languages","stargazers_url":"https://api.github.com/repos/mdumke/myflix/stargazers","contributors_url":"https://api.github.com/repos/mdumke/myflix/contributors","subscribers_url":"https://api.github.com/repos/mdumke/myflix/subscribers","subscription_url":"https://api.github.com/repos/mdumke/myflix/subscription","commits_url":"https://api.github.com/repos/mdumke/myflix/commits{/sha}","git_commits_url":"https://api.github.com/repos/mdumke/myflix/git/commits{/sha}","comments_url":"https://api.github.com/repos/mdumke/myflix/comments{/number}","issue_comment_url":"https://api.github.com/repos/mdumke/myflix/issues/comments{/number}","contents_url":"https://api.github.com/repos/mdumke/myflix/contents/{+path}","compare_url":"https://api.github.com/repos/mdumke/myflix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mdumke/myflix/merges","archive_url":"https://api.github.com/repos/mdumke/myflix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mdumke/myflix/downloads","issues_url":"https://api.github.com/repos/mdumke/myflix/issues{/number}","pulls_url":"https://api.github.com/repos/mdumke/myflix/pulls{/number}","milestones_url":"https://api.github.com/repos/mdumke/myflix/milestones{/number}","notifications_url":"https://api.github.com/repos/mdumke/myflix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mdumke/myflix/labels{/name}","releases_url":"https://api.github.com/repos/mdumke/myflix/releases{/id}","created_at":"2015-10-12T10:51:35Z","updated_at":"2015-10-18T19:45:17Z","pushed_at":"2015-11-08T21:08:35Z","git_url":"git://github.com/mdumke/myflix.git","ssh_url":"git@github.com:mdumke/myflix.git","clone_url":"https://github.com/mdumke/myflix.git","svn_url":"https://github.com/mdumke/myflix","homepage":"","size":564,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mdumke/myflix/pulls/3"},"html":{"href":"https://github.com/mdumke/myflix/pull/3"},"issue":{"href":"https://api.github.com/repos/mdumke/myflix/issues/3"},"comments":{"href":"https://api.github.com/repos/mdumke/myflix/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/mdumke/myflix/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/mdumke/myflix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mdumke/myflix/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/mdumke/myflix/statuses/795ca7ad73f335d9e2b1040abeb501065bfa2edc"}}}}