Class: Rails::AddOns::ResourcesControllerSpecGenerator

Inherits:
Generators::Base
  • Object
show all
Defined in:
lib/generators/rails/add_ons/resources_controller_spec_generator.rb

Overview

This will generate specs for create, read, update, delete and list.

Example:

rails g rails:add_ons:resources_controller_spec --uri /de/backend/uploads
  create  spec/features/de/backend/uploads_feature_spec.rb

If your resource class does not match the last part of your url (i.e. /de/posts would guess the resource class to Post) you can specify the resource name like this:

RESOURCE_CLASS=Blog::Post rails g rails:add_ons:resources_controller_spec --uri /de/posts
  create  spec/features/de/posts_feature_spec.rb

Instance Method Summary collapse

Instance Method Details

#edit_form_dom_selectorObject


28
29
30
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 28

def edit_form_dom_selector
  ".edit_#{resource_class.demodulize.underscore}"
end

#factory_nameObject


40
41
42
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 40

def factory_name
  underscored_resource_class
end

#generate_specObject


48
49
50
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 48

def generate_spec
  template 'spec.rb', "spec/features#{uri}_feature_spec.rb"
end

#new_form_dom_selectorObject


32
33
34
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 32

def new_form_dom_selector
  "#new_#{resource_class.demodulize.underscore}"
end

#resource_classObject


36
37
38
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 36

def resource_class
  @resource_class ||= ENV.fetch('RESOURCE_CLASS') { @uri.split('/').last.camelize.singularize }
end

#underscored_resource_classObject


44
45
46
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 44

def underscored_resource_class
  @undescored_resource_class ||= resource_class.underscore.gsub('/', '_')
end

#uriObject


24
25
26
# File 'lib/generators/rails/add_ons/resources_controller_spec_generator.rb', line 24

def uri
  @uri ||= options['uri']
end