Permalink
Browse files

LH-516 (Tender #414) Prefer SessionHash#to_hash, if available, to dep…

…recated SessionHash#data
  • Loading branch information...
1 parent ceb324c commit 0bc773df0a1333ec74987117d558033f051155a8 @jasonm jasonm committed Nov 27, 2009
Showing with 40 additions and 1 deletion.
  1. +9 −1 lib/hoptoad_notifier/catcher.rb
  2. +31 −0 test/catcher_test.rb
@@ -57,7 +57,7 @@ def ignore_user_agent? #:nodoc:
def request_data_for_hoptoad
{ :parameters => filter_if_filtering(params.to_hash),
- :session_data => session.data,
+ :session_data => session_data,
:controller => params[:controller],
:action => params[:action],
:url => "#{request.protocol}#{request.host}#{request.request_uri}",
@@ -73,5 +73,13 @@ def filter_if_filtering(hash)
end
end
+ def session_data
+ if session.respond_to?(:to_hash)
+ session.to_hash
+ else
+ session.data
+ end
+ end
+
end
end
View
@@ -255,4 +255,35 @@ def process_action_with_automatic_notification(args = {})
end
end
+ should "call session.to_hash if available" do
+ hash_data = {:key => :value}
+
+ session = ActionController::TestSession.new
+ ActionController::TestSession.stubs(:new).returns(session)
+ session.stubs(:to_hash).returns(hash_data)
+
+ process_action_with_automatic_notification
+ assert_received(session, :to_hash)
+ assert_received(session, :data) { |expect| expect.never }
+ assert_caught_and_sent
+ end
+
+ should "call session.data if session.to_hash is undefined" do
+ hash_data = {:key => :value}
+
+ session = ActionController::TestSession.new
+ ActionController::TestSession.stubs(:new).returns(session)
+ session.stubs(:data).returns(hash_data)
+ if session.respond_to?(:to_hash)
+ class << session
+ undef to_hash
+ end
+ end
+
+ process_action_with_automatic_notification
+ assert_received(session, :to_hash) { |expect| expect.never }
+ assert_received(session, :data) { |expect| expect.at_least_once }
+ assert_caught_and_sent
+ end
+
end

0 comments on commit 0bc773d

Please sign in to comment.