class Rspec::Generators::ScaffoldGenerator
@private
Attributes
generator_args[R]
Public Class Methods
new(*args, &blk)
click to toggle source
Calls superclass method
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 23 def initialize(*args, &blk) @generator_args = args.first super(*args, &blk) end
Public Instance Methods
generate_controller_spec()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 28 def generate_controller_spec return unless options[:controller_specs] if options[:api] template 'api_controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller') else template 'controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller') end end
generate_request_spec()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 38 def generate_request_spec return unless options[:request_specs] if options[:api] template 'api_request_spec.rb', template_file(folder: 'requests') else template 'request_spec.rb', template_file(folder: 'requests') end end
generate_routing_spec()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 58 def generate_routing_spec return unless options[:routing_specs] template_file = File.join( 'spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb" ) template 'routing_spec.rb', template_file end
generate_view_specs()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 48 def generate_view_specs return if options[:api] return unless options[:view_specs] && options[:template_engine] copy_view :edit copy_view :index unless options[:singleton] copy_view :new copy_view :show end
Protected Instance Methods
copy_view(view)
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 73 def copy_view(view) template "#{view}_spec.rb", File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb") end
ns_file_name()
click to toggle source
support for namespaced-resources
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 79 def ns_file_name return file_name if ns_parts.empty? "#{ns_prefix.map(&:underscore).join('/')}_#{ns_suffix.singularize.underscore}" end
ns_parts()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 92 def ns_parts @ns_parts ||= begin parts = generator_args[0].split(/\/|::/) parts.size > 1 ? parts : [] end end
ns_prefix()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 99 def ns_prefix @ns_prefix ||= ns_parts[0..-2] end
ns_suffix()
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 103 def ns_suffix @ns_suffix ||= ns_parts[-1] end
ns_table_name()
click to toggle source
support for namespaced-resources
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 86 def ns_table_name return table_name if ns_parts.empty? "#{ns_prefix.map(&:underscore).join('/')}/#{ns_suffix.tableize}" end
raw_value_for(attribute)
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 111 def raw_value_for(attribute) case attribute.type when :string attribute.name.titleize when :integer, :float @attribute_id_map ||= {} @attribute_id_map[attribute] ||= @attribute_id_map.keys.size.next + attribute.default else attribute.default end end
template_file(folder:, suffix: '')
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 123 def template_file(folder:, suffix: '') File.join('spec', folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb") end
value_for(attribute)
click to toggle source
# File lib/generators/rspec/scaffold/scaffold_generator.rb, line 107 def value_for(attribute) raw_value_for(attribute).inspect end