Skip to content

Commit 59197f2

Browse files
committed
refactored turbolinks spec in order to show turbolinks issues
1 parent fdc44ee commit 59197f2

File tree

1 file changed

+123
-20
lines changed

1 file changed

+123
-20
lines changed
Lines changed: 123 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,145 @@
11
describe "Turbolinks integration", type: :feature, js: true do
2-
before(:all) do
3-
FileUtils.cp('spec/usage/application_with_turbolinks.js', 'spec/dummy/app/assets/javascripts/application.js')
4-
end
52

6-
before do
7-
Rails.application.routes.draw do
8-
get '/turbolinks', to: 'turbolinks#my_action', as: 'turbolinks_test_action'
3+
class TestController < ActionController::Base
4+
5+
before_action :check_params
6+
7+
def check_params
8+
expect_params(params.permit!.to_h)
99
end
1010

11-
class TurbolinksController < ActionController::Base
12-
layout "application"
11+
def expect_params(params)
12+
end
1313

14-
include Matestack::Ui::Core::ApplicationHelper
14+
end
15+
16+
it "Matestack can be used with turbolinks" do
1517

16-
def my_action
18+
module Apps
19+
end
20+
21+
class Apps::TurbolinksTest < Matestack::Ui::App
22+
def response
23+
components {
24+
nav do
25+
link path: :turbolinks1_path do
26+
button text: "Link to Page 1"
27+
end
28+
transition path: :turbolinks2_path do
29+
button text: "Transition to Page 2"
30+
end
31+
link path: :turbolinks3_path do
32+
button text: "Link to Page 3"
33+
end
34+
end
35+
main do
36+
page_content
37+
end
38+
}
1739
end
1840
end
1941

20-
module Pages::Turbolinks
42+
module Pages::TurbolinksTest
2143
end
2244

23-
class Pages::Turbolinks::MyAction < Matestack::Ui::Page
45+
class Pages::TurbolinksTest::Page1 < Matestack::Ui::Page
2446
def response
2547
components {
26-
plain "Hello from matestack with turbolinks"
48+
plain "Hello from matestack with turbolinks - Page 1"
2749
}
2850
end
2951
end
30-
end
52+
class Pages::TurbolinksTest::Page2 < Matestack::Ui::Page
53+
def response
54+
components {
55+
plain "Hello from matestack with turbolinks - Page 2"
56+
}
57+
end
58+
end
59+
class Pages::TurbolinksTest::Page3 < Matestack::Ui::Page
60+
def response
61+
components {
62+
plain "Hello from matestack with turbolinks - Page 3"
63+
action action_config do
64+
button text: "click me"
65+
end
66+
}
67+
end
3168

32-
after do
33-
FileUtils.cp('spec/usage/application.js', 'spec/dummy/app/assets/javascripts/application.js')
69+
def action_config
70+
return {
71+
method: :post,
72+
path: :action_test_path,
73+
data: {
74+
foo: "bar"
75+
}
76+
}
77+
end
78+
end
79+
80+
Rails.application.routes.append do
81+
get '/turbolinks1', to: 'turbolinks_test#page1', as: :turbolinks1
82+
get '/turbolinks2', to: 'turbolinks_test#page2', as: :turbolinks2
83+
get '/turbolinks3', to: 'turbolinks_test#page3', as: :turbolinks3
84+
post '/action_test', to: 'action_test#test'
85+
end
3486
Rails.application.reload_routes!
35-
end
3687

37-
specify "Matestack can be used with turbolinks" do
38-
visit "/turbolinks"
88+
class TurbolinksTestController < ActionController::Base
89+
layout "application_with_turbolinks"
90+
91+
include Matestack::Ui::Core::ApplicationHelper
92+
93+
def page1
94+
responder_for(Pages::TurbolinksTest::Page1)
95+
end
96+
def page2
97+
responder_for(Pages::TurbolinksTest::Page2)
98+
end
99+
def page3
100+
responder_for(Pages::TurbolinksTest::Page3)
101+
end
102+
end
103+
104+
class ActionTestController < TestController
105+
106+
def test
107+
render json: {}, status: 200
108+
end
109+
110+
end
111+
allow_any_instance_of(ActionTestController).to receive(:expect_params)
112+
113+
114+
visit "/turbolinks1"
115+
116+
expect(page).to have_text "Hello from matestack with turbolinks - Page 1"
117+
118+
click_button "Transition to Page 2"
119+
120+
expect(page).to have_text "Hello from matestack with turbolinks - Page 2"
121+
122+
click_button "Link to Page 1"
123+
124+
expect(page).to have_text "Hello from matestack with turbolinks - Page 1"
125+
126+
click_button "Transition to Page 2"
127+
128+
expect(page).to have_text "Hello from matestack with turbolinks - Page 2"
129+
130+
click_button "Link to Page 1"
131+
132+
expect(page).to have_text "Hello from matestack with turbolinks - Page 1"
133+
134+
visit "/turbolinks3"
135+
136+
expect(page).to have_text "Hello from matestack with turbolinks - Page 3"
137+
138+
expect_any_instance_of(ActionTestController).to receive(:expect_params)
139+
.with(hash_including(:foo => "bar"))
140+
141+
click_button "click me"
39142

40-
expect(page).to have_text "Hello from matestack without turbolinks"
143+
expect(page).to have_text "Hello from matestack with turbolinks - Page 3"
41144
end
42145
end

0 commit comments

Comments
 (0)