Reviewed-on: #379 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #379 でマージされました.
このコミットが含まれているのは:
@@ -4,11 +4,12 @@ require 'rails_helper'
|
||||
RSpec.describe 'post_similarity:calc' do
|
||||
include RakeTaskHelper
|
||||
|
||||
it 'calls Similarity::Calc with Post and :tags' do
|
||||
it 'calculates similarities from active tags only' do
|
||||
# 必要最低限のデータ
|
||||
t1 = Tag.create!(name: "t1")
|
||||
t2 = Tag.create!(name: "t2")
|
||||
t3 = Tag.create!(name: "t3")
|
||||
deprecated_tag = Tag.create!(name: 'deprecated', deprecated_at: Time.current)
|
||||
|
||||
p1 = Post.create!(url: "https://example.com/1")
|
||||
p2 = Post.create!(url: "https://example.com/2")
|
||||
@@ -22,6 +23,8 @@ RSpec.describe 'post_similarity:calc' do
|
||||
PostTag.create!(post: p2, tag: t3)
|
||||
|
||||
PostTag.create!(post: p3, tag: t3)
|
||||
PostTag.create!(post: p1, tag: deprecated_tag)
|
||||
PostTag.create!(post: p2, tag: deprecated_tag)
|
||||
|
||||
expect { run_rake_task("post_similarity:calc") }
|
||||
.to change { PostSimilarity.count }.from(0)
|
||||
@@ -29,6 +32,6 @@ RSpec.describe 'post_similarity:calc' do
|
||||
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)
|
||||
expect(ps.cos).to be_within(0.0001).of(0.5)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ require 'rails_helper'
|
||||
RSpec.describe 'tag_similarity:calc' do
|
||||
include RakeTaskHelper
|
||||
|
||||
it 'calls Similarity::Calc with Tag and :posts' do
|
||||
it 'calculates similarities for active tags only' do
|
||||
# 必要最低限のデータ
|
||||
t1 = Tag.create!(name: "t1")
|
||||
t2 = Tag.create!(name: "t2")
|
||||
t3 = Tag.create!(name: "t3")
|
||||
deprecated_tag = Tag.create!(name: 'deprecated', deprecated_at: Time.current)
|
||||
|
||||
p1 = Post.create!(url: "https://example.com/1")
|
||||
p2 = Post.create!(url: "https://example.com/2")
|
||||
@@ -22,6 +23,7 @@ RSpec.describe 'tag_similarity:calc' do
|
||||
PostTag.create!(post: p2, tag: t3)
|
||||
|
||||
PostTag.create!(post: p3, tag: t3)
|
||||
PostTag.create!(post: p1, tag: deprecated_tag)
|
||||
|
||||
expect { run_rake_task("tag_similarity:calc") }
|
||||
.to change { TagSimilarity.count }.from(0)
|
||||
@@ -29,6 +31,7 @@ RSpec.describe 'tag_similarity:calc' do
|
||||
ps = TagSimilarity.find_by!(tag_id: t1.id, target_tag_id: t2.id)
|
||||
ps_rev = TagSimilarity.find_by!(tag_id: t2.id, target_tag_id: t1.id)
|
||||
expect(ps_rev.cos).to eq(ps.cos)
|
||||
expect(TagSimilarity.where(tag_id: deprecated_tag.id)).to be_empty
|
||||
expect(TagSimilarity.where(target_tag_id: deprecated_tag.id)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする