to-csv 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +21 -15
- data/MIT-LICENSE +20 -20
- data/README.rdoc +237 -212
- data/Rakefile +52 -52
- data/lib/to_csv.rb +64 -63
- data/lib/to_csv/csv_converter.rb +237 -174
- data/test/database.yml +6 -4
- data/test/fixtures/block_buster.rb +3 -0
- data/test/fixtures/block_busters.yml +3 -0
- data/test/fixtures/movie.rb +8 -7
- data/test/fixtures/movies.yml +21 -19
- data/test/fixtures/people.yml +8 -7
- data/test/fixtures/person.rb +5 -3
- data/test/fixtures/schema.rb +17 -12
- data/test/lib/activerecord_test_case.rb +21 -20
- data/test/lib/activerecord_test_connector.rb +34 -32
- data/test/lib/load_fixtures.rb +10 -9
- 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 +186 -163
- metadata +62 -28
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,163 +1,186 @@
|
|
1
|
-
#encoding:
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require '
|
5
|
-
require '
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
['
|
27
|
-
['
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
['
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
['
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
['
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
'
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
'
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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\
|
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\
|
83
|
-
assert_equal @movies.to_csv(:except => :studio), @movies.to_csv(:except => [:studio])
|
84
|
-
assert_equal "Dvd release date;Number of discs;Studio\
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_timestamps_option
|
88
|
-
assert_equal "Created at;Number of discs\
|
89
|
-
assert_equal "Created at;Number of discs\
|
90
|
-
assert_equal "Created at;Number of discs\
|
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
|
98
|
-
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\
|
99
|
-
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\
|
100
|
-
assert_equal "2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\
|
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\
|
105
|
-
assert_equal "Dvd release date;Number of discs;Studio;Subtitles;Title\
|
106
|
-
assert_equal "Dvd release date;Studio;Subtitles;Title;Number of discs\
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_locale_option
|
110
|
-
assert_equal "Data de
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_primary_key_option
|
114
|
-
assert_equal "Name\
|
115
|
-
assert_equal "Name\
|
116
|
-
assert_equal "Name\
|
117
|
-
assert_equal "Cod;Name\
|
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\
|
121
|
-
assert_equal "Name\
|
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\
|
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
|
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\
|
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
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'activerecord_test_case'))
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '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 => ';', :encoding => 'UTF-8' }
|
13
|
+
@movies = Movie.all
|
14
|
+
@people = Person.all(:order => :name)
|
15
|
+
@block_busters = BlockBuster.all
|
16
|
+
store_translations('en-US', 'pt-BR')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_simple_array
|
20
|
+
csv = ['Alfréd Hitchcock', 'Robert Mitchum', 'Lucille Ball'].to_csv
|
21
|
+
assert_equal "Alfréd Hitchcock;Robert Mitchum;Lucille Ball\n", csv
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_matrix
|
25
|
+
csv = [
|
26
|
+
['Name', 'Age'],
|
27
|
+
['Icaro', 22],
|
28
|
+
['Gabriel', 16]
|
29
|
+
].to_csv
|
30
|
+
|
31
|
+
assert_equal "Name;Age\nIcaro;22\nGabriel;16\n", csv
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_array_of_matrixes
|
35
|
+
csv = [
|
36
|
+
[
|
37
|
+
['Name', 'Alfred'],
|
38
|
+
['Gender', 'M']
|
39
|
+
],
|
40
|
+
[
|
41
|
+
['Name', 'Robert'],
|
42
|
+
['Gender', 'M']
|
43
|
+
],
|
44
|
+
[
|
45
|
+
['Name', 'Lucille'],
|
46
|
+
['Gender', 'F']
|
47
|
+
]
|
48
|
+
].to_csv
|
49
|
+
|
50
|
+
assert_equal "Name;Gender\nAlfred;M\nRobert;M\nLucille;F\n", csv
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_array_of_hashes
|
54
|
+
csv = [
|
55
|
+
{
|
56
|
+
'Name' => 'Icaro',
|
57
|
+
'E-mail' => 'icaro.ldm@gmail.com'
|
58
|
+
},
|
59
|
+
{
|
60
|
+
'Name' => 'Gabriel',
|
61
|
+
'E-mail' => 'gaby@gmail.com'
|
62
|
+
}
|
63
|
+
].to_csv
|
64
|
+
|
65
|
+
order_01 = "Name;E-mail\nIcaro;icaro.ldm@gmail.com\nGabriel;gaby@gmail.com\n"
|
66
|
+
order_02 = "E-mail;Name\nicaro.ldm@gmail.com;Icaro\ngaby@gmail.com;Gabriel\n"
|
67
|
+
|
68
|
+
assert order_01 == csv || order_02 == csv
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_without_options
|
72
|
+
assert_equal "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title\n1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21: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 "Cod;Dvd release date;Number of discs;Subtitles;Title\n1;2008-12-08 22:00:00;2;English, French, Spanish;The Dark Knight\n2;2007-10-22 21: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 "Cod;Dvd release date;Number of discs;Studio\n1;2008-12-08 22:00:00;2;Warner Home Video\n2;2007-10-22 21:00:00;1;Warner Home Video\n", @movies.to_csv(:except => [:title, :subtitles])
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_timestamps_option
|
88
|
+
assert_equal "Cod;Created at;Number of discs\n1;2009-12-12 00:00:00;2\n2;2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at])
|
89
|
+
assert_equal "Cod;Created at;Number of discs\n1;2009-12-12 00:00:00;2\n2;2009-11-11 00:00:00;1\n", @movies.to_csv(:except => [:title, :subtitles, :studio, :dvd_release_date, :updated_at], :timestamps => false)
|
90
|
+
assert_equal "Cod;Created at;Number of discs\n1;2009-12-12 00:00:00;2\n2;2009-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;Cod;Dvd release date;Number of discs;Studio;Title\nEnglish, French, Spanish;1;2008-12-08 22:00:00;2;Warner Home Video;The Dark Knight\nEnglish, Spanish, French;2;2007-10-22 21:00:00;1;Warner Home Video;2001 - A Space Odyssey\n", @movies.to_csv(:headers => :subtitles)
|
98
|
+
assert_equal "1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => false)
|
99
|
+
assert_equal "1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [false])
|
100
|
+
assert_equal "1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21: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 "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title\n1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => :all)
|
105
|
+
assert_equal "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title\n1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey\n", @movies.to_csv(:headers => [:all])
|
106
|
+
assert_equal "Cod;Dvd release date;Studio;Subtitles;Title;Number of discs\n1;2008-12-08 22:00:00;Warner Home Video;English, French, Spanish;The Dark Knight;2\n2;2007-10-22 21: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 "Cod;Data de Lan\303\247amento do DVD;N\303\272mero de Discos;Studio;Legendas;T\303\255tulo\n1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21: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 "Block buster;Name\n1;Gabriel\n1;Icaro\n", @people.to_csv
|
115
|
+
assert_equal "Block buster;Name\n1;Gabriel\n1;Icaro\n", @people.to_csv(:primary_key => false)
|
116
|
+
assert_equal "Block buster;Name\n1;Gabriel\n1;Icaro\n", @people.to_csv(:primary_key => nil)
|
117
|
+
assert_equal "Block buster;Cod;Name\n1;2;Gabriel\n1;1;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 "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title\n1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight\n2;2007-10-22 21: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 "Block buster;Name\n1;Gabriel\n1;Icaro\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 "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title\n1;2008-12-08 22:00:00;02;Warner Home Video;English, French, Spanish;THE DARK KNIGHT\n2;2007-10-22 21: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;Cod;Dvd release date;Number of discs;Studio;Subtitles;Title\n00001;1;2008-12-08 22:00:00;02;Warner Home Video;English, French, Spanish;THE DARK KNIGHT\n00002;2;2007-10-22 21: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 => ',', :encoding => 'UTF-8' }
|
145
|
+
assert_equal "\xEF\xBB\xBFCod,Created at,Data de Lançamento do DVD,Id,Número de Discos,Studio,Legendas,Título,Updated at\n1,2009-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
|
+
def test_include_belongs_to
|
156
|
+
csv = @movies.to_csv(:include => :person)
|
157
|
+
assert_equal "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title;Person block buster;Person cod;Person name\n1;2008-12-08 22:00:00;2;Warner Home Video;English, French, Spanish;The Dark Knight;1;1;Icaro\n2;2007-10-22 21:00:00;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey;1;2;Gabriel\n", csv
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_include_has_many
|
161
|
+
csv = @people.to_csv(:include => :movies)
|
162
|
+
assert_equal "Block buster;Name;Movies 1 cod;Movies 1 created at;Movies 1 dvd release date;Movies 1;Movies 1 number of discs;Movies 1 studio;Movies 1 subtitles;Movies 1 title;Movies 1 updated at\n1;Gabriel;2;2009-11-11 00:00:00;2007-10-22 21:00:00;2;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey;2009-11-11 00:00:00\n1;Icaro;1;2009-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", csv
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_include_has_many_and_belongs_to
|
166
|
+
csv = @people.to_csv(:include => [:movies, :block_buster])
|
167
|
+
assert_equal "Block buster;Name;Movies 1 cod;Movies 1 created at;Movies 1 dvd release date;Movies 1;Movies 1 number of discs;Movies 1 studio;Movies 1 subtitles;Movies 1 title;Movies 1 updated at;Block buster address\n1;Gabriel;2;2009-11-11 00:00:00;2007-10-22 21:00:00;2;1;Warner Home Video;English, Spanish, French;2001 - A Space Odyssey;2009-11-11 00:00:00;1201 Elm Street;1\n1;Icaro;1;2009-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;1201 Elm Street;1\n", csv
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_block_passed_with_include
|
171
|
+
csv = @movies.to_csv(:include => :person) do |row, movie|
|
172
|
+
row.title = movie.title.upcase
|
173
|
+
row.number_of_discs = "%02d" % movie.number_of_discs
|
174
|
+
end
|
175
|
+
assert_equal "Cod;Dvd release date;Number of discs;Studio;Subtitles;Title;Person block buster;Person cod;Person name\n1;2008-12-08 22:00:00;02;Warner Home Video;English, French, Spanish;THE DARK KNIGHT;1;1;Icaro\n2;2007-10-22 21:00:00;01;Warner Home Video;English, Spanish, French;2001 - A SPACE ODYSSEY;1;2;Gabriel\n", csv
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
def store_translations(*locales)
|
180
|
+
locale_path = File.join(File.dirname(__FILE__), 'locales')
|
181
|
+
locales.each do |locale|
|
182
|
+
I18n.backend.store_translations locale, YAML.load_file(File.join(locale_path, "#{ locale }.yml"))
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- "\xC3\x8Dcaro Leopoldino da Motta"
|
@@ -9,39 +15,57 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-08-09 00:00:00 -03:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: activesupport
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 5
|
23
34
|
version: 2.3.5
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: activerecord
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 5
|
33
50
|
version: 2.3.5
|
34
|
-
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
35
53
|
- !ruby/object:Gem::Dependency
|
36
54
|
name: sqlite3-ruby
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
40
58
|
requirements:
|
41
59
|
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 21
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 2
|
65
|
+
- 5
|
43
66
|
version: 1.2.5
|
44
|
-
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
45
69
|
description: Convert arrays to CSV (array of hashes, matrixes, ActiveRecord objects etc).
|
46
70
|
email: icaro.ldm@gmail.com
|
47
71
|
executables: []
|
@@ -49,29 +73,31 @@ executables: []
|
|
49
73
|
extensions: []
|
50
74
|
|
51
75
|
extra_rdoc_files:
|
52
|
-
- CHANGELOG.rdoc
|
53
76
|
- README.rdoc
|
77
|
+
- CHANGELOG.rdoc
|
54
78
|
files:
|
55
79
|
- init.rb
|
56
80
|
- MIT-LICENSE
|
57
81
|
- Rakefile
|
58
82
|
- lib/to_csv/csv_converter.rb
|
59
83
|
- lib/to_csv.rb
|
60
|
-
- test/
|
61
|
-
- test/
|
62
|
-
- test/fixtures/movies.yml
|
63
|
-
- test/fixtures/people.yml
|
64
|
-
- test/fixtures/person.rb
|
65
|
-
- test/fixtures/schema.rb
|
84
|
+
- test/tasks.rake
|
85
|
+
- test/lib/load_fixtures.rb
|
66
86
|
- test/lib/activerecord_test_case.rb
|
67
87
|
- test/lib/activerecord_test_connector.rb
|
68
|
-
- test/lib/load_fixtures.rb
|
69
88
|
- test/locales/en-US.yml
|
70
89
|
- test/locales/pt-BR.yml
|
71
|
-
- test/tasks.rake
|
72
90
|
- test/to_csv_test.rb
|
73
|
-
-
|
91
|
+
- test/database.yml
|
92
|
+
- test/fixtures/movies.yml
|
93
|
+
- test/fixtures/schema.rb
|
94
|
+
- test/fixtures/person.rb
|
95
|
+
- test/fixtures/block_buster.rb
|
96
|
+
- test/fixtures/people.yml
|
97
|
+
- test/fixtures/block_busters.yml
|
98
|
+
- test/fixtures/movie.rb
|
74
99
|
- README.rdoc
|
100
|
+
- CHANGELOG.rdoc
|
75
101
|
has_rdoc: true
|
76
102
|
homepage: http://github.com/ilmotta/to-csv
|
77
103
|
licenses: []
|
@@ -93,21 +119,29 @@ rdoc_options: []
|
|
93
119
|
require_paths:
|
94
120
|
- lib
|
95
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
96
123
|
requirements:
|
97
124
|
- - ">="
|
98
125
|
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
126
|
+
hash: 57
|
127
|
+
segments:
|
128
|
+
- 1
|
129
|
+
- 8
|
130
|
+
- 7
|
131
|
+
version: 1.8.7
|
101
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
102
134
|
requirements:
|
103
135
|
- - ">="
|
104
136
|
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
105
140
|
version: "0"
|
106
|
-
version:
|
107
141
|
requirements: []
|
108
142
|
|
109
143
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.3.
|
144
|
+
rubygems_version: 1.3.7
|
111
145
|
signing_key:
|
112
146
|
specification_version: 3
|
113
147
|
summary: Convert arrays to CSV (array of hashes, matrixes, ActiveRecord objects etc).
|