jump_back 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jump_back/engine.rb +1 -0
  3. data/lib/jump_back/link_back.rb +31 -0
  4. data/lib/jump_back/options_parser.rb +17 -10
  5. data/lib/jump_back/path_finder.rb +36 -0
  6. data/lib/jump_back/redirect_back.rb +2 -6
  7. data/lib/jump_back/return_to_referer.rb +2 -2
  8. data/lib/jump_back/urls.rb +28 -0
  9. data/lib/jump_back/version.rb +1 -1
  10. data/lib/jump_back.rb +3 -0
  11. data/spec/controller/application_controller_spec.rb +4 -19
  12. data/spec/controller/tests_controller_spec.rb +85 -85
  13. data/spec/dummy/app/controllers/tests_controller.rb +12 -12
  14. data/spec/dummy/app/views/tests/blank.html.erb +10 -0
  15. data/spec/dummy/app/views/tests/clear_and_save.html.erb +17 -0
  16. data/spec/dummy/app/views/tests/save.html.erb +10 -0
  17. data/spec/dummy/config/routes.rb +11 -59
  18. data/spec/dummy/db/test.sqlite3 +0 -0
  19. data/spec/dummy/log/development.log +4 -104
  20. data/spec/dummy/log/test.log +275 -18408
  21. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  22. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  23. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  24. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  25. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  26. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  27. data/spec/features/controller_methods_spec.rb +38 -0
  28. data/spec/features/view_helpers_spec.rb +87 -0
  29. metadata +15 -14
  30. data/lib/jump_back/redirection_determiner.rb +0 -14
  31. data/lib/jump_back/referer_interpreter.rb +0 -34
  32. data/spec/dummy/app/views/tests/edit.html.erb +0 -3
  33. data/spec/dummy/app/views/tests/index.html.erb +0 -6
  34. data/spec/dummy/app/views/tests/new.html.erb +0 -6
  35. data/spec/dummy/db/development.sqlite3 +0 -0
  36. data/spec/features/jump_back_feature_spec.rb +0 -38
@@ -0,0 +1,38 @@
1
+ feature 'controller methods' do
2
+ describe 'redirect_back' do
3
+ it 'redirects back' do
4
+ visit save_path
5
+ click_button 'Post to redirect_with_options'
6
+ expect(current_path).to eq(save_path)
7
+ end
8
+ end
9
+
10
+ describe 'return_to_referer' do
11
+ it 'returns to saved referer' do
12
+ visit clear_and_save_path
13
+ click_link 'Go to save page'
14
+ visit blank_path
15
+ click_button 'Put to return_with_options'
16
+ expect(current_path).to eq(clear_and_save_path)
17
+ end
18
+
19
+ it 'doesn\'t reset referer if not cleared' do
20
+ visit clear_and_save_path
21
+ click_link 'Go to save page'
22
+ visit blank_path
23
+ click_link 'Go to save page'
24
+ visit blank_path
25
+ click_button 'Put to return_with_options'
26
+ expect(current_path).to eq(clear_and_save_path)
27
+ end
28
+
29
+ it 'resets referer if cleared' do
30
+ visit clear_and_save_path
31
+ click_link 'Go to save page'
32
+ click_link 'Go to edit page'
33
+ visit blank_path
34
+ click_button 'Put to return_with_options'
35
+ expect(current_path).to eq(save_path)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,87 @@
1
+ feature 'view helpers' do
2
+
3
+ describe 'link_back' do
4
+
5
+ it 'creates a link back to referer' do
6
+ visit clear_and_save_path
7
+ click_link 'Go to save page'
8
+ click_link 'back'
9
+ expect(current_path).to eq(clear_and_save_path)
10
+ end
11
+
12
+ it 'links to default with no referer' do
13
+ visit save_path
14
+ click_link 'back'
15
+ expect(current_path).to eq(root_path)
16
+ end
17
+
18
+ it 'links to provided path with no referer' do
19
+ visit blank_path
20
+ click_link 'back'
21
+ expect(current_path).to eq(clear_and_save_path)
22
+ end
23
+
24
+ it 'ignores provided path if referer exists' do
25
+ visit save_path
26
+ click_link 'Go to blank page'
27
+ click_link 'back'
28
+ expect(current_path).to eq(save_path)
29
+ end
30
+
31
+ describe 'arguments' do
32
+
33
+ it 'accepts a name argument' do
34
+ visit clear_and_save_path
35
+ expect(page).to have_link('Go back from whence you came!')
36
+ end
37
+
38
+ it 'accepts both name and path arguments' do
39
+ visit blank_path
40
+ click_link 'A back link'
41
+ expect(current_path).to eq(save_path)
42
+ end
43
+
44
+ it 'accepts additional link_to options' do
45
+ visit clear_and_save_path
46
+ expect(page).to have_css('a.red', text: 'back')
47
+ end
48
+
49
+ it 'accepts additional link_to options with a name but no path' do
50
+ visit clear_and_save_path
51
+ expect(page).to have_css('a#just-name[data-remote=true]', text: 'Just a name!')
52
+ end
53
+
54
+ it 'accepts additional link_to options with a path but no name' do
55
+ visit clear_and_save_path
56
+ expect(page).to have_css('a[href="/tests/save"][data-method=put]', text: 'back')
57
+ end
58
+
59
+ it 'accepts all three arguments' do
60
+ visit clear_and_save_path
61
+ expect(page).to have_css('a#all-options[href="/tests/save"]', text: 'All options!')
62
+ end
63
+
64
+ it 'handles an href as text if a default argument exists' do
65
+ visit clear_and_save_path
66
+ expect(page).to have_css('a[href="/tests/save"]', text: 'http://localhost:3000/tests/clear_and_save')
67
+ end
68
+ end
69
+
70
+ context 'with an offsite referer' do
71
+
72
+ it 'doesn\'t link back to offsite referers' do
73
+ Capybara.current_session.driver.header 'Referer', 'http://rubyonrails.org/'
74
+ visit clear_and_save_path
75
+ click_link 'Go back from whence you came!'
76
+ expect(current_path).to eq(root_path)
77
+ end
78
+
79
+ it 'links back to offsite referers with offsite flag' do
80
+ Capybara.current_session.driver.header 'Referer', 'http://rubyonrails.org/'
81
+ visit clear_and_save_path
82
+ click_link 'Offsite okay!'
83
+ expect(current_url).to eq('http://rubyonrails.org/')
84
+ end
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jump_back
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Debelak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -79,11 +79,12 @@ files:
79
79
  - Rakefile
