f6de272f55
#228 #228 #228 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #232
35 lines
1020 B
Ruby
35 lines
1020 B
Ruby
require 'rails_helper'
|
|
|
|
|
|
RSpec.describe 'post_similarity:calc' do
|
|
include RakeTaskHelper
|
|
|
|
it 'calls Similarity::Calc with Post and :tags' do
|
|
# 必要最低限のデータ
|
|
t1 = Tag.create!(name: "t1")
|
|
t2 = Tag.create!(name: "t2")
|
|
t3 = Tag.create!(name: "t3")
|
|
|
|
p1 = Post.create!(url: "https://example.com/1")
|
|
p2 = Post.create!(url: "https://example.com/2")
|
|
p3 = Post.create!(url: "https://example.com/3")
|
|
|
|
# kept スコープが絡むなら、PostTag がデフォで kept になる前提
|
|
PostTag.create!(post: p1, tag: t1)
|
|
PostTag.create!(post: p1, tag: t2)
|
|
|
|
PostTag.create!(post: p2, tag: t1)
|
|
PostTag.create!(post: p2, tag: t3)
|
|
|
|
PostTag.create!(post: p3, tag: t3)
|
|
|
|
expect { run_rake_task("post_similarity:calc") }
|
|
.to change { PostSimilarity.count }.from(0)
|
|
|
|
ps = PostSimilarity.find_by!(post_id: p1.id, target_post_id: p2.id)
|
|
ps_rev = PostSimilarity.find_by!(post_id: p2.id, target_post_id: p1.id)
|
|
expect(ps_rev.cos).to eq(ps.cos)
|
|
end
|
|
end
|
|
|