Sha256: a5136e0940903a3d58dcc7acc05625e774d2f434c30af27b895da5e84bd2a0aa

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 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
        file_w_include(name) { 'MongoMapper::Document' }
      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
        file_w_include(name) { 'Mongoid::Document' }
      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

8 entries across 8 versions & 2 rubygems

Version Path
generator-spec-0.4.2 lib/rspec_for_generators/rails_helpers/rails_orm.rb
generator-spec-0.4.1 lib/rspec_for_generators/rails_helpers/rails_orm.rb
generator-spec-0.4.0 lib/rspec_for_generators/rails_helpers/rails_orm.rb
generator-spec-0.3.5 lib/rspec_for_generators/rails_helpers/rails_orm.rb
generator-spec-0.3.4 lib/rspec_for_generators/rails_helpers/rails_orm.rb
generator-spec-0.3.3 lib/rspec_for_generators/rails_helpers/rails_orm.rb
rspec_for_generators-0.3.1 lib/rspec_for_generators/rails_helpers/rails_orm.rb
rspec_for_generators-0.3.0 lib/rspec_for_generators/rails_helpers/rails_orm.rb