diff --git a/app/controllers/promoter/events_controller.rb b/app/controllers/promoter/events_controller.rb
index 9a8510e..31e2ada 100644
--- a/app/controllers/promoter/events_controller.rb
+++ b/app/controllers/promoter/events_controller.rb
@@ -95,7 +95,8 @@ class Promoter::EventsController < ApplicationController
# Duplicate an event and all its ticket types
def duplicate
- @new_event = @event.duplicate
+ clone_ticket_types = params[:clone_ticket_types] == "true"
+ @new_event = @event.duplicate(clone_ticket_types: clone_ticket_types)
if @new_event
redirect_to edit_promoter_event_path(@new_event), notice: "Événement dupliqué avec succès! Vous pouvez maintenant modifier les détails de l'événement copié."
diff --git a/app/models/event.rb b/app/models/event.rb
index 9fff976..44122d9 100755
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -103,7 +103,7 @@ class Event < ApplicationRecord
end
# Duplicate an event with all its ticket types
- def duplicate
+ def duplicate(clone_ticket_types: true)
# Duplicate the event
new_event = self.dup
new_event.name = "Copie de #{name}"
@@ -114,11 +114,13 @@ class Event < ApplicationRecord
Event.transaction do
if new_event.save
- # Duplicate all ticket types
- ticket_types.each do |ticket_type|
- new_ticket_type = ticket_type.dup
- new_ticket_type.event = new_event
- new_ticket_type.save!
+ # Duplicate all ticket types if requested
+ if clone_ticket_types
+ ticket_types.each do |ticket_type|
+ new_ticket_type = ticket_type.dup
+ new_ticket_type.event = new_event
+ new_ticket_type.save!
+ end
end
new_event
else
diff --git a/app/views/promoter/events/show.html.erb b/app/views/promoter/events/show.html.erb
index b6fa621..930de4d 100644
--- a/app/views/promoter/events/show.html.erb
+++ b/app/views/promoter/events/show.html.erb
@@ -1,5 +1,63 @@
<% content_for(:title, @event.name) %>
+
+
@@ -39,10 +97,58 @@
Modifier
<% end %>
- <%= button_to duplicate_promoter_event_path(@event), method: :post, class: "w-full sm:w-auto inline-flex items-center justify-center px-4 py-2 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200" do %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Dupliquer l'événement
+
+
+
+ Choisissez les options de duplication pour "<%= @event.name %>".
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<% if @event.draft? %>
<% if @event.ticket_types.blank? %>
diff --git a/test/controllers/promoter/events_controller_test.rb b/test/controllers/promoter/events_controller_test.rb
index 5731acf..512a214 100644
--- a/test/controllers/promoter/events_controller_test.rb
+++ b/test/controllers/promoter/events_controller_test.rb
@@ -56,7 +56,7 @@ class Promoter::EventsControllerTest < ActionDispatch::IntegrationTest
# Duplicate the event
assert_difference('Event.count', 1) do
- post duplicate_promoter_event_path(@event)
+ post duplicate_promoter_event_path(@event), params: { clone_ticket_types: "true" }
end
# Check that the new event was created
@@ -76,5 +76,53 @@ class Promoter::EventsControllerTest < ActionDispatch::IntegrationTest
assert_equal "VIP Ticket", new_event.ticket_types.find_by(name: "VIP Ticket").name
end
+ test "should duplicate an event without ticket types" do
+ sign_in @promoter
+
+ # Create ticket types for the event
+ ticket_type1 = TicketType.create!(
+ name: "Standard Ticket",
+ description: "A standard ticket for the event with all the basic access",
+ price_cents: 2000,
+ quantity: 100,
+ sale_start_at: 1.day.ago,
+ sale_end_at: @event.start_time - 1.hour,
+ event: @event
+ )
+
+ ticket_type2 = TicketType.create!(
+ name: "VIP Ticket",
+ description: "A VIP ticket for the event with special access",
+ price_cents: 5000,
+ quantity: 50,
+ sale_start_at: 1.day.ago,
+ sale_end_at: @event.start_time - 1.hour,
+ event: @event
+ )
+
+ # Verify that ticket types were created successfully
+ assert ticket_type1.valid?
+ assert ticket_type2.valid?
+
+ # Duplicate the event without ticket types
+ assert_difference('Event.count', 1) do
+ post duplicate_promoter_event_path(@event), params: { clone_ticket_types: "false" }
+ end
+
+ # Check that the new event was created
+ assert_redirected_to edit_promoter_event_path(Event.last)
+ assert_equal "Événement dupliqué avec succès! Vous pouvez maintenant modifier les détails de l'événement copié.", flash[:notice]
+
+ # Check that the new event has the correct attributes
+ new_event = Event.last
+ assert_equal "Copie de #{@event.name}", new_event.name
+ assert_equal "draft", new_event.state
+ assert_equal @event.venue_name, new_event.venue_name
+ assert_equal @event.venue_address, new_event.venue_address
+
+ # Check that ticket types were NOT duplicated
+ assert_equal 0, new_event.ticket_types.count
+ end
+
# Add tests for new, create, etc. as needed
end
diff --git a/test/models/event_test.rb b/test/models/event_test.rb
index 1778fbf..78f2e55 100755
--- a/test/models/event_test.rb
+++ b/test/models/event_test.rb
@@ -295,4 +295,26 @@ class EventTest < ActiveSupport::TestCase
assert_equal "Standard", duplicated_event.ticket_types.find_by(name: "Standard").name
assert_equal "VIP", duplicated_event.ticket_types.find_by(name: "VIP").name
end
+
+ test "should duplicate event without ticket types" do
+ user = User.create!(email: "test@example.com", password: "password123", password_confirmation: "password123")
+ event = Event.create!(name: "Original Event", slug: "original", description: "A description that is sufficiently long", venue_name: "v", venue_address: "a", user: user, latitude: 48.0, longitude: 2.0, start_time: 1.week.from_now, state: :published)
+
+ # Create ticket types
+ ticket_type1 = TicketType.create!(name: "Standard", description: "A standard ticket for the event", price_cents: 2000, quantity: 100, sale_start_at: 1.day.ago, sale_end_at: event.start_time - 1.hour, event: event)
+ ticket_type2 = TicketType.create!(name: "VIP", description: "A VIP ticket for the event", price_cents: 5000, quantity: 50, sale_start_at: 1.day.ago, sale_end_at: event.start_time - 1.hour, event: event)
+
+ # Duplicate the event without ticket types
+ duplicated_event = event.duplicate(clone_ticket_types: false)
+
+ # Check that duplication was successful
+ assert_not_nil duplicated_event
+ assert_equal "Copie de #{event.name}", duplicated_event.name
+ assert_equal "draft", duplicated_event.state
+ assert_equal event.venue_name, duplicated_event.venue_name
+ assert_equal event.venue_address, duplicated_event.venue_address
+
+ # Check that ticket types were NOT duplicated
+ assert_equal 0, duplicated_event.ticket_types.count
+ end
end