Skip to content

Instantly share code, notes, and snippets.

@Evanto
Created August 18, 2017 09:49
Show Gist options
  • Save Evanto/c244e786087abc20536543bf6b6c1e9b to your computer and use it in GitHub Desktop.
Save Evanto/c244e786087abc20536543bf6b6c1e9b to your computer and use it in GitHub Desktop.
require 'rails_helper'
RSpec.describe AttachmentsController, type: :controller do
let!(:question) { create(:question) }
let!(:answer2) { create(:answer, question: question) }
describe 'DELETE #destroy' do
sign_in_user
let!(:answer) { create(:answer, question: question, user: @user) }
let!(:attachment) { create(:attachment) }
context 'answer of author' do
it "deletes author's attachment" do
expect { delete :destroy, params: { id: attachment.id, format: :js } }.to change(Attachment, :count).by(-1)
end
it 'renders destroy template' do
delete :destroy, params: { id: attachment, format: :js }
expect(response).to render_template :destroy
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment