Sha256: bd6b734d5ffa94f54d2d0a9d2e6d5096a1eb955f9f1de51d625c6354a8a80dab

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

#!/usr/bin/env ruby -w
require 'test/unit'
require "axlsx/acts_as_xlsx"
require 'active_record'

require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))

class TestActsAsXlsx < Test::Unit::TestCase

  class Post < ActiveRecord::Base
    acts_as_xlsx :columns=>[:name, :title, :content, :votes, :ranking], :i18n => 'activerecord.attributes'
  end

  def test_xlsx_options
    assert_equal([:name, :title, :content, :votes, :ranking], Post.xlsx_columns)
    assert_equal('activerecord.attributes', Post.xlsx_i18n)
  end

end

class TestToXlsx < Test::Unit::TestCase

  def test_xlsx_columns
    assert_equal( Post.xlsx_columns, Post.column_names.map {|c| c.to_sym})
  end

  def test_to_xslx_vanilla
    p = Post.to_xlsx
    assert_equal("Id",p.workbook.worksheets.first.rows.first.cells.first.value)
    assert_equal(2,p.workbook.worksheets.first.rows.last.cells.first.value)
  end

  def test_columns
    p = Post.to_xlsx :columns => [:name, :title, :content, :votes]
    sheet = p.workbook.worksheets.first
    assert_equal(sheet.rows.first.cells.size, Post.xlsx_columns.size - 3)
    assert_equal("Name",sheet.rows.first.cells.first.value)
    assert_equal(7,sheet.rows.last.cells.last.value)
  end

  def test_method_in_columns
    p = Post.to_xlsx :columns=>[:name, :votes, :content, :ranking]
    sheet = p.workbook.worksheets.first
    assert_equal("Name", sheet.rows.first.cells.first.value)
    assert_equal(Post.last.ranking, sheet.rows.last.cells.last.value)
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_xlsx-1.0.0 test/tc_acts_as_xlsx.rb