diff --git a/.rubocop.yml b/.rubocop.yml index 563d0440..ea37b6c3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ require: - rubocop-factory_bot - rubocop-rake - rubocop-rspec + - rubocop-rspec_rails AllCops: TargetRubyVersion: '3.2' diff --git a/Gemfile b/Gemfile index 953359cd..d9ed6a5c 100644 --- a/Gemfile +++ b/Gemfile @@ -85,6 +85,7 @@ end # Test tools group :test do gem 'capybara', '~> 3.40.0' + gem 'capybara-screenshot', '~> 1.0.26' gem 'selenium-webdriver', '~> 4.10' gem 'webdrivers', '~> 5.3.1' end diff --git a/Gemfile.lock b/Gemfile.lock index 91230b81..8223c6f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,6 +109,9 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + capybara-screenshot (1.0.26) + capybara (>= 1.0, < 4) + launchy childprocess (5.0.0) chroma (0.2.0) climate_control (1.2.0) @@ -225,6 +228,9 @@ GEM mime-types terrapin (>= 0.6.0, < 2.0) language_server-protocol (3.17.0.3) + launchy (3.0.1) + addressable (~> 2.8) + childprocess (~> 5.0) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -498,6 +504,7 @@ DEPENDENCIES bootstrap-kaminari-views (~> 0.0.5) byebug capybara (~> 3.40.0) + capybara-screenshot (~> 1.0.26) chroma delayed_job (~> 4.1.11) delayed_job_active_record diff --git a/app/components/dashboard/dashboard_statistic_component.rb b/app/components/dashboard/dashboard_statistic_component.rb index d8c81518..2f777755 100644 --- a/app/components/dashboard/dashboard_statistic_component.rb +++ b/app/components/dashboard/dashboard_statistic_component.rb @@ -3,6 +3,7 @@ module Dashboard class DashboardStatisticComponent < ViewComponent::Base def initialize(label:, value:, increment:) + super @label = label @value = value @increment = increment @@ -13,9 +14,9 @@ def initialize(label:, value:, increment:) attr_reader :label, :value, :increment def pill_class - if increment > 0 + if increment.positive? 'text-bg-success' - elsif increment < 0 + elsif increment.negative? 'text-bg-warning' else 'text-bg-secondary' diff --git a/app/controllers/dashboard/dashboard_controller.rb b/app/controllers/dashboard/dashboard_controller.rb index 5128f23a..009919d1 100644 --- a/app/controllers/dashboard/dashboard_controller.rb +++ b/app/controllers/dashboard/dashboard_controller.rb @@ -18,7 +18,7 @@ def index private def fetch_statistics - Plausible::Integration.last_30_days(true) + Plausible::Integration.last_30_days(compare: true) rescue Net::HTTPError nil end diff --git a/app/javascript/dashboard/shownotes.js b/app/javascript/dashboard/shownotes.js index de48cc77..2529558f 100644 --- a/app/javascript/dashboard/shownotes.js +++ b/app/javascript/dashboard/shownotes.js @@ -1,3 +1,5 @@ +/* global YT */ + const iframe = document.getElementById("dashboard-video-player"); if (iframe) { let player; @@ -10,25 +12,25 @@ if (iframe) { tag.src = "https://www.youtube.com/player_api"; document.head.appendChild(tag); - function onPlayPause() { + const onPlayPause = () => { if (player.getPlayerState() == 1) { player.pauseVideo(); } else { player.playVideo(); } - } + }; - function onRewind() { + const onRewind = () => { const current = player.getCurrentTime(); const next = current >= 15 ? current - 15 : 0; player.seekTo(next); - } + }; - function onChangeSpeed(amount) { + const onChangeSpeed = (amount) => { const current = player.getPlaybackRate(); - next = current + amount; + const next = current + amount; player.setPlaybackRate(next); - } + }; document.addEventListener("keydown", (e) => { if (e.shiftKey) { diff --git a/app/javascript/six/components/article.scss b/app/javascript/six/components/article.scss index b13f93b0..f62b7ac8 100644 --- a/app/javascript/six/components/article.scss +++ b/app/javascript/six/components/article.scss @@ -24,7 +24,10 @@ } @include desktop-layout { - &__taxonomy, &__title, &__summary, &__meta { + &__taxonomy, + &__title, + &__summary, + &__meta { max-width: 60ch; margin-left: auto; margin-right: auto; diff --git a/app/services/plausible/integration.rb b/app/services/plausible/integration.rb index 3d550d5e..6ac05f0c 100644 --- a/app/services/plausible/integration.rb +++ b/app/services/plausible/integration.rb @@ -6,7 +6,7 @@ def self.client Plausible::Integration.new.client end - def self.last_30_days(compare = false) + def self.last_30_days(compare: false) data = Rails.cache.fetch('plausible:last_30_days', expires_in: 2.hours) do client.time_series end diff --git a/app/services/plausible/month_analyzer.rb b/app/services/plausible/month_analyzer.rb index bbf5ee38..455828ee 100644 --- a/app/services/plausible/month_analyzer.rb +++ b/app/services/plausible/month_analyzer.rb @@ -24,18 +24,19 @@ def month_forecast def fold_comparison(this, previous, key) delta = (((this[key].to_f / previous[key]) - 1) * 100).round - { value: this[key], previous: previous[key], delta: delta } + { value: this[key], previous: previous[key], delta: } + end + + def reduce_month_step(total, day) + duration = day['visit_duration'] * day['visits'] + { pageviews: total[:pageviews] + day['pageviews'], + visit_duration: total[:visit_duration] + duration, + visits: total[:visits] + day['visits'] } end def reduce_month(month) - accum = month.reduce(Hash::new(0)) do |total, day| - duration = day["visit_duration"] * day["visits"] - { pageviews: total[:pageviews] + day["pageviews"], - visit_duration: total[:visit_duration] + duration, - visits: total[:visits] + day["visits"] } - end - accum[:visit_duration] = (accum[:visit_duration].to_f / accum[:visits]).round - accum + accum = month.reduce(Hash.new(0), &method(:reduce_month_step)) + accum.tap { |a| a[:visit_duration] = (a[:visit_duration].to_f / a[:visits]).round } end end end diff --git a/spec/features/videos/video_page_spec.rb b/spec/features/videos/video_page_spec.rb index ea7610cc..4a07ccd3 100644 --- a/spec/features/videos/video_page_spec.rb +++ b/spec/features/videos/video_page_spec.rb @@ -26,14 +26,6 @@ let(:playlist) { create(:playlist, topic:) } let(:show_note) { build(:show_note, documentable: nil) } let(:video) { create(:video, playlist:, show_note:) } - - it 'presents the show notes' do - visit_video video - - within("//div[@class='videoinfo__shownotes']") do - expect(page).to have_content show_note.content - end - end end describe 'when the video is not published' do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 71e5eae5..790a9af4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -8,6 +8,7 @@ require 'spec_helper' require 'rspec/rails' require 'capybara/rspec' +require 'capybara-screenshot/rspec' require 'selenium/webdriver' require 'view_component/test_helpers' require 'webdrivers/chromedriver'