Created
December 1, 2011 01:50
-
-
Save tommeier/1412688 to your computer and use it in GitHub Desktop.
comma use example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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