Skip to content

Commit ae16087

Browse files
Merge pull request #60 from zachasme/configurable-base-controller
Make base controller class configurable
2 parents 5226fec + ae7dd88 commit ae16087

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

app/controllers/litestream/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Litestream
2-
class ApplicationController < ActionController::Base
2+
class ApplicationController < Litestream.base_controller_class.constantize
33
protect_from_forgery with: :exception
44

55
if Litestream.password

lib/litestream.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def initialize
3535

3636
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command,
3737
:config_path
38+
mattr_accessor :base_controller_class, default: "::ApplicationController"
3839

3940
class << self
4041
def verify!(database_path)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class MyApplicationController < ApplicationController
2+
end

test/dummy/config/environments/test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@
6161

6262
# Raise error when a before_action's only/except options reference missing actions
6363
config.action_controller.raise_on_missing_callback_actions = true
64+
65+
config.litestream.base_controller_class = "MyApplicationController"
6466
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "test_helper"
2+
3+
class Litestream::BaseApplicationControllerTest < ActiveSupport::TestCase
4+
test "engine's ApplicationController inherits from host's ApplicationController by default" do
5+
assert Litestream::ApplicationController < ApplicationController
6+
end
7+
8+
test "engine's ApplicationController inherits from configured base_controller_class" do
9+
assert Litestream::ApplicationController < MyApplicationController
10+
end
11+
end

0 commit comments

Comments
 (0)