action-segue 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile.lock +1 -1
- data/action-segue.gemspec +1 -1
- data/lib/action_segue/segue_registration.rb +3 -2
- data/spec/action_segue/integration_spec.rb +49 -19
- data/spec/fixtures/fake_application.rb +35 -1
- data/spec/spec_helper.rb +0 -1
- metadata +3 -4
- data/spec/fixtures/controllers.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69556f8e5237a6c112f20962f608f174f37cbc7
|
4
|
+
data.tar.gz: 999a724ac87d3ccbcd19606066e522cf12209c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fabc1c0a66b0002846f37e7bd8a4f13dfa9d29d323a6d714b930e3d23366cd8125bdbeed92467156c4c06831d4dbd92b1600cf2131c0b0c0a1ee706db2f6750c
|
7
|
+
data.tar.gz: 4fe3ed51cb51b1a32a1203172f212aaa56f07a945178d2a20cbb8f32630474d9420977ae540cae0b20a84dfedf52f9a06eda239ede7ba69290c2e00ba8872dd5
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/action-segue.gemspec
CHANGED
@@ -15,7 +15,8 @@ module ActionSegue
|
|
15
15
|
# Completes the segue named ++id++ and redirects back to the start point, or
|
16
16
|
# fallback url.
|
17
17
|
def complete_segue_with_redirect(id, or_redirect_to:)
|
18
|
-
if
|
18
|
+
if session[:action_segues].present? && session[:action_segues][id].present?
|
19
|
+
segue = session[:action_segues].delete(id)
|
19
20
|
Rails.logger.debug "[ActionSegue] completed '#{id}'. Redirecting to #{or_redirect_to}"
|
20
21
|
redirect_to url_for(segue.params)
|
21
22
|
else
|
@@ -33,7 +34,7 @@ module ActionSegue
|
|
33
34
|
# Completes the last segue, regardless of what it was, or redirects to the fallback
|
34
35
|
# if no segues are in progress.
|
35
36
|
def complete_current_segue_with_redirect(or_redirect_to:)
|
36
|
-
complete_segue_with_redirect session[:action_segues].keys.last, or_redirect_to: or_redirect_to
|
37
|
+
complete_segue_with_redirect session[:action_segues].try(:keys).try(:last), or_redirect_to: or_redirect_to
|
37
38
|
end
|
38
39
|
|
39
40
|
end
|
@@ -6,30 +6,60 @@ describe NamedSeguesController, type: :controller do
|
|
6
6
|
session[:action_segues] = nil
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
describe "selecting a particular segue" do
|
10
|
+
it "should store the segue on the first page" do
|
11
|
+
get :segue_start_page
|
12
|
+
expect(session[:action_segues][:named_segue].params).to eq({ "controller" => "named_segues", "action" => "segue_start_page" })
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should redirect to the segue entry point" do
|
16
|
+
get :segue_start_page
|
17
|
+
get :normal_page
|
18
|
+
get :segue_complete_page
|
19
|
+
expect(response).to redirect_to(segue_start_page_named_segue_path)
|
20
|
+
end
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
it "should redirect to the fallback if the segue doesn't exist" do
|
23
|
+
get :second_segue_start_page
|
24
|
+
get :segue_complete_page
|
25
|
+
expect(response).to redirect_to(normal_page_named_segue_path)
|
26
|
+
end
|
19
27
|
end
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
describe "completing any segue" do
|
30
|
+
it "should complete the most resent segue in the stack" do
|
31
|
+
get :segue_start_page
|
32
|
+
get :second_segue_start_page
|
33
|
+
get :segue_complete_last_page
|
34
|
+
expect(response).to redirect_to(second_segue_start_page_named_segue_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should remove the segue after it is completed" do
|
38
|
+
get :second_segue_start_page
|
39
|
+
get :segue_complete_last_page
|
40
|
+
expect(session[:action_segues]).to eq({})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should redirect to the fallback if the stack is empty" do
|
44
|
+
get :segue_complete_last_page
|
45
|
+
expect(response).to redirect_to(normal_page_named_segue_path)
|
46
|
+
end
|
26
47
|
end
|
27
48
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
49
|
+
describe "cleaning up" do
|
50
|
+
it "should remove the segue from the stack after it is completed" do
|
51
|
+
get :segue_start_page
|
52
|
+
get :normal_page
|
53
|
+
get :segue_complete_page
|
54
|
+
expect(session[:action_segues]).to eq({})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be possible to remove the segue" do
|
58
|
+
get :segue_start_page
|
59
|
+
get :segue_clear_page
|
60
|
+
get :segue_complete_page
|
61
|
+
expect(response).to redirect_to(normal_page_named_segue_path)
|
62
|
+
end
|
33
63
|
end
|
34
64
|
|
35
65
|
end
|
@@ -7,7 +7,8 @@ module Rails
|
|
7
7
|
@routes.draw do
|
8
8
|
resource :named_segue, only: [] do
|
9
9
|
collection do
|
10
|
-
get :segue_start_page, :normal_page, :segue_complete_page, :segue_clear_page
|
10
|
+
get :segue_start_page, :normal_page, :segue_complete_page, :segue_clear_page,
|
11
|
+
:second_segue_start_page, :segue_complete_last_page
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -18,3 +19,36 @@ module Rails
|
|
18
19
|
@app ||= App.new
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
class NamedSeguesController < ActionController::Base
|
24
|
+
include Rails.application.routes.url_helpers
|
25
|
+
|
26
|
+
register_segue action: :segue_start_page, as: :named_segue
|
27
|
+
register_segue action: :second_segue_start_page, as: :another_segue
|
28
|
+
|
29
|
+
def segue_start_page
|
30
|
+
render text: "Start page"
|
31
|
+
end
|
32
|
+
|
33
|
+
def normal_page
|
34
|
+
render text: "Normal page"
|
35
|
+
end
|
36
|
+
|
37
|
+
def segue_complete_page
|
38
|
+
complete_segue_with_redirect :named_segue, or_redirect_to: { action: :normal_page }
|
39
|
+
end
|
40
|
+
|
41
|
+
def segue_clear_page
|
42
|
+
clear_segue :named_segue
|
43
|
+
render text: "Clear page"
|
44
|
+
end
|
45
|
+
|
46
|
+
def second_segue_start_page
|
47
|
+
render text: "Second start page"
|
48
|
+
end
|
49
|
+
|
50
|
+
def segue_complete_last_page
|
51
|
+
complete_current_segue_with_redirect or_redirect_to: { action: :normal_page }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-segue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- ".editorconfig"
|
83
83
|
- ".gitignore"
|
84
84
|
- ".rspec"
|
85
|
+
- ".travis.yml"
|
85
86
|
- Gemfile
|
86
87
|
- Gemfile.lock
|
87
88
|
- README.md
|
@@ -91,7 +92,6 @@ files:
|
|
91
92
|
- lib/action_segue/segue.rb
|
92
93
|
- lib/action_segue/segue_registration.rb
|
93
94
|
- spec/action_segue/integration_spec.rb
|
94
|
-
- spec/fixtures/controllers.rb
|
95
95
|
- spec/fixtures/fake_application.rb
|
96
96
|
- spec/spec_helper.rb
|
97
97
|
homepage: https://github.com/iZettle/action-segue
|
@@ -120,6 +120,5 @@ specification_version: 4
|
|
120
120
|
summary: Control Rails redirect flows with smarter redirect logic
|
121
121
|
test_files:
|
122
122
|
- spec/action_segue/integration_spec.rb
|
123
|
-
- spec/fixtures/controllers.rb
|
124
123
|
- spec/fixtures/fake_application.rb
|
125
124
|
- spec/spec_helper.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class NamedSeguesController < ActionController::Base
|
2
|
-
include Rails.application.routes.url_helpers
|
3
|
-
|
4
|
-
register_segue action: :segue_start_page, as: :named_segue
|
5
|
-
|
6
|
-
def segue_start_page
|
7
|
-
render text: "Start page"
|
8
|
-
end
|
9
|
-
|
10
|
-
def normal_page
|
11
|
-
render text: "Normal page"
|
12
|
-
end
|
13
|
-
|
14
|
-
def segue_complete_page
|
15
|
-
complete_segue_with_redirect :named_segue, or_redirect_to: { action: :normal_page }
|
16
|
-
end
|
17
|
-
|
18
|
-
def segue_clear_page
|
19
|
-
clear_segue :named_segue
|
20
|
-
render text: "Clear page"
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|