Skip to content

Instantly share code, notes, and snippets.

@tommeier
Created December 1, 2011 01:50
Show Gist options
  • Select an option

  • Save tommeier/1412688 to your computer and use it in GitHub Desktop.

Select an option

Save tommeier/1412688 to your computer and use it in GitHub Desktop.
comma use example
class CommaModel < ActiveRecord::Base
# =======
# = CSV =
# =======
comma do
some_column
native_column
association :to_s => 'Custom Label'
column_with_lambda 'Custom Header' do |p| p && Money.new(p) end
association_2 { |s| "'#{s.to_s(:csv)}" }
end
end
#Specs
it 'collection should respond to #to_comma' do
CommaModel.first(2).should respond_to(:to_comma)
end
it 'should respond to #to_comma' do
CommaModel.first.should respond_to(:to_comma)
end
it 'should export all rows to csv format' do
@model = CommaModel.first
expected = <<-EOF
Column Header, Another Column Header, Some more
123, 355.93, 1930.09
EOF
@model.to_comma.should == expected
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment