From 5ef4e4d88760e2cceb787ca71b04cb7b25f3486b Mon Sep 17 00:00:00 2001 From: auliafaizahr Date: Tue, 6 Aug 2024 20:06:17 +0700 Subject: [PATCH 1/6] Fix speaker model as rubocop suggested --- app/models/speaker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/speaker.rb b/app/models/speaker.rb index 36d6d42..3548220 100644 --- a/app/models/speaker.rb +++ b/app/models/speaker.rb @@ -43,7 +43,7 @@ def format_links end def url_exists? - links.each { |_, url| errors.add(:links, 'This url is not valid') unless url_valid?(url) } + links.each_value { |_, url| errors.add(:links, 'This url is not valid') unless url_valid?(url) } end def empty_links? From 96740bc4c24d889da513b9c1d37e4b2057f09f1b Mon Sep 17 00:00:00 2001 From: auliafaizahr Date: Tue, 6 Aug 2024 20:23:54 +0700 Subject: [PATCH 2/6] Add pagination for speakers module --- Gemfile.lock | 199 +++++++++--------- app/controllers/admin/speakers_controller.rb | 4 +- app/controllers/admin_controller.rb | 2 + app/views/admin/speakers/index.html.erb | 23 +- .../admin/speakers_controller_spec.rb | 7 + spec/system/admin_login_system_spec.rb | 15 ++ 6 files changed, 149 insertions(+), 101 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a541254..4f826f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,45 +77,48 @@ GEM i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) ast (2.4.2) - bcrypt (3.1.19) + base64 (0.2.0) + bcrypt (3.1.20) + bigdecimal (3.1.8) bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.18.4) msgpack (~> 1.2) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) - capybara (3.39.2) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) coderay (1.1.3) - concurrent-ruby (1.3.1) + concurrent-ruby (1.3.3) crass (1.0.6) - cssbundling-rails (1.2.0) + cssbundling-rails (1.4.1) railties (>= 6.0.0) + csv (3.3.0) date (3.3.4) debug (1.7.2) irb (>= 1.5.0) reline (>= 0.3.1) declarative (0.0.20) - devise (4.9.2) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.0) - erubi (1.12.0) + diff-lcs (1.5.1) + erubi (1.13.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -123,20 +126,21 @@ GEM railties (>= 5.0.0) faker (2.18.0) i18n (>= 1.6, < 2) - faraday (2.7.4) - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) + faraday (2.10.1) + faraday-net_http (>= 2.0, < 3.2) + logger faraday-mashify (0.1.1) faraday (~> 2.0) hashie faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (3.0.2) - ffi (1.15.5) - gli (2.21.1) + faraday-net_http (3.1.1) + net-http + ffi (1.17.0-x86_64-linux-gnu) + gli (2.21.5) globalid (1.2.1) activesupport (>= 6.1) - google-apis-core (0.11.1) + google-apis-core (0.11.3) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -144,10 +148,9 @@ GEM representable (~> 3.0) retriable (>= 2.0, < 4.a) rexml - webrick - google-apis-drive_v3 (0.43.0) + google-apis-drive_v3 (0.46.0) google-apis-core (>= 0.11.0, < 2.a) - google-apis-sheets_v4 (0.24.0) + google-apis-sheets_v4 (0.26.0) google-apis-core (>= 0.11.0, < 2.a) googleauth (1.5.1) faraday (>= 0.17.3, < 3.a) @@ -157,7 +160,8 @@ GEM os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) hashie (5.0.0) - httparty (0.21.0) + httparty (0.22.0) + csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) httpclient (2.8.3) @@ -165,20 +169,23 @@ GEM httparty (> 0) i18n (1.14.5) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.7.4) - reline (>= 0.3.6) - jbuilder (2.11.5) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - jsbundling-rails (1.1.2) + jsbundling-rails (1.3.1) railties (>= 6.0.0) - json (2.6.3) - jwt (2.7.1) + json (2.7.2) + jwt (2.8.2) + base64 language_server-protocol (3.17.0.3) - listen (3.8.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + logger (1.6.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -187,36 +194,39 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) memoist (0.16.2) - method_source (1.0.0) + method_source (1.1.0) mini_mime (1.1.5) mini_portile2 (2.8.7) - minitest (5.23.1) + minitest (5.24.1) msgpack (1.7.2) multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.3.0) - net-imap (0.4.10) + multi_xml (0.7.1) + bigdecimal (~> 3.1) + multipart-post (2.4.1) + net-http (0.4.1) + uri + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol - nio4r (2.7.0) - nokogiri (1.16.5) + nio4r (2.7.3) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) orm_adapter (0.5.0) os (1.1.4) package_json (0.1.0) - pagy (6.2.0) - parallel (1.23.0) - parser (3.2.2.3) + pagy (6.5.0) + parallel (1.25.1) + parser (3.3.4.0) ast (~> 2.4.1) racc pg (1.4.6) @@ -224,14 +234,16 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (5.0.3) + pry-rails (0.3.11) + pry (>= 0.13.0) + psych (5.1.2) + stringio + public_suffix (6.0.1) puma (6.4.2) nio4r (~> 2.0) - pundit (2.3.1) + pundit (2.3.2) activesupport (>= 3.0.0) - racc (1.8.0) + racc (1.8.1) rack (2.2.9) rack-mini-profiler (2.3.4) rack (>= 1.2.0) @@ -272,55 +284,56 @@ GEM thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) - regexp_parser (2.8.1) - reline (0.3.7) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.9) io-console (~> 0.5) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) retriable (3.1.2) - rexml (3.2.8) - strscan (>= 3.0.9) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rexml (3.3.4) + strscan + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (6.1.1) + rspec-support (~> 3.13.0) + rspec-rails (6.1.3) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) - rspec-core (~> 3.12) - rspec-expectations (~> 3.12) - rspec-mocks (~> 3.12) - rspec-support (~> 3.12) - rspec-support (3.12.1) - rubocop (1.55.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) rubyzip (2.3.2) sassc (2.4.0) ffi (~> 1.9) @@ -330,7 +343,9 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (4.15.0) + selenium-webdriver (4.23.0) + base64 (~> 0.2) + logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) @@ -343,7 +358,7 @@ GEM semantic_range (>= 2.3.0) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) - signet (0.17.0) + signet (0.19.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) @@ -355,18 +370,19 @@ GEM gli hashie websocket-driver - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - stimulus-rails (1.2.1) + stimulus-rails (1.2.2) railties (>= 6.0.0) + stringio (3.1.1) strscan (3.1.0) thor (1.3.1) - tilt (2.2.0) + tilt (2.4.0) timeout (0.4.1) trailblazer-option (0.1.2) truncate_html (0.9.3) @@ -377,31 +393,24 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) + uri (0.13.0) warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webrick (1.8.1) - websocket (1.2.10) + websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.13) + zeitwerk (2.6.17) PLATFORMS - arm64-darwin-21 - arm64-darwin-22 - arm64-darwin-23 - x86_64-darwin-19 - x86_64-darwin-20 - x86_64-darwin-21 - x86_64-darwin-22 x86_64-linux DEPENDENCIES @@ -447,4 +456,4 @@ RUBY VERSION ruby 3.2.2p53 BUNDLED WITH - 2.4.5 + 2.4.10 diff --git a/app/controllers/admin/speakers_controller.rb b/app/controllers/admin/speakers_controller.rb index 596c930..28078db 100644 --- a/app/controllers/admin/speakers_controller.rb +++ b/app/controllers/admin/speakers_controller.rb @@ -1,12 +1,14 @@ # frozen_string_literal: true module Admin class SpeakersController < AdminController + include Pagy::Backend + before_action :authorize_event before_action :set_speaker, only: %w[show edit update destroy] # GET /admin/speakers def index - @speakers = Speaker.all + @pagy, @speakers = pagy(Speaker.all, items: 15) end # GET /admin/speakers/1 diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d81e816..758176b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true class AdminController < ApplicationController + include Pagy::Backend + before_action :authenticate_user! rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized diff --git a/app/views/admin/speakers/index.html.erb b/app/views/admin/speakers/index.html.erb index 26fb4c8..f7b484b 100644 --- a/app/views/admin/speakers/index.html.erb +++ b/app/views/admin/speakers/index.html.erb @@ -1,10 +1,23 @@ -

