objectreload-pagination 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/action_controller/rescue_with_helper.rb +16 -0
- data/lib/pagination.rb +10 -2
- data/test/collection_test.rb +0 -4
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# When an exception happens inside a view, it is wrapped with an
|
2
|
+
# ActionView::TemplateError. The lookup for the rescue_with_handler
|
3
|
+
# then fails to find the handle for the original exception. This solution
|
4
|
+
# special cases the template error to look also at the wrapped exception
|
5
|
+
# and if there is a handler for that exception, then call it and ignore
|
6
|
+
# the wrapping.
|
7
|
+
module RescueWithHelper
|
8
|
+
def rescue_with_handler(exception)
|
9
|
+
if ((exception.class == ActionView::TemplateError) &&
|
10
|
+
(orig_exception = exception.original_exception) &&
|
11
|
+
(orig_handler = handler_for_rescue(orig_exception)))
|
12
|
+
exception = orig_exception
|
13
|
+
end
|
14
|
+
super(exception)
|
15
|
+
end
|
16
|
+
end
|
data/lib/pagination.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
require 'active_record/base_extensions'
|
3
3
|
require 'active_record/scope_extensions'
|
4
4
|
|
5
|
+
# Loads
|
6
|
+
require 'action_controller/rescue_with_helper'
|
7
|
+
|
5
8
|
# Loads internal pagination classes
|
6
9
|
require 'pagination/collection'
|
7
10
|
require 'pagination/named_scope'
|
@@ -11,6 +14,11 @@ require 'pagination/view_helpers'
|
|
11
14
|
# Loads the :paginate view helper
|
12
15
|
ActionView::Base.send :include, Pagination::ViewHelpers
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
# Load :rescue_with_handler - solution: https://rails.lighthouseapp.com/projects/8994/tickets/2034-exceptions-in-views-hard-to-catch
|
18
|
+
ActionController::Base.send :include, RescueWithHelper
|
19
|
+
|
20
|
+
ActionController::Base.send(:rescue_from, Pagination::InvalidPage, :with => :not_found)
|
21
|
+
|
22
|
+
def not_found
|
23
|
+
render_optional_error_file 404
|
16
24
|
end
|
data/test/collection_test.rb
CHANGED
@@ -57,10 +57,6 @@ class CollectionTest < Test::Unit::TestCase
|
|
57
57
|
should "rise an error ArgumentError" do
|
58
58
|
assert_raise(ArgumentError) { paginate_collection(@collection, 2, -2) }
|
59
59
|
end
|
60
|
-
|
61
|
-
should "test_rescue_response_hook_presence" do
|
62
|
-
assert_equal :not_found, ActionController::Base.rescue_responses['Pagination::InvalidPage']
|
63
|
-
end
|
64
60
|
end
|
65
61
|
|
66
62
|
context "collection is empty" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mateusz Drozdzynski
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-05 00:00:00 +03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- Rakefile
|
36
36
|
- VERSION
|
37
37
|
- init.rb
|
38
|
+
- lib/action_controller/rescue_with_helper.rb
|
38
39
|
- lib/active_record/base_extensions.rb
|
39
40
|
- lib/active_record/scope_extensions.rb
|
40
41
|
- lib/pagination.rb
|