docbrown/spec/requests/admin/response_templates_spec.rb
Ridhwana 3a4da2dd5a
RFC 50: Remove hardcoded paths and use path_helpers instead (in the specs) (#13549)
* feat: update the paths in the spec files

* feat: update hardcoded paths with path helpers

* chore: update hardcoded paths to path helpers

* chore: hardcode describe blocks

* chore: oops

* feat: update some more hardcoded to use link_to's

* fix broken tests

* chore: admin_articles path

* chore: oops remove rails helper

* feat: add starting /

* chore: more pre slashes

* chore: add pre slashes

* chore: some small typos

* fix: oops
2021-04-28 21:32:51 +02:00

116 lines
3.6 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/advanced/response_templates", type: :request do
let(:admin) { create(:user, :admin) }
before { sign_in admin }
describe "GET /admin/advanced/response_templates" do
it "renders with status 200" do
get admin_response_templates_path
expect(response.status).to eq 200
end
context "when there are response templates to render" do
it "renders with status 200" do
create(:response_template)
get admin_response_templates_path
expect(response.status).to eq 200
end
end
context "when a single resource admin" do
let(:single_resource_admin) { create(:user, :single_resource_admin, resource: ResponseTemplate) }
it "renders with status 200" do
sign_in single_resource_admin
get admin_response_templates_path
expect(response.status).to eq 200
end
end
end
describe "GET /admin/advanced/response_templates/new" do
it "renders with status 200" do
get admin_response_templates_path
expect(response.status).to eq 200
end
end
describe "POST /admin/advanced/response_templates" do
it "successfully creates a response template" do
post admin_response_templates_path, params: {
response_template: {
type_of: "mod_comment",
content_type: "body_markdown",
content: "nice job!",
title: "something"
}
}
expect(ResponseTemplate.count).to eq 1
end
it "shows a proper error message if the request was invalid" do
post admin_response_templates_path, params: {
response_template: {
type_of: "mod_comment",
content_type: "html",
content: "nice job!",
title: "something"
}
}
expect(response.body).to include(ResponseTemplate::COMMENT_VALIDATION_MSG)
end
end
describe "GET /admin/advanced/response_templates/:id/edit" do
let(:response_template) { create(:response_template) }
it "renders successfully if a valid response template was found" do
get edit_admin_response_template_path(response_template.id)
expect(response).to have_http_status(:ok)
end
it "renders the response template's attributes" do
get edit_admin_response_template_path(response_template.id)
expect(response.body).to include(
CGI.escapeHTML(response_template.content),
CGI.escapeHTML(response_template.title),
response_template.content_type,
response_template.type_of,
)
end
end
describe "PATCH /admin/advanced/response_templates/:id" do
it "successfully updates with a valid request" do
response_template = create(:response_template)
new_title = generate(:title)
patch admin_response_template_path(response_template.id), params: {
response_template: {
title: new_title
}
}
expect(response_template.reload.title).to eq new_title
end
it "renders an error if the request was invalid" do
response_template = create(:response_template)
patch admin_response_template_path(response_template.id), params: {
response_template: {
content_type: "html"
}
}
expect(response.body).to include(ResponseTemplate::COMMENT_VALIDATION_MSG)
end
end
describe "DELETE /admin/advanced/response_templates/:id" do
it "successfully deletes the response template" do
response_template = create(:response_template)
delete admin_response_template_path(response_template.id)
expect { response_template.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end