From b2f4659792510efba04bdaccb04c702f7c04c240 Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Thu, 25 Feb 2016 11:16:27 +0000 Subject: [PATCH] Pass discourse username to TopicRetriever from embed controller When you specify `discourse_username` param on the embed URL, it should translate to creating the post with that username. This commit ensures that this is now the case. --- app/controllers/embed_controller.rb | 3 ++- spec/controllers/embed_controller_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb index 58b6cbda3e8..bc1fbaea86e 100644 --- a/app/controllers/embed_controller.rb +++ b/app/controllers/embed_controller.rb @@ -8,6 +8,7 @@ class EmbedController < ApplicationController def comments embed_url = params[:embed_url] + embed_username = params[:discourse_username] topic_id = nil if embed_url.present? @@ -35,7 +36,7 @@ class EmbedController < ApplicationController end elsif embed_url.present? - Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url) + Jobs.enqueue(:retrieve_topic, user_id: current_user.try(:id), embed_url: embed_url, author_username: embed_username) render 'loading' end diff --git a/spec/controllers/embed_controller_spec.rb b/spec/controllers/embed_controller_spec.rb index 52a6387b317..9539666d6c9 100644 --- a/spec/controllers/embed_controller_spec.rb +++ b/spec/controllers/embed_controller_spec.rb @@ -4,6 +4,7 @@ describe EmbedController do let(:host) { "eviltrout.com" } let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" } + let(:discourse_username) { "eviltrout" } it "is 404 without an embed_url" do get :comments @@ -94,6 +95,12 @@ describe EmbedController do TopicView.expects(:new).with(123, nil, {limit: 100, exclude_first: true, exclude_deleted_users: true}) get :comments, embed_url: embed_url end + + it "provides the topic retriever with the discourse username when provided" do + TopicRetriever.expects(:new).with(embed_url, has_entry({author_username: discourse_username})) + get :comments, embed_url: embed_url, discourse_username: discourse_username + end + end end