Speaker List

+
+

Speaker List

+
- <%= link_to new_admin_speaker_path, class: "btn btn-primary btn-md mb-4" do %> - Create new Speaker - - <% end %> +
+ <%= link_to new_admin_speaker_path, class: "btn btn-primary btn-md mb-4" do %> + Create new Speaker + + <% end %> +
+
+
+
+
+
+
+ <%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %> +
+
diff --git a/spec/controllers/admin/speakers_controller_spec.rb b/spec/controllers/admin/speakers_controller_spec.rb index b376f02..ce070b7 100644 --- a/spec/controllers/admin/speakers_controller_spec.rb +++ b/spec/controllers/admin/speakers_controller_spec.rb @@ -19,12 +19,19 @@ end context 'when user is admin' do + before { create_list(:speaker, 20) } before { sign_in create(:user, :admin) } it 'returns a success response' do get :index expect(response).to be_successful end + + it 'assigns @speakers and @pagy' do + get :index + expect(assigns(:pagy)).to be_a(Pagy) + expect(assigns(:speakers).size).to eq(15) + end end end diff --git a/spec/system/admin_login_system_spec.rb b/spec/system/admin_login_system_spec.rb index 086944d..ffa9b75 100644 --- a/spec/system/admin_login_system_spec.rb +++ b/spec/system/admin_login_system_spec.rb @@ -57,6 +57,8 @@ end context 'admin is logged in' do + before { create_list(:speaker, 20) } + it 'enables me to logout from WNB.rb admin' do login_as user @@ -65,6 +67,19 @@ expect(page).to have_current_path(root_path) end + + it 'shows speakers pagination with pagy' do + login_as user + + visit admin_dashboard_path + click_link 'Speakers' + expect(page).to have_selector('.pagy-bootstrap-nav') + + #check by count speakers data by row in table + within('#speakers tbody') do + expect(page).to have_selector('tr', count: 15) + end + end end end From 0cc4cad0ece06c39738e3dbb70196c33b14d5a51 Mon Sep 17 00:00:00 2001 From: auliafaizahr Date: Tue, 6 Aug 2024 20:06:17 +0700 Subject: [PATCH 3/6] Fix speaker model as rubocop suggested --- app/models/speaker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/speaker.rb b/app/models/speaker.rb index 36d6d42..3548220 100644 --- a/app/models/speaker.rb +++ b/app/models/speaker.rb @@ -43,7 +43,7 @@ def format_links end def url_exists? - links.each { |_, url| errors.add(:links, 'This url is not valid') unless url_valid?(url) } + links.each_value { |_, url| errors.add(:links, 'This url is not valid') unless url_valid?(url) } end def empty_links? From d6f7eee1628f158744e80d14720f110989566312 Mon Sep 17 00:00:00 2001 From: auliafaizahr Date: Tue, 6 Aug 2024 20:23:54 +0700 Subject: [PATCH 4/6] Add pagination for speakers module --- Gemfile.lock | 197 +++++++++--------- app/controllers/admin/speakers_controller.rb | 4 +- app/controllers/admin_controller.rb | 2 + app/views/admin/speakers/index.html.erb | 23 +- .../admin/speakers_controller_spec.rb | 7 + spec/system/admin_login_system_spec.rb | 15 ++ 6 files changed, 148 insertions(+), 100 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8803bd6..4f826f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,45 +77,48 @@ GEM i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) ast (2.4.2) - bcrypt (3.1.19) + base64 (0.2.0) + bcrypt (3.1.20) + bigdecimal (3.1.8) bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.18.4) msgpack (~> 1.2) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) - capybara (3.39.2) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) coderay (1.1.3) - concurrent-ruby (1.3.1) + concurrent-ruby (1.3.3) crass (1.0.6) - cssbundling-rails (1.2.0) + cssbundling-rails (1.4.1) railties (>= 6.0.0) + csv (3.3.0) date (3.3.4) debug (1.7.2) irb (>= 1.5.0) reline (>= 0.3.1) declarative (0.0.20) - devise (4.9.2) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.0) - erubi (1.12.0) + diff-lcs (1.5.1) + erubi (1.13.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -123,20 +126,21 @@ GEM railties (>= 5.0.0) faker (2.18.0) i18n (>= 1.6, < 2) - faraday (2.7.4) - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) + faraday (2.10.1) + faraday-net_http (>= 2.0, < 3.2) + logger faraday-mashify (0.1.1) faraday (~> 2.0) hashie faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (3.0.2) - ffi (1.15.5) - gli (2.21.1) + faraday-net_http (3.1.1) + net-http + ffi (1.17.0-x86_64-linux-gnu) + gli (2.21.5) globalid (1.2.1) activesupport (>= 6.1) - google-apis-core (0.11.1) + google-apis-core (0.11.3) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -144,10 +148,9 @@ GEM representable (~> 3.0) retriable (>= 2.0, < 4.a) rexml - webrick - google-apis-drive_v3 (0.43.0) + google-apis-drive_v3 (0.46.0) google-apis-core (>= 0.11.0, < 2.a) - google-apis-sheets_v4 (0.24.0) + google-apis-sheets_v4 (0.26.0) google-apis-core (>= 0.11.0, < 2.a) googleauth (1.5.1) faraday (>= 0.17.3, < 3.a) @@ -157,7 +160,8 @@ GEM os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) hashie (5.0.0) - httparty (0.21.0) + httparty (0.22.0) + csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) httpclient (2.8.3) @@ -165,20 +169,23 @@ GEM httparty (> 0) i18n (1.14.5) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.7.4) - reline (>= 0.3.6) - jbuilder (2.11.5) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - jsbundling-rails (1.1.2) + jsbundling-rails (1.3.1) railties (>= 6.0.0) - json (2.6.3) - jwt (2.7.1) + json (2.7.2) + jwt (2.8.2) + base64 language_server-protocol (3.17.0.3) - listen (3.8.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + logger (1.6.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -187,36 +194,39 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) memoist (0.16.2) - method_source (1.0.0) + method_source (1.1.0) mini_mime (1.1.5) mini_portile2 (2.8.7) - minitest (5.23.1) + minitest (5.24.1) msgpack (1.7.2) multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.3.0) - net-imap (0.4.10) + multi_xml (0.7.1) + bigdecimal (~> 3.1) + multipart-post (2.4.1) + net-http (0.4.1) + uri + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol - nio4r (2.7.0) - nokogiri (1.16.5) + nio4r (2.7.3) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) orm_adapter (0.5.0) os (1.1.4) package_json (0.1.0) - pagy (6.2.0) - parallel (1.23.0) - parser (3.2.2.3) + pagy (6.5.0) + parallel (1.25.1) + parser (3.3.4.0) ast (~> 2.4.1) racc pg (1.4.6) @@ -224,14 +234,16 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (5.0.3) + pry-rails (0.3.11) + pry (>= 0.13.0) + psych (5.1.2) + stringio + public_suffix (6.0.1) puma (6.4.2) nio4r (~> 2.0) - pundit (2.3.1) + pundit (2.3.2) activesupport (>= 3.0.0) - racc (1.8.0) + racc (1.8.1) rack (2.2.9) rack-mini-profiler (2.3.4) rack (>= 1.2.0) @@ -272,55 +284,56 @@ GEM thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) - regexp_parser (2.8.1) - reline (0.3.7) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.9) io-console (~> 0.5) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) retriable (3.1.2) - rexml (3.3.3) + rexml (3.3.4) strscan - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (6.1.1) + rspec-support (~> 3.13.0) + rspec-rails (6.1.3) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) - rspec-core (~> 3.12) - rspec-expectations (~> 3.12) - rspec-mocks (~> 3.12) - rspec-support (~> 3.12) - rspec-support (3.12.1) - rubocop (1.55.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) rubyzip (2.3.2) sassc (2.4.0) ffi (~> 1.9) @@ -330,7 +343,9 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (4.15.0) + selenium-webdriver (4.23.0) + base64 (~> 0.2) + logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) @@ -343,7 +358,7 @@ GEM semantic_range (>= 2.3.0) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) - signet (0.17.0) + signet (0.19.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) @@ -355,18 +370,19 @@ GEM gli hashie websocket-driver - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - stimulus-rails (1.2.1) + stimulus-rails (1.2.2) railties (>= 6.0.0) + stringio (3.1.1) strscan (3.1.0) thor (1.3.1) - tilt (2.2.0) + tilt (2.4.0) timeout (0.4.1) trailblazer-option (0.1.2) truncate_html (0.9.3) @@ -377,31 +393,24 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) + uri (0.13.0) warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webrick (1.8.1) - websocket (1.2.10) + websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.13) + zeitwerk (2.6.17) PLATFORMS - arm64-darwin-21 - arm64-darwin-22 - arm64-darwin-23 - x86_64-darwin-19 - x86_64-darwin-20 - x86_64-darwin-21 - x86_64-darwin-22 x86_64-linux DEPENDENCIES @@ -447,4 +456,4 @@ RUBY VERSION ruby 3.2.2p53 BUNDLED WITH - 2.4.5 + 2.4.10 diff --git a/app/controllers/admin/speakers_controller.rb b/app/controllers/admin/speakers_controller.rb index 596c930..28078db 100644 --- a/app/controllers/admin/speakers_controller.rb +++ b/app/controllers/admin/speakers_controller.rb @@ -1,12 +1,14 @@ # frozen_string_literal: true module Admin class SpeakersController < AdminController + include Pagy::Backend + before_action :authorize_event before_action :set_speaker, only: %w[show edit update destroy] # GET /admin/speakers def index - @speakers = Speaker.all + @pagy, @speakers = pagy(Speaker.all, items: 15) end # GET /admin/speakers/1 diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d81e816..758176b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true class AdminController < ApplicationController + include Pagy::Backend + before_action :authenticate_user! rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized diff --git a/app/views/admin/speakers/index.html.erb b/app/views/admin/speakers/index.html.erb index 26fb4c8..f7b484b 100644 --- a/app/views/admin/speakers/index.html.erb +++ b/app/views/admin/speakers/index.html.erb @@ -1,10 +1,23 @@ -

