Sha256: a383d776f7e52ca8ef71fc46b4ff3b9d589426a9842023c13b9033851024eaed

Contents?: true

Size: 1012 Bytes

Versions: 7

Compression:

Stored size: 1012 Bytes

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

if defined? DataMapper

  describe Comma, 'generating CSV from an DataMapper object' do

    class Person
      include DataMapper::Resource

      property :id, Serial
      property :name, String
      property :age, Integer

      def self.teenagers
        all(:age.gte => 13) & all(:age.lte => 19)
      end

      comma do
        name
        age
      end
    end
    DataMapper.finalize

    before(:all) do
      DataMapper.setup(:default, 'sqlite::memory:')
      DataMapper.auto_migrate!
    end

    after(:all) do
    end

    describe "case" do
      before do
        @person = Person.new(:age => 18, :name => 'Junior')
        @person.save
      end

      it 'should extend scope to add a #to_comma method which will return CSV content for objects within the scope' do
        Person.teenagers.to_comma.should == "Name,Age\nJunior,18\n"
      end

      it 'should find in batches' do
        Person.teenagers.to_comma
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
comma-4.0.1 spec/comma/rails/data_mapper_collection_spec.rb
comma-4.0.0 spec/comma/rails/data_mapper_collection_spec.rb
comma-3.2.4 spec/comma/rails/data_mapper_collection_spec.rb
comma-3.2.3 spec/comma/rails/data_mapper_collection_spec.rb
comma-3.2.2 spec/comma/rails/data_mapper_collection_spec.rb
comma-3.2.1 spec/comma/rails/data_mapper_collection_spec.rb
comma-3.2.0 spec/comma/rails/data_mapper_collection_spec.rb