Sha256: 060cea4a6aec74918d9a53c9e270187f510e9d54ba048481713d1499a253a0d3

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'rspec_for_generators/rails_helpers/rails_model'

module RSpec::Rails
  module Orm
    module Base
      include RSpec::Rails::Model

      protected

      def clazz name
        "class #{name.to_s.camelize}"
      end

      def file name
        %Q{#{clazz name}
          #{yield if block_given?}
        end}
      end

      def file_w_include name
        file name { "include #{yield}" if block_given?}
      end

      def file_w_inherit name
        %Q{#{clazz name} < #{yield if block_given?}
        end}
      end
    end

    module ActiveRecord
      include RSpec::Rails::Orm::Base

      def file_content(name)
        file_w_inherit(name) {'ActiveRecord::Base'}
      end
    end

    module MongoMapper
      include RSpec::Rails::Orm::Base

      def file_content name, type = :document
        type_content = type == :document ? 'MongoMapper::Document' : 'MongoMapper::EmbeddedDocument'
        file_w_include(name) { type_content } 
      end

      def field name, type = nil
        return "key :#{name}, #{type}" if type
        "key :#{name}"
      end
    end

    module Mongoid
      include RSpec::Rails::Orm::Base

      def file_content name, type = :document
        type_content = type == :document ? 'Mongoid::Document' : 'Mongoid::EmbeddedDocument'
        file_w_include(name) { type_content }
      end

      def field name, type = nil
        return "field :#{name}, :type => #{type}" if type
        "field :#{name}"
      end
    end

    module DataMapper
      include RSpec::Rails::Orm::Base

      def file_content name
        file_w_include(name) { 'DataMapper::Resource' }
      end

      def field name, type = nil
        return "property :#{name}, #{type}" if type
        "property :#{name}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
generator-spec-0.4.3 lib/rspec_for_generators/rails_helpers/rails_orm.rb