aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailbox/test/generators
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-12-24 15:16:22 -0500
committerGeorge Claghorn <george@basecamp.com>2018-12-25 21:32:35 -0500
commita5b2fff64ca0c1fa7be5124f40a251d991c10a85 (patch)
tree33a79841402b7151e52d9ad3949ce54f320c10aa /actionmailbox/test/generators
parent4298df00ae6219b9b5b7c40f281d4fa4d66f4383 (diff)
parentdcddff1d2d0c695318670686a27429a76f20ae03 (diff)
downloadrails-a5b2fff64ca0c1fa7be5124f40a251d991c10a85.tar.gz
rails-a5b2fff64ca0c1fa7be5124f40a251d991c10a85.tar.bz2
rails-a5b2fff64ca0c1fa7be5124f40a251d991c10a85.zip
Import Action Mailbox
Diffstat (limited to 'actionmailbox/test/generators')
-rw-r--r--actionmailbox/test/generators/mailbox_generator_test.rb85
1 files changed, 85 insertions, 0 deletions
diff --git a/actionmailbox/test/generators/mailbox_generator_test.rb b/actionmailbox/test/generators/mailbox_generator_test.rb
new file mode 100644
index 0000000000..624fbef420
--- /dev/null
+++ b/actionmailbox/test/generators/mailbox_generator_test.rb
@@ -0,0 +1,85 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require "rails/generators/mailbox/mailbox_generator"
+
+class MailboxGeneratorTest < Rails::Generators::TestCase
+ destination File.expand_path("../../tmp", __dir__)
+ setup :prepare_destination
+ tests Rails::Generators::MailboxGenerator
+
+ arguments ["inbox"]
+
+ def test_mailbox_skeleton_is_created
+ run_generator
+
+ assert_file "app/mailboxes/inbox_mailbox.rb" do |mailbox|
+ assert_match(/class InboxMailbox < ApplicationMailbox/, mailbox)
+ assert_match(/def process/, mailbox)
+ assert_no_match(%r{# routing /something/i => :somewhere}, mailbox)
+ end
+
+ assert_file "app/mailboxes/application_mailbox.rb" do |mailbox|
+ assert_match(/class ApplicationMailbox < ActionMailbox::Base/, mailbox)
+ assert_match(%r{# routing /something/i => :somewhere}, mailbox)
+ assert_no_match(/def process/, mailbox)
+ end
+ end
+
+ def test_mailbox_skeleton_is_created_with_namespace
+ run_generator %w(inceptions/inbox -t=test_unit)
+
+ assert_file "app/mailboxes/inceptions/inbox_mailbox.rb" do |mailbox|
+ assert_match(/class Inceptions::InboxMailbox < ApplicationMailbox/, mailbox)
+ assert_match(/def process/, mailbox)
+ assert_no_match(%r{# routing /something/i => :somewhere}, mailbox)
+ end
+
+ assert_file "test/mailboxes/inceptions/inbox_mailbox_test.rb" do |mailbox|
+ assert_match(/class Inceptions::InboxMailboxTest < ActionMailbox::TestCase/, mailbox)
+ assert_match(/# test "receive mail" do/, mailbox)
+ assert_match(/# to: '"someone" <someone@example.com>,/, mailbox)
+ end
+
+ assert_file "app/mailboxes/application_mailbox.rb" do |mailbox|
+ assert_match(/class ApplicationMailbox < ActionMailbox::Base/, mailbox)
+ assert_match(%r{# routing /something/i => :somewhere}, mailbox)
+ assert_no_match(/def process/, mailbox)
+ end
+ end
+
+ def test_check_class_collision
+ Object.send :const_set, :InboxMailbox, Class.new
+ content = capture(:stderr) { run_generator }
+ assert_match(/The name 'InboxMailbox' is either already used in your application or reserved/, content)
+ ensure
+ Object.send :remove_const, :InboxMailbox
+ end
+
+ def test_invokes_default_test_framework
+ run_generator %w(inbox -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)
+ assert_match(/# to: '"someone" <someone@example.com>,/, test)
+ end
+ end
+
+ def test_mailbox_on_revoke
+ run_generator
+ run_generator ["inbox"], behavior: :revoke
+
+ assert_no_file "app/mailboxes/inbox_mailbox.rb"
+ end
+
+ def test_mailbox_suffix_is_not_duplicated
+ run_generator %w(inbox_mailbox -t=test_unit)
+
+ assert_no_file "app/mailboxes/inbox_mailbox_mailbox.rb"
+ assert_file "app/mailboxes/inbox_mailbox.rb"
+
+ assert_no_file "test/mailboxes/inbox_mailbox_mailbox_test.rb"
+ assert_file "test/mailboxes/inbox_mailbox_test.rb"
+ end
+end