Module: RSpec::Rails::Model

Included in:
Orm::Base
Defined in:
lib/rspec_for_generators/rails_helpers/rails_model.rb

Instance Method Summary collapse

Instance Method Details

#create_model(name, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 3

def create_model name, &block      
  file = model_file_name(name)
  unless File.exist?(file)    
    FileUtils.mkdir_p File.dirname(file)
    File.open(file, 'w') do |f|  
      f.puts file_content(name)
      yield f if block_given?
    end
  end
end

#model_file_name(name) ⇒ Object



23
24
25
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 23

def model_file_name name
  File.join(::Rails.root, "app/models/#{name}.rb")
end

#remove_model(name) ⇒ Object



14
15
16
17
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 14

def remove_model name
  file = model_file_name(name)
  FileUtils.rm_f(file) if File.exist?(file)
end

#remove_models(*names) ⇒ Object



19
20
21
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 19

def remove_models *names
  names.each{|name| remove_model name }
end