* Add dual booting logic to Gemfile This might be helpful for the Rails 6.0 upgrade project. * Add more than one gemfile to Travis' configuration We want to see how the application behaves with more than one Rails versions: - Gemfile -> Rails 5.2 - Gemfile.next -> Rails 6.0 This will help us figure out what needs to be addressed before migrating to Rails 6.0. If you want to read more about this technique (dual booting) you can check out this page: https://www.fastruby.io/blog/upgrade-rails/dual-boot/dual-boot-with-rails-6-0-beta.html * Fix joins * Upgrade Gemfile.next.lock * Make sure we're installing the correct versions of gems * Add Rails 6 notes * Update rubocop in Gemfile.next.lock * Fix organization spec * Fix page_views_spec * Add Rails 6 and run rails app:update * Remove some tricks * Remove Gemfile.next for now * Fix .content_type deprecation * Fix deprecation of .where.not NAND/NOR behavior * Fix deprecation of parameterized emails * Fix specs * Remove next flag for now * Fix spec (hopefully) * Add wait_for_javascript * Fix spec, thanks @maestromac! * Try without wait for javascript hack * Remove unnecessary bin/update * Remove file that snuck in the rebase * Update the vendored gems * Replace migrate+db:setup with db:prepare * Update vendored gems * Fix Gemfile.lock and update vendored stuff * Fix Gemfile.lock to be the same as master's minus the changes Co-authored-by: rhymes <rhymesete@gmail.com>
132 lines
4.1 KiB
Ruby
132 lines
4.1 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "PageViews", type: :request do
|
|
let(:user) { create(:user, :trusted) }
|
|
let(:article) { create(:article) }
|
|
|
|
describe "POST /page_views" do
|
|
context "when user signed in" do
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it "creates a new page view" do
|
|
post "/page_views", params: {
|
|
article_id: article.id
|
|
}
|
|
expect(article.reload.page_views.size).to eq(1)
|
|
expect(article.reload.page_views_count).to eq(1)
|
|
expect(user.reload.page_views.size).to eq(1)
|
|
expect(PageView.last.counts_for_number_of_views).to eq(1)
|
|
end
|
|
|
|
it "sends referrer" do
|
|
post "/page_views", params: {
|
|
article_id: article.id,
|
|
referrer: "test"
|
|
}
|
|
expect(PageView.last.referrer).to eq("test")
|
|
end
|
|
|
|
it "sends user agent" do
|
|
post "/page_views", params: {
|
|
article_id: article.id,
|
|
user_agent: "test"
|
|
}
|
|
expect(PageView.last.user_agent).to eq("test")
|
|
end
|
|
end
|
|
|
|
context "when part of field test" do
|
|
before do
|
|
sign_in user
|
|
allow(Users::RecordFieldTestEventWorker).to receive(:perform_async)
|
|
end
|
|
|
|
it "converts field test" do
|
|
post "/page_views", params: {
|
|
article_id: article.id,
|
|
referrer: "test"
|
|
}
|
|
expect(Users::RecordFieldTestEventWorker).to have_received(:perform_async).with(user.id, :user_home_feed, "user_views_article_four_days_in_week")
|
|
end
|
|
end
|
|
|
|
context "when user not signed in" do
|
|
it "creates a new page view" do
|
|
post "/page_views", params: {
|
|
article_id: article.id
|
|
}
|
|
expect(article.reload.page_views.size).to eq(1)
|
|
expect(article.reload.page_views_count).to eq(10)
|
|
expect(user.reload.page_views.size).to eq(0)
|
|
expect(PageView.last.counts_for_number_of_views).to eq(10)
|
|
end
|
|
|
|
it "stores aggregate page views" do
|
|
post "/page_views", params: { article_id: article.id }
|
|
post "/page_views", params: { article_id: article.id }
|
|
expect(article.reload.page_views_count).to eq(20)
|
|
end
|
|
|
|
it "stores aggregate organic page views" do
|
|
post "/page_views", params: { article_id: article.id, referrer: "https://www.google.com/" }
|
|
post "/page_views", params: { article_id: article.id }
|
|
expect(article.reload.organic_page_views_count).to eq(10)
|
|
expect(article.reload.organic_page_views_past_week_count).to eq(10)
|
|
expect(article.reload.organic_page_views_past_month_count).to eq(10)
|
|
post "/page_views", params: { article_id: article.id, referrer: "https://www.google.com/" }
|
|
expect(article.reload.organic_page_views_count).to eq(20)
|
|
post "/page_views", params: { article_id: article.id }
|
|
expect(article.reload.organic_page_views_count).to eq(20)
|
|
end
|
|
|
|
it "sends referrer" do
|
|
post "/page_views", params: {
|
|
article_id: article.id,
|
|
referrer: "test"
|
|
}
|
|
expect(PageView.last.referrer).to eq("test")
|
|
end
|
|
|
|
it "sends user agent" do
|
|
post "/page_views", params: {
|
|
article_id: article.id,
|
|
user_agent: "test"
|
|
}
|
|
expect(PageView.last.user_agent).to eq("test")
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "PUT /page_views/:id" do
|
|
context "when user is signed in" do
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it "updates a new page view time on page by 15" do
|
|
post "/page_views", params: { article_id: article.id }
|
|
|
|
put "/page_views/#{article.id}"
|
|
|
|
expect(PageView.last.time_tracked_in_seconds).to eq(30)
|
|
end
|
|
|
|
it "does not update an invalid page view" do
|
|
invalid_id = article.id + 100
|
|
expect { put "/page_views/#{invalid_id}" }.not_to raise_error
|
|
end
|
|
end
|
|
|
|
context "when user is not signed in" do
|
|
it "updates a new page view time on page by 15" do
|
|
post "/page_views", params: {
|
|
article_id: article.id
|
|
}
|
|
put "/page_views/#{article.id}"
|
|
expect(PageView.last.time_tracked_in_seconds).to eq(15)
|
|
end
|
|
end
|
|
end
|
|
end
|