diff --git a/Gemfile b/Gemfile index 2a5f647..df32188 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + group :development do gem 'translations-manager', git: 'https://github.com/discourse/translations-manager.git' end diff --git a/app/serializers/concerns/topic_answer_mixin.rb b/app/serializers/concerns/topic_answer_mixin.rb index a767ab9..b3c5fc7 100644 --- a/app/serializers/concerns/topic_answer_mixin.rb +++ b/app/serializers/concerns/topic_answer_mixin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module TopicAnswerMixin def self.included(klass) klass.attributes :has_accepted_answer, :can_have_answer diff --git a/bin/pull_translations.rb b/bin/pull_translations.rb index a4052d8..ecfee12 100755 --- a/bin/pull_translations.rb +++ b/bin/pull_translations.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'translations_manager' diff --git a/plugin.rb b/plugin.rb index 8a66f83..3000b04 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # name: discourse-solved # about: Add a solved button to answers on Discourse # version: 0.1 diff --git a/spec/integration/solved_spec.rb b/spec/integration/solved_spec.rb index 845af00..5d47aca 100644 --- a/spec/integration/solved_spec.rb +++ b/spec/integration/solved_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe "Managing Posts solved status" do diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index 2e4e27b..9b815b4 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' require_dependency 'site' diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 106bdf0..f653b54 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1,50 +1,52 @@ -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)) } - - def schema_json(answerCount) - if answerCount > 0 - answer_json = ',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"dateCreated":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}"}}' % { - 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 - } - else - answer_json = "" - end - - '' % { - title: topic.title, - question_text: p1.excerpt, - question_likes: p1.like_count, - answerCount: answerCount, - created_at: topic.created_at.as_json, - username1: topic.user&.name, - answer_json: answer_json - } - end - - before do - SiteSetting.allow_solved_on_all_topics = true - end - - it 'should include correct schema information in header' do - get "/t/#{topic.slug}/#{topic.id}" - - expect(response.body).to include(schema_json(0)) - - 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(schema_json(1)) - end -end +# frozen_string_literal: true + +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)) } + + def schema_json(answerCount) + if answerCount > 0 + answer_json = ',"acceptedAnswer":{"@type":"Answer","text":"%{answer_text}","upvoteCount":%{answer_likes},"dateCreated":"%{answered_at}","url":"%{answer_url}","author":{"@type":"Person","name":"%{username2}"}}' % { + 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 + } + else + answer_json = "" + end + + '' % { + title: topic.title, + question_text: p1.excerpt, + question_likes: p1.like_count, + answerCount: answerCount, + created_at: topic.created_at.as_json, + username1: topic.user&.name, + answer_json: answer_json + } + end + + before do + SiteSetting.allow_solved_on_all_topics = true + end + + it 'should include correct schema information in header' do + get "/t/#{topic.slug}/#{topic.id}" + + expect(response.body).to include(schema_json(0)) + + 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(schema_json(1)) + end +end diff --git a/spec/serializers/topic_answer_mixin_spec.rb b/spec/serializers/topic_answer_mixin_spec.rb index ec92b98..64b0faa 100644 --- a/spec/serializers/topic_answer_mixin_spec.rb +++ b/spec/serializers/topic_answer_mixin_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe TopicAnswerMixin do