Skip to content

Commit 9fa2a8f

Browse files
committed
made changes to allow changing layouts to test turbolinks
1 parent 5345896 commit 9fa2a8f

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

app/helpers/matestack/ui/core/application_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def responder_for(page_class, options = {})
2626
end
2727
if params[:only_page]
2828
render html: render_page(page_class, true)
29+
elsif params[:layout]
30+
render html: render_page(page_class), layout: params[:layout]
2931
else
3032
render html: render_page(page_class), layout: true
3133
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This is a manifest file that'll be compiled into application.js, which will include all the files
2+
// listed below.
3+
//
4+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6+
//
7+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
9+
//
10+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11+
// about supported directives.
12+
//
13+
//= require rails-ujs
14+
//= require activestorage
15+
//= require turbolinks
16+
//= require matestack-ui-core
17+
//= require_tree .
18+
19+
//= require demo/component
20+
21+
App.cable.subscriptions.create("MatestackUiCoreChannel", {
22+
received(data) {
23+
MatestackUiCore.matestackEventHub.$emit('MatestackUiCoreChannel', data)
24+
}
25+
});

spec/dummy/app/controllers/example_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ def page
55
responder_for(ExamplePage)
66
end
77

8+
def turbolinks
9+
responder_for(ExamplePage, {options: 'turbolinks'})
10+
end
11+
812
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dummy</title>
5+
<%= csrf_meta_tags %>
6+
<%= csp_meta_tag %>
7+
8+
<%= stylesheet_link_tag 'application', media: 'all' %>
9+
<%= javascript_include_tag 'application_with_turbolinks' %>
10+
</head>
11+
12+
<body>
13+
<div id="matestack_ui">
14+
<%= yield %>
15+
</div>
16+
</body>
17+
</html>

spec/dummy/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
end
1919

2020
get '/example', to: 'example#page'
21+
get '/example_turbolinks', to: 'example#turbolinks'
2122

2223
scope :my_app do
2324
get 'my_first_page', to: 'my_app#my_first_page'

spec/usage/base/turbolinks_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
describe "Turbolinks", type: :feature, js: true do
2+
describe "when turbolinks is enabled" do
3+
it "enables the main Vue component on turbolinks:ready" do
4+
class ExamplePage < Matestack::Ui::Page
5+
def response
6+
components {
7+
heading text: "Hello world"
8+
}
9+
end
10+
end
11+
12+
visit "/example_turbolinks"
13+
14+
static_output = page.html
15+
expect(static_output).to include("<h1></h1>")
16+
end
17+
end
18+
19+
describe "when turbolinks is not enabled" do
20+
it "enables the main Vue component on page load" do
21+
class ExamplePage < Matestack::Ui::Page
22+
def response
23+
components {
24+
heading text: XSS::EVIL_SCRIPT
25+
}
26+
end
27+
end
28+
29+
visit "/example"
30+
31+
static_output = page.html
32+
expect(static_output).to include("<h1></h1>")
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)