From 2660ae1739481ecf69d56d31ee2e2cf063106fe9 Mon Sep 17 00:00:00 2001 From: rhymes Date: Fri, 17 May 2019 05:29:57 +0200 Subject: [PATCH] Use cached_tag_list_array for tags (#2857) --- app/views/api/v0/articles/show.json.jbuilder | 2 +- spec/requests/api/v0/articles_spec.rb | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/views/api/v0/articles/show.json.jbuilder b/app/views/api/v0/articles/show.json.jbuilder index f8abc0c5d..218f31963 100644 --- a/app/views/api/v0/articles/show.json.jbuilder +++ b/app/views/api/v0/articles/show.json.jbuilder @@ -7,7 +7,7 @@ json.published_at @article.published_at json.readable_publish_date @article.readable_publish_date json.social_image article_social_image_url(@article) json.tag_list @article.cached_tag_list -json.tags @article.cached_tag_list.split(", ") +json.tags @article.cached_tag_list_array json.slug @article.slug json.path @article.path json.url @article.url diff --git a/spec/requests/api/v0/articles_spec.rb b/spec/requests/api/v0/articles_spec.rb index ad9136aa2..c0b8a841b 100644 --- a/spec/requests/api/v0/articles_spec.rb +++ b/spec/requests/api/v0/articles_spec.rb @@ -77,14 +77,15 @@ RSpec.describe "Api::V0::Articles", type: :request do end describe "GET /api/articles/:id" do + let(:article) { create(:article) } + it "gets article based on ID" do - article = create(:article) get "/api/articles/#{article.id}" - expect(JSON.parse(response.body)["title"]).to eq(article.title) + expect(json_response["title"]).to eq(article.title) end it "fails with an unpublished article" do - article = create(:article, published: false) + article.update_columns(published: false) get "/api/articles/#{article.id}" expect(response).to have_http_status(:not_found) end @@ -93,6 +94,11 @@ RSpec.describe "Api::V0::Articles", type: :request do get "/api/articles/99999" expect(response).to have_http_status(:not_found) end + + it "contains tags as an array" do + get "/api/articles/#{article.id}" + expect(json_response["tags"]).to eq(article.decorate.cached_tag_list_array) + end end describe "POST /api/articles" do