Sha256: 45e3c0e50509e49792454b1d8c8fc10c7b0c93d44cf2418801c8b6a0a8a9b6f9

Contents?: true

Size: 991 Bytes

Versions: 5

Compression:

Stored size: 991 Bytes

Contents

require 'rails_helper'

describe Tabulatr::Data::Formatting do
  class DummyFormattingClass
    include Tabulatr::Data::Formatting
    def table_columns; end
  end

  before(:each) do
    @dummy = DummyFormattingClass.new
    @dummy.instance_variable_set('@relation', Product.all)
    column = Tabulatr::Renderer::Column.from(
        name: :title,
        klass: Product,
        table_name: :products,
        sort_sql: "products.title",
        filter_sql: "products.title"
    )
    allow(@dummy).to receive(:table_columns).and_return([column])
  end

  describe '#apply_formats' do
    it 'applies given formatting block to a column' do
      allow(@dummy).to receive(:format_row).and_return(nil)
      p = Product.create!(title: 'title of product')
      @dummy.table_columns.first.output = ->(record){record.title.upcase}
      result = @dummy.apply_formats
      expect(result.count).to be 1
      expect(result.first[:products][:title]).to eql 'TITLE OF PRODUCT'
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tabulatr2-0.9.20 spec/lib/tabulatr/data/formatting_spec.rb
tabulatr2-0.9.19 spec/lib/tabulatr/data/formatting_spec.rb
tabulatr2-0.9.18 spec/lib/tabulatr/data/formatting_spec.rb
tabulatr2-0.9.17 spec/lib/tabulatr/data/formatting_spec.rb
tabulatr2-0.9.16 spec/lib/tabulatr/data/formatting_spec.rb