From 754aa295ba71798c58bdaa407770e22751945459 Mon Sep 17 00:00:00 2001 From: Alex Kwiatkowski & Will Bagby Date: Tue, 7 Aug 2012 12:56:58 -0400 Subject: [PATCH] Return empty hash when url_options not provided --- lib/active_model/serializer.rb | 2 +- test/serializer_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index edd99e46..7920d591 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -449,7 +449,7 @@ module ActiveModel end def url_options - @options[:url_options] + @options[:url_options] || {} end # Returns a json representation of the serializable diff --git a/test/serializer_test.rb b/test/serializer_test.rb index 3a708580..beab64fd 100644 --- a/test/serializer_test.rb +++ b/test/serializer_test.rb @@ -143,6 +143,12 @@ class SerializerTest < ActiveModel::TestCase assert_equal({ :host => "test.local" }, user_serializer.url_options) end + def test_serializer_returns_empty_hash_without_url_options + user = User.new + user_serializer = UserSerializer.new(user) + assert_equal({}, user_serializer.url_options) + end + def test_pretty_accessors user = User.new user.superuser = true