{"action":"created","comment":{"url":"https://api.github.com/repos/yogadeveloper/railgun/pulls/comments/64148277","id":64148277,"diff_hunk":"@@ -1,60 +1,71 @@\n require 'rails_helper'\n \n RSpec.describe AnswersController, type: :controller do\n-  let(:question) { create(:question) }\n-  let(:answers) { create_list(:answer, 2, question: question) }\n-  describe 'GET #index' do\n-    it 'populates an array of all answers for this question' do\n-      get :index, question_id: question\n-      expect(assigns(:answers)).to match_array(answers)\n-    end\n-  end\n-  \n-  describe 'GET #new' do\n-    before { get :new, question_id: question.id }\n-      \n-    it 'assigns new answer to @answer' do\n-      expect(assigns(:answer)).to be_a_new(Answer)\n-      end\n-\n-    it 'renders new view' do\n-      expect(response).to render_template :new\n-      end\n-  end\n+  sign_in_user\n+  let(:question) { create(:question, user: @user) }\n+  let!(:answer) { create(:answer, question: question, user: @user) }\n \n-  describe 'GET #show' do\n-    before { get :show, question_id: question, id: answer }\n-  \n-      xit 'assigns the requested answer to @answer'\n-  end\n-\n- describe 'POST #create' do\n+  describe 'POST #create' do\n     context 'with valid attributes' do\n       \n       it 'saves the new answer in the database' do\n         expect { \n-          post :create, question_id: question, answer: attributes_for(:answer) \n+          post :create, question_id: question, answer: attributes_for(:answer), format: :js \n           }.to change(question.answers, :count).by(1) \n       end\n-\n-      it 'redirects to answers show view' do\n-        post :create, question_id: question, answer: attributes_for(:answer)\n-        expect(response).to redirect_to question_path(question)\n+      it 'belongs to current user' do\n+        expect { \n+          post :create, question_id: question, answer: attributes_for(:answer), format: :js\n+          }.to change(@user.answers, :count).by(1)\n+      end\n+      it 'render create template' do\n+        post :create, question_id: question, answer: attributes_for(:answer), format: :js\n+        expect(response).to render_template 'answers/create'\n       end\n     end\n \n     context 'with invalid attribues' do\n       it 'does not save the answer' do\n         expect { \n-          post :create, question_id: question, answer: attributes_for(:invalid_answer)\n+          post :create, question_id: question, answer: attributes_for(:invalid_answer), format: :js\n         }.to_not change(Answer, :count)\n       end\n     \n       it 're-renders new view' do\n-        post :create, question_id: question, answer: attributes_for(:invalid_answer)\n-        expect(response).to render_template(:new) \n+        post :create, question_id: question, answer: attributes_for(:invalid_answer), format: :js\n+        expect(response).to render_template 'questions/show'\n       end\n     end    \n   end\n+\n+  describe 'DELETE #destroy' do\n+\n+    context 'answer belongs to user' do\n+      it 'destroys answer' do\n+        expect { delete :destroy, id: answer.id \n+          }.to change(@user.answers, :count).by(-1)\n+      end\n+      it 'redirect to current question' do\n+        delete :destroy, id: answer.id, question_id: question\n+        expect(response).to redirect_to question_path(question)\n+      end\n+    end\n+\n+    context 'answer belongs to another user' do\n+#      let(:new_user) { create :user }\n+#      let(:new_answer) { create :answer, question: question, user: new_user }\n+#      before { sign_in(new_user) }\n+\n+      it 'does not destroy answer' do\n+#        expect { delete :destroy, id: answer.id}.to_not change(Answer, :count)\n+\n+# А как будет правильно написать тест, что пользователь не может удалить вопрос, при условии,","path":"spec/controllers/answers_controller_spec.rb","position":97,"original_position":97,"commit_id":"88f16516bd647f373ced1ee30943ffdf75a89728","original_commit_id":"88f16516bd647f373ced1ee30943ffdf75a89728","user":{"login":"vkurennov","id":968537,"avatar_url":"https://avatars.githubusercontent.com/u/968537?v=3","gravatar_id":"","url":"https://api.github.com/users/vkurennov","html_url":"https://github.com/vkurennov","followers_url":"https://api.github.com/users/vkurennov/followers","following_url":"https://api.github.com/users/vkurennov/following{/other_user}","gists_url":"https://api.github.com/users/vkurennov/gists{/gist_id}","starred_url":"https://api.github.com/users/vkurennov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkurennov/subscriptions","organizations_url":"https://api.github.com/users/vkurennov/orgs","repos_url":"https://api.github.com/users/vkurennov/repos","events_url":"https://api.github.com/users/vkurennov/events{/privacy}","received_events_url":"https://api.github.com/users/vkurennov/received_events","type":"User","site_admin":false},"body":"Тогда надо написать тест на то, что будет выкинуто исключение ActiveRecord::NotFound, в этом тебе поможет матчер raise_error","created_at":"2016-05-22T11:19:27Z","updated_at":"2016-05-22T11:19:27Z","html_url":"https://github.com/yogadeveloper/railgun/pull/4#discussion_r64148277","pull_request_url":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/yogadeveloper/railgun/pulls/comments/64148277"},"html":{"href":"https://github.com/yogadeveloper/railgun/pull/4#discussion_r64148277"},"pull_request":{"href":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4","id":70885099,"html_url":"https://github.com/yogadeveloper/railgun/pull/4","diff_url":"https://github.com/yogadeveloper/railgun/pull/4.diff","patch_url":"https://github.com/yogadeveloper/railgun/pull/4.patch","issue_url":"https://api.github.com/repos/yogadeveloper/railgun/issues/4","number":4,"state":"open","locked":false,"title":"Lesson 6 ajax","user":{"login":"yogadeveloper","id":18226239,"avatar_url":"https://avatars.githubusercontent.com/u/18226239?v=3","gravatar_id":"","url":"https://api.github.com/users/yogadeveloper","html_url":"https://github.com/yogadeveloper","followers_url":"https://api.github.com/users/yogadeveloper/followers","following_url":"https://api.github.com/users/yogadeveloper/following{/other_user}","gists_url":"https://api.github.com/users/yogadeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/yogadeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yogadeveloper/subscriptions","organizations_url":"https://api.github.com/users/yogadeveloper/orgs","repos_url":"https://api.github.com/users/yogadeveloper/repos","events_url":"https://api.github.com/users/yogadeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/yogadeveloper/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-20T16:50:11Z","updated_at":"2016-05-22T11:19:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ebb8fc2035510a053529901f42b3eeac685bf4a8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4/commits","review_comments_url":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4/comments","review_comment_url":"https://api.github.com/repos/yogadeveloper/railgun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yogadeveloper/railgun/issues/4/comments","statuses_url":"https://api.github.com/repos/yogadeveloper/railgun/statuses/88f16516bd647f373ced1ee30943ffdf75a89728","head":{"label":"yogadeveloper:Lesson-6-Ajax","ref":"Lesson-6-Ajax","sha":"88f16516bd647f373ced1ee30943ffdf75a89728","user":{"login":"yogadeveloper","id":18226239,"avatar_url":"https://avatars.githubusercontent.com/u/18226239?v=3","gravatar_id":"","url":"https://api.github.com/users/yogadeveloper","html_url":"https://github.com/yogadeveloper","followers_url":"https://api.github.com/users/yogadeveloper/followers","following_url":"https://api.github.com/users/yogadeveloper/following{/other_user}","gists_url":"https://api.github.com/users/yogadeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/yogadeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yogadeveloper/subscriptions","organizations_url":"https://api.github.com/users/yogadeveloper/orgs","repos_url":"https://api.github.com/users/yogadeveloper/repos","events_url":"https://api.github.com/users/yogadeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/yogadeveloper/received_events","type":"User","site_admin":false},"repo":{"id":57003872,"name":"railgun","full_name":"yogadeveloper/railgun","owner":{"login":"yogadeveloper","id":18226239,"avatar_url":"https://avatars.githubusercontent.com/u/18226239?v=3","gravatar_id":"","url":"https://api.github.com/users/yogadeveloper","html_url":"https://github.com/yogadeveloper","followers_url":"https://api.github.com/users/yogadeveloper/followers","following_url":"https://api.github.com/users/yogadeveloper/following{/other_user}","gists_url":"https://api.github.com/users/yogadeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/yogadeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yogadeveloper/subscriptions","organizations_url":"https://api.github.com/users/yogadeveloper/orgs","repos_url":"https://api.github.com/users/yogadeveloper/repos","events_url":"https://api.github.com/users/yogadeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/yogadeveloper/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yogadeveloper/railgun","description":"RailGun OverFlow app. This is my training project on Thinknetica","fork":false,"url":"https://api.github.com/repos/yogadeveloper/railgun","forks_url":"https://api.github.com/repos/yogadeveloper/railgun/forks","keys_url":"https://api.github.com/repos/yogadeveloper/railgun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yogadeveloper/railgun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yogadeveloper/railgun/teams","hooks_url":"https://api.github.com/repos/yogadeveloper/railgun/hooks","issue_events_url":"https://api.github.com/repos/yogadeveloper/railgun/issues/events{/number}","events_url":"https://api.github.com/repos/yogadeveloper/railgun/events","assignees_url":"https://api.github.com/repos/yogadeveloper/railgun/assignees{/user}","branches_url":"https://api.github.com/repos/yogadeveloper/railgun/branches{/branch}","tags_url":"https://api.github.com/repos/yogadeveloper/railgun/tags","blobs_url":"https://api.github.com/repos/yogadeveloper/railgun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yogadeveloper/railgun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yogadeveloper/railgun/git/refs{/sha}","trees_url":"https://api.github.com/repos/yogadeveloper/railgun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yogadeveloper/railgun/statuses/{sha}","languages_url":"https://api.github.com/repos/yogadeveloper/railgun/languages","stargazers_url":"https://api.github.com/repos/yogadeveloper/railgun/stargazers","contributors_url":"https://api.github.com/repos/yogadeveloper/railgun/contributors","subscribers_url":"https://api.github.com/repos/yogadeveloper/railgun/subscribers","subscription_url":"https://api.github.com/repos/yogadeveloper/railgun/subscription","commits_url":"https://api.github.com/repos/yogadeveloper/railgun/commits{/sha}","git_commits_url":"https://api.github.com/repos/yogadeveloper/railgun/git/commits{/sha}","comments_url":"https://api.github.com/repos/yogadeveloper/railgun/comments{/number}","issue_comment_url":"https://api.github.com/repos/yogadeveloper/railgun/issues/comments{/number}","contents_url":"https://api.github.com/repos/yogadeveloper/railgun/contents/{+path}","compare_url":"https://api.github.com/repos/yogadeveloper/railgun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yogadeveloper/railgun/merges","archive_url":"https://api.github.com/repos/yogadeveloper/railgun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yogadeveloper/railgun/downloads","issues_url":"https://api.github.com/repos/yogadeveloper/railgun/issues{/number}","pulls_url":"https://api.github.com/repos/yogadeveloper/railgun/pulls{/number}","milestones_url":"https://api.github.com/repos/yogadeveloper/railgun/milestones{/number}","notifications_url":"https://api.github.com/repos/yogadeveloper/railgun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yogadeveloper/railgun/labels{/name}","releases_url":"https://api.github.com/repos/yogadeveloper/railgun/releases{/id}","deployments_url":"https://api.github.com/repos/yogadeveloper/railgun/deployments","created_at":"2016-04-25T01:45:36Z","updated_at":"2016-04-25T06:27:22Z","pushed_at":"2016-05-22T02:27:06Z","git_url":"git://github.com/yogadeveloper/railgun.git","ssh_url":"git@github.com:yogadeveloper/railgun.git","clone_url":"https://github.com/yogadeveloper/railgun.git","svn_url":"https://github.com/yogadeveloper/railgun","homepage":"","size":82,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"yogadeveloper:master","ref":"master","sha":"85136d6dd4e9ca045c7409d3d58ad5c4e584f65f","user":{"login":"yogadeveloper","id":18226239,"avatar_url":"https://avatars.githubusercontent.com/u/18226239?v=3","gravatar_id":"","url":"https://api.github.com/users/yogadeveloper","html_url":"https://github.com/yogadeveloper","followers_url":"https://api.github.com/users/yogadeveloper/followers","following_url":"https://api.github.com/users/yogadeveloper/following{/other_user}","gists_url":"https://api.github.com/users/yogadeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/yogadeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yogadeveloper/subscriptions","organizations_url":"https://api.github.com/users/yogadeveloper/orgs","repos_url":"https://api.github.com/users/yogadeveloper/repos","events_url":"https://api.github.com/users/yogadeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/yogadeveloper/received_events","type":"User","site_admin":false},"repo":{"id":57003872,"name":"railgun","full_name":"yogadeveloper/railgun","owner":{"login":"yogadeveloper","id":18226239,"avatar_url":"https://avatars.githubusercontent.com/u/18226239?v=3","gravatar_id":"","url":"https://api.github.com/users/yogadeveloper","html_url":"https://github.com/yogadeveloper","followers_url":"https://api.github.com/users/yogadeveloper/followers","following_url":"https://api.github.com/users/yogadeveloper/following{/other_user}","gists_url":"https://api.github.com/users/yogadeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/yogadeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yogadeveloper/subscriptions","organizations_url":"https://api.github.com/users/yogadeveloper/orgs","repos_url":"https://api.github.com/users/yogadeveloper/repos","events_url":"https://api.github.com/users/yogadeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/yogadeveloper/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yogadeveloper/railgun","description":"RailGun OverFlow app. This is my training project on Thinknetica","fork":false,"url":"https://api.github.com/repos/yogadeveloper/railgun","forks_url":"https://api.github.com/repos/yogadeveloper/railgun/forks","keys_url":"https://api.github.com/repos/yogadeveloper/railgun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yogadeveloper/railgun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yogadeveloper/railgun/teams","hooks_url":"https://api.github.com/repos/yogadeveloper/railgun/hooks","issue_events_url":"https://api.github.com/repos/yogadeveloper/railgun/issues/events{/number}","events_url":"https://api.github.com/repos/yogadeveloper/railgun/events","assignees_url":"https://api.github.com/repos/yogadeveloper/railgun/assignees{/user}","branches_url":"https://api.github.com/repos/yogadeveloper/railgun/branches{/branch}","tags_url":"https://api.github.com/repos/yogadeveloper/railgun/tags","blobs_url":"https://api.github.com/repos/yogadeveloper/railgun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yogadeveloper/railgun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yogadeveloper/railgun/git/refs{/sha}","trees_url":"https://api.github.com/repos/yogadeveloper/railgun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yogadeveloper/railgun/statuses/{sha}","languages_url":"https://api.github.com/repos/yogadeveloper/railgun/languages","stargazers_url":"https://api.github.com/repos/yogadeveloper/railgun/stargazers","contributors_url":"https://api.github.com/repos/yogadeveloper/railgun/contributors","subscribers_url":"https://api.github.com/repos/yogadeveloper/railgun/subscribers","subscription_url":"https://api.github.com/repos/yogadeveloper/railgun/subscription","commits_url":"https://api.github.com/repos/yogadeveloper/railgun/commits{/sha}","git_commits_url":"https://api.github.com/repos/yogadeveloper/railgun/git/commits{/sha}","comments_url":"https://api.github.com/repos/yogadeveloper/railgun/comments{/number}","issue_comment_url":"https://api.github.com/repos/yogadeveloper/railgun/issues/comments{/number}","contents_url":"https://api.github.com/repos/yogadeveloper/railgun/contents/{+path}","compare_url":"https://api.github.com/repos/yogadeveloper/railgun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yogadeveloper/railgun/merges","archive_url":"https://api.github.com/repos/yogadeveloper/railgun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yogadeveloper/railgun/downloads","issues_url":"https://api.github.com/repos/yogadeveloper/railgun/issues{/number}","pulls_url":"https://api.github.com/repos/yogadeveloper/railgun/pulls{/number}","milestones_url":"https://api.github.com/repos/yogadeveloper/railgun/milestones{/number}","notifications_url":"https://api.github.com/repos/yogadeveloper/railgun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yogadeveloper/railgun/labels{/name}","releases_url":"https://api.github.com/repos/yogadeveloper/railgun/releases{/id}","deployments_url":"https://api.github.com/repos/yogadeveloper/railgun/deployments","created_at":"2016-04-25T01:45:36Z","updated_at":"2016-04-25T06:27:22Z","pushed_at":"2016-05-22T02:27:06Z","git_url":"git://github.com/yogadeveloper/railgun.git","ssh_url":"git@github.com:yogadeveloper/railgun.git","clone_url":"https://github.com/yogadeveloper/railgun.git","svn_url":"https://github.com/yogadeveloper/railgun","homepage":"","size":82,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4"},"html":{"href":"https://github.com/yogadeveloper/railgun/pull/4"},"issue":{"href":"https://api.github.com/repos/yogadeveloper/railgun/issues/4"},"comments":{"href":"https://api.github.com/repos/yogadeveloper/railgun/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/yogadeveloper/railgun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yogadeveloper/railgun/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/yogadeveloper/railgun/statuses/88f16516bd647f373ced1ee30943ffdf75a89728"}}}}
{"actor":{"display_login":"vkurennov"}}