Speaker List

+
+

Speaker List

+
- <%= link_to new_admin_speaker_path, class: "btn btn-primary btn-md mb-4" do %> - Create new Speaker - - <% end %> +
+ <%= link_to new_admin_speaker_path, class: "btn btn-primary btn-md mb-4" do %> + Create new Speaker + + <% end %> +
+
+
+
+
+
+
+ <%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %> +
+
diff --git a/spec/controllers/admin/speakers_controller_spec.rb b/spec/controllers/admin/speakers_controller_spec.rb index b376f02..ce070b7 100644 --- a/spec/controllers/admin/speakers_controller_spec.rb +++ b/spec/controllers/admin/speakers_controller_spec.rb @@ -19,12 +19,19 @@ end context 'when user is admin' do + before { create_list(:speaker, 20) } before { sign_in create(:user, :admin) } it 'returns a success response' do get :index expect(response).to be_successful end + + it 'assigns @speakers and @pagy' do + get :index + expect(assigns(:pagy)).to be_a(Pagy) + expect(assigns(:speakers).size).to eq(15) + end end end diff --git a/spec/system/admin_login_system_spec.rb b/spec/system/admin_login_system_spec.rb index 086944d..ffa9b75 100644 --- a/spec/system/admin_login_system_spec.rb +++ b/spec/system/admin_login_system_spec.rb @@ -57,6 +57,8 @@ end context 'admin is logged in' do + before { create_list(:speaker, 20) } + it 'enables me to logout from WNB.rb admin' do login_as user @@ -65,6 +67,19 @@ expect(page).to have_current_path(root_path) end + + it 'shows speakers pagination with pagy' do + login_as user + + visit admin_dashboard_path + click_link 'Speakers' + expect(page).to have_selector('.pagy-bootstrap-nav') + + #check by count speakers data by row in table + within('#speakers tbody') do + expect(page).to have_selector('tr', count: 15) + end + end end end From 029368bf9f4780952b37bd34e933a9bcabc545ff Mon Sep 17 00:00:00 2001 From: auliafaizahr Date: Wed, 7 Aug 2024 16:06:53 +0700 Subject: [PATCH 5/6] Restore missing platforms in Gemfile.lock --- Gemfile.lock | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 4f826f4..d0ff349 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -411,6 +411,13 @@ GEM zeitwerk (2.6.17) PLATFORMS + arm64-darwin-21 + arm64-darwin-22 + arm64-darwin-23 + x86_64-darwin-19 + x86_64-darwin-20 + x86_64-darwin-21 + x86_64-darwin-22 x86_64-linux DEPENDENCIES From 8a84c711ecb0a4b00ae652bf4659948a55b243d4 Mon Sep 17 00:00:00 2001 From: auliafaizahr Date: Wed, 7 Aug 2024 17:25:38 +0700 Subject: [PATCH 6/6] Add pagination in events module --- Gemfile.lock | 192 ++++++++++-------- app/controllers/admin/events_controller.rb | 2 +- app/controllers/admin_controller.rb | 2 + app/models/speaker.rb | 2 +- app/views/admin/events/index.html.erb | 28 ++- .../admin/events_controller_spec.rb | 7 + spec/system/admin_login_system_spec.rb | 15 ++ 7 files changed, 151 insertions(+), 97 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8803bd6..e6efd94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,45 +77,48 @@ GEM i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) ast (2.4.2) - bcrypt (3.1.19) + base64 (0.2.0) + bcrypt (3.1.20) + bigdecimal (3.1.8) bindex (0.8.1) - bootsnap (1.16.0) + bootsnap (1.18.4) msgpack (~> 1.2) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) - capybara (3.39.2) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) coderay (1.1.3) - concurrent-ruby (1.3.1) + concurrent-ruby (1.3.3) crass (1.0.6) - cssbundling-rails (1.2.0) + cssbundling-rails (1.4.1) railties (>= 6.0.0) + csv (3.3.0) date (3.3.4) debug (1.7.2) irb (>= 1.5.0) reline (>= 0.3.1) declarative (0.0.20) - devise (4.9.2) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.0) - erubi (1.12.0) + diff-lcs (1.5.1) + erubi (1.13.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -123,20 +126,23 @@ GEM railties (>= 5.0.0) faker (2.18.0) i18n (>= 1.6, < 2) - faraday (2.7.4) - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) + faraday (2.10.1) + faraday-net_http (>= 2.0, < 3.2) + logger faraday-mashify (0.1.1) faraday (~> 2.0) hashie faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (3.0.2) - ffi (1.15.5) - gli (2.21.1) + faraday-net_http (3.1.1) + net-http + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) + gli (2.21.5) globalid (1.2.1) activesupport (>= 6.1) - google-apis-core (0.11.1) + google-apis-core (0.11.3) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -144,10 +150,9 @@ GEM representable (~> 3.0) retriable (>= 2.0, < 4.a) rexml - webrick - google-apis-drive_v3 (0.43.0) + google-apis-drive_v3 (0.46.0) google-apis-core (>= 0.11.0, < 2.a) - google-apis-sheets_v4 (0.24.0) + google-apis-sheets_v4 (0.26.0) google-apis-core (>= 0.11.0, < 2.a) googleauth (1.5.1) faraday (>= 0.17.3, < 3.a) @@ -157,7 +162,8 @@ GEM os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) hashie (5.0.0) - httparty (0.21.0) + httparty (0.22.0) + csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) httpclient (2.8.3) @@ -165,20 +171,23 @@ GEM httparty (> 0) i18n (1.14.5) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.7.4) - reline (>= 0.3.6) - jbuilder (2.11.5) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - jsbundling-rails (1.1.2) + jsbundling-rails (1.3.1) railties (>= 6.0.0) - json (2.6.3) - jwt (2.7.1) + json (2.7.2) + jwt (2.8.2) + base64 language_server-protocol (3.17.0.3) - listen (3.8.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + logger (1.6.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -187,36 +196,39 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) memoist (0.16.2) - method_source (1.0.0) + method_source (1.1.0) mini_mime (1.1.5) mini_portile2 (2.8.7) - minitest (5.23.1) + minitest (5.24.1) msgpack (1.7.2) multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.3.0) - net-imap (0.4.10) + multi_xml (0.7.1) + bigdecimal (~> 3.1) + multipart-post (2.4.1) + net-http (0.4.1) + uri + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0.1) + net-smtp (0.5.0) net-protocol - nio4r (2.7.0) - nokogiri (1.16.5) + nio4r (2.7.3) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) orm_adapter (0.5.0) os (1.1.4) package_json (0.1.0) - pagy (6.2.0) - parallel (1.23.0) - parser (3.2.2.3) + pagy (6.5.0) + parallel (1.25.1) + parser (3.3.4.0) ast (~> 2.4.1) racc pg (1.4.6) @@ -224,14 +236,16 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (5.0.3) + pry-rails (0.3.11) + pry (>= 0.13.0) + psych (5.1.2) + stringio + public_suffix (6.0.1) puma (6.4.2) nio4r (~> 2.0) - pundit (2.3.1) + pundit (2.3.2) activesupport (>= 3.0.0) - racc (1.8.0) + racc (1.8.1) rack (2.2.9) rack-mini-profiler (2.3.4) rack (>= 1.2.0) @@ -272,55 +286,56 @@ GEM thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) - rake (13.1.0) + rake (13.2.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) - regexp_parser (2.8.1) - reline (0.3.7) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.9) io-console (~> 0.5) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) - responders (3.1.0) + responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) retriable (3.1.2) - rexml (3.3.3) + rexml (3.3.4) strscan - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (6.1.1) + rspec-support (~> 3.13.0) + rspec-rails (6.1.3) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) - rspec-core (~> 3.12) - rspec-expectations (~> 3.12) - rspec-mocks (~> 3.12) - rspec-support (~> 3.12) - rspec-support (3.12.1) - rubocop (1.55.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) rubyzip (2.3.2) sassc (2.4.0) ffi (~> 1.9) @@ -330,7 +345,9 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (4.15.0) + selenium-webdriver (4.23.0) + base64 (~> 0.2) + logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) @@ -343,7 +360,7 @@ GEM semantic_range (>= 2.3.0) shoulda-matchers (5.3.0) activesupport (>= 5.2.0) - signet (0.17.0) + signet (0.19.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) @@ -355,18 +372,19 @@ GEM gli hashie websocket-driver - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - stimulus-rails (1.2.1) + stimulus-rails (1.2.2) railties (>= 6.0.0) + stringio (3.1.1) strscan (3.1.0) thor (1.3.1) - tilt (2.2.0) + tilt (2.4.0) timeout (0.4.1) trailblazer-option (0.1.2) truncate_html (0.9.3) @@ -377,22 +395,22 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) + uri (0.13.0) warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webrick (1.8.1) - websocket (1.2.10) + websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.13) + zeitwerk (2.6.17) PLATFORMS arm64-darwin-21 @@ -447,4 +465,4 @@ RUBY VERSION ruby 3.2.2p53 BUNDLED WITH - 2.4.5 + 2.4.10 diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 2c7f3f5..8155dd6 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -7,7 +7,7 @@ class EventsController < AdminController before_action :set_event, only: %w[edit update destroy] def index - @pagy, @events = pagy(Event.includes(:speakers).order(date: :desc)) + @pagy, @events = pagy(Event.includes(:speakers).order(date: :desc), items: 15) end def new diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d81e816..758176b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true class AdminController < ApplicationController + include Pagy::Backend + before_action :authenticate_user! rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized diff --git a/app/models/speaker.rb b/app/models/speaker.rb index 36d6d42..3548220 100644 --- a/app/models/speaker.rb +++ b/app/models/speaker.rb @@ -43,7 +43,7 @@ def format_links end def url_exists? - links.each { |_, url| errors.add(:links, 'This url is not valid') unless url_valid?(url) } + links.each_value { |_, url| errors.add(:links, 'This url is not valid') unless url_valid?(url) } end def empty_links? diff --git a/app/views/admin/events/index.html.erb b/app/views/admin/events/index.html.erb index 98faa4f..927de57 100644 --- a/app/views/admin/events/index.html.erb +++ b/app/views/admin/events/index.html.erb @@ -1,14 +1,26 @@ -

