-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix empty template source #15
base: master
Are you sure you want to change the base?
Conversation
When the template got compiled by rails the source is `nil`
When do you run into a empty source in a compiled template ? |
@fnordfish any news? |
Hi @ccocchi, thanks for reminding me... Well, we run a lot of rspec tests against the JSON-API our Rails app exposes. Do you think this is more a Rails or RSpec issue? |
No I think it is a rabl-rails weird behavior. Did you try to set |
Yes, I have tried to set |
I use RSpec for testing 2 fairly large applications using rabl-rails and I never ran into this problem. But I dont really see why Rails nil the source in this case, since |
I'll try to build one. My guess is, that this happens to "partial templates" - but I'm not really sure. We converted our rabl app to rabl-railsm (which was fairly straight forward btw) so there was no last change to check. |
So it seems @fnordfish commit fixes the issue. WIth Rabl-Rails without this commit With this commit So +1 from me on this PR. 👍 |
So, I've created an test app and in this one I cannot reproduce this. However, in my big-app I have partials and extends with |
Pretty similar results with small tests sets. Like I said, if you have the rspec configuration to "random" it'll run the tests in different order and maybe its the same issue I was running into. When I used the --tag focus to only test a small set of the suit, the test passed with flying colors until I added more and more tests. My guess is that once rails renders certain amount of views, it nils the template source. I switched to Api::V1::WebApiController applications #application_details with valid account id and app id includes the application name
Failure/Error: post :application_details, account_id: account_id, application_id: client_app_id
ActionView::Template::Error:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
# ./app/views/client_applications/details.json.rabl:2:in `_app_views_client_applications_details_json_rabl___2241378183412652733_70127943037700'
# ./app/controllers/api/v1/web_api_controller.rb:262:in `application_details'
# ./spec/controllers/api/v1/web_api_controller_spec.rb:103:in `do_app_details'
# ./spec/controllers/api/v1/web_api_controller_spec.rb:110:in `block (5 levels) in <top (required)>' Pretty much same issue with random errors popping up with different seeds but at least is a different issue. Not the nil source. I'll debug and let you know what I find out. |
@Tonkpils seems, that your |
Using @fnordfish actually I think i never used a starting slash in any of my extends/partial, I will test with it. Anyway thanks to both of you. |
@fnordfish Yeah, I realized that as soon as I left the office. Agreed @ccocchi thanks for the awesome gem! |
Hmm, running into this problem today. Not entirely sure why either. |
In my case, setting Spoke too soon: failed on another run. I seem to have narrowed this down to the following scenario: I had two controllers that were rendering to the same template, one by directly rendering the template and another by extending through a child: object :@user
attributes :id, :nickname I changed the controller that was rendering the above template directly to just render to json without using the Rabl template and the problem went away. Also interesting: the problem only occurred when the spec for controller that was rendering the above template directly was run BEFORE the spec for the template that rendered the above template through a child extension. |
I can confirm it in my small-test app where I try to use rails-api. It appear SOMETIMES when I try to get "localhost:3000/tours.json". Rails server restart helps. ActionView::Template::Error (can't convert nil into String):
1: collection :@tours
2: extends "tours/show"
app/views/tours/index.json.rabl:2:in `_app_views_tours_index_json_rabl___2066067952812563330_14493560'
app/controllers/tours_controller.rb:6:in `index' my repo and tag where this issue appears Additional information how to reproduce the issue:
I find a workaround for it that works for me: |
I cloned your repo and tried to reproduce your bug, but still no errors on my side :( With ruby 1.9.3, rails 3.2.11 |
I had this same issue with partials, and isolated it to LookupContext improperly resolving paths without extensions (in a single session, it works, but stops). The seemingly stable fix was to use the full filename and extension rather than just name (eg. users/index.json.rabl vs users/index). |
It does seem adding extensions fixes the issue of source being set to nil. Digging a bit deeper into this. Doing something like this seems to cause the issue. shared/success.json.rabl object false
node(:status) { :success }
node(:message) { @message } cool/show.json.rabl object false
node(:cool) { partial('cool/_show', object: @cool) }
extends 'shared/success' Seems without an extension on ActionView::Template::Error:
no implicit conversion of nil into String I'm not sure what would be the correct way of fixing this issue. If the only option is to make sure that the extends contains the proper extension , the documentation should reflect this. Thoughts @ccocchi |
When rails compiles a template, it nils-out it's source.
For most (normal) requests this does not matter, but when running a bunch of tests this may happen (at least to me)