diff --git a/Gemfile b/Gemfile index 8c6596c..7f97811 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem "font_awesome5_rails" gem "friendly_id" gem "image_processing", "~> 1.2" gem "jsbundling-rails" -gem "madmin", "~> 1.2" +gem "madmin" gem "mission_control-jobs" gem "name_of_person" gem "nokogiri", ">= 1.13.4" diff --git a/Gemfile.lock b/Gemfile.lock index 4f515f0..c18aeb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,29 +1,29 @@ GEM remote: https://rubygems.org/ specs: - actioncable (8.0.3) - actionpack (= 8.0.3) - activesupport (= 8.0.3) + actioncable (8.0.4) + actionpack (= 8.0.4) + activesupport (= 8.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (8.0.3) - actionpack (= 8.0.3) - activejob (= 8.0.3) - activerecord (= 8.0.3) - activestorage (= 8.0.3) - activesupport (= 8.0.3) + actionmailbox (8.0.4) + actionpack (= 8.0.4) + activejob (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) mail (>= 2.8.0) - actionmailer (8.0.3) - actionpack (= 8.0.3) - actionview (= 8.0.3) - activejob (= 8.0.3) - activesupport (= 8.0.3) + actionmailer (8.0.4) + actionpack (= 8.0.4) + actionview (= 8.0.4) + activejob (= 8.0.4) + activesupport (= 8.0.4) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (8.0.3) - actionview (= 8.0.3) - activesupport (= 8.0.3) + actionpack (8.0.4) + actionview (= 8.0.4) + activesupport (= 8.0.4) nokogiri (>= 1.8.5) rack (>= 2.2.4) rack-session (>= 1.0.1) @@ -31,35 +31,35 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (8.0.3) - actionpack (= 8.0.3) - activerecord (= 8.0.3) - activestorage (= 8.0.3) - activesupport (= 8.0.3) + actiontext (8.0.4) + actionpack (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (8.0.3) - activesupport (= 8.0.3) + actionview (8.0.4) + activesupport (= 8.0.4) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (8.0.3) - activesupport (= 8.0.3) + activejob (8.0.4) + activesupport (= 8.0.4) globalid (>= 0.3.6) - activemodel (8.0.3) - activesupport (= 8.0.3) - activerecord (8.0.3) - activemodel (= 8.0.3) - activesupport (= 8.0.3) + activemodel (8.0.4) + activesupport (= 8.0.4) + activerecord (8.0.4) + activemodel (= 8.0.4) + activesupport (= 8.0.4) timeout (>= 0.4.0) - activestorage (8.0.3) - actionpack (= 8.0.3) - activejob (= 8.0.3) - activerecord (= 8.0.3) - activesupport (= 8.0.3) + activestorage (8.0.4) + actionpack (= 8.0.4) + activejob (= 8.0.4) + activerecord (= 8.0.4) + activesupport (= 8.0.4) marcel (~> 1.0) - activesupport (8.0.3) + activesupport (8.0.4) base64 benchmark (>= 0.3) bigdecimal @@ -80,8 +80,8 @@ GEM american_date (1.3.0) ast (2.4.3) aws-eventstream (1.4.0) - aws-partitions (1.1177.0) - aws-sdk-core (3.235.0) + aws-partitions (1.1183.0) + aws-sdk-core (3.237.0) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.992.0) aws-sigv4 (~> 1.9) @@ -89,10 +89,10 @@ GEM bigdecimal jmespath (~> 1, >= 1.6.1) logger - aws-sdk-kms (1.115.0) + aws-sdk-kms (1.117.0) aws-sdk-core (~> 3, >= 3.234.0) aws-sigv4 (~> 1.5) - aws-sdk-s3 (1.201.0) + aws-sdk-s3 (1.203.1) aws-sdk-core (~> 3, >= 3.234.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) @@ -103,9 +103,9 @@ GEM benchmark (0.5.0) bigdecimal (3.3.1) bindex (0.8.1) - bootsnap (1.18.6) + bootsnap (1.19.0) msgpack (~> 1.2) - brakeman (7.1.0) + brakeman (7.1.1) racc builder (3.3.0) bundler-audit (0.9.2) @@ -126,7 +126,7 @@ GEM cssbundling-rails (1.4.3) railties (>= 6.0.0) csv (3.3.5) - date (3.4.1) + date (3.5.0) devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -149,7 +149,7 @@ GEM concurrent-ruby (~> 1.0) logger zeitwerk (~> 2.6) - erb (5.1.1) + erb (6.0.0) erubi (1.13.1) et-orbi (1.4.0) tzinfo @@ -196,14 +196,14 @@ GEM activesupport (>= 6.0.0) railties (>= 6.0.0) io-console (0.8.1) - irb (1.15.2) + irb (1.15.3) pp (>= 0.6.0) rdoc (>= 4.0.0) reline (>= 0.4.2) jmespath (1.6.2) jsbundling-rails (1.3.1) railties (>= 6.0.0) - json (2.15.1) + json (2.16.0) jwt (3.1.2) base64 language_server-protocol (3.17.0.5) @@ -215,9 +215,11 @@ GEM loofah (2.24.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) - madmin (1.2.11) + madmin (2.1.3) + importmap-rails pagy (>= 3.5) - rails (>= 6.0.3) + propshaft + rails (>= 7.0.0) mail (2.9.0) logger mini_mime (>= 0.1.1) @@ -233,7 +235,7 @@ GEM mini_magick (5.3.1) logger mini_mime (1.1.5) - minitest (5.26.0) + minitest (5.26.2) mission_control-jobs (1.1.0) actioncable (>= 7.1) actionpack (>= 7.1) @@ -257,7 +259,7 @@ GEM net-smtp (0.5.1) net-protocol netrc (0.11.0) - nio4r (2.7.4) + nio4r (2.7.5) nokogiri (1.18.10-aarch64-linux-gnu) racc (~> 1.4) nokogiri (1.18.10-aarch64-linux-musl) @@ -278,9 +280,11 @@ GEM http (>= 4.0.0) rails (>= 5.2.0) orm_adapter (0.5.0) - pagy (9.4.0) + pagy (43.0.6) + json + yaml parallel (1.27.0) - parser (3.3.9.0) + parser (3.3.10.0) ast (~> 2.4.1) racc pg (1.6.2) @@ -290,13 +294,17 @@ GEM pg (1.6.2-x86_64-darwin) pg (1.6.2-x86_64-linux) pg (1.6.2-x86_64-linux-musl) - phonelib (0.10.12) + phonelib (0.10.13) pp (0.6.3) prettyprint pretender (0.6.0) actionpack (>= 7.1) prettyprint (0.2.0) prism (1.6.0) + propshaft (1.3.1) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack psych (5.2.6) date stringio @@ -307,7 +315,7 @@ GEM activesupport (>= 3.0.0) raabro (1.4.0) racc (1.8.1) - rack (3.2.3) + rack (3.2.4) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) @@ -315,20 +323,20 @@ GEM rack (>= 1.3) rackup (2.2.1) rack (>= 3) - rails (8.0.3) - actioncable (= 8.0.3) - actionmailbox (= 8.0.3) - actionmailer (= 8.0.3) - actionpack (= 8.0.3) - actiontext (= 8.0.3) - actionview (= 8.0.3) - activejob (= 8.0.3) - activemodel (= 8.0.3) - activerecord (= 8.0.3) - activestorage (= 8.0.3) - activesupport (= 8.0.3) + rails (8.0.4) + actioncable (= 8.0.4) + actionmailbox (= 8.0.4) + actionmailer (= 8.0.4) + actionpack (= 8.0.4) + actiontext (= 8.0.4) + actionview (= 8.0.4) + activejob (= 8.0.4) + activemodel (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) bundler (>= 1.15.0) - railties (= 8.0.3) + railties (= 8.0.4) rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest @@ -336,9 +344,9 @@ GEM rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - railties (8.0.3) - actionpack (= 8.0.3) - activesupport (= 8.0.3) + railties (8.0.4) + actionpack (= 8.0.4) + activesupport (= 8.0.4) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -346,17 +354,17 @@ GEM tsort (>= 0.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.3.0) + rake (13.3.1) ransack (4.4.1) activerecord (>= 7.2) activesupport (>= 7.2) i18n - rdoc (6.15.0) + rdoc (6.15.1) erb psych (>= 4.0.0) tsort regexp_parser (2.11.3) - reline (0.6.2) + reline (0.6.3) io-console (~> 0.5) responders (3.2.0) actionpack (>= 7.0) @@ -372,7 +380,7 @@ GEM rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-mocks (3.13.6) + rspec-mocks (3.13.7) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-rails (8.0.2) @@ -384,7 +392,7 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.6) - rubocop (1.81.6) + rubocop (1.81.7) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -395,26 +403,26 @@ GEM rubocop-ast (>= 1.47.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.47.1) + rubocop-ast (1.48.0) parser (>= 3.3.7.2) prism (~> 1.4) - rubocop-rails (2.33.4) + rubocop-rails (2.34.0) activesupport (>= 4.2.0) lint_roller (~> 1.1) rack (>= 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.44.0, < 2.0) - rubocop-rspec (3.7.0) + rubocop-rspec (3.8.0) lint_roller (~> 1.1) - rubocop (~> 1.72, >= 1.72.1) + rubocop (~> 1.81) ruby-progressbar (1.13.0) ruby-vips (2.2.5) ffi (~> 1.12) logger ruby_http_client (3.5.5) - rubyzip (3.2.1) + rubyzip (3.2.2) securerandom (0.4.1) - selenium-webdriver (4.37.0) + selenium-webdriver (4.38.0) base64 (~> 0.2) logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) @@ -422,7 +430,7 @@ GEM websocket (~> 1.0) sendgrid-ruby (6.7.0) ruby_http_client (~> 3.4) - sentry-ruby (6.0.0) + sentry-ruby (6.1.0) bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) solid_cable (3.0.12) @@ -430,7 +438,7 @@ GEM activejob (>= 7.2) activerecord (>= 7.2) railties (>= 7.2) - solid_queue (1.2.2) + solid_queue (1.2.4) activejob (>= 7.1) activerecord (>= 7.1) concurrent-ruby (>= 1.3.1) @@ -447,13 +455,13 @@ GEM sprockets (>= 3.0.0) stimulus-rails (1.3.4) railties (>= 6.0.0) - stringio (3.1.7) + stringio (3.1.8) strip_attributes (2.0.1) activemodel (>= 3.0, < 9.0) thor (1.4.0) - timeout (0.4.3) + timeout (0.4.4) tsort (0.2.0) - turbo-rails (2.0.17) + turbo-rails (2.0.20) actionpack (>= 7.1.0) railties (>= 7.1.0) tzinfo (2.0.6) @@ -461,7 +469,7 @@ GEM unicode-display_width (3.2.0) unicode-emoji (~> 4.1) unicode-emoji (4.1.0) - uri (1.0.4) + uri (1.1.1) useragent (0.16.11) warden (1.2.9) rack (>= 2.0.9) @@ -482,6 +490,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) + yaml (0.4.0) zeitwerk (2.7.3) PLATFORMS @@ -512,7 +521,7 @@ DEPENDENCIES friendly_id image_processing (~> 1.2) jsbundling-rails - madmin (~> 1.2) + madmin mission_control-jobs name_of_person nokogiri (>= 1.13.4) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ecc9e15..844c0ee 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - include Pagy::Backend + include Pagy::Method include Pundit::Authorization impersonates :user @@ -55,6 +55,6 @@ def use_fluid_container def user_not_authorized flash[:alert] = t("controllers.application_controller.not_authorized") - redirect_back(fallback_location: root_path) + redirect_back_or_to(root_path) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ed6a048..de6be79 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,2 @@ module ApplicationHelper - include Pagy::Frontend end diff --git a/spec/support/pagy_stub_helper.rb b/spec/support/pagy_stub_helper.rb new file mode 100644 index 0000000..a258a8f --- /dev/null +++ b/spec/support/pagy_stub_helper.rb @@ -0,0 +1,44 @@ +module PagyStubHelper + # rubocop:disable Lint/StructNewOverride + PagyStub = Struct.new( + :page, + :last, + :next, + :prev, + :offset, + :limit, + :count, + keyword_init: true + ) + # rubocop:enable Lint/StructNewOverride + + # Usage with a real collection: + # pagy = pagy_stub_for(collection, page: 2, limit: 10) + # + # Usage with an integer to be assigned to count: + # pagy = pagy_stub_for(3, page: 2, limit: 10) + # + def pagy_stub_for(collection_or_count, page: 1, limit: 20) + count = + if collection_or_count.respond_to?(:count) + collection_or_count.count + else + Integer(collection_or_count) + end + + last = (count.to_f / limit).ceil + last = 1 if last.zero? # behave nicely with empty collections + page = page.clamp(1, last) + offset = (page - 1) * limit + + PagyStub.new( + page: page, + last: last, + next: (page < last ? page + 1 : nil), + prev: (page > 1 ? page - 1 : nil), + offset: offset, + limit: limit, + count: count + ) + end +end diff --git a/spec/view_objects/meetings_view_object_spec.rb b/spec/view_objects/meetings_view_object_spec.rb index 0b4a988..0e0e126 100644 --- a/spec/view_objects/meetings_view_object_spec.rb +++ b/spec/view_objects/meetings_view_object_spec.rb @@ -1,12 +1,15 @@ require "rails_helper" describe MeetingsViewObject do + include PagyStubHelper + subject { described_class.new(meetings, view_context, pagy) } let(:unit) { units(:sunny_hills) } let(:meetings) { unit.meetings } let(:view_context) { MeetingsController.new.view_context } - let(:pagy) { Pagy.new(count: 1, page: 1) } + let(:pagy) { pagy_stub_for(current_meeting, page: 1, limit: 10) } + let(:current_meeting) { [meetings.first] } before do allow(view_context).to receive(:current_user).and_return(unit.users.first)