diff --git a/app/models/topic.rb b/app/models/topic.rb
index 5a9cdbe7f..4a8af7a58 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -707,6 +707,14 @@ class Topic < ActiveRecord::Base
end
end
+ def has_topic_embed?
+ TopicEmbed.where(topic_id: id).exists?
+ end
+
+ def expandable_first_post?
+ SiteSetting.embeddable_host.present? && SiteSetting.embed_truncate? && has_topic_embed?
+ end
+
private
def update_category_topic_count_by(num)
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb
index db7d04955..503ff305a 100644
--- a/app/serializers/topic_view_serializer.rb
+++ b/app/serializers/topic_view_serializer.rb
@@ -37,7 +37,8 @@ class TopicViewSerializer < ApplicationSerializer
:highest_post_number,
:last_read_post_number,
:deleted_by,
- :actions_summary
+ :actions_summary,
+ :expandable_first_post
# Define a delegator for each attribute of the topic we want
attributes *topic_attributes
@@ -164,4 +165,12 @@ class TopicViewSerializer < ApplicationSerializer
result
end
+ def expandable_first_post
+ true
+ end
+
+ def include_expandable_first_post?
+ object.topic.expandable_first_post?
+ end
+
end
diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb
index da91e1257..e75ea0a98 100644
--- a/spec/models/topic_embed_spec.rb
+++ b/spec/models/topic_embed_spec.rb
@@ -33,6 +33,7 @@ describe TopicEmbed do
# It converts relative URLs to absolute
post.cooked.start_with?("hello world new post hello
").should be_true
+ post.topic.has_topic_embed?.should be_true
TopicEmbed.where(topic_id: post.topic_id).should be_present
end
diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb
index 460a09057..74bf0deb1 100644
--- a/spec/models/topic_spec.rb
+++ b/spec/models/topic_spec.rb
@@ -1320,4 +1320,35 @@ describe Topic do
Topic.calculate_avg_time(1.day.ago)
end
end
+
+ describe "expandable_first_post?" do
+ let(:topic) { Fabricate.build(:topic) }
+
+ before do
+ SiteSetting.stubs(:embeddable_host).returns("http://eviltrout.com")
+ SiteSetting.stubs(:embed_truncate?).returns(true)
+ topic.stubs(:has_topic_embed?).returns(true)
+ end
+
+ it "is true with the correct settings and topic_embed" do
+ topic.expandable_first_post?.should be_true
+ end
+
+ it "is false if embeddable_host is blank" do
+ SiteSetting.stubs(:embeddable_host).returns(nil)
+ topic.expandable_first_post?.should be_false
+ end
+
+ it "is false if embed_truncate? is false" do
+ SiteSetting.stubs(:embed_truncate?).returns(false)
+ topic.expandable_first_post?.should be_false
+ end
+
+ it "is false if has_topic_embed? is false" do
+ topic.stubs(:has_topic_embed?).returns(false)
+ topic.expandable_first_post?.should be_false
+ end
+
+
+ end
end