Sha256: 9a3617423d054912f3054341b4ba01947ebf08a298c1bbdbb7bbd3059444dfe0

Contents?: true

Size: 838 Bytes

Versions: 1

Compression:

Stored size: 838 Bytes

Contents

require 'spec_helper'

if defined? Mongoid

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

    class Person
      include Mongoid::Document

      field :name, :type => String
      field :age, :type => Integer

      scope :teenagers, between(:age => 13..19)

      comma do
        name
        age
      end
    end

    after(:all) do
      Mongoid.purge!
    end

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

      it 'should extend ActiveRecord::NamedScope::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

1 entries across 1 versions & 1 rubygems

Version Path
comma-4.2.0 spec/comma/rails/mongoid_spec.rb