Skip to content

Commit 3baff10

Browse files
committed
Merge pull request #717 from r-ideas/0-9-stable
fixed issue with rendering Hash which appears in rails 4.2.0.beta4
2 parents 64cc538 + 23c2e67 commit 3baff10

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ rvm:
77
- ruby-head
88
- jruby-19mode
99
- rbx-2
10+
- ruby-head
1011

1112
sudo: false
1213

14+
install:
15+
- bundle install --retry=3
16+
1317
env:
1418
- "RAILS_VERSION=3.2.17"
1519
- "RAILS_VERSION=4.0.3"

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def format_keys(format)
5656
attr_reader :key_format
5757

5858
def serializer_for(resource, options = {})
59-
if resource.respond_to?(:each)
59+
if resource.respond_to?(:each) && !resource.is_a?(Hash)
6060
if Object.constants.include?(:ArraySerializer)
6161
::ArraySerializer
6262
else

test/integration/action_controller/namespaced_serialization_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def render_comment
1919
def render_comments
2020
render json: [Comment.new(content: 'Comment 1')]
2121
end
22+
23+
def render_hash
24+
render json: {message: 'not found'}, status: 404
25+
end
2226
end
2327

2428
tests TestNamespace::MyController
@@ -42,6 +46,11 @@ def test_array_fallback_to_a_version_without_namespace
4246
get :render_comments
4347
assert_serializer CommentSerializer
4448
end
49+
50+
def test_render_hash_regression
51+
get :render_hash
52+
assert_equal JSON.parse(response.body), {'message' => 'not found'}
53+
end
4554
end
4655

4756
class OptionNamespacedSerializationTest < ActionController::TestCase
@@ -93,4 +102,4 @@ def test_array_fallback_to_a_version_without_namespace
93102
end
94103

95104
end
96-
end
105+
end

0 commit comments

Comments
 (0)