Skip to content

Instantly share code, notes, and snippets.

@zzak
Created July 23, 2013 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzak/6065288 to your computer and use it in GitHub Desktop.
Save zzak/6065288 to your computer and use it in GitHub Desktop.
$ 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
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"]
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