fix: Moving out from french for dev

This commit is contained in:
kbe
2025-09-05 23:13:01 +02:00
parent 7009245ab0
commit 974edce238
4 changed files with 10 additions and 99 deletions

View File

@@ -48,6 +48,7 @@ class TicketsController < ApplicationController
end end
end end
# Display ticket details
def show def show
@ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by( @ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by(
tickets: { id: params[:ticket_id] }, tickets: { id: params[:ticket_id] },
@@ -59,23 +60,25 @@ class TicketsController < ApplicationController
end end
# Download PDF ticket - only accessible by ticket owner # 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 def download_ticket
# Find ticket and ensure it belongs to current user # Find ticket and ensure it belongs to current user
@ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by( @ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by(
tickets: { id: params[:ticket_id] }, tickets: { id: params[:ticket_id] },
orders: { user_id: current_user.id } orders: { user_id: current_user.id }
) )
if @ticket.nil? if @ticket.nil?
redirect_to dashboard_path, alert: "Billet non trouvé ou vous n'avez pas l'autorisation d'accéder à ce billet" redirect_to dashboard_path, alert: "Billet non trouvé ou vous n'avez pas l'autorisation d'accéder à ce billet"
return return
end end
# Generate PDF # Generate PDF
pdf_content = @ticket.to_pdf pdf_content = @ticket.to_pdf
# Send PDF as download # Send PDF as download
send_data pdf_content, send_data pdf_content,
filename: "ticket_#{@ticket.id}_#{@ticket.event.name.parameterize}.pdf", filename: "ticket_#{@ticket.id}_#{@ticket.event.name.parameterize}.pdf",
type: "application/pdf", type: "application/pdf",
disposition: "attachment" disposition: "attachment"

View File

@@ -25,6 +25,6 @@ module Aperonight
# config.eager_load_paths << Rails.root.join("extras") # config.eager_load_paths << Rails.root.join("extras")
config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}")] config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}")]
config.i18n.default_locale = :fr # config.i18n.default_locale = :fr
end end
end end

View File

@@ -39,8 +39,8 @@ Rails.application.routes.draw do
get "events/:slug.:id", to: "events#show", as: "event" get "events/:slug.:id", to: "events#show", as: "event"
# === Orders (scoped to events) === # === Orders (scoped to events) ===
get "events/:slug.:id/orders/new", to: "orders#new", as: "event_order_new" get "orders/new/events/:slug.:id", to: "orders#new", as: "event_order_new"
post "events/:slug.:id/orders", to: "orders#create", as: "event_order_create" post "orders/create/events/:slug.:id", to: "orders#create", as: "event_order_create"
resources :orders, only: [ :show ] do resources :orders, only: [ :show ] do
member do member do

View File

@@ -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