Event List

-
- <%= link_to new_admin_event_path, class: "btn btn-primary btn-md mb-4" do %> - Create new Event - - <% end %> -
- <%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %> +
+
+

Event List

+
+
+
+ <%= link_to new_admin_event_path, class: "btn btn-primary btn-md mb-4" do %> + Create new Event + + <% end %> +
+
+
+
+ <%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %> +
+
+
+
+
diff --git a/spec/controllers/admin/events_controller_spec.rb b/spec/controllers/admin/events_controller_spec.rb index c3803f0..66d0f72 100644 --- a/spec/controllers/admin/events_controller_spec.rb +++ b/spec/controllers/admin/events_controller_spec.rb @@ -23,6 +23,7 @@ end context 'when user is admin' do + before { create_list(:event, 20) } let(:user) { create(:user, :admin) } before { sign_in user } @@ -30,6 +31,12 @@ get :index expect(response).to have_http_status(200) end + + it 'assigns @events and @pagy' do + get :index + expect(assigns(:pagy)).to be_a(Pagy) + expect(assigns(:events).size).to eq(15) + end end end diff --git a/spec/system/admin_login_system_spec.rb b/spec/system/admin_login_system_spec.rb index 086944d..5591603 100644 --- a/spec/system/admin_login_system_spec.rb +++ b/spec/system/admin_login_system_spec.rb @@ -57,6 +57,8 @@ end context 'admin is logged in' do + before { create_list(:event, 20) } + it 'enables me to logout from WNB.rb admin' do login_as user @@ -65,6 +67,19 @@ expect(page).to have_current_path(root_path) end + + it 'shows events with pagy' do + login_as user + + visit admin_dashboard_path + click_link 'Events' + expect(page).to have_selector('.pagy-bootstrap-nav') + + #check by count events data by row in table + within('#events tbody') do + expect(page).to have_selector('tr', count: 15) + end + end end end