From 9b7d81bd3a55bdd49213b520986943a3d291bd5c Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 16 Jan 2019 00:23:38 +0530 Subject: [PATCH] add the rspec test cases for commit 684df58 --- spec/requests/topics_controller_spec.rb | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/requests/topics_controller_spec.rb diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb new file mode 100644 index 0000000..19b6e35 --- /dev/null +++ b/spec/requests/topics_controller_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe TopicsController do + let(:p1) { Fabricate(:post, like_count: 1) } + let(:topic) { p1.topic } + let(:p2) { Fabricate(:post, like_count: 2, topic: topic, user: Fabricate(:user)) } + + before do + SiteSetting.allow_solved_on_all_topics = true + end + + it 'should include correct schema information in header' do + p2.custom_fields["is_accepted_answer"] = true + p2.save_custom_fields + + topic.custom_fields["accepted_answer_post_id"] = p2.id + topic.save_custom_fields + + get "/t/#{topic.slug}/#{topic.id}" + + expect(response.body).to include('' % { + title: topic.title, + question_text: p1.excerpt, + question_likes: p1.like_count, + reply_count: topic.reply_count, + created_at: topic.created_at.as_json, + username1: topic.user&.name, + answer_text: p2.excerpt, + answer_likes: p2.like_count, + answered_at: p2.created_at.as_json, + answer_url: p2.full_url, + username2: p2.user&.username + }) + end +end