diff --git a/app/views/promoter/events/show.html.erb b/app/views/promoter/events/show.html.erb
index f1dc632..6596c20 100644
--- a/app/views/promoter/events/show.html.erb
+++ b/app/views/promoter/events/show.html.erb
@@ -174,9 +174,9 @@
- <% if @event.image.present? %>
+ <% if @event.image.attached? %>
-

+ <%= image_tag @event.event_image_variant(:large), alt: @event.name, class: "w-full h-full object-cover" %>
<% end %>
diff --git a/config/environments/test.rb b/config/environments/test.rb
index c2095b1..63f2c1d 100755
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -50,4 +50,11 @@ Rails.application.configure do
# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
+
+ # Configure Stripe for testing
+ config.stripe = {
+ publishable_key: "pk_test_test",
+ secret_key: "sk_test_test",
+ signing_secret: "whsec_test_test"
+ }
end
diff --git a/db/migrate/20250929222613_create_active_storage_tables.active_storage.rb b/db/migrate/20250929222613_create_active_storage_tables.active_storage.rb
new file mode 100644
index 0000000..6bd8bd0
--- /dev/null
+++ b/db/migrate/20250929222613_create_active_storage_tables.active_storage.rb
@@ -0,0 +1,57 @@
+# This migration comes from active_storage (originally 20170806125915)
+class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
+ def change
+ # Use Active Record's configured type for primary and foreign keys
+ primary_key_type, foreign_key_type = primary_and_foreign_key_types
+
+ create_table :active_storage_blobs, id: primary_key_type do |t|
+ t.string :key, null: false
+ t.string :filename, null: false
+ t.string :content_type
+ t.text :metadata
+ t.string :service_name, null: false
+ t.bigint :byte_size, null: false
+ t.string :checksum
+
+ if connection.supports_datetime_with_precision?
+ t.datetime :created_at, precision: 6, null: false
+ else
+ t.datetime :created_at, null: false
+ end
+
+ t.index [ :key ], unique: true
+ end
+
+ create_table :active_storage_attachments, id: primary_key_type do |t|
+ t.string :name, null: false
+ t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
+ t.references :blob, null: false, type: foreign_key_type
+
+ if connection.supports_datetime_with_precision?
+ t.datetime :created_at, precision: 6, null: false
+ else
+ t.datetime :created_at, null: false
+ end
+
+ t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
+ t.foreign_key :active_storage_blobs, column: :blob_id
+ end
+
+ create_table :active_storage_variant_records, id: primary_key_type do |t|
+ t.belongs_to :blob, null: false, index: false, type: foreign_key_type
+ t.string :variation_digest, null: false
+
+ t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
+ t.foreign_key :active_storage_blobs, column: :blob_id
+ end
+ end
+
+ private
+ def primary_and_foreign_key_types
+ config = Rails.configuration.generators
+ setting = config.options[config.orm][:primary_key_type]
+ primary_key_type = setting || :primary_key
+ foreign_key_type = setting || :bigint
+ [ primary_key_type, foreign_key_type ]
+ end
+end
diff --git a/db/migrate/20250929222616_add_image_to_events.rb b/db/migrate/20250929222616_add_image_to_events.rb
new file mode 100644
index 0000000..6056dca
--- /dev/null
+++ b/db/migrate/20250929222616_add_image_to_events.rb
@@ -0,0 +1,4 @@
+class AddImageToEvents < ActiveRecord::Migration[8.0]
+ def change
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ed5c678..5cc56c2 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,35 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.0].define(version: 2025_09_28_181311) do
+ActiveRecord::Schema[8.0].define(version: 2025_09_29_222616) do
+ create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
+ t.string "name", null: false
+ t.string "record_type", null: false
+ t.bigint "record_id", null: false
+ t.bigint "blob_id", null: false
+ t.datetime "created_at", null: false
+ t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
+ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
+ end
+
+ create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
+ t.string "key", null: false
+ t.string "filename", null: false
+ t.string "content_type"
+ t.text "metadata"
+ t.string "service_name", null: false
+ t.bigint "byte_size", null: false
+ t.string "checksum"
+ t.datetime "created_at", null: false
+ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
+ end
+
+ create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
+ t.bigint "blob_id", null: false
+ t.string "variation_digest", null: false
+ t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
+ end
+
create_table "events", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.string "slug", null: false
@@ -130,6 +158,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_28_181311) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
+ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
+ add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "order_promotion_codes", "orders"
add_foreign_key "order_promotion_codes", "promotion_codes"
add_foreign_key "promotion_codes", "events"
diff --git a/debug_promotion_test.rb b/debug_promotion_test.rb
new file mode 100755
index 0000000..aa4caf6
--- /dev/null
+++ b/debug_promotion_test.rb
@@ -0,0 +1,74 @@
+#!/usr/bin/env ruby
+
+# Debug script to understand the test failure
+require_relative './config/environment'
+
+# Load test data
+user = User.find_by(email: 'user1@example.com')
+event = Event.find_by(name: 'Summer Concert')
+
+puts "User: #{user.inspect}"
+puts "Event: #{event.inspect}"
+
+# Create a new order for the test
+order = user.orders.create!(event: event, status: "draft", expires_at: 15.minutes.from_now, total_amount_cents: 2000)
+puts "Order: #{order.inspect}"
+
+# Create ticket type and ticket
+ticket_type = TicketType.create!(
+ name: "Test Ticket Type",
+ description: "A valid description for the ticket type that is long enough",
+ price_cents: 2000,
+ quantity: 10,
+ sale_start_at: Time.current,
+ sale_end_at: Time.current + 1.day,
+ requires_id: false,
+ event: event
+)
+
+ticket = Ticket.create!(
+ order: order,
+ ticket_type: ticket_type,
+ status: "draft",
+ first_name: "John",
+ last_name: "Doe",
+ price_cents: 2000
+)
+
+puts "Ticket: #{ticket.inspect}"
+puts "Ticket valid?: #{ticket.valid?}"
+puts "Order tickets count: #{order.tickets.count}"
+
+# Recalculate the order total
+order.calculate_total!
+puts "Order total: #{order.total_amount_cents}"
+
+# Create a unique promotion code
+unique_code = "TESTDISCOUNT_#{SecureRandom.hex(4)}"
+puts "Creating promotion code with code: #{unique_code}"
+
+promotion_code = PromotionCode.create(
+ code: unique_code,
+ discount_amount_cents: 500,
+ expires_at: 1.month.from_now,
+ active: true,
+ user: user,
+ event: event
+)
+
+puts "Promotion code: #{promotion_code.inspect}"
+puts "Promotion code valid?: #{promotion_code.valid?}"
+
+# Check if order already has promotion codes
+puts "Order promotion codes before: #{order.promotion_codes.count}"
+
+# Try to apply the promotion code
+begin
+ order.promotion_codes << promotion_code
+ puts "Successfully added promotion code to order"
+rescue => e
+ puts "Error adding promotion code: #{e.message}"
+ puts e.backtrace.first(5)
+end
+
+puts "Order promotion codes after: #{order.promotion_codes.count}"
\ No newline at end of file
diff --git a/debug_test.rb b/debug_test.rb
new file mode 100755
index 0000000..6fa4f32
--- /dev/null
+++ b/debug_test.rb
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+
+# Debug script to understand the test failure
+require_relative './config/environment'
+
+# Load test data
+user = User.find_by(email: 'user1@example.com')
+event = Event.find_by(name: 'Summer Concert')
+order = Order.find_by(status: 'draft')
+
+puts "User: #{user.inspect}"
+puts "Event: #{event.inspect}"
+puts "Order: #{order.inspect}"
+
+# Check if the user can manage events
+puts "User can manage events: #{user.can_manage_events?}"
+
+# Create a promotion code
+promotion_code = PromotionCode.create(
+ code: "TESTDISCOUNT",
+ discount_amount_cents: 500,
+ expires_at: 1.month.from_now,
+ active: true,
+ user: user,
+ event: event
+)
+
+puts "Promotion code: #{promotion_code.inspect}"
+puts "Promotion code valid?: #{promotion_code.valid_for_use?}"
+
+# Try to create a ticket type and ticket
+ticket_type = TicketType.create!(
+ name: "Test Ticket Type",
+ description: "A valid description for the ticket type that is long enough",
+ price_cents: 2000,
+ quantity: 10,
+ sale_start_at: Time.current,
+ sale_end_at: Time.current + 1.day,
+ requires_id: false,
+ event: event
+)
+
+puts "Ticket type: #{ticket_type.inspect}"
+
+# Create ticket with all required fields
+ticket = Ticket.create!(
+ order: order,
+ ticket_type: ticket_type,
+ status: "draft",
+ first_name: "John",
+ last_name: "Doe",
+ price_cents: 2000
+)
+
+puts "Ticket: #{ticket.inspect}"
+puts "Ticket valid?: #{ticket.valid?}"
+puts "Ticket errors: #{ticket.errors.full_messages}" unless ticket.valid?
+
+# Recalculate order total
+order.calculate_total!
+puts "Order total: #{order.total_amount_cents}"
+
+# Test the promotion code application
+puts "Applying promotion code..."
+order.promotion_codes << promotion_code
+order.calculate_total!
+puts "Order total after promotion: #{order.total_amount_cents}"
\ No newline at end of file
diff --git a/test/controllers/orders_controller_promotion_test.rb b/test/controllers/orders_controller_promotion_test.rb
index fe3c958..d9d3370 100644
--- a/test/controllers/orders_controller_promotion_test.rb
+++ b/test/controllers/orders_controller_promotion_test.rb
@@ -1,4 +1,5 @@
require "test_helper"
+require "securerandom"
class OrdersControllerPromotionTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
@@ -7,7 +8,8 @@ class OrdersControllerPromotionTest < ActionDispatch::IntegrationTest
def setup
@user = users(:one)
@event = events(:concert_event)
- @order = orders(:draft_order)
+ # Create a new order for the test to ensure proper associations
+ @order = @user.orders.create!(event: @event, status: "draft", expires_at: 15.minutes.from_now, total_amount_cents: 2000)
sign_in @user
end
@@ -25,19 +27,27 @@ class OrdersControllerPromotionTest < ActionDispatch::IntegrationTest
event: @event
)
- Ticket.create!(
+ ticket = Ticket.create!(
order: @order,
ticket_type: ticket_type,
status: "draft",
first_name: "John",
- last_name: "Doe"
+ last_name: "Doe",
+ price_cents: 2000
)
+ # Debug the ticket creation
+ puts "Ticket saved: #{ticket.persisted?}"
+ puts "Ticket errors: #{ticket.errors.full_messages}" unless ticket.valid?
+ puts "Order tickets count: #{@order.tickets.count}"
+
# Recalculate the order total
@order.calculate_total!
+ # Use a unique code for each test run
+ unique_code = "TESTDISCOUNT_#{SecureRandom.hex(4)}"
promotion_code = PromotionCode.create(
- code: "TESTDISCOUNT",
+ code: unique_code,
discount_amount_cents: 500, # €5.00
expires_at: 1.month.from_now,
active: true,
@@ -45,7 +55,9 @@ class OrdersControllerPromotionTest < ActionDispatch::IntegrationTest
event: @event
)
- get checkout_order_path(@order), params: { promotion_code: "TESTDISCOUNT" }
+ get checkout_order_path(@order), params: { promotion_code: unique_code }
+ puts "Response status: #{response.status}"
+ puts "Response body: #{response.body}" if response.status != 200
assert_response :success
assert_not_nil flash.now[:notice]
assert_match /Code promotionnel appliqué: TESTDISCOUNT/, flash.now[:notice]
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
index 18b375a..d3edc98 100755
--- a/test/fixtures/users.yml
+++ b/test/fixtures/users.yml
@@ -5,6 +5,7 @@ one:
encrypted_password: <%= Devise::Encryptor.digest(User, 'password123') %>
last_name: Trump
first_name: Donald
+ is_professionnal: true
onboarding_completed: true
two:
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 07293c9..b7c4747 100755
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -19,6 +19,14 @@ module ActiveSupport
# Add more helper methods to be used by all tests here...
+ # Mock Stripe for tests
+ setup do
+ # Mock Stripe checkout session creation
+ Stripe::Checkout::Session.stubs(:create).returns(
+ Struct.new(:id, :url).new("cs_test_session", "https://checkout.stripe.com/test")
+ )
+ end
+
# Helper to create users with completed onboarding by default for tests
def create_test_user(attributes = {})
User.create!({