docbrown/spec/models/page_view_spec.rb
Alex f6c2f46fbb
Move Search::RemoveFromIndexJob to Sidekiq (#5637) [deploy]
* Create RemoveFromIndexWorker

* Create spec for RemoveFromIndexWorker

* Update RemoveFromIndexJob to RemoveFromIndexWorker

- Update references from the job to the new worker
- Update specs to use the new worker
- Fix spec in comment_spec that causes linter/RuboCop violation

* Remove unnecessary argument nil check

* Update spec for missing data
2020-01-23 11:27:28 -08:00

36 lines
1 KiB
Ruby

require "rails_helper"
RSpec.describe PageView, type: :model do
let(:page_view) { create(:page_view, referrer: "http://example.com/page") }
it { is_expected.to belong_to(:user).optional }
it { is_expected.to belong_to(:article) }
context "when callbacks are triggered before create" do
describe "#domain" do
it "is automatically set when a new page view is created" do
expect(page_view.domain).to eq("example.com")
end
end
describe "#path" do
it "is automatically set when a new page view is created" do
expect(page_view.path).to eq("/page")
end
end
end
describe "indexing" do
it "indexes updated records" do
sidekiq_assert_enqueued_with(job: Search::IndexWorker, args: ["PageView", page_view.id]) do
page_view.update(path: "/")
end
end
it "removes deleted records" do
sidekiq_assert_enqueued_with(job: Search::RemoveFromIndexWorker, args: [described_class.algolia_index_name, page_view.id]) do
page_view.destroy
end
end
end
end