bug fixes + tests
This commit is contained in:
@@ -324,6 +324,10 @@ div#c-posts {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.similar-posts {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
#add-fav-button, #remove-fav-button {
|
#add-fav-button, #remove-fav-button {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
module PostSets
|
module PostSets
|
||||||
class Similar < PostSets::Post
|
class Similar < PostSets::Post
|
||||||
def initialize(post)
|
def initialize(post)
|
||||||
super(tags)
|
super("")
|
||||||
|
@post = post
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
@posts ||= begin
|
@posts ||= begin
|
||||||
post_ids, scores = RecommenderService.similar(post)
|
response = RecommenderService.similar(@post)
|
||||||
post_ids = post_ids.reject {|x| x == post.id}.slice(0, 5)
|
post_ids = response.reject {|x| x[0] == @post.id}.slice(0, 5).map {|x| x[0]}
|
||||||
Post.find(post_ids)
|
::Post.find(post_ids)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def presenter
|
def presenter
|
||||||
::Presenters::PostSetPresenters::Post.new(self)
|
::PostSetPresenters::Post.new(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div class="recent-posts">
|
<div class="similar-posts">
|
||||||
<p>You might also like:</p>
|
<p><em>You might also like:</em></p>
|
||||||
|
|
||||||
<div>
|
<section>
|
||||||
<%= PostSets::Similar.new(post).presenter.post_previews_html(self) %>
|
<%= PostSets::Similar.new(post).presenter.post_previews_html(self) %>
|
||||||
</div>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -115,6 +115,22 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get post_path(@post), params: {:id => @post.id}
|
get post_path(@post), params: {:id => @post.id}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when the recommend service is enabled" do
|
||||||
|
setup do
|
||||||
|
@post2 = create(:post)
|
||||||
|
RecommenderService.stubs(:enabled?).returns(true)
|
||||||
|
RecommenderService.stubs(:available?).returns(true)
|
||||||
|
RecommenderService.stubs(:similar).returns([[@post.id, "1.0"], [@post2.id, "0.01"]])
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render a section for similar posts" do
|
||||||
|
get_auth post_path(@post), @user
|
||||||
|
assert_response :success
|
||||||
|
assert_select ".similar-posts"
|
||||||
|
assert_select ".similar-posts #post_#{@post2.id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "update action" do
|
context "update action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user