Fix nil organizations in home page feed endpoint (#6223) [deploy]
* wip * Fix up test * Reverted accidental change to seeds.rb Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
This commit is contained in:
parent
d13a790b5d
commit
e836ccb94f
2 changed files with 45 additions and 13 deletions
|
|
@ -12,7 +12,11 @@ article_methods_to_include = %i[
|
|||
json.array!(@stories) do |article|
|
||||
json.extract! article, *article_attributes_to_include
|
||||
json.user article.cached_user.as_json["table"]
|
||||
json.organization article.cached_organization.as_json["table"]
|
||||
|
||||
if article.cached_organization?
|
||||
json.organization article.cached_organization.as_json["table"]
|
||||
end
|
||||
|
||||
json.tag_list article.cached_tag_list_array
|
||||
json.extract! article, *article_methods_to_include
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,27 +4,55 @@ RSpec.describe "Stories::FeedsIndex", type: :request do
|
|||
let(:title) { "My post" }
|
||||
let(:user) { create(:user, name: "Josh") }
|
||||
let(:organization) { create(:organization, name: "JoshCo") }
|
||||
let!(:article) { create(:article, title: title, featured: true, user: user, organization: organization) }
|
||||
let(:tags) { "alpha, beta, delta, gamma" }
|
||||
let(:article) { create(:article, title: title, featured: true, user: user, organization: organization, tags: tags) }
|
||||
|
||||
before do
|
||||
article
|
||||
end
|
||||
|
||||
describe "GET feeds index" do
|
||||
let(:response_json) { JSON.parse(response.body) }
|
||||
let(:response_article) { response_json.first }
|
||||
|
||||
it "renders article list as json" do
|
||||
get "/stories/feed", headers: headers
|
||||
context "when organization and tags are present" do
|
||||
it "renders article list as json" do
|
||||
get "/stories/feed", headers: headers
|
||||
|
||||
expect(response.content_type).to eq("application/json")
|
||||
expect(response_article["id"]).to eq article.id
|
||||
expect(response_article["title"]).to eq title
|
||||
expect(response_article["user_id"]).to eq user.id
|
||||
expect(response_article["user"]["name"]).to eq user.name
|
||||
expect(response_article["organization_id"]).to eq organization.id
|
||||
expect(response_article["organization"]["name"]).to eq organization.name
|
||||
expect(response_article["tag_list"]).to eq article.decorate.cached_tag_list_array
|
||||
expect(response.content_type).to eq("application/json")
|
||||
expect(response_article["id"]).to eq article.id
|
||||
expect(response_article["title"]).to eq title
|
||||
expect(response_article["user_id"]).to eq user.id
|
||||
expect(response_article["user"]["name"]).to eq user.name
|
||||
expect(response_article["organization_id"]).to eq organization.id
|
||||
expect(response_article["organization"]["name"]).to eq organization.name
|
||||
expect(response_article["tag_list"]).to eq article.decorate.cached_tag_list_array
|
||||
end
|
||||
end
|
||||
|
||||
context "when there isn't an organization attached to the article" do
|
||||
let(:organization) { nil }
|
||||
|
||||
it "omits organization keys from json" do
|
||||
get "/stories/feed", headers: headers
|
||||
|
||||
expect(response_article["organization_id"]).to eq nil
|
||||
expect(response_article["organization"]).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when there aren't any tags on the article" do
|
||||
let(:tags) { nil }
|
||||
|
||||
it "renders an empty tag list" do
|
||||
get "/stories/feed", headers: headers
|
||||
|
||||
expect(response_article["tag_list"]).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
context "when timeframe parameter is present" do
|
||||
let(:feed_service) { Articles::Feed.new(number_of_articles: 1, page: 1, tag: []) }
|
||||
let(:feed_service) { Articles::Feed.new(number_of_articles: 1, page: 1, tag: []) }
|
||||
|
||||
it "calls the feed service for a timeframe" do
|
||||
allow(Articles::Feed).to receive(:new).and_return(feed_service)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue