Class: Crudspec::Generators::SpecGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spec_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ SpecGenerator

Returns a new instance of SpecGenerator.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/spec_generator.rb', line 11

def initialize(*args, &block)
  super

  @controller_actions = []

  controller_args.each do |arg|
    @controller_actions << arg
    @controller_actions << 'create' if arg == 'new'
    @controller_actions << 'update' if arg == 'edit'
  end

  @controller_actions.uniq!
  @controller_actions = all_actions if @controller_actions.empty?
end

Instance Method Details

#generate_spec_fileObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/spec_generator.rb', line 26

def generate_spec_file
  underscored = controller_name.underscore
  underscored = underscored + '_controller' unless underscored.match(/_controller$/)
  @class_name = underscored.classify
  @devise = options[:devise] if options[:devise]

  # Really?
  @model_name = @class_name.demodulize.match(/(.+)Controller$/)[1].underscore.singularize
  file_path = "spec/controllers/#{underscored}_spec.rb"

  template('controller_spec.rb', file_path)
end