ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
1020 B

  1. require 'rails_helper'
  2. RSpec.describe 'post_similarity:calc' do
  3. include RakeTaskHelper
  4. it 'calls Similarity::Calc with Post and :tags' do
  5. # 必要最低限のデータ
  6. t1 = Tag.create!(name: "t1")
  7. t2 = Tag.create!(name: "t2")
  8. t3 = Tag.create!(name: "t3")
  9. p1 = Post.create!(url: "https://example.com/1")
  10. p2 = Post.create!(url: "https://example.com/2")
  11. p3 = Post.create!(url: "https://example.com/3")
  12. # kept スコープが絡むなら、PostTag がデフォで kept になる前提
  13. PostTag.create!(post: p1, tag: t1)
  14. PostTag.create!(post: p1, tag: t2)
  15. PostTag.create!(post: p2, tag: t1)
  16. PostTag.create!(post: p2, tag: t3)
  17. PostTag.create!(post: p3, tag: t3)
  18. expect { run_rake_task("post_similarity:calc") }
  19. .to change { PostSimilarity.count }.from(0)
  20. ps = PostSimilarity.find_by!(post_id: p1.id, target_post_id: p2.id)
  21. ps_rev = PostSimilarity.find_by!(post_id: p2.id, target_post_id: p1.id)
  22. expect(ps_rev.cos).to eq(ps.cos)
  23. end
  24. end