File: mailer_generator.rb

package info (click to toggle)
ruby-rspec-rails 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,804 kB
  • sloc: ruby: 10,881; sh: 198; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'generators/rspec'
require "rspec/rails/feature_check"

module Rspec
  module Generators
    # @private
    class MailerGenerator < Base
      argument :actions, type: :array, default: [], banner: "method method"

      def generate_mailer_spec
        file_suffix = file_name.end_with?('mailer') ? 'spec.rb' : 'mailer_spec.rb'
        template "mailer_spec.rb", target_path('mailers', class_path, [file_name, file_suffix].join('_'))
      end

      def generate_fixtures_files
        actions.each do |action|
          @action, @path = action, File.join(file_path, action)
          template "fixture", target_path("fixtures", @path)
        end
      end

      def generate_preview_files
        return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?

        file_suffix = file_name.end_with?('mailer') ? 'preview.rb' : 'mailer_preview.rb'
        template "preview.rb", target_path("mailers/previews", class_path, [file_name, file_suffix].join('_'))
      end
    end
  end
end