Class: Concern::ModelGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/concern/model/model_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_rspec_helperObject



10
11
12
# File 'lib/generators/concern/model/model_generator.rb', line 10

def copy_rspec_helper
  copy_file("mock_table_helper.rb", "spec/support/mock_table_helper.rb") if invoke?
end

#create_concernsObject



4
5
6
7
8
# File 'lib/generators/concern/model/model_generator.rb', line 4

def create_concerns
  setting_path = "models/concerns"
  template "concern.erb", File.join("app", setting_path, class_path, "#{file_name}.rb")
  template "model_spec.erb", File.join("spec", setting_path, class_path, "#{file_name}_spec.rb")
end

#inject_codeObject



14
15
16
17
18
19
20
21
# File 'lib/generators/concern/model/model_generator.rb', line 14

def inject_code
  rspec_helper = Rails.root.join(*%w[spec rails_helper.rb])
  inject_into_file rspec_helper, before: /^ActiveRecord::Migration\.maintain_test_schema!/ do <<-'CODE'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

  CODE
  end if injectable?(rspec_helper)
end