aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDino Maric <dino.onex@gmail.com>2018-12-15 13:41:23 +0100
committerDino Maric <dino.onex@gmail.com>2018-12-15 16:33:39 +0100
commit8415a6c5cf883f7ce6fe93b80ec99072fb04be83 (patch)
tree17a4e88934c3f9dee74ef9ce880acb3d8869645e
parent749e923539075eef407e5d9b8c7c151a3b3171d4 (diff)
downloadrails-8415a6c5cf883f7ce6fe93b80ec99072fb04be83.tar.gz
rails-8415a6c5cf883f7ce6fe93b80ec99072fb04be83.tar.bz2
rails-8415a6c5cf883f7ce6fe93b80ec99072fb04be83.zip
Fix Rails generators
1.Don't generate ApplicationMailboxTest when executing installer 2. Hookup test_unit, so console doesn't throw errors
-rw-r--r--lib/generators/rails/USAGE (renamed from lib/rails/generators/mailbox/USAGE)0
-rw-r--r--lib/generators/rails/mailbox_generator.rb (renamed from lib/rails/generators/mailbox/mailbox_generator.rb)6
-rw-r--r--lib/generators/rails/templates/application_mailbox.rb.tt (renamed from lib/rails/generators/mailbox/templates/application_mailbox.rb.tt)0
-rw-r--r--lib/generators/rails/templates/mailbox.rb.tt (renamed from lib/rails/generators/mailbox/templates/mailbox.rb.tt)0
-rw-r--r--lib/generators/test_unit/mailbox_generator.rb20
-rw-r--r--lib/generators/test_unit/templates/mailbox_test.rb.tt (renamed from lib/rails/generators/mailbox/templates/mailbox_test.rb.tt)0
-rw-r--r--lib/tasks/install.rake2
-rw-r--r--test/generators/mailbox_generator_test.rb15
8 files changed, 26 insertions, 17 deletions
diff --git a/lib/rails/generators/mailbox/USAGE b/lib/generators/rails/USAGE
index d679dd63ae..d679dd63ae 100644
--- a/lib/rails/generators/mailbox/USAGE
+++ b/lib/generators/rails/USAGE
diff --git a/lib/rails/generators/mailbox/mailbox_generator.rb b/lib/generators/rails/mailbox_generator.rb
index 5511545a98..7b43173480 100644
--- a/lib/rails/generators/mailbox/mailbox_generator.rb
+++ b/lib/generators/rails/mailbox_generator.rb
@@ -7,9 +7,7 @@ module Rails
argument :actions, type: :array, default: [:process], banner: "method method"
- def check_class_collision
- class_collisions "#{class_name}Mailbox", "#{class_name}MailboxTest"
- end
+ check_class_collision suffix: "Mailbox"
def create_mailbox_file
template "mailbox.rb", File.join("app/mailboxes", class_path, "#{file_name}_mailbox.rb")
@@ -19,8 +17,6 @@ module Rails
template "application_mailbox.rb", application_mailbox_file_name
end
end
-
- template "mailbox_test.rb", File.join('test/mailboxes', class_path, "#{file_name}_mailbox_test.rb")
end
hook_for :test_framework
diff --git a/lib/rails/generators/mailbox/templates/application_mailbox.rb.tt b/lib/generators/rails/templates/application_mailbox.rb.tt
index be51eb3639..be51eb3639 100644
--- a/lib/rails/generators/mailbox/templates/application_mailbox.rb.tt
+++ b/lib/generators/rails/templates/application_mailbox.rb.tt
diff --git a/lib/rails/generators/mailbox/templates/mailbox.rb.tt b/lib/generators/rails/templates/mailbox.rb.tt
index 9788bd9bb4..9788bd9bb4 100644
--- a/lib/rails/generators/mailbox/templates/mailbox.rb.tt
+++ b/lib/generators/rails/templates/mailbox.rb.tt
diff --git a/lib/generators/test_unit/mailbox_generator.rb b/lib/generators/test_unit/mailbox_generator.rb
new file mode 100644
index 0000000000..2ec7d11a2f
--- /dev/null
+++ b/lib/generators/test_unit/mailbox_generator.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module TestUnit
+ module Generators
+ class MailboxGenerator < ::Rails::Generators::NamedBase
+ source_root File.expand_path("templates", __dir__)
+
+ check_class_collision suffix: "MailboxTest"
+
+ def create_test_files
+ template "mailbox_test.rb", File.join("test/mailboxes", class_path, "#{file_name}_mailbox_test.rb")
+ end
+
+ private
+ def file_name # :doc:
+ @_file_name ||= super.sub(/_mailbox\z/i, "")
+ end
+ end
+ end
+end
diff --git a/lib/rails/generators/mailbox/templates/mailbox_test.rb.tt b/lib/generators/test_unit/templates/mailbox_test.rb.tt
index 41749808e3..41749808e3 100644
--- a/lib/rails/generators/mailbox/templates/mailbox_test.rb.tt
+++ b/lib/generators/test_unit/templates/mailbox_test.rb.tt
diff --git a/lib/tasks/install.rake b/lib/tasks/install.rake
index 1f4c071494..598e30c2d4 100644
--- a/lib/tasks/install.rake
+++ b/lib/tasks/install.rake
@@ -8,7 +8,7 @@ namespace :action_mailbox do
task install: %w[ environment run_generator copy_migrations ]
task :run_generator do
- system "#{RbConfig.ruby} ./bin/rails generate mailbox application"
+ system "#{RbConfig.ruby} ./bin/rails generate mailbox application --no-test-framework"
end
task :copy_migrations do
diff --git a/test/generators/mailbox_generator_test.rb b/test/generators/mailbox_generator_test.rb
index 9295c2d8c8..46f1dc6ea0 100644
--- a/test/generators/mailbox_generator_test.rb
+++ b/test/generators/mailbox_generator_test.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
require "test_helper"
-require "rails/generators/mailbox/mailbox_generator"
+require "generators/rails/mailbox_generator"
class MailboxGeneratorTest < Rails::Generators::TestCase
destination File.expand_path("../../tmp", File.dirname(__FILE__))
@@ -33,7 +34,7 @@ class MailboxGeneratorTest < Rails::Generators::TestCase
end
def test_invokes_default_test_framework
- run_generator %w(inbox foo bar)
+ run_generator %w(inbox foo bar -t=test_unit)
assert_file "test/mailboxes/inbox_mailbox_test.rb" do |test|
assert_match(/class InboxMailboxTest < ActionMailbox::TestCase/, test)
assert_match(/# test "receive mail" do/, test)
@@ -41,14 +42,6 @@ class MailboxGeneratorTest < Rails::Generators::TestCase
end
end
- def test_check_test_class_collision
- Object.send :const_set, :InboxMailboxTest, Class.new
- content = capture(:stderr) { run_generator }
- assert_match(/The name 'InboxMailboxTest' is either already used in your application or reserved/, content)
- ensure
- Object.send :remove_const, :InboxMailboxTest
- end
-
def test_actions_are_turned_into_methods
run_generator %w(inbox foo bar)
@@ -66,7 +59,7 @@ class MailboxGeneratorTest < Rails::Generators::TestCase
end
def test_mailbox_suffix_is_not_duplicated
- run_generator ["inbox_mailbox"]
+ run_generator %w(inbox_mailbox -t=test_unit)
assert_no_file "app/mailboxes/inbox_mailbox_mailbox.rb"
assert_file "app/mailboxes/inbox_mailbox.rb"