Skip to content

Commit

Permalink
Merge branch 'master' into 0.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jun 23, 2016
2 parents 0f3a22b + 2140038 commit c74f12b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
20 changes: 20 additions & 0 deletions test/action/callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
action.article.must_be_nil
end
end

describe 'on handled error' do
it 'stops the callbacks execution and passes the control on exception handling' do
action = HandledErrorBeforeMethodAction.new
response = action.call({})

response[0].must_equal 404
action.article.must_be_nil
end
end
end

describe '#after' do
Expand Down Expand Up @@ -97,5 +107,15 @@
action.egg.must_be_nil
end
end

describe 'on handled error' do
it 'stops the callbacks execution and passes the control on exception handling' do
action = HandledErrorAfterMethodAction.new
response = action.call({})

response[0].must_equal 404
action.egg.must_be_nil
end
end
end
end
26 changes: 23 additions & 3 deletions test/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
599 => 'Network connect timeout error'
}

class RecordNotFound < StandardError
end

module Test
class Index
include Hanami::Action
Expand Down Expand Up @@ -349,6 +352,16 @@ def set_article
end
end

class HandledErrorBeforeMethodAction < BeforeMethodAction
configuration.handle_exceptions true
handle_exception RecordNotFound => 404

private
def set_article
raise RecordNotFound.new
end
end

class BeforeBlockAction
include Hanami::Action

Expand Down Expand Up @@ -425,6 +438,16 @@ def set_egg
end
end

class HandledErrorAfterMethodAction < AfterMethodAction
configuration.handle_exceptions true
handle_exception RecordNotFound => 404

private
def set_egg
raise RecordNotFound.new
end
end

class AfterBlockAction
include Hanami::Action

Expand Down Expand Up @@ -635,9 +658,6 @@ def call(params)
end
end

class RecordNotFound < StandardError
end

class HandledExceptionAction
include Hanami::Action
handle_exception RecordNotFound => 404
Expand Down

0 comments on commit c74f12b

Please sign in to comment.