diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 15a4b17..8343f65 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ # Copyright (C) 2024 Manuel Bustillo class ApplicationController < ActionController::Base + set_current_tenant_through_filter before_action :set_tenant before_action :authenticate_user! after_action :set_csrf_cookie @@ -47,7 +48,7 @@ class ApplicationController < ActionController::Base end def set_tenant - ActsAsTenant.current_tenant = Wedding.find_by(slug: params[:slug]) + set_current_tenant(Wedding.find_by!(slug: params[:slug])) end def development_swagger? diff --git a/config/initializers/acts_as_tenant.rb b/config/initializers/acts_as_tenant.rb new file mode 100644 index 0000000..c535737 --- /dev/null +++ b/config/initializers/acts_as_tenant.rb @@ -0,0 +1,5 @@ +# Copyright (C) 2024 Manuel Bustillo + +ActsAsTenant.configure do |config| + config.require_tenant = !Rails.env.test? +end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index e493f6b..9d93073 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,12 +2,15 @@ NUMBER_OF_GUESTS = 50 -TablesArrangement.delete_all -Expense.delete_all -Guest.delete_all -Group.delete_all +ActsAsTenant.without_tenant do + TablesArrangement.delete_all + Expense.delete_all + Guest.delete_all + Group.delete_all + + Wedding.delete_all +end -Wedding.delete_all wedding = Wedding.create!(slug: :default, date: 1.year.from_now) ActsAsTenant.with_tenant(wedding) do