Module: RSpec::Rails::Model

Defined in:
lib/rspec_for_generators/rails_helpers/rails_model.rb

Defined Under Namespace

Modules: ActiveRecord, DataMapper, MongoMapper, Mongoid

Instance Method Summary collapse

Instance Method Details

#create_model(name, &block) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 64

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



84
85
86
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 84

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

#remove_model(name) ⇒ Object



75
76
77
78
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 75

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

#remove_models(*names) ⇒ Object



80
81
82
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 80

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

#set_orm(orm) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rspec_for_generators/rails_helpers/rails_model.rb', line 50

def set_orm orm
  orm_module = case orm
  when :active_record
    ActiveRecord
  when :data_mapper
    DataMapper
  when :mongo_mapper
    MongoMapper
  when :mongoid
    Mongoid
  end
  include orm_module
end