80
80
  - lib/jump_back.rb
81
81
  - lib/jump_back/engine.rb
82
+ - lib/jump_back/link_back.rb
82
83
  - lib/jump_back/options_parser.rb
84
+ - lib/jump_back/path_finder.rb
83
85
  - lib/jump_back/redirect_back.rb
84
- - lib/jump_back/redirection_determiner.rb
85
- - lib/jump_back/referer_interpreter.rb
86
86
  - lib/jump_back/return_to_referer.rb
87
+ - lib/jump_back/urls.rb
87
88
  - lib/jump_back/version.rb
88
89
  - lib/tasks/jump_back_tasks.rake
89
90
  - spec/controller/application_controller_spec.rb
@@ -96,9 +97,9 @@ files:
96
97
  - spec/dummy/app/controllers/tests_controller.rb
97
98
  - spec/dummy/app/helpers/application_helper.rb
98
99
  - spec/dummy/app/views/layouts/application.html.erb
99
- - spec/dummy/app/views/tests/edit.html.erb
100
- - spec/dummy/app/views/tests/index.html.erb
101
- - spec/dummy/app/views/tests/new.html.erb
100
+ - spec/dummy/app/views/tests/blank.html.erb
101
+ - spec/dummy/app/views/tests/clear_and_save.html.erb
102
+ - spec/dummy/app/views/tests/save.html.erb
102
103
  - spec/dummy/bin/bundle
103
104
  - spec/dummy/bin/rails
104
105
  - spec/dummy/bin/rake
@@ -121,7 +122,6 @@ files:
121
122
  - spec/dummy/config/locales/en.yml
122
123
  - spec/dummy/config/routes.rb
123
124
  - spec/dummy/config/secrets.yml
124
- - spec/dummy/db/development.sqlite3
125
125
  - spec/dummy/db/schema.rb
126
126
  - spec/dummy/db/test.sqlite3
127
127
  - spec/dummy/log/development.log
@@ -136,7 +136,8 @@ files:
136
136
  - spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
137
137
  - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
138
138
  - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
139
- - spec/features/jump_back_feature_spec.rb
139
+ - spec/features/controller_methods_spec.rb
140
+ - spec/features/view_helpers_spec.rb
140
141
  - spec/spec_helper.rb
141
142
  homepage: https://github.com/pdebelak/jump_back
142
143
  licenses:
@@ -171,9 +172,9 @@ test_files:
171
172
  - spec/dummy/app/controllers/tests_controller.rb
172
173
  - spec/dummy/app/helpers/application_helper.rb
