docbrown/spec/serializers/search/article_serializer_spec.rb
Molly Struve 385e167f74
Clear Elasticsearch Data Instead of Resetting Entire Index for Specs (#7602)
* Clear Elasticsearch Data Instead of Resetting Entire Index for Specs

* only reset for specs that are messing with index creation and deletion, recreate indexes before and after those

* add back elasticsearch meta info to specs and update data update specs

* update serializer specs

* update search and rest of specs with new meta data tag
2020-04-30 11:59:10 -04:00

23 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe Search::ArticleSerializer do
let(:user) { create(:user) }
let(:organization) { create(:organization) }
let(:tag) { create(:tag, name: "ama", bg_color_hex: "#f3f3f3", text_color_hex: "#cccccc") }
let(:article) { create(:article, user: user, organization: organization, tags: tag.name) }
it "serializes an article" do
data_hash = described_class.new(article).serializable_hash.dig(:data, :attributes)
user_data = Search::NestedUserSerializer.new(user).serializable_hash.dig(:data, :attributes)
expect(data_hash[:user]).to eq(user_data)
expect(data_hash.dig(:organization, :id)).to eq(organization.id)
expect(data_hash.dig(:flare_tag_hash, :name)).to eq(tag.name)
expect(data_hash.keys).to include(:id, :body_text, :hotness_score)
end
it "creates valid json for Elasticsearch", elasticsearch: "FeedContent" do
data_hash = described_class.new(article).serializable_hash.dig(:data, :attributes)
result = Article::SEARCH_CLASS.index(article.id, data_hash)
expect(result["result"]).to eq("created")
end
end