From 974edce2380f5ceac18581e0368ec1a761690ea7 Mon Sep 17 00:00:00 2001 From: kbe Date: Fri, 5 Sep 2025 23:13:01 +0200 Subject: [PATCH] fix: Moving out from french for dev --- app/controllers/tickets_controller.rb | 11 ++- config/application.rb | 2 +- config/routes.rb | 4 +- ...ticket_pdf_generator_customer_name_test.rb | 92 ------------------- 4 files changed, 10 insertions(+), 99 deletions(-) delete mode 100644 test/services/ticket_pdf_generator_customer_name_test.rb diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 1465aea..3d26b30 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -48,6 +48,7 @@ class TicketsController < ApplicationController end end + # Display ticket details def show @ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by( tickets: { id: params[:ticket_id] }, @@ -59,23 +60,25 @@ class TicketsController < ApplicationController end # Download PDF ticket - only accessible by ticket owner + # User must be authenticated to download ticket + # TODO: change ID to an unique identifier (UUID) def download_ticket # Find ticket and ensure it belongs to current user @ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by( tickets: { id: params[:ticket_id] }, orders: { user_id: current_user.id } ) - + if @ticket.nil? redirect_to dashboard_path, alert: "Billet non trouvé ou vous n'avez pas l'autorisation d'accéder à ce billet" return end - + # Generate PDF pdf_content = @ticket.to_pdf - + # Send PDF as download - send_data pdf_content, + send_data pdf_content, filename: "ticket_#{@ticket.id}_#{@ticket.event.name.parameterize}.pdf", type: "application/pdf", disposition: "attachment" diff --git a/config/application.rb b/config/application.rb index c114b6a..227f091 100755 --- a/config/application.rb +++ b/config/application.rb @@ -25,6 +25,6 @@ module Aperonight # config.eager_load_paths << Rails.root.join("extras") config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}")] - config.i18n.default_locale = :fr + # config.i18n.default_locale = :fr end end diff --git a/config/routes.rb b/config/routes.rb index 1d37fa3..ed528a3 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,8 +39,8 @@ Rails.application.routes.draw do get "events/:slug.:id", to: "events#show", as: "event" # === Orders (scoped to events) === - get "events/:slug.:id/orders/new", to: "orders#new", as: "event_order_new" - post "events/:slug.:id/orders", to: "orders#create", as: "event_order_create" + get "orders/new/events/:slug.:id", to: "orders#new", as: "event_order_new" + post "orders/create/events/:slug.:id", to: "orders#create", as: "event_order_create" resources :orders, only: [ :show ] do member do diff --git a/test/services/ticket_pdf_generator_customer_name_test.rb b/test/services/ticket_pdf_generator_customer_name_test.rb deleted file mode 100644 index 3127954..0000000 --- a/test/services/ticket_pdf_generator_customer_name_test.rb +++ /dev/null @@ -1,92 +0,0 @@ -require "test_helper" - -class TicketPdfGeneratorCustomerNameTest < ActiveSupport::TestCase - def setup - # Stub QR code generation to avoid dependency issues - mock_qrcode = mock("qrcode") - mock_qrcode.stubs(:modules).returns([]) - RQRCode::QRCode.stubs(:new).returns(mock_qrcode) - - @user = User.create!( - email: "test@example.com", - password: "password123", - password_confirmation: "password123" - ) - - @event = Event.create!( - name: "Test Event", - slug: "test-event", - description: "A valid description for the test event that is long enough", - latitude: 48.8566, - longitude: 2.3522, - venue_name: "Test Venue", - venue_address: "123 Test Street", - user: @user, - start_time: 1.week.from_now, - end_time: 1.week.from_now + 3.hours, - state: :published - ) - - @ticket_type = TicketType.create!( - name: "General Admission", - description: "General admission tickets with full access to the event", - price_cents: 2500, - quantity: 100, - sale_start_at: Time.current, - sale_end_at: @event.start_time - 1.hour, - requires_id: false, - event: @event - ) - - @order = Order.create!( - user: @user, - event: @event, - status: "paid", - total_amount_cents: 2500 - ) - - @ticket = Ticket.create!( - order: @order, - ticket_type: @ticket_type, - status: "active", - first_name: "John", - last_name: "Doe", - qr_code: "test-qr-code-123" - ) - end - - test "should include customer name in PDF" do - generator = TicketPdfGenerator.new(@ticket) - pdf_string = generator.generate - - assert_not_nil pdf_string - assert_kind_of String, pdf_string - assert pdf_string.length > 0 - - # Check if it starts with PDF header - assert pdf_string.start_with?("%PDF") - - # Check that the PDF is larger than expected (indicating content was added) - # The customer name should make the PDF larger - assert pdf_string.length > 1000, "PDF should be substantial in size" - end - - test "should generate valid PDF with customer name" do - # Update ticket with name containing special characters - @ticket.update!(first_name: "José", last_name: "Martínez") - - generator = TicketPdfGenerator.new(@ticket) - pdf_string = generator.generate - - assert_not_nil pdf_string - assert_kind_of String, pdf_string - assert pdf_string.length > 0 - - # Check if it starts with PDF header - assert pdf_string.start_with?("%PDF") - - # Check that the PDF is valid - assert pdf_string.length > 1000, "PDF should be substantial in size" - assert pdf_string.end_with?("%%EOF\n"), "PDF should end with EOF marker" - end -end \ No newline at end of file