Sha256: c3e076c32203125d2b87f4947d195458e06a420937ae0797fe6391141aff7757

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 Bytes

Contents

module RSpec::Rails
  module Model  
    include RSpec::Rails::App    
      
    def create_model name, type=nil, &block      
      file = model_file_name(name)
      unless File.exist?(file)    
        FileUtils.mkdir_p File.dirname(file)
        File.open(file, 'w') do |f|
          raise "You must include an ORM helper in your model spec, fx: include RSpec::Rails::Orm::ActiveRecord" if !respond_to? :file_content
          f.puts file_content(name, type)
          yield f if block_given?
        end
      end
    end  

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

    def remove_models *names
      names.each{|name| remove_model name }
    end      
    
    def model_file_name name
      File.join(model_dir, "#{name}.rb")
    end        
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
generator-spec-0.4.8 lib/generator_spec/rails_helpers/rails_model.rb
generator-spec-0.4.7 lib/generator_spec/rails_helpers/rails_model.rb