From a9acb8642e1737425a786f2a68c204e2fbd31ea5 Mon Sep 17 00:00:00 2001 From: Zak Henry Date: Tue, 9 Jul 2019 15:09:20 +0100 Subject: [PATCH] Add markdown to article api response (#3394) * Add failing test asserting markdown is returned * Add markdown to the get article api response --- app/views/api/v0/articles/show.json.jbuilder | 1 + spec/requests/api/v0/articles_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/views/api/v0/articles/show.json.jbuilder b/app/views/api/v0/articles/show.json.jbuilder index 60dff4afd..fdead1c67 100644 --- a/app/views/api/v0/articles/show.json.jbuilder +++ b/app/views/api/v0/articles/show.json.jbuilder @@ -21,6 +21,7 @@ json.published_at @article.published_at&.utc&.iso8601 json.last_comment_at @article.last_comment_at&.utc&.iso8601 json.body_html @article.processed_html +json.body_markdown @article.body_markdown json.ltag_style(@article.liquid_tags_used.map { |ltag| Rails.application.assets["ltags/#{ltag}.css"].to_s.html_safe }) json.ltag_script(@article.liquid_tags_used.map { |ltag| ltag.script.html_safe }) diff --git a/spec/requests/api/v0/articles_spec.rb b/spec/requests/api/v0/articles_spec.rb index e51993218..f9c1d77fe 100644 --- a/spec/requests/api/v0/articles_spec.rb +++ b/spec/requests/api/v0/articles_spec.rb @@ -83,6 +83,11 @@ RSpec.describe "Api::V0::Articles", type: :request do get "/api/articles/#{article.id}" expect(json_response["title"]).to eq(article.title) end + + it "contains article markdown content" do + get "/api/articles/#{article.id}" + expect(json_response["body_markdown"]).to eq(article.body_markdown) + end it "fails with an unpublished article" do article.update_columns(published: false)