docbrown/spec/requests/editor_spec.rb
Anna Buianova 7d053471f8
Rubocop fixes in spec/requests (#18946)
* Rubocop fixes in spec/requests

* Fixed spec/requests/api/v0/articles_spec.rb

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2023-01-12 19:10:16 +03:00

84 lines
2.1 KiB
Ruby

require "rails_helper"
RSpec.describe "Editor" do
describe "GET /new" do
subject(:request_call) { get new_path }
let(:user) { create(:user) }
context "when not authenticated" do
it { is_expected.to eq(200) }
end
context "when authenticated and authorized" do
before { login_as user }
it "is a successful response" do
# We have lots of Cypress tests of the behavior of the `/new` page. Let's make sure we're
# verifying AuthN/AuthZ things.
get new_path
expect(response).to have_http_status(:ok)
end
end
end
describe "GET /:article/edit" do
let(:user) { create(:user) }
let(:article) { create(:article, user: user) }
context "when not logged-in" do
it "redirects to /enter" do
get "/#{user.username}/#{article.slug}/edit"
expect(response).to redirect_to(sign_up_path)
end
end
context "when logged-in" do
it "render markdown form" do
sign_in user
get "/#{user.username}/#{article.slug}/edit"
expect(response).to have_http_status(:ok)
end
end
end
describe "POST /articles/preview" do
let(:user) { create(:user) }
let(:article) { create(:article, user: user) }
let(:headers) { { "Content-Type": "application/json", Accept: "application/json" } }
context "when not logged-in" do
it "redirects to /enter" do
post "/articles/preview", headers: headers
expect(response).to have_http_status(:unauthorized)
end
end
context "when logged-in" do
it "returns json" do
sign_in user
post "/articles/preview", headers: headers
expect(response.media_type).to eq("application/json")
end
end
context "with front matter" do
it "returns successfully" do
sign_in user
article_body = <<~MARKDOWN
---
---
Hello
MARKDOWN
post "/articles/preview",
headers: headers,
params: { article_body: article_body },
as: :json
expect(response).to be_successful
end
end
end
end