173
174
  - spec/dummy/app/views/layouts/application.html.erb
174
- - spec/dummy/app/views/tests/edit.html.erb
175
- - spec/dummy/app/views/tests/index.html.erb
176
- - spec/dummy/app/views/tests/new.html.erb
175
+ - spec/dummy/app/views/tests/blank.html.erb
176
+ - spec/dummy/app/views/tests/clear_and_save.html.erb
177
+ - spec/dummy/app/views/tests/save.html.erb
177
178
  - spec/dummy/bin/bundle
178
179
  - spec/dummy/bin/rails
179
180
  - spec/dummy/bin/rake
@@ -196,7 +197,6 @@ test_files:
196
197
  - spec/dummy/config/routes.rb
197
198
  - spec/dummy/config/secrets.yml
198
199
  - spec/dummy/config.ru
199
- - spec/dummy/db/development.sqlite3
200
200
  - spec/dummy/db/schema.rb
201
201
  - spec/dummy/db/test.sqlite3
202
202
  - spec/dummy/log/development.log
@@ -213,5 +213,6 @@ test_files:
213
213
  - spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
214
214
  - spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
215
215
  - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
216
- - spec/features/jump_back_feature_spec.rb
216
+ - spec/features/controller_methods_spec.rb
217
+ - spec/features/view_helpers_spec.rb
217
218
  - spec/spec_helper.rb
@@ -1,14 +0,0 @@
1
- module JumpBack
2
-
3
- class RedirectionDeterminer
4
- attr_reader :path
5
-
6
- def initialize(request, path, options)
7
- @path = path_determiner(request, path, options)
8
- end
9
-
10
- def path_determiner(request, path, options)
11
- RefererInterpreter.back?(request, options) ? :back : path
12
- end
13
- end
14
- end
@@ -1,34 +0,0 @@
1
- module JumpBack
2
-
3
- class RefererInterpreter
4
-
5
- def self.back?(request, options)
6
- has_referer?(request) ? is_local?(request, options) ? true : false : false
7
- end
8
-
9
- def self.has_referer?(request)
10
- !request.env["HTTP_REFERER"].blank? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
11
- end
12
-
13
- def self.is_local?(request, options)
14
- return true if options[:offsite]
15
- host = host(request.env["HTTP_REFERER"])
16
- !(host && host != request.host)
17
- end
18
-
19
- private
20
-
21
- def self.host(string)
22
- return URI.parse(string).host if uri? string
23
- end
24
-
25
- def self.uri?(string)
26
- uri = URI.parse(string)
27
- %w( http https ).include?(uri.scheme)
28
- rescue URI::BadURIError
29
- false
30
- rescue URI::InvalidURIError
31
- false
32
- end
33
- end
34
- end
@@ -1,3 +0,0 @@
1
- Edit Page
2
-
3
- <%= link_to 'Go to new page', new_test_path %>
@@ -1,6 +0,0 @@
1
- Index Page
2
- <%= form_tag test_path(1), method: :put do %>
3
- <%= submit_tag 'Update test' %>
4
- <% end %>
5
-
6
- <%= link_to 'Go to new page', new_test_path %>
@@ -1,6 +0,0 @@
1
- New Page
2
- <%= form_tag tests_path do %>
3
- <%= submit_tag 'New test' %>
4
- <% end %>
5
-
6
- <%= link_to 'Go to edit page', edit_test_path(1) %>
Binary file
@@ -1,38 +0,0 @@
1
- feature 'jump_back features' do
2
- describe 'redirect_back' do
3
- it 'should redirect back' do
4
- visit new_test_path
5
- click_button 'New test'
6
- expect(page).to have_content('New Page')
7
- end
8
- end
9
-
10
- describe 'return_to_referer' do
11
- it 'should return to saved referer' do
12
- visit edit_test_path(1)
13
- click_link 'Go to new page'
14
- visit tests_path
15
- click_button 'Update test'
16
- expect(page).to have_content('Edit Page')
17
- end
18
-
19
- it 'should not reset referer if not cleared' do
20
- visit edit_test_path(1)
21
- click_link 'Go to new page'
22
- visit tests_path
23
- click_link 'Go to new page'
24
- visit tests_path
25
- click_button 'Update test'
26
- expect(page).to have_content('Edit Page')
27
- end
28
-
29
- it 'should reset referer if cleared' do
30
- visit edit_test_path(1)
31
- click_link 'Go to new page'
32
- click_link 'Go to edit page'
33
- visit tests_path
34
- click_button 'Update test'
35
- expect(page).to have_content('New Page')
36
- end
37
- end
38
- end