class Rspec::Generators::JbuilderGenerator
Public Instance Methods
generate_view_specs()
click to toggle source
# File lib/generators/rspec/jbuilder_generator.rb, line 16 def generate_view_specs source_paths << File.expand_path("../templates", __FILE__) copy_view :index copy_view :show end
Protected Instance Methods
copy_view(view)
click to toggle source
# File lib/generators/rspec/jbuilder_generator.rb, line 24 def copy_view(view) template "#{view}_spec.rb", File.join("spec/views", controller_file_path, "#{view}.json.jbuilder_spec.rb") end
ns_file_name()
click to toggle source
support for namespaced-resources
# File lib/generators/rspec/jbuilder_generator.rb, line 30 def ns_file_name ns_parts.empty? ? file_name : "#{ns_parts[0].underscore}_#{ns_parts[1].singularize.underscore}" end
ns_parts()
click to toggle source
# File lib/generators/rspec/jbuilder_generator.rb, line 39 def ns_parts @ns_parts ||= begin matches = ARGV[0].to_s.match(/\A(\w+)(?:\/|::)(\w+)/) matches ? [matches[1], matches[2]] : [] end end
ns_table_name()
click to toggle source
support for namespaced-resources
# File lib/generators/rspec/jbuilder_generator.rb, line 35 def ns_table_name ns_parts.empty? ? table_name : "#{ns_parts[0].underscore}/#{ns_parts[1].tableize}" end
raw_value_for(attribute)
click to toggle source
# File lib/generators/rspec/jbuilder_generator.rb, line 50 def raw_value_for(attribute) case attribute.type when :string attribute.name.titleize when :integer @attribute_id_map ||= {} @attribute_id_map[attribute] ||= @attribute_id_map.keys.size.next else attribute.default end end
value_for(attribute)
click to toggle source
# File lib/generators/rspec/jbuilder_generator.rb, line 46 def value_for(attribute) raw_value_for(attribute).inspect end