to-csv 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +15 -9
- data/MIT-LICENSE +20 -20
- data/README.rdoc +212 -191
- data/Rakefile +52 -52
- data/lib/to_csv.rb +63 -59
- data/lib/to_csv/csv_converter.rb +174 -175
- data/test/database.yml +3 -3
- data/test/fixtures/movie.rb +6 -1
- data/test/fixtures/movies.yml +18 -18
- data/test/fixtures/people.yml +6 -6
- data/test/fixtures/person.rb +2 -2
- data/test/fixtures/schema.rb +11 -11
- data/test/lib/activerecord_test_case.rb +19 -19
- data/test/lib/activerecord_test_connector.rb +31 -31
- data/test/lib/load_fixtures.rb +8 -8
- data/test/locales/en-US.yml +27 -27
- data/test/locales/pt-BR.yml +147 -147
- data/test/tasks.rake +7 -7
- data/test/to_csv_test.rb +163 -150
- metadata +10 -10
data/test/tasks.rake
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
|
-
desc 'Test to_csv plugin'
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.pattern = 'test/**/*_test.rb'
|
6
|
-
t.verbose = true
|
7
|
-
t.libs << 'test'
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
desc 'Test to_csv plugin'
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.pattern = 'test/**/*_test.rb'
|
6
|
+
t.verbose = true
|
7
|
+
t.libs << 'test'
|
8
8
|
end
|
data/test/to_csv_test.rb
CHANGED
@@ -1,150 +1,163 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'test/lib/activerecord_test_case'
|
5
|
-
require 'test/lib/load_fixtures'
|
6
|
-
|
7
|
-
class ToCsvTest < ActiveRecordTestCase
|
8
|
-
fixtures :movies
|
9
|
-
|
10
|
-
def setup
|
11
|
-
ToCSV.byte_order_marker = ToCSV.locale = ToCSV.primary_key = ToCSV.timestamps = false
|
12
|
-
ToCSV.csv_options = { :col_sep => ';' }
|
13
|
-
@movies = Movie.all
|
14
|
-
@people = Person.all(:order => :name)
|
15
|
-
store_translations('en-US', 'pt-BR')
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_simple_array
|
19
|
-
csv = ['Alfred Hitchcock', 'Robert Mitchum', 'Lucille Ball'].to_csv
|
20
|
-
assert_equal "Alfred Hitchcock;Robert Mitchum;Lucille Ball\n", csv
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_matrix
|
24
|
-
csv = [
|
25
|
-
['Name', 'Age'],
|
26
|
-
['Icaro', 22],
|
27
|
-
['Gabriel', 16]
|
28
|
-
].to_csv
|
29
|
-
|
30
|
-
assert_equal "Name;Age\nIcaro;22\nGabriel;16\n", csv
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_array_of_matrixes
|
34
|
-
csv = [
|
35
|
-
[
|
36
|
-
['Name', 'Alfred'],
|
37
|
-
['Gender', 'M']
|
38
|
-
],
|
39
|
-
[
|
40
|
-
['Name', 'Robert'],
|
41
|
-
['Gender', 'M']
|
42
|
-
],
|
43
|
-
[
|
44
|
-
['Name', 'Lucille'],
|
45
|
-
['Gender', 'F']
|
46
|
-
]
|
47
|
-
].to_csv
|
48
|
-
|
49
|
-
assert_equal "Name;Gender\nAlfred;M\nRobert;M\nLucille;F\n", csv
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_array_of_hashes
|
53
|
-
csv = [
|
54
|
-
{
|
55
|
-
'Name' => 'Icaro',
|
56
|
-
'E-mail' => 'icaro.ldm@gmail.com'
|
57
|
-
},
|
58
|
-
{
|
59
|
-
'Name' => 'Gabriel',
|
60
|
-
'E-mail' => 'gaby@gmail.com'
|
61
|
-
}
|
62
|
-
].to_csv
|
63
|
-
|
64
|
-
order_01 = "Name;E-mail\nIcaro;icaro.ldm@gmail.com\nGabriel;gaby@gmail.com\n"
|
65
|
-
order_02 = "E-mail;Name\nicaro.ldm@gmail.com;Icaro\ngaby@gmail.com;Gabriel\n"
|
66
|
-
|
67
|
-
|
68
|
-
assert order_01 == csv || order_02 == csv
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_without_options
|
72
|
-
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_only_option
|
76
|
-
assert_equal "Title\nThe Dark Knight\n2001 - A Space Odyssey\n", @movies.to_csv(:only => :title)
|
77
|
-
assert_equal @movies.to_csv(:only => :title), @movies.to_csv(:only => [:title])
|
78
|
-
assert_equal "Studio;Title\nWarner Home Video;The Dark Knight\nWarner Home Video;2001 - A Space Odyssey\n", @movies.to_csv(:only => [:title, :studio])
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_except_option
|
82
|
-
assert_equal "Dvd release date;Number of discs;Subtitles;Title\n2008-12-08 22:00:00;2;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:except => :studio)
|
83
|
-
assert_equal @movies.to_csv(:except => :studio), @movies.to_csv(:except => [:studio])
|
84
|
-
assert_equal "Dvd release date;Number of discs;Studio\n2008-12-08 22:00:00;2;Warner Home Video\n2007-10-22 22:00:00;1;Warner Home Video\n", @movies.to_csv(:except => [:title, :subtitles])
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_timestamps_option
|
88
|
-
assert_equal "Created at;Number of discs\n2009-12-12 00:00:00;2\n2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at])
|
89
|
-
assert_equal "Created at;Number of discs\n2009-12-12 00:00:00;2\n2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at], :timestamps => false)
|
90
|
-
assert_equal "Created at;Number of discs\n2009-12-12 00:00:00;2\n2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at], :timestamps => true)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_headers_option
|
94
|
-
assert_equal "Icaro;23\n", ['Icaro', 23].to_csv(:headers => false)
|
95
|
-
assert_equal "Icaro;23\n", [ [:name, :age], ['Icaro', 23] ].to_csv(:headers => false)
|
96
|
-
assert_equal "Icaro;23\n", [ [[:name, 'Icaro'], [:age, 23]] ].to_csv(:headers => false)
|
97
|
-
assert_equal "Subtitles;Dvd release date;Number of discs;Studio;Title\nEnglish, French, Spanish;2008-12-08 22:00:00;2;Warner Home Video;The Dark Knight\nEnglish, Spanish, French;2007-10-22 22:00:00;1;Warner Home Video;2001 - A Space Odyssey\n", @movies.to_csv(:headers => :subtitles)
|
98
|
-
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => false)
|
99
|
-
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [false])
|
100
|
-
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [])
|
101
|
-
assert_equal "Title;Number of discs\nThe Dark Knight;2\n2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => [:title, :number_of_discs], :only => [:number_of_discs, :title])
|
102
|
-
assert_equal "Title;Number of discs\nThe Dark Knight;2\n2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => [:title, :all], :only => [:number_of_discs, :title])
|
103
|
-
assert_equal "Title;Number of discs\nThe Dark Knight;2\n2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => :title, :only => [:number_of_discs, :title])
|
104
|
-
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => :all)
|
105
|
-
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [:all])
|
106
|
-
assert_equal "Dvd release date;Studio;Subtitles;Title;Number of discs\n2008-12-08 22:00:00;Warner Home Video;English, French, Spanish;The Dark Knight;2\n2007-10-22 22:00:00;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => [:all, :subtitles, :title, :number_of_discs])
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_locale_option
|
110
|
-
assert_equal "Data de Lançamento do DVD;Número de Discos;Studio;Legendas;Título\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:locale => 'pt-BR')
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_primary_key_option
|
114
|
-
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv
|
115
|
-
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv(:primary_key => false)
|
116
|
-
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv(:primary_key => nil)
|
117
|
-
assert_equal "Cod;Name\n2;Gabriel\n1;Icaro\n", @people.to_csv(:primary_key => true)
|
118
|
-
assert_equal "Number of discs\n2\n1\n", @movies.to_csv(:primary_key => true, :only => [:number_of_discs])
|
119
|
-
assert_equal "Number of discs\n2\n1\n", @movies.to_csv(:only => [:number_of_discs, :id])
|
120
|
-
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:primary_key => true, :except => :id)
|
121
|
-
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv(:methods => :cod)
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_block_passed
|
125
|
-
csv = @movies.to_csv do |
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;02;Warner Home Video;English, French, Spanish;THE DARK KNIGHT\n2007-10-22 22:00:00;01;Warner Home Video;English, Spanish, French;2001 - A SPACE ODYSSEY\n", csv
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'test/lib/activerecord_test_case'
|
5
|
+
require 'test/lib/load_fixtures'
|
6
|
+
|
7
|
+
class ToCsvTest < ActiveRecordTestCase
|
8
|
+
fixtures :movies
|
9
|
+
|
10
|
+
def setup
|
11
|
+
ToCSV.byte_order_marker = ToCSV.locale = ToCSV.primary_key = ToCSV.timestamps = false
|
12
|
+
ToCSV.csv_options = { :col_sep => ';' }
|
13
|
+
@movies = Movie.all
|
14
|
+
@people = Person.all(:order => :name)
|
15
|
+
store_translations('en-US', 'pt-BR')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_simple_array
|
19
|
+
csv = ['Alfred Hitchcock', 'Robert Mitchum', 'Lucille Ball'].to_csv
|
20
|
+
assert_equal "Alfred Hitchcock;Robert Mitchum;Lucille Ball\n", csv
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_matrix
|
24
|
+
csv = [
|
25
|
+
['Name', 'Age'],
|
26
|
+
['Icaro', 22],
|
27
|
+
['Gabriel', 16]
|
28
|
+
].to_csv
|
29
|
+
|
30
|
+
assert_equal "Name;Age\nIcaro;22\nGabriel;16\n", csv
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_array_of_matrixes
|
34
|
+
csv = [
|
35
|
+
[
|
36
|
+
['Name', 'Alfred'],
|
37
|
+
['Gender', 'M']
|
38
|
+
],
|
39
|
+
[
|
40
|
+
['Name', 'Robert'],
|
41
|
+
['Gender', 'M']
|
42
|
+
],
|
43
|
+
[
|
44
|
+
['Name', 'Lucille'],
|
45
|
+
['Gender', 'F']
|
46
|
+
]
|
47
|
+
].to_csv
|
48
|
+
|
49
|
+
assert_equal "Name;Gender\nAlfred;M\nRobert;M\nLucille;F\n", csv
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_array_of_hashes
|
53
|
+
csv = [
|
54
|
+
{
|
55
|
+
'Name' => 'Icaro',
|
56
|
+
'E-mail' => 'icaro.ldm@gmail.com'
|
57
|
+
},
|
58
|
+
{
|
59
|
+
'Name' => 'Gabriel',
|
60
|
+
'E-mail' => 'gaby@gmail.com'
|
61
|
+
}
|
62
|
+
].to_csv
|
63
|
+
|
64
|
+
order_01 = "Name;E-mail\nIcaro;icaro.ldm@gmail.com\nGabriel;gaby@gmail.com\n"
|
65
|
+
order_02 = "E-mail;Name\nicaro.ldm@gmail.com;Icaro\ngaby@gmail.com;Gabriel\n"
|
66
|
+
|
67
|
+
|
68
|
+
assert order_01 == csv || order_02 == csv
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_without_options
|
72
|
+
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_only_option
|
76
|
+
assert_equal "Title\nThe Dark Knight\n2001 - A Space Odyssey\n", @movies.to_csv(:only => :title)
|
77
|
+
assert_equal @movies.to_csv(:only => :title), @movies.to_csv(:only => [:title])
|
78
|
+
assert_equal "Studio;Title\nWarner Home Video;The Dark Knight\nWarner Home Video;2001 - A Space Odyssey\n", @movies.to_csv(:only => [:title, :studio])
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_except_option
|
82
|
+
assert_equal "Dvd release date;Number of discs;Subtitles;Title\n2008-12-08 22:00:00;2;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:except => :studio)
|
83
|
+
assert_equal @movies.to_csv(:except => :studio), @movies.to_csv(:except => [:studio])
|
84
|
+
assert_equal "Dvd release date;Number of discs;Studio\n2008-12-08 22:00:00;2;Warner Home Video\n2007-10-22 22:00:00;1;Warner Home Video\n", @movies.to_csv(:except => [:title, :subtitles])
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_timestamps_option
|
88
|
+
assert_equal "Created at;Number of discs\n2009-12-12 00:00:00;2\n2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at])
|
89
|
+
assert_equal "Created at;Number of discs\n2009-12-12 00:00:00;2\n2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at], :timestamps => false)
|
90
|
+
assert_equal "Created at;Number of discs\n2009-12-12 00:00:00;2\n2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at], :timestamps => true)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_headers_option
|
94
|
+
assert_equal "Icaro;23\n", ['Icaro', 23].to_csv(:headers => false)
|
95
|
+
assert_equal "Icaro;23\n", [ [:name, :age], ['Icaro', 23] ].to_csv(:headers => false)
|
96
|
+
assert_equal "Icaro;23\n", [ [[:name, 'Icaro'], [:age, 23]] ].to_csv(:headers => false)
|
97
|
+
assert_equal "Subtitles;Dvd release date;Number of discs;Studio;Title\nEnglish, French, Spanish;2008-12-08 22:00:00;2;Warner Home Video;The Dark Knight\nEnglish, Spanish, French;2007-10-22 22:00:00;1;Warner Home Video;2001 - A Space Odyssey\n", @movies.to_csv(:headers => :subtitles)
|
98
|
+
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => false)
|
99
|
+
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [false])
|
100
|
+
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [])
|
101
|
+
assert_equal "Title;Number of discs\nThe Dark Knight;2\n2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => [:title, :number_of_discs], :only => [:number_of_discs, :title])
|
102
|
+
assert_equal "Title;Number of discs\nThe Dark Knight;2\n2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => [:title, :all], :only => [:number_of_discs, :title])
|
103
|
+
assert_equal "Title;Number of discs\nThe Dark Knight;2\n2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => :title, :only => [:number_of_discs, :title])
|
104
|
+
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => :all)
|
105
|
+
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [:all])
|
106
|
+
assert_equal "Dvd release date;Studio;Subtitles;Title;Number of discs\n2008-12-08 22:00:00;Warner Home Video;English, French, Spanish;The Dark Knight;2\n2007-10-22 22:00:00;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey;1\n", @movies.to_csv(:headers => [:all, :subtitles, :title, :number_of_discs])
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_locale_option
|
110
|
+
assert_equal "Data de Lançamento do DVD;Número de Discos;Studio;Legendas;Título\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:locale => 'pt-BR')
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_primary_key_option
|
114
|
+
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv
|
115
|
+
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv(:primary_key => false)
|
116
|
+
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv(:primary_key => nil)
|
117
|
+
assert_equal "Cod;Name\n2;Gabriel\n1;Icaro\n", @people.to_csv(:primary_key => true)
|
118
|
+
assert_equal "Number of discs\n2\n1\n", @movies.to_csv(:primary_key => true, :only => [:number_of_discs])
|
119
|
+
assert_equal "Number of discs\n2\n1\n", @movies.to_csv(:only => [:number_of_discs, :id])
|
120
|
+
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2007-10-22 22:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:primary_key => true, :except => :id)
|
121
|
+
assert_equal "Name\nGabriel\nIcaro\n", @people.to_csv(:methods => :cod)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_block_passed
|
125
|
+
csv = @movies.to_csv do |row, movie|
|
126
|
+
row.title = movie.title.upcase
|
127
|
+
row.number_of_discs = "%02d" % movie.number_of_discs
|
128
|
+
end
|
129
|
+
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\n2008-12-08 22:00:00;02;Warner Home Video;English, French, Spanish;THE DARK KNIGHT\n2007-10-22 22:00:00;01;Warner Home Video;English, Spanish, French;2001 - A SPACE ODYSSEY\n", csv
|
130
|
+
|
131
|
+
csv = @movies.to_csv(:headers => [:id, :all], :primary_key => true) do |row, movie|
|
132
|
+
row.id = "%05d" % movie.id
|
133
|
+
row.title = movie.title.upcase
|
134
|
+
row.number_of_discs = "%02d" % movie.number_of_discs
|
135
|
+
end
|
136
|
+
assert_equal "Id;Dvd release date;Number of discs;Studio;Subtitles;Title\n00001;2008-12-08 22:00:00;02;Warner Home Video;English, French, Spanish;THE DARK KNIGHT\n00002;2007-10-22 22:00:00;01;Warner Home Video;English, Spanish, French;2001 - A SPACE ODYSSEY\n", csv
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_default_settings
|
140
|
+
ToCSV.byte_order_marker = true
|
141
|
+
ToCSV.locale = 'pt-BR'
|
142
|
+
ToCSV.primary_key = true
|
143
|
+
ToCSV.timestamps = true
|
144
|
+
ToCSV.csv_options = { :col_sep => ',' }
|
145
|
+
assert_equal "\xEF\xBB\xBFCreated at,Data de Lançamento do DVD,Id,Número de Discos,Studio,Legendas,Título,Updated at\n2009-12-12 00:00:00,2008-12-08 22:00:00,1,2,Warner Home Video,\"English, French, Spanish\",The Dark Knight,2009-12-12 00:00:00\n", Array(@movies.first).to_csv
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_scopes
|
149
|
+
@movies = Movie.number_of_discs_gte(2)
|
150
|
+
assert_equal "Title\nThe Dark Knight\n", @movies.to_csv(:only => :title)
|
151
|
+
@movies = Movie.dvd_release_date_lte(DateTime.new(2007, 12, 31))
|
152
|
+
assert_equal "Title\n2001 - A Space Odyssey\n", @movies.to_csv(:only => :title)
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def store_translations(*locales)
|
158
|
+
locale_path = File.join(File.dirname(__FILE__), 'locales')
|
159
|
+
locales.each do |locale|
|
160
|
+
I18n.backend.store_translations locale, YAML.load_file(File.join(locale_path, "#{ locale }.yml"))
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "\xC3\x8Dcaro Leopoldino da Motta"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-04 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -57,19 +57,19 @@ files:
|
|
57
57
|
- Rakefile
|
58
58
|
- lib/to_csv/csv_converter.rb
|
59
59
|
- lib/to_csv.rb
|
60
|
-
- test/
|
61
|
-
- test/fixtures/
|
60
|
+
- test/database.yml
|
61
|
+
- test/fixtures/movie.rb
|
62
62
|
- test/fixtures/movies.yml
|
63
|
-
- test/fixtures/schema.rb
|
64
63
|
- test/fixtures/people.yml
|
65
|
-
- test/fixtures/
|
66
|
-
- test/
|
67
|
-
- test/locales/en-US.yml
|
68
|
-
- test/locales/pt-BR.yml
|
64
|
+
- test/fixtures/person.rb
|
65
|
+
- test/fixtures/schema.rb
|
69
66
|
- test/lib/activerecord_test_case.rb
|
70
67
|
- test/lib/activerecord_test_connector.rb
|
71
68
|
- test/lib/load_fixtures.rb
|
72
|
-
- test/
|
69
|
+
- test/locales/en-US.yml
|
70
|
+
- test/locales/pt-BR.yml
|
71
|
+
- test/tasks.rake
|
72
|
+
- test/to_csv_test.rb
|
73
73
|
- CHANGELOG.rdoc
|
74
74
|
- README.rdoc
|
75
75
|
has_rdoc: true
|