Sha256: 30198b942c85b39b365488c505c1d47a1bf7decc3d46ddc85f98757bf513d093

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe "CloudXLS::CSVWriter" do
  before do
    @writer = CloudXLS::CSVWriter
  end

  describe "with array" do
    # spec'ed in cloudlxs-ruby gem
  end

  describe "#text with AR" do
    before do
      Post.delete_all
      @post = Post.create(
        :title           => "hello world",
        :visits          => 12_032,
        :conversion_rate => 0.24,
        :published_on    => Date.new(2013,12,24),
        :expired_at      => DateTime.new(2013,12,25,12,30,30),
        :unix_timestamp  => DateTime.new(2013,12,25,12,30,30),
        :published       => false)
    end

    it "given no records should just return titles" do
      Post.delete_all
      expect( @writer.text(Post.all, :columns => [:title, :visits]) ).to eq("Title,Visits")
    end

    it "should work with a Post.all" do
      expect( @writer.text(Post.all, :columns => [:title, :visits]) ).to eq("Title,Visits\nhello world,12032")
    end

    it "should work with a Post.limit" do
      expect( @writer.text(Post.limit(10), :columns => [:title, :visits]) ).to eq("Title,Visits\nhello world,12032")
    end

    it "should work with a Post.all.to_a" do
      expect( @writer.text(Post.all.to_a, :columns => [:title, :visits]) ).to eq("Title,Visits\nhello world,12032")
    end

    it "should write xmlschema for DateTime" do
      expect( @writer.text(Post.all, :columns => [:expired_at]) ).to eq("Expired At\n2013-12-25T12:30:30.000+0000")
    end

    it "should write YYYY-MM-DD for Date" do
      expect( @writer.text(Post.all, :columns => [:published_on]) ).to eq("Published On\n2013-12-24")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cloudxls-rails-0.4.3 spec/csv_writer_spec.rb
cloudxls-rails-0.4.2 spec/csv_writer_spec.rb
cloudxls-rails-0.4.1 spec/csv_writer_spec.rb
cloudxls-rails-0.4.0 spec/csv_writer_spec.rb