123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- require 'dotenv/load'
- require 'spec_helper'
-
- require_relative '../db/connect'
- require_relative '../lib/search'
- require_relative '../lib/models/post'
- require_relative '../lib/models/thread'
-
- RSpec.describe 'Search' do
- around(:each) do |example|
- DB.transaction(rollback: :always, auto_savepoint: true) { example.run }
- end
-
- before do
- @thread1 = VLV::Thread.create(title: "This is a thread with many words in the title")
- @thread2 = VLV::Thread.create(title: "Thread words")
- @post1 = VLV::Post.create(body: "This is a post with many words in the body", thread_id: @thread1.id)
- @post2 = VLV::Post.create(body: "Post words", thread_id: @thread2.id)
- end
-
- describe '#search_threads' do
- it "finds threads with matching words" do
- threads = search_threads('thread words', '', nil, nil, nil, nil, false)
- expect(threads.map(&:title)).to match_array([@thread1.title, @thread2.title])
- end
-
- context "with exact_match" do
- it "only finds threads with exactly matching phrases" do
- threads = search_threads('thread words', '', nil, nil, nil, nil, true)
- expect(threads.map(&:title)).to match_array([@thread2.title])
- end
- end
- end
-
- describe '#search_posts' do
- it "finds posts with matching words" do
- posts = search_posts('post words', '', nil, nil, nil, false)
- expect(posts.map(&:body)).to match_array([@post1.body, @post2.body])
- end
-
- context "with exact_match" do
- it "only finds posts with exactly matching phrases" do
- posts = search_posts('post words', '', nil, nil, nil, true)
- expect(posts.map(&:body)).to match_array([@post2.body])
- end
- end
- end
- end
|