From 4494a752c3c568c65fa899c54486153a1a5fa187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 23 Jun 2009 19:10:42 +0200 Subject: Change current sstructure. --- railties/test/generators/actions_test.rb | 184 +++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 railties/test/generators/actions_test.rb (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb new file mode 100644 index 0000000000..6030504fa3 --- /dev/null +++ b/railties/test/generators/actions_test.rb @@ -0,0 +1,184 @@ +require 'abstract_unit' +require 'generators/generator_test_helper' + +class ActionsTest < GeneratorTestCase + def setup + super + @git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git' + @svn_plugin_uri = 'svn://svnhub.com/technoweenie/restful-authentication/trunk' + end + + def test_apply_loads_and_evaluates_a_template + template = <<-TEMPLATE + @foo = "FOO" + TEMPLATE + template.instance_eval "def read; self; end" # Make the string respond to read + + generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) + action :apply, "http://gist.github.com/103208.txt" + assert_equal generator.instance_variable_get("@foo"), "FOO" + end + + def test_file_should_write_data_to_file_path + action :file, 'lib/test_file.rb', 'heres test data' + assert_file 'lib/test_file.rb', 'heres test data' + end + + def test_file_should_write_block_contents_to_file_path + action(:file, 'lib/test_file.rb'){ 'heres block data' } + assert_file 'lib/test_file.rb', 'heres block data' + end + + def test_plugin_with_git_option_should_run_plugin_install + generator.expects(:run).once.with("ruby script/plugin install #{@git_plugin_uri}", false) + action :plugin, 'restful-authentication', :git => @git_plugin_uri + end + + def test_plugin_with_svn_option_should_run_plugin_install + generator.expects(:run).once.with("ruby script/plugin install #{@svn_plugin_uri}", false) + action :plugin, 'restful-authentication', :svn => @svn_plugin_uri + end + + def test_plugin_with_git_option_and_submodule_should_use_git_scm + generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", false) + action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true + end + + def test_plugin_with_no_options_should_skip_method + generator.expects(:run).never + action :plugin, 'rest_auth', {} + end + + def test_gem_should_put_gem_dependency_in_enviroment + run_generator + action :gem, 'will-paginate' + assert_file 'config/environment.rb', /config\.gem 'will\-paginate'/ + end + + def test_gem_with_options_should_include_options_in_gem_dependency_in_environment + run_generator + action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com' + + regexp = /#{Regexp.escape("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'")}/ + assert_file 'config/environment.rb', regexp + end + + def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment + run_generator + action :gem, 'rspec', :env => 'test' + assert_file 'config/environments/test.rb', /config\.gem 'rspec'/ + end + + def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments + run_generator + action :gem, 'quietbacktrace', :env => %w[ development test ] + assert_file 'config/environments/development.rb', /config\.gem 'quietbacktrace'/ + assert_file 'config/environments/test.rb', /config\.gem 'quietbacktrace'/ + end + + def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly + run_generator + action :gem, 'mislav-will-paginate', :lib => false + assert_file 'config/environment.rb', /config\.gem 'mislav\-will\-paginate'\, :lib => false/ + end + + def test_environment_should_include_data_in_environment_initializer_block + run_generator + load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' + action :environment, load_paths + assert_file 'config/environment.rb', /#{Regexp.escape(load_paths)}/ + end + + def test_environment_with_block_should_include_block_contents_in_environment_initializer_block + run_generator + + action :environment do + '# This wont be added' + '# This will be added' + end + + assert_file 'config/environment.rb', /# This will be added/ + end + + def test_git_with_symbol_should_run_command_using_git_scm + generator.expects(:run).once.with('git init') + action :git, :init + end + + def test_git_with_hash_should_run_each_command_using_git_scm + generator.expects(:run).times(2) + action :git, :rm => 'README', :add => '.' + end + + def test_vendor_should_write_data_to_file_in_vendor + action :vendor, 'vendor_file.rb', '# vendor data' + assert_file 'vendor/vendor_file.rb', '# vendor data' + end + + def test_lib_should_write_data_to_file_in_lib + action :lib, 'my_library.rb', 'class MyLibrary' + assert_file 'lib/my_library.rb', 'class MyLibrary' + end + + def test_rakefile_should_write_date_to_file_in_lib_tasks + action :rakefile, 'myapp.rake', 'task :run => [:environment]' + assert_file 'lib/tasks/myapp.rake', 'task :run => [:environment]' + end + + def test_initializer_should_write_date_to_file_in_config_initializers + action :initializer, 'constants.rb', 'MY_CONSTANT = 42' + assert_file 'config/initializers/constants.rb', 'MY_CONSTANT = 42' + end + + def test_generate_should_run_script_generate_with_argument_and_options + generator.expects(:run).once.with('ruby script/generate model MyModel', false) + action :generate, 'model', 'MyModel' + end + + def test_rake_should_run_rake_command_with_development_env + generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', false) + action :rake, 'log:clear' + end + + def test_rake_with_env_option_should_run_rake_command_in_env + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', false) + action :rake, 'log:clear', :env => 'production' + end + + def test_rake_with_sudo_option_should_run_rake_command_with_sudo + generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', false) + action :rake, 'log:clear', :sudo => true + end + + def test_capify_should_run_the_capify_command + generator.expects(:run).once.with('capify .', false) + action :capify! + end + + def test_freeze_should_freeze_rails_edge + generator.expects(:run).once.with('rake rails:freeze:edge', false) + action :freeze! + end + + def test_route_should_add_data_to_the_routes_block_in_config_routes + run_generator + route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" + action :route, route_command + assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/ + end + + protected + + def run_generator + silence(:stdout) { Rails::Generators::AppGenerator.start [destination_root] } + end + + def generator(config={}) + @generator ||= Rails::Generators::Base.new([], {}, { :root => destination_root }.merge!(config)) + end + + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end + +end -- cgit v1.2.3 From f596495556f871650ed6b7a67128e4fd13cd3773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 25 Jun 2009 10:18:00 +0200 Subject: Tests for plugin generator. --- railties/test/generators/actions_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 6030504fa3..a0502e9112 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -1,7 +1,8 @@ require 'abstract_unit' -require 'generators/generator_test_helper' +require 'generators/generators_test_helper' +require 'generators/rails/app/app_generator' -class ActionsTest < GeneratorTestCase +class ActionsTest < GeneratorsTestCase def setup super @git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git' -- cgit v1.2.3 From 4f3e44fa03ab8fc47f75fa710b28c72b9b2328b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 28 Jun 2009 12:00:13 +0200 Subject: Move file action only to app generator. --- railties/test/generators/actions_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index a0502e9112..baf687336a 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -20,13 +20,13 @@ class ActionsTest < GeneratorsTestCase assert_equal generator.instance_variable_get("@foo"), "FOO" end - def test_file_should_write_data_to_file_path - action :file, 'lib/test_file.rb', 'heres test data' + def test_create_file_should_write_data_to_file_path + action :create_file, 'lib/test_file.rb', 'heres test data' assert_file 'lib/test_file.rb', 'heres test data' end - def test_file_should_write_block_contents_to_file_path - action(:file, 'lib/test_file.rb'){ 'heres block data' } + def test_create_file_should_write_block_contents_to_file_path + action(:create_file, 'lib/test_file.rb'){ 'heres block data' } assert_file 'lib/test_file.rb', 'heres block data' end -- cgit v1.2.3 From da09d46ed463459eb651f6c1e6af923e283da6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 4 Jul 2009 16:57:14 +0200 Subject: Make generators test pass with latest Thor version --- railties/test/generators/actions_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index baf687336a..c17b599582 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -31,12 +31,12 @@ class ActionsTest < GeneratorsTestCase end def test_plugin_with_git_option_should_run_plugin_install - generator.expects(:run).once.with("ruby script/plugin install #{@git_plugin_uri}", false) + generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", false) action :plugin, 'restful-authentication', :git => @git_plugin_uri end def test_plugin_with_svn_option_should_run_plugin_install - generator.expects(:run).once.with("ruby script/plugin install #{@svn_plugin_uri}", false) + generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", false) action :plugin, 'restful-authentication', :svn => @svn_plugin_uri end @@ -132,7 +132,7 @@ class ActionsTest < GeneratorsTestCase end def test_generate_should_run_script_generate_with_argument_and_options - generator.expects(:run).once.with('ruby script/generate model MyModel', false) + generator.expects(:run_ruby_script).once.with('script/generate model MyModel', false) action :generate, 'model', 'MyModel' end -- cgit v1.2.3 From 35925a8995e4b3522e4a4e4e52a3a18c9c1cee52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 4 Jul 2009 17:34:48 +0200 Subject: Ensure that rails templates methods are invoked with the proper extensions [#2531 status:resolved] --- railties/test/generators/actions_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index c17b599582..57ac3f0950 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -151,16 +151,34 @@ class ActionsTest < GeneratorsTestCase action :rake, 'log:clear', :sudo => true end + def test_rake_uses_ruby_extension + Thor::Util.expects(:ruby_command).returns('ruby.bat') + generator.expects(:run).once.with('rake.bat log:clear RAILS_ENV=development', false) + action :rake, 'log:clear' + end + def test_capify_should_run_the_capify_command generator.expects(:run).once.with('capify .', false) action :capify! end + def test_capify_uses_ruby_extension + Thor::Util.expects(:ruby_command).returns('ruby.bat') + generator.expects(:run).once.with('capify.bat .', false) + action :capify! + end + def test_freeze_should_freeze_rails_edge generator.expects(:run).once.with('rake rails:freeze:edge', false) action :freeze! end + def test_freeze_uses_ruby_extension + Thor::Util.expects(:ruby_command).returns('ruby.bat') + generator.expects(:run).once.with('rake.bat rails:freeze:edge', false) + action :freeze! + end + def test_route_should_add_data_to_the_routes_block_in_config_routes run_generator route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" -- cgit v1.2.3 From 66d1b968d108787114372144e97f4f817847892b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 6 Jul 2009 18:31:28 +0200 Subject: Make specs pass on Ruby 1.9. --- railties/test/generators/actions_test.rb | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 57ac3f0950..3313e92c31 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -98,7 +98,10 @@ class ActionsTest < GeneratorsTestCase '# This will be added' end - assert_file 'config/environment.rb', /# This will be added/ + assert_file 'config/environment.rb' do |content| + assert_match /# This will be added/, content + assert_no_match /# This wont be added/, content + end end def test_git_with_symbol_should_run_command_using_git_scm @@ -151,34 +154,16 @@ class ActionsTest < GeneratorsTestCase action :rake, 'log:clear', :sudo => true end - def test_rake_uses_ruby_extension - Thor::Util.expects(:ruby_command).returns('ruby.bat') - generator.expects(:run).once.with('rake.bat log:clear RAILS_ENV=development', false) - action :rake, 'log:clear' - end - def test_capify_should_run_the_capify_command generator.expects(:run).once.with('capify .', false) action :capify! end - def test_capify_uses_ruby_extension - Thor::Util.expects(:ruby_command).returns('ruby.bat') - generator.expects(:run).once.with('capify.bat .', false) - action :capify! - end - def test_freeze_should_freeze_rails_edge generator.expects(:run).once.with('rake rails:freeze:edge', false) action :freeze! end - def test_freeze_uses_ruby_extension - Thor::Util.expects(:ruby_command).returns('ruby.bat') - generator.expects(:run).once.with('rake.bat rails:freeze:edge', false) - action :freeze! - end - def test_route_should_add_data_to_the_routes_block_in_config_routes run_generator route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" -- cgit v1.2.3 From a06c825b464758a0c22f8b089a596e46f1bba5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 14 Jul 2009 22:20:43 +0200 Subject: Updated vendored Thor to 0.11.1 and update Rails::Generators. --- railties/test/generators/actions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 3313e92c31..e8b10522b9 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -178,7 +178,7 @@ class ActionsTest < GeneratorsTestCase end def generator(config={}) - @generator ||= Rails::Generators::Base.new([], {}, { :root => destination_root }.merge!(config)) + @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config)) end def action(*args, &block) -- cgit v1.2.3 From b4ef958de6b16294094de28d00ba25fe2f48accc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 20:16:37 +0200 Subject: Change false to :verbose => false as in new Thor version. --- railties/test/generators/actions_test.rb | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index e8b10522b9..9a8d8075a1 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -20,6 +20,17 @@ class ActionsTest < GeneratorsTestCase assert_equal generator.instance_variable_get("@foo"), "FOO" end + def test_apply_uses_padding_in_the_applied_template + template = <<-TEMPLATE + say_status :cool, :padding + TEMPLATE + template.instance_eval "def read; self; end" + + generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) + content = action(:apply, "http://gist.github.com/103208.txt") + assert_match /cool padding/, content + end + def test_create_file_should_write_data_to_file_path action :create_file, 'lib/test_file.rb', 'heres test data' assert_file 'lib/test_file.rb', 'heres test data' @@ -31,17 +42,17 @@ class ActionsTest < GeneratorsTestCase end def test_plugin_with_git_option_should_run_plugin_install - generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", false) + generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", :verbose => false) action :plugin, 'restful-authentication', :git => @git_plugin_uri end def test_plugin_with_svn_option_should_run_plugin_install - generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", false) + generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", :verbose => false) action :plugin, 'restful-authentication', :svn => @svn_plugin_uri end def test_plugin_with_git_option_and_submodule_should_use_git_scm - generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", false) + generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", :verbose => false) action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true end @@ -135,32 +146,32 @@ class ActionsTest < GeneratorsTestCase end def test_generate_should_run_script_generate_with_argument_and_options - generator.expects(:run_ruby_script).once.with('script/generate model MyModel', false) + generator.expects(:run_ruby_script).once.with('script/generate model MyModel', :verbose => false) action :generate, 'model', 'MyModel' end def test_rake_should_run_rake_command_with_development_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', false) + generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', :verbose => false) action :rake, 'log:clear' end def test_rake_with_env_option_should_run_rake_command_in_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', false) + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false) action :rake, 'log:clear', :env => 'production' end def test_rake_with_sudo_option_should_run_rake_command_with_sudo - generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', false) + generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false) action :rake, 'log:clear', :sudo => true end def test_capify_should_run_the_capify_command - generator.expects(:run).once.with('capify .', false) + generator.expects(:run).once.with('capify .', :verbose => false) action :capify! end def test_freeze_should_freeze_rails_edge - generator.expects(:run).once.with('rake rails:freeze:edge', false) + generator.expects(:run).once.with('rake rails:freeze:edge', :verbose => false) action :freeze! end -- cgit v1.2.3 From d6a590a7107eabd9c3ab067c60bef904da62f174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 16 Jul 2009 11:17:19 +0200 Subject: Modified rake tasks to use new app generator structure and updated Thor version. --- railties/test/generators/actions_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 9a8d8075a1..aeddb21d1f 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -31,6 +31,19 @@ class ActionsTest < GeneratorsTestCase assert_match /cool padding/, content end + def test_apply_does_not_log_status_if_required + template = <<-TEMPLATE + say_status :cool, :padding + TEMPLATE + template.instance_eval "def read; self; end" + + generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) + content = action(:apply, "http://gist.github.com/103208.txt", :verbose => false) + + assert_match /cool padding/, content + assert_no_match /apply http/, content + end + def test_create_file_should_write_data_to_file_path action :create_file, 'lib/test_file.rb', 'heres test data' assert_file 'lib/test_file.rb', 'heres test data' -- cgit v1.2.3 From edd07b5a7a37783f398a156b2eb99b5b2733a0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 23 Jul 2009 14:30:49 +0200 Subject: Updated vendored thor to 0.11.3. --- railties/test/generators/actions_test.rb | 35 -------------------------------- 1 file changed, 35 deletions(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index aeddb21d1f..0cda49702b 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -9,41 +9,6 @@ class ActionsTest < GeneratorsTestCase @svn_plugin_uri = 'svn://svnhub.com/technoweenie/restful-authentication/trunk' end - def test_apply_loads_and_evaluates_a_template - template = <<-TEMPLATE - @foo = "FOO" - TEMPLATE - template.instance_eval "def read; self; end" # Make the string respond to read - - generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) - action :apply, "http://gist.github.com/103208.txt" - assert_equal generator.instance_variable_get("@foo"), "FOO" - end - - def test_apply_uses_padding_in_the_applied_template - template = <<-TEMPLATE - say_status :cool, :padding - TEMPLATE - template.instance_eval "def read; self; end" - - generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) - content = action(:apply, "http://gist.github.com/103208.txt") - assert_match /cool padding/, content - end - - def test_apply_does_not_log_status_if_required - template = <<-TEMPLATE - say_status :cool, :padding - TEMPLATE - template.instance_eval "def read; self; end" - - generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) - content = action(:apply, "http://gist.github.com/103208.txt", :verbose => false) - - assert_match /cool padding/, content - assert_no_match /apply http/, content - end - def test_create_file_should_write_data_to_file_path action :create_file, 'lib/test_file.rb', 'heres test data' assert_file 'lib/test_file.rb', 'heres test data' -- cgit v1.2.3