mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-22 03:38:03 +00:00
- Update migration to support both PostgreSQL (jsonb) and SQLite (json) - Fix Rails 8 compatibility (remove config.assets) - Configure Pundit to use current_player instead of current_user - Add explicit fixture class mappings for engine fixtures - Configure standalone mode for tests - Update test fixtures with proper timestamps and structure - Improve game test to create data programmatically Tests now run with 10/12 assertions passing. Remaining errors are due to missing test scenario files, which can be addressed separately.
36 lines
994 B
Ruby
36 lines
994 B
Ruby
module BreakEscape
|
|
class ApplicationController < ActionController::Base
|
|
protect_from_forgery with: :exception
|
|
|
|
# Include Pundit if available
|
|
include Pundit::Authorization if defined?(Pundit)
|
|
|
|
# Helper method to get current player (polymorphic)
|
|
def current_player
|
|
if BreakEscape.standalone_mode?
|
|
# Standalone mode - get/create demo user
|
|
@current_player ||= DemoUser.first_or_create!(handle: 'demo_player')
|
|
else
|
|
# Mounted mode - use Hacktivity's current_user
|
|
current_user
|
|
end
|
|
end
|
|
helper_method :current_player
|
|
|
|
# Tell Pundit to use current_player as the user for authorization
|
|
def pundit_user
|
|
current_player
|
|
end
|
|
|
|
# Handle authorization errors
|
|
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
|
|
|
private
|
|
|
|
def user_not_authorized
|
|
flash[:alert] = "You are not authorized to perform this action."
|
|
redirect_to(request.referrer || root_path)
|
|
end
|
|
end
|
|
end
|