There are two problems engrained in this: 1. The undocumented expectation of `/new` needed to other sites linking with prefill information. 2. The prefill parameters being lost during the authentication process. The first bug was introduced as part forem/forem#16536. The second is likely introduced as part of a Rails upgrade (namely `request.path` most likely once included the query parameters but with our current implementation it does not). Closes forem/forem#17292
84 lines
2.1 KiB
Ruby
84 lines
2.1 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Editor", type: :request 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
|