Skip to content
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

Support Strict Locals #557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/generators/rails/templates/partial.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# locals: (<%= singular_table_name %>:)

json.extract! <%= singular_table_name %>, <%= full_attributes_list %>
json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
<%- virtual_attributes.each do |attribute| -%>
Expand Down
1 change: 1 addition & 0 deletions test/jbuilder_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase
end

assert_file 'app/views/posts/_post.json.jbuilder' do |content|
assert_match %r{# locals: \(post:\)}, content
assert_match %r{json\.extract! post, :id, :title, :body}, content
assert_match %r{:created_at, :updated_at}, content
assert_match %r{json\.url post_url\(post, format: :json\)}, content
Expand Down
1 change: 1 addition & 0 deletions test/jbuilder_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class JbuilderTemplateTest < ActiveSupport::TestCase
POST_PARTIAL = <<-JBUILDER
# locals: (json:, post:)
json.extract! post, :id, :body
json.author do
first_name, last_name = post.author_name.split(nil, 2)
Expand Down
Loading