nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.65k stars 335 forks source link

extends with object false doesn't output anything #347

Closed axsuul closed 11 years ago

axsuul commented 11 years ago
# bar.json.rabl
object false

extends "foo"

# foo.json.rabl
node(:baz) { "blah" }

This outputs

{}

How do I go about getting it work with object being false?

nesquena commented 11 years ago

What is inside the foo template? You could always do:

# bar.json.rabl
object false

node :foo do
  partial "foo", :object => @foo
end

# foo.json.rabl
node(:baz) { "blah" }

Not sure what your desired output is.

axsuul commented 11 years ago

Sorry, my desired output is

{
    "baz": "blah"
}

The foo template contains

node(:baz) { "blah" }

Is there a way to make it work with extends?

nesquena commented 11 years ago

Oh I see now, thanks for clarifying. The extends should actually work fine with object false. I have used that pattern many times before. If it doesn't I would like to understand why. If you do this:

child Object.new => :foo do
  extends "foo"
end

What output do you get?

axsuul commented 11 years ago
object false

child Object.new => :foo do
  extends "foo"
end

gets me

{
    "foo": {
        "baz": "blah"
    }
}

So that looks like it works as intended. However, just

object false

extends "foo"

returns

{}
nesquena commented 11 years ago

Ok thanks for following up, I will try to see if I can reproduce and fix this today. Will post updates here

axsuul commented 11 years ago

Appreciate it! If it helps, I'm using 0.7.3.

nesquena commented 11 years ago

@axsuul Can you try 0.7.4 and verify it fixes this issue, I added a corresponding unit test for this case.

axsuul commented 11 years ago

Getting an error on extends. Odd that it can't be reproduced in the tests. Looks like https://github.com/nesquena/rabl/blob/8b2e55940ad31149831323091f0be321cbddd73b/lib/rabl/partials.rb#L24 is the culprit.

/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:113:in `merge!'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:113:in `extends'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:34:in `block in compile_hash'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:33:in `each'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:33:in `compile_hash'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:21:in `block in build'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:142:in `cache_results'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/builder.rb:20:in `build'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/engine.rb:48:in `to_hash'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/engine.rb:60:in `to_json'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/engine.rb:36:in `block in render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/engine.rb:272:in `cache_results'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rabl-0.7.4/lib/rabl/engine.rb:36:in `render'
app/views/api/v1/products/index.json.rabl:1:in `_app_views_api_v__products_index_json_rabl__3128105579393135503_45543480'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/template.rb:145:in `block in render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:125:in `instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/template.rb:143:in `render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `block in instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:45:in `render_template'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:18:in `render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:36:in `render_template'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:17:in `render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:110:in `_render_template'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:103:in `render_to_body'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:88:in `render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/rendering.rb:16:in `render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/core_ext/benchmark.rb:5:in `ms'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:39:in `render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:167:in `process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:436:in `_run__2476586199832736636__process_action__1347677533323877775__callbacks'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `block in instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `instrument'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:121:in `process'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:45:in `process'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal.rb:203:in `dispatch'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal.rb:246:in `block in action'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:73:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:36:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:600:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/bullet-4.2.0/lib/bullet/rack.rb:11:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/sass-3.2.1/lib/sass/plugin/rack.rb:54:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/head.rb:14:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/flash.rb:242:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/cookies.rb:339:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/query_cache.rb:64:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `_run__2436179186748141887__call__4606126127445307977__callbacks'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:65:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/rack/logger.rb:26:in `call_app'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/rack/logger.rb:16:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/quiet_assets-1.0.1/lib/quiet_assets.rb:20:in `call_with_quiet_assets'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/static.rb:62:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/engine.rb:479:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:223:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/rack/log_tailer.rb:17:in `call'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/connection.rb:81:in `block in pre_process'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/connection.rb:79:in `catch'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/connection.rb:79:in `pre_process'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/connection.rb:54:in `process'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/connection.rb:39:in `receive_data'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/backends/base.rb:63:in `start'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/server.rb:159:in `start'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:265:in `start'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in `start'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:55:in `block in <top (required)>'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
/home.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
nesquena commented 11 years ago

Any idea what the error or exception message actually was? The stacktrace doesn't seem to have any message of what went wrong in merge! I want to try and replicate a test case

axsuul commented 11 years ago

Ah, man, sorry I totally forgot the message. It was

can't convert Array into Hash

This was the test case that I used again

# bar.json.rabl
object false

extends "foo"

# foo.json.rabl
node(:baz) { "blah" }

Hmm, doing some more investigation, will post here when I know more.

nesquena commented 11 years ago

Here's the corresponding test passing: https://github.com/nesquena/rabl/blob/master/test/renderer_test.rb#L125-142, looks almost identical. That error means the result of the extends led to an array being returned which shouldn't be happening. Is there anything about the test case that I am missing. Could you possibly open the source and print out what the result is here? The failure is on this line: https://github.com/nesquena/rabl/blob/8b2e55940ad31149831323091f0be321cbddd73b/lib/rabl/builder.rb#L113

nesquena commented 11 years ago

I added one more thing to ensure the incorrect array doesn't try to be merged in HEAD. Can you switch to using rabl from git (master) so we can play with fixes until we get it working. My guess is if you switch to rabl HEAD you will stop seeing an exception but likely still won't see the node you expect. I would love to figure out why if you can help me reproduce with a test case or by sending me an example where it happens.

axsuul commented 11 years ago

So yea, I tried HEAD and the node isn't there. Back to 0.7.4, with this setup

# users_controller.rb
def index
  @users = [User.new, User.new, User.new]
end

# index.json.rabl
object false

extends "foo"

# foo.json.rabl
node(:baz) { "blah" }

I am getting the exception. And result is [{:baz=>"blah"},{:baz=>"blah"},{:baz=>"blah"}]. However, what's odd is that if I change only the instance variable within the controller method to

def index
  @blah = []
end

result becomes {:baz=>"blah"} and the JSON response is right. I tried to get a failing test case with scope but no luck. Does this help at all? Please let me know!

nesquena commented 11 years ago

I'll have to see if I can reproduce this issue, but that does help a lot actually understanding that it has something to do with the ivar that is set. Are you referencing the @users ivar anywhere explicitly in the rabl template? Clearly the issue is from the 'object' being (possibly incorrectly) assigned to the users collection.

axsuul commented 11 years ago

I checked everywhere and it doesn't look like I am. If you can't reproduce it, maybe it's something that's cached.

nesquena commented 11 years ago

It might be an issue with the object being incorrectly inferred based on the name of the controller. I assume the controller is users?

nesquena commented 11 years ago

@axsuul I think I may have fixed it, can you try it again in HEAD and confirm? I will bump to 0.7.5

axsuul commented 11 years ago

Yep, works perfectly now :+1: Thanks for your help and sorry that this issue turned into such a monstrosity. Glad we got it sorted out!

nesquena commented 11 years ago

That's great, I appreciate your help and your patience figuring out what was the root cause. Once I was able to reproduce it in a test, fixing it was actually a one line change (as is usually the case). Will release 0.7.5 right now.

axsuul commented 11 years ago

Haha, love them tests. Learned a lot by looking at your tests, I honestly wouldn't have known how to write a test for this case.

nesquena commented 11 years ago

It was an interesting edge case, and I love running into edge cases because once caught, we have the corresponding regression test forever.