Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

rails/rails#11573

View scaffold_generator_test.diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ ruby -Itest test/generators/scaffold_generator_test.rb
Run options: --seed 61346
 
# Running:
 
.F............
 
Finished in 1.572028s, 8.9057 runs/s, 152.6690 assertions/s.
 
1) Failure:
ScaffoldGeneratorTest#test_scaffold_generator_belongs_to [test/generators/scaffold_generator_test.rb:307]:
Expected /<%= f\.text_field :currency_id %>/ to match "<%= form_for(@account) do |f| %>\n <% if @account.errors.any? %>\n <div id=\"error_explanation\">\n <h2><%= pluralize(@account.errors.count, \"error\") %> prohibited this account from being saved:</h2>\n\n <ul>\n <% @account.errors.full_messages.each do |msg| %>\n <li><%= msg %></li>\n <% end %>\n </ul>\n </div>\n <% end %>\n\n <div class=\"field\">\n <%= f.label :name %><br>\n <%= f.text_field :name %>\n </div>\n <div class=\"field\">\n <%= f.label :currency %><br>\n <%= f.text_field :currency %>\n </div>\n <div class=\"actions\">\n <%= f.submit %>\n </div>\n<% end %>\n".
 
14 runs, 240 assertions, 1 failures, 0 errors, 0 skips
View scaffold_generator_test.diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index d5ad978..cbc5a95 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -286,6 +286,31 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
 
+ def test_scaffold_generator_belongs_to
+ run_generator ["account", "name", "currency:belongs_to"]
+
+ assert_file "app/models/account.rb", /belongs_to :currency/
+
+ assert_migration "db/migrate/create_accounts.rb" do |m|
+ assert_method :change, m do |up|
+ assert_match(/t\.string :name/, up)
+ assert_match(/t\.belongs_to :currency/, up)
+ end
+ end
+
+ assert_file "app/controllers/accounts_controller.rb" do |content|
+ assert_instance_method :account_params, content do |m|
+ assert_match(/permit\(:name, :currency_id\)/, m)
+ end
+ end
+
+ assert_file "app/views/accounts/_form.html.erb" do |content|
+ assert_match(/<%= f\.text_field :name %>/, content)
+ assert_match(/<%= f\.text_field :currency_id %>/, content)
+ end
+
+ end
+
def test_scaffold_generator_password_digest
run_generator ["user", "name", "password:digest"]
View scaffold_generator_test.diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
def test_scaffold_generator_belongs_to
run_generator ["account", "name", "currency:belongs_to"]
 
assert_file "app/models/account.rb", /belongs_to :currency/
 
assert_migration "db/migrate/create_accounts.rb" do |m|
assert_method :change, m do |up|
assert_match(/t\.string :name/, up)
assert_match(/t\.belongs_to :currency/, up)
end
end
 
assert_file "app/controllers/accounts_controller.rb" do |content|
assert_instance_method :account_params, content do |m|
assert_match(/permit\(:name, :currency_id\)/, m)
end
end
 
assert_file "app/views/accounts/_form.html.erb" do |content|
assert_match(/<%= f\.text_field :name %>/, content)
assert_match(/<%= f\.text_field :currency_id %>/, content)
end
 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.