Files
grecia/spec/controllers/documents_controller_spec.rb
Javi Martín a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00

30 lines
1.1 KiB
Ruby

require "rails_helper"
describe DocumentsController do
describe "DELETE destroy" do
context "Poll answers administration", :admin do
let(:current_answer) { create(:poll_question_answer, poll: create(:poll)) }
let(:future_answer) { create(:poll_question_answer, poll: create(:poll, :future)) }
it "is not possible for an already started poll" do
document = create(:document, documentable: current_answer)
delete :destroy, params: { id: document }
expect(flash[:alert]).to eq "You do not have permission to " \
"carry out the action 'destroy' on Document."
expect(Document.count).to eq 1
end
it "is possible for a not started poll" do
document = create(:document, documentable: future_answer)
request.env["HTTP_REFERER"] = admin_answer_documents_path(future_answer)
delete :destroy, params: { id: document }
expect(response).to redirect_to admin_answer_documents_path(future_answer)
expect(flash[:notice]).to eq "Document was deleted successfully."
expect(Document.count).to eq 0
end
end
end
end