File tree 2 files changed +38
-1
lines changed
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ def initialize &block
32
32
yield configuration
33
33
post_configure
34
34
prepare_database
35
- prepare_app
36
35
end
37
36
38
37
# Allows middleware to be inserted at the bottom of the shared middlware stack
@@ -54,12 +53,18 @@ def use_ui_auth middleware
54
53
@make_it_later_ui_auth . make_it_later ( middleware )
55
54
end
56
55
56
+ def use_custom_ui custom_ui
57
+ @custom_ui = custom_ui
58
+ end
59
+
57
60
def call env
58
61
running_app . call env
59
62
end
60
63
61
64
private
62
65
66
+ attr_reader :custom_ui
67
+
63
68
def post_configure
64
69
configure_logger
65
70
SuckerPunch . logger = configuration . custom_logger || SemanticLogger [ 'SuckerPunch' ]
@@ -101,6 +106,7 @@ def prepare_app
101
106
configure_middleware
102
107
103
108
# need this first so UI login logic is performed before API login logic
109
+ @cascade_apps << build_custom_ui if custom_ui
104
110
@cascade_apps << build_ui
105
111
106
112
if configuration . enable_diagnostic_endpoints
@@ -139,6 +145,14 @@ def build_ui
139
145
builder
140
146
end
141
147
148
+ def build_custom_ui
149
+ logger . info "Mounting Custom UI"
150
+ builder = ::Rack ::Builder . new
151
+ builder . use Rack ::PactBroker ::AcceptsHtmlFilter
152
+ builder . run @custom_ui
153
+ builder
154
+ end
155
+
142
156
def build_api
143
157
logger . info "Mounting PactBroker::API"
144
158
require 'pact_broker/api'
@@ -174,6 +188,7 @@ def configure_logger
174
188
175
189
def running_app
176
190
@running_app ||= begin
191
+ prepare_app
177
192
apps = @cascade_apps
178
193
@app_builder . map "/" do
179
194
run Rack ::Cascade . new ( apps )
Original file line number Diff line number Diff line change @@ -65,6 +65,28 @@ def self.calls
65
65
end
66
66
end
67
67
68
+ describe "use_custom_ui" do
69
+ context "when the UI returns a non 404 response" do
70
+ let ( :custom_ui ) { double ( 'ui' , call : [ 200 , { } , [ "hello" ] ] ) }
71
+
72
+ it "returns the given page" do
73
+ app . use_custom_ui ( custom_ui )
74
+
75
+ get "/" , nil , { "HTTP_ACCEPT" => "text/html" }
76
+ expect ( last_response . body ) . to eq "hello"
77
+ end
78
+ end
79
+
80
+ context "when the UI returns a 404 response" do
81
+ let ( :custom_ui ) { double ( 'ui' , call : [ 404 , { } , [ ] ] ) }
82
+
83
+ it "passes on the call to the rest of the app" do
84
+ get "/" , nil , { "HTTP_ACCEPT" => "text/html" }
85
+ expect ( last_response . status ) . to eq 200
86
+ end
87
+ end
88
+ end
89
+
68
90
describe "use_xxx_auth" do
69
91
class TestAuth
70
92
def initialize app , *args , &block
You can’t perform that action at this time.
0 commit comments