docbrown/spec/models/page_view_spec.rb
rhymes 7da7a16d8d Pro: add referrers to dashboard and single article stats (#3295)
* Reorganize PageViewsController

* Add domain and path to PageView model

* Add before_create callback to populate domain and path

* Add list of referrers to AnalyticsService

* Add referrers to the UI

* Remove useless referrers card and tweak table line height

* Add referrer stats to article stats page

* Add not null and empty default to domain and path

* Refactor JS analytics client

* create_list is a step back here

* Revert "Add not null and empty default to domain and path"

This reverts commit bc02440076047a887c65d300bccd4661ecc8ffd0.

* Add index on domain concurrently

* Make the script more robust
2019-06-25 13:58:09 -04:00

22 lines
637 B
Ruby

require "rails_helper"
RSpec.describe PageView, type: :model do
let(:article) { create(:article) }
it { is_expected.to belong_to(:user).optional }
it { is_expected.to belong_to(:article) }
describe "#domain" do
it "is automatically set when a new page view is created" do
pv = create(:page_view, referrer: "http://example.com/page")
expect(pv.reload.domain).to eq("example.com")
end
end
describe "#path" do
it "is automatically set when a new page view is created" do
pv = create(:page_view, referrer: "http://example.com/page")
expect(pv.reload.path).to eq("/page")
end
end
end