* 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
20 lines
852 B
Ruby
20 lines
852 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Search::CommentSerializer do
|
|
let(:user) { create(:user) }
|
|
let(:article) { create(:article, user: user) }
|
|
let(:comment) { create(:comment, user: user, commentable: article) }
|
|
|
|
it "serializes an comment" do
|
|
data_hash = described_class.new(comment).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.keys).to include(:id, :body_text, :hotness_score, :title)
|
|
end
|
|
|
|
it "creates valid json for Elasticsearch", elasticsearch: "FeedContent" do
|
|
data_hash = described_class.new(comment).serializable_hash.dig(:data, :attributes)
|
|
result = Comment::SEARCH_CLASS.index(comment.id, data_hash)
|
|
expect(result["result"]).to eq("created")
|
|
end
|
|
end
|