Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper test generators [#1199 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
- Loading branch information
1 parent
d22fe41
commit 3c9beb3
Showing
18 changed files
with
179 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class <%= class_name %>HelperTest < ActionView::TestCase | ||
end |
24 changes: 24 additions & 0 deletions
24
railties/lib/rails_generator/generators/components/helper/USAGE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Description: | ||
Stubs out a new helper. Pass the helper name, either | ||
CamelCased or under_scored. | ||
|
||
To create a helper within a module, specify the helper name as a | ||
path like 'parent_module/helper_name'. | ||
|
||
This generates a helper class in app/helpers and a helper test | ||
suite in test/unit/helpers. | ||
|
||
Example: | ||
`./script/generate helper CreditCard` | ||
|
||
Credit card helper. | ||
Helper: app/helpers/credit_card_helper.rb | ||
Test: test/unit/helpers/credit_card_helper_test.rb | ||
|
||
Modules Example: | ||
`./script/generate helper 'admin/credit_card'` | ||
|
||
Credit card admin helper. | ||
Helper: app/helpers/admin/credit_card_helper.rb | ||
Test: test/unit/helpers/admin/credit_card_helper_test.rb | ||
|
25 changes: 25 additions & 0 deletions
25
railties/lib/rails_generator/generators/components/helper/helper_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class HelperGenerator < Rails::Generator::NamedBase | ||
def manifest | ||
record do |m| | ||
# Check for class naming collisions. | ||
m.class_collisions class_path, "#{class_name}Helper", "#{class_name}HelperTest" | ||
|
||
# Helper and helper test directories. | ||
m.directory File.join('app/helpers', class_path) | ||
m.directory File.join('test/unit/helpers', class_path) | ||
|
||
# Helper and helper test class. | ||
|
||
m.template 'helper.rb', | ||
File.join('app/helpers', | ||
class_path, | ||
"#{file_name}_helper.rb") | ||
|
||
m.template 'helper_test.rb', | ||
File.join('test/unit/helpers', | ||
class_path, | ||
"#{file_name}_helper_test.rb") | ||
|
||
end | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
railties/lib/rails_generator/generators/components/helper/templates/helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module <%= class_name %>Helper | ||
end |
4 changes: 4 additions & 0 deletions
4
railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class <%= class_name %>HelperTest < ActionView::TestCase | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class <%= controller_class_name %>HelperTest < ActionView::TestCase | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class <%= controller_class_name %>HelperTest < ActionView::TestCase | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require File.dirname(__FILE__) + '/generator_test_helper' | ||
|
||
class RailsHelperGeneratorTest < GeneratorTestCase | ||
def test_helper_generates_helper | ||
run_generator('helper', %w(products)) | ||
|
||
assert_generated_helper_for :products | ||
assert_generated_helper_test_for :products | ||
end | ||
|
||
def test_helper_generates_namespaced_helper | ||
run_generator('helper', %w(admin::products)) | ||
|
||
assert_generated_helper_for "admin::products" | ||
assert_generated_helper_test_for "admin::products" | ||
end | ||
|
||
def test_helper_generates_namespaced_and_not_namespaced_helpers | ||
run_generator('helper', %w(products)) | ||
|
||
# We have to require the generated helper to show the problem because | ||
# the test helpers just check for generated files and contents but | ||
# do not actually load them. But they have to be loaded (as in a real environment) | ||
# to make the second generator run fail | ||
require "#{RAILS_ROOT}/app/helpers/products_helper" | ||
|
||
assert_nothing_raised do | ||
begin | ||
run_generator('helper', %w(admin::products)) | ||
ensure | ||
# cleanup | ||
Object.send(:remove_const, :ProductsHelper) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.