From 6b37c67b47e7df68af81556254e6f31a9baa74a6 Mon Sep 17 00:00:00 2001 From: Kevin BATAILLE Date: Tue, 26 Aug 2025 02:57:17 +0200 Subject: [PATCH] wip: Kaminari pagination --- Gemfile | 4 +- app/controllers/parties_controller.rb | 3 +- .../twitter_bootstrap/_paginator.html.erb | 25 ++++++++++++ app/views/parties/index.html.erb | 3 +- test/models/party_test.rb | 38 ++++++++++++++----- 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 app/views/kaminari/twitter_bootstrap/_paginator.html.erb diff --git a/Gemfile b/Gemfile index 6bec694..15c9858 100644 --- a/Gemfile +++ b/Gemfile @@ -73,8 +73,6 @@ end gem "devise", "~> 4.9" # Pagination gem -# gem "kaminari" +gem "kaminari", "~> 1.2" # gem "net-pop", "~> 0.1.2" - -gem "kaminari", "~> 1.2" diff --git a/app/controllers/parties_controller.rb b/app/controllers/parties_controller.rb index 176aefb..0625990 100644 --- a/app/controllers/parties_controller.rb +++ b/app/controllers/parties_controller.rb @@ -1,7 +1,8 @@ class PartiesController < ApplicationController # Display all events def index - @parties = Party.includes(:user).upcoming.page(params[:page]).per(12) + @parties = Party.includes(:user).upcoming.page(params[:page]).per(1) + # @parties = Party.page(params[:page]).per(12) end # Display desired event diff --git a/app/views/kaminari/twitter_bootstrap/_paginator.html.erb b/app/views/kaminari/twitter_bootstrap/_paginator.html.erb new file mode 100644 index 0000000..c192aaf --- /dev/null +++ b/app/views/kaminari/twitter_bootstrap/_paginator.html.erb @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/app/views/parties/index.html.erb b/app/views/parties/index.html.erb index c383aa8..e2a0e34 100644 --- a/app/views/parties/index.html.erb +++ b/app/views/parties/index.html.erb @@ -39,7 +39,8 @@
- <%= paginate @parties, theme: 'twitter_bootstrap' %> + <%# paginate @parties, theme: 'twitter_bootstrap' %> + <%= paginate @parties %>
<% else %>
diff --git a/test/models/party_test.rb b/test/models/party_test.rb index 4409943..b989051 100644 --- a/test/models/party_test.rb +++ b/test/models/party_test.rb @@ -29,7 +29,7 @@ class PartyTest < ActiveSupport::TestCase test "should not save party without latitude" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", longitude: 2.3522 ) @@ -38,7 +38,7 @@ class PartyTest < ActiveSupport::TestCase test "should not save party without longitude" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", latitude: 48.8566 ) @@ -47,7 +47,7 @@ class PartyTest < ActiveSupport::TestCase test "should not save party with invalid latitude" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", latitude: 95.0, longitude: 2.3522, @@ -59,7 +59,7 @@ class PartyTest < ActiveSupport::TestCase test "should not save party with invalid longitude" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", latitude: 48.8566, longitude: 190.0, @@ -71,7 +71,7 @@ class PartyTest < ActiveSupport::TestCase test "should not save party without slug" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", latitude: 48.8566, longitude: 2.3522, @@ -83,7 +83,7 @@ class PartyTest < ActiveSupport::TestCase test "should not save party with slug less than 3 characters" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", latitude: 48.8566, longitude: 2.3522, @@ -94,6 +94,26 @@ class PartyTest < ActiveSupport::TestCase assert_not party.save end + test "should save valid party" do + user = User.create!( + email: "test@example.com", + password: "password123", + password_confirmation: "password123" + ) + + party = Party.new( + name: "Valid Party Name", + slug: "valid-party-name", + description: "Valid description for the party that is long enough", + latitude: 48.8566, + longitude: 2.3522, + venue_name: "Test Venue", + venue_address: "123 Test Street", + user: user, + ) + assert party.save + end + # Test enum states test "should have valid states" do assert_equal %w[draft published canceled sold_out], Party.states.keys @@ -101,7 +121,7 @@ class PartyTest < ActiveSupport::TestCase test "should default to draft state" do party = Party.new( - name: "Valid Party Name", + name: "Valid Party Name", description: "Valid description for the party that is long enough", latitude: 48.8566, longitude: 2.3522, @@ -128,7 +148,7 @@ class PartyTest < ActiveSupport::TestCase assert_equal :ticket_types, association.options[:through] end - # Test scopes - using class methods directly to avoid DB connection issues + # Test scopes test "should respond to featured scope" do assert_respond_to Party, :featured end @@ -140,4 +160,4 @@ class PartyTest < ActiveSupport::TestCase test "should respond to search_by_name scope" do assert_respond_to Party, :search_by_name end -end \ No newline at end of file +end