Fix NoMethodError on Nil for article preview (#16569)
* Fix NoMethodError on Nil for article preview * Remove commented out debugging code
This commit is contained in:
parent
36acb7c9a0
commit
66846c7a17
2 changed files with 30 additions and 3 deletions
|
|
@ -90,11 +90,19 @@ class ArticlesController < ApplicationController
|
|||
format.json { render json: @article.errors, status: :unprocessable_entity }
|
||||
else
|
||||
format.json do
|
||||
front_matter = parsed.front_matter.to_h
|
||||
if front_matter["tags"]
|
||||
tags = Article.new.tag_list.add(front_matter["tags"], parser: ActsAsTaggableOn::TagParser)
|
||||
end
|
||||
if front_matter["cover_image"]
|
||||
cover_image = ApplicationController.helpers.cloud_cover_url(front_matter["cover_image"])
|
||||
end
|
||||
|
||||
render json: {
|
||||
processed_html: processed_html,
|
||||
title: parsed["title"],
|
||||
tags: (Article.new.tag_list.add(parsed["tags"], parser: ActsAsTaggableOn::TagParser) if parsed["tags"]),
|
||||
cover_image: (ApplicationController.helpers.cloud_cover_url(parsed["cover_image"]) if parsed["cover_image"])
|
||||
title: front_matter["title"],
|
||||
tags: tags,
|
||||
cover_image: cover_image
|
||||
}, status: :ok
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -66,5 +66,24 @@ RSpec.describe "Editor", type: :request do
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue