Skip to content

Instantly share code, notes, and snippets.

@Evanto
Evanto / answers.coffee1
Last active July 10, 2017 10:59
форма не появляется по клику на edit свежедобавленного ответа
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Объявляем функцию ready, внутри которой можно поместить обработчики событий и другой код,
# который должен выполняться при загрузке страницы
ready = -> # оборачиваем все до строки 15 в функцию ready
# Это наш функция-обработчик, перенесенная сюда из document.ready ($ ->)
$('.edit-answer-link').click (e) -> # событие ниже работает по клику на элемент с классом .edit-answer-link
@Evanto
Evanto / answers_controller_spec.rb
Created July 6, 2017 22:02
answers_controller_spec.rb jul6
require 'rails_helper'
RSpec.describe AnswersController, type: :controller do
sign_in_user
let!(:question) { create(:question) }
let!(:answer) { create(:answer, user: @user) }
describe 'DELETE #destroy' do
before { answer }
@Evanto
Evanto / _answer.html.slim
Created July 5, 2017 11:20
404 form doesn't save an updated answer
- if answer.persisted?
= answer.body
- if current_user&.author_of? answer
p= link_to "delete answer", answer_path(answer), method: :delete
p= link_to 'edit', '', class: 'edit-answer-link', data: { answer_id: answer.id }
p
@Evanto
Evanto / _answer.html.slim
Created July 3, 2017 20:00
Ajax-2-edit-answers
- if answer.persisted?
= answer.body
- if current_user&.author_of? answer
p= link_to "delete answer", answer_path(answer), method: :delete
p= link_to 'edit', '', class: 'edit-answer-link', data: { answer_id: answer.id }
p
ubuntu@rails-dev-box:~/www/qna$ rspec spec/acceptance/answer_question_spec.rb
F..
Failures:
1) User answers a question
In order to answer a question
I want to be able to fill the answer form on a page of a question
Authenticated user answers a question
ubuntu@rails-dev-box:~/www/qna$ rspec spec/acceptance/answer_question_spec.rb
F..
Failures:
1) User answers a question
In order to answer a question
I want to be able to fill the answer form on a page of a question
Authenticated user answers a question
Failure/Error: visit new_user_session_path # юзер идет на страницу логина
ubuntu@rails-dev-box:~/www/qna$ bundle
error: cannot open .git/FETCH_HEAD: Permission denied
Retrying `git fetch --force --quiet --tags "/home/ubuntu/.bundle/cache/git/shoulda-matchers-e04e9ade87805b3667f97d976fd84556605e66f8"` due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/ubuntu/.bundle/cache/git/shoulda-matchers-e04e9ade87805b3667f97d976fd84556605e66f8"` in directory /var/lib/gems/2.4.0/bundler/gems/shoulda-matchers-ead87017a6c1 has failed.
If this error persists you could try removing the cache directory '/home/ubuntu/.bundle/cache/git/shoulda-matchers-e04e9ade87805b3667f97d976fd84556605e66f8'error: cannot open .git/FETCH_HEAD: Permission denied
Retrying `git fetch --force --quiet --tags "/home/ubuntu/.bundle/cache/git/shoulda-matchers-e04e9ade87805b3667f97d976fd84556605e66f8"` due to error (3/4): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/ubuntu/.bundle/cache/git/shoulda-matcher
require 'rails_helper'
RSpec.describe AnswersController, type: :controller do
sign_in_user
let(:question) { create(:question) }
let(:answer) { create(:answer, question: question) }
describe 'DELETE #destroy' do
before { answer }
ubuntu@rails-dev-box:~/www/qna$ rspec spec/controllers/answers_controller_spec.rb
F.......
Failures:
1) AnswersController DELETE #destroy 1) user deletes his answer deletes users answer
Failure/Error:
expect { delete :destroy, params: { question_id: answer.question, id: answer } }
.to change(answer.user.answers, :count).by(-1)
require 'rails_helper'
RSpec.describe QuestionsController, type: :controller do
sign_in_user
let(:question) { create(:question, user: user) }
let(:user) { create(:user) }
describe 'GET #index' do
let(:questions) { create_list(:question, 2) }
before { get :index }