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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b90ce3d4469b84001c3943b782e42fd6cfdf1b95
4
- data.tar.gz: e892a1627ab29669d3f66c7d1148d8a2dd7b38a7
3
+ metadata.gz: d69556f8e5237a6c112f20962f608f174f37cbc7
4
+ data.tar.gz: 999a724ac87d3ccbcd19606066e522cf12209c79
5
5
  SHA512:
6
- metadata.gz: 8efd253601337c233e0bb5a4cd94edf3c141f96567db1f9688eda0093784c58fd4209db6b3d8e4618f83b29dffac428c38ed0d64a12bfedb39d020ec9ceaa767
7
- data.tar.gz: 384ba41ad591820698b6cd81bfcde02d76bd0b2165772ea14ac2c87a15f3fd317b93b645d4d7eda24f380086ac16f0e85dcb59b5adc383e6714a1c304c2dbb6f
6
+ metadata.gz: fabc1c0a66b0002846f37e7bd8a4f13dfa9d29d323a6d714b930e3d23366cd8125bdbeed92467156c4c06831d4dbd92b1600cf2131c0b0c0a1ee706db2f6750c
7
+ data.tar.gz: 4fe3ed51cb51b1a32a1203172f212aaa56f07a945178d2a20cbb8f32630474d9420977ae540cae0b20a84dfedf52f9a06eda239ede7ba69290c2e00ba8872dd5
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.0
5
+ - 2.2.0
6
+ script: bundle exec rspec spec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action-segue (0.0.1)
4
+ action-segue (1.0.1)
5
5
  railties (>= 4.2.0, < 5)
6
6
 
7
7
  GEM
data/action-segue.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "action-segue"
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
  s.authors = ["Damien Timewell"]
7
7
  s.email = ["mail@damientimewell.com"]
8
8
  s.licenses = ['MIT']
@@ -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 segue = session[:action_segues].delete(id)
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
- it "should store the segue on the first page" do
10
- get :segue_start_page
11
- expect(session[:action_segues][:named_segue].params).to eq({ "controller" => "named_segues", "action" => "segue_start_page" })
12
- end
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
- it "should redirect to the segue entry point" do
15
- get :segue_start_page
16
- get :normal_page
17
- get :segue_complete_page
18
- expect(response).to redirect_to(segue_start_page_named_segue_path)
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
- it "should remove the segue from the stack after it is completed" do
22
- get :segue_start_page
23
- get :normal_page
24
- get :segue_complete_page
25
- expect(session[:action_segues]).to eq({})
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
- it "should be possible to remove the segue" do
29
- get :segue_start_page
30
- get :segue_clear_page
31
- get :segue_complete_page
32
- expect(response).to redirect_to(normal_page_named_segue_path)
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
@@ -6,7 +6,6 @@ ActionSegue.load_action_segue
6
6
 
7
7
  require "rspec/rails"
8
8
  require "fixtures/fake_application"
9
- require "fixtures/controllers"
10
9
 
11
10
  Rails.logger = Logger.new(STDOUT)
12
11
  Rails.logger.level = Logger::ERROR
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.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-07 00:00:00.000000000 Z
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