forked from minitest/minitest-rails
/
scaffold_generator.rb
43 lines (36 loc) · 1.36 KB
/
scaffold_generator.rb
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
31
32
33
34
35
36
37
38
39
40
41
42
43
require "generators/mini_test"
require "rails/generators/resource_helpers"
module MiniTest
module Generators
class ScaffoldGenerator < Base
include ::Rails::Generators::ResourceHelpers
argument :actions, :type => :array, :default => [], :banner => "action action"
class_option :spec, :type => :boolean, :default => false, :desc => "Use MiniTest::Spec DSL"
check_class_collision :suffix => "ControllerTest"
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
def create_test_files
if options[:spec]
template "controller_spec.rb",
File.join("test/controllers",
class_path,
"#{controller_file_name}_controller_test.rb")
else
template "controller_test.rb",
File.join("test/controllers",
class_path,
"#{controller_file_name}_controller_test.rb")
end
end
def accessible_attributes
attributes.reject(&:reference?)
end
def attributes_hash
return if accessible_attributes.empty?
accessible_attributes.map do |a|
name = a.name
key_value name, "@#{singular_table_name}.#{name}"
end.sort.join(', ')
end
end
end
end