diff options
author | Rasesh Patel <raspat1@gmail.com> | 2017-05-24 01:34:07 -0400 |
---|---|---|
committer | Rasesh Patel <raspat1@gmail.com> | 2018-10-14 15:54:53 -0400 |
commit | ecb2850a04adc6c6665f9a30a1d60ca73965ccfa (patch) | |
tree | 28d60f8fc3b0172a55073c780fb4d8b31ed2db51 /railties/test/generators | |
parent | 99c87ad2474d5c5b6e52ceac34c3cf9f9cb57f9f (diff) | |
download | rails-ecb2850a04adc6c6665f9a30a1d60ca73965ccfa.tar.gz rails-ecb2850a04adc6c6665f9a30a1d60ca73965ccfa.tar.bz2 rails-ecb2850a04adc6c6665f9a30a1d60ca73965ccfa.zip |
Show object ids in scaffold pages when displaying referenced objects
Resolve Issue#29200
When scaffolding a model that references another model the
generated show and index html pages display the object directly
on the page. Basically, it just shows a memory address. That is
not very helpful. In this commit we show the object's id rather
than the memory address.
This updates the scaffold templates and the json builder files.
Diffstat (limited to 'railties/test/generators')
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 21b5013484..3cffdddd38 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -435,8 +435,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end - def test_scaffold_generator_belongs_to - run_generator ["account", "name", "currency:belongs_to"] + def test_scaffold_generator_belongs_to_and_references + run_generator ["account", "name", "currency:belongs_to", "user:references"] assert_file "app/models/account.rb", /belongs_to :currency/ @@ -449,7 +449,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/controllers/accounts_controller.rb" do |content| assert_instance_method :account_params, content do |m| - assert_match(/permit\(:name, :currency_id\)/, m) + assert_match(/permit\(:name, :currency_id, :user_id\)/, m) end end @@ -457,6 +457,16 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_match(/^\W{4}<%= form\.text_field :name %>/, content) assert_match(/^\W{4}<%= form\.text_field :currency_id %>/, content) end + + assert_file "app/views/accounts/index.html.erb" do |content| + assert_match(/^\W{8}<td><%= account\.name %><\/td>/, content) + assert_match(/^\W{8}<td><%= account\.user_id %><\/td>/, content) + end + + assert_file "app/views/accounts/show.html.erb" do |content| + assert_match(/^\W{2}<%= @account\.name %>/, content) + assert_match(/^\W{2}<%= @account\.user_id %>/, content) + end end def test_scaffold_generator_database |