Sha256: 95a032b95f2936d77a2c62301f595446fde5f1321baaa47210a412c2a3926377

Contents?: true

Size: 890 Bytes

Versions: 7

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

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 # rubocop:disable Metrics/LineLength
        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.7.0 spec/comma/rails/mongoid_spec.rb
comma-4.6.0 spec/comma/rails/mongoid_spec.rb
comma-4.5.0 spec/comma/rails/mongoid_spec.rb
comma-4.4.0 spec/comma/rails/mongoid_spec.rb
comma-4.3.2 spec/comma/rails/mongoid_spec.rb
comma-4.3.1 spec/comma/rails/mongoid_spec.rb
comma-4.3.0 spec/comma/rails/mongoid_spec.rb