csv_madness 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of csv_madness might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.document +5 -0
- data/CHANGELOG.markdown +4 -0
- data/Gemfile +2 -7
- data/Rakefile +12 -78
- data/VERSION +1 -1
- data/lib/csv_madness/builder.rb +91 -9
- data/lib/csv_madness/column.rb +30 -0
- data/lib/csv_madness/column_methods/core_methods.rb +6 -0
- data/lib/csv_madness/column_methods/default_value_methods.rb +7 -0
- data/lib/csv_madness/column_methods/error_methods.rb +19 -0
- data/lib/csv_madness/column_methods/fetch_methods.rb +11 -0
- data/lib/csv_madness/column_methods/typing_methods.rb +24 -0
- data/lib/csv_madness/column_set.rb +5 -0
- data/lib/csv_madness/column_type.rb +74 -0
- data/lib/csv_madness/column_types/date.rb +14 -0
- data/lib/csv_madness/column_types/float.rb +25 -0
- data/lib/csv_madness/column_types/integer.rb +17 -0
- data/lib/csv_madness/column_types/string.rb +9 -0
- data/lib/csv_madness/data_accessor_module.rb +79 -79
- data/lib/csv_madness/gem_api.rb +11 -2
- data/lib/csv_madness/index_set.rb +36 -0
- data/lib/csv_madness/indexer.rb +105 -0
- data/lib/csv_madness/record.rb +68 -42
- data/lib/csv_madness/record_filter.rb +68 -0
- data/lib/csv_madness/record_methods/method_methods.rb +57 -0
- data/lib/csv_madness/sheet.rb +160 -76
- data/lib/csv_madness/sheet_methods/class_methods.rb +11 -4
- data/lib/csv_madness/sheet_methods/column_methods.rb +95 -107
- data/lib/csv_madness/sheet_methods/file_methods.rb +9 -6
- data/lib/csv_madness/sheet_methods/indexing.rb +104 -23
- data/lib/csv_madness/sheet_methods/record_methods.rb +123 -47
- data/lib/csv_madness/sheet_methods/sorting_methods.rb +10 -0
- data/lib/csv_madness/utils/const_proc.rb +19 -0
- data/lib/csv_madness/utils/counter.rb +24 -0
- data/lib/csv_madness/utils/counter_proc.rb +31 -0
- data/lib/csv_madness/utils/looker_upper.rb +36 -0
- data/lib/csv_madness.rb +1 -0
- data/test/csv/nil_headers.csv +5 -0
- data/test/csv/out/.gitkeep +0 -0
- data/test/csv/pokemon.csv +9 -0
- data/test/csv/test_column_types.csv +2 -2
- data/test/helper.rb +9 -6
- data/test/test_builder.rb +36 -0
- data/test/test_csv_madness.rb +28 -18
- data/test/test_index_set.rb +30 -0
- data/test/test_indexer.rb +50 -0
- data/test/test_reloading_spreadsheet.rb +4 -2
- data/test/test_sheet.rb +164 -27
- data/test/test_utils.rb +99 -0
- metadata +66 -38
data/test/test_csv_madness.rb
CHANGED
|
@@ -55,9 +55,9 @@ class TestCsvMadness < MadTestCase
|
|
|
55
55
|
cell = "*#{cell}*"
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
bill = @simple.fetch(:id, "2")
|
|
59
|
-
mary = @simple.fetch(:id, "1")
|
|
60
|
-
|
|
58
|
+
bill = @simple.fetch(:id, "*2*")
|
|
59
|
+
mary = @simple.fetch(:id, "*1*")
|
|
60
|
+
|
|
61
61
|
assert_equal "*Bill*", bill.fname
|
|
62
62
|
assert_equal "*Moore*", mary.lname
|
|
63
63
|
assert_equal "*1*", mary.id
|
|
@@ -104,6 +104,7 @@ class TestCsvMadness < MadTestCase
|
|
|
104
104
|
|
|
105
105
|
should "parse a date column with one invalid date" do
|
|
106
106
|
@simple.set_column_type( :born, :date )
|
|
107
|
+
debugger
|
|
107
108
|
born1 = @simple[0].born
|
|
108
109
|
born3 = @simple[2].born
|
|
109
110
|
assert_kind_of Time, born1
|
|
@@ -114,29 +115,36 @@ class TestCsvMadness < MadTestCase
|
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
should "successfully decorate record objects with new functionality" do
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@simple.add_extra_method( :full_name ) do |record|
|
|
121
|
+
"#{record.fname} #{record.lname}"
|
|
122
|
+
end
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
end
|
|
124
|
+
@simple.add_extra_method( :name_last_first ) do |record|
|
|
125
|
+
"#{record.lname}, #{record.fname}"
|
|
125
126
|
end
|
|
126
|
-
|
|
127
|
-
@simple.add_record_methods( moduul )
|
|
128
|
-
|
|
127
|
+
|
|
129
128
|
assert @simple[0].respond_to?( :full_name )
|
|
130
129
|
assert_equal "Mary Moore", @simple[0].full_name
|
|
131
130
|
assert @simple[0].respond_to?( :name_last_first )
|
|
132
131
|
assert_equal "Moore, Mary", @simple[0].name_last_first
|
|
133
132
|
end
|
|
133
|
+
|
|
134
|
+
should "add extra method that takes an additional argument" do
|
|
135
|
+
@simple.add_extra_method( :excited ) do |record, mark_of_excitement = "!"|
|
|
136
|
+
"#{record.fname} #{record.lname}#{mark_of_excitement}"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
assert_equal "Mary Moore!", @simple[0].excited
|
|
141
|
+
assert_equal "Mary Moore?", @simple[0].excited("?")
|
|
142
|
+
end
|
|
143
|
+
|
|
134
144
|
|
|
135
145
|
should "add methods to record objects (block form)" do
|
|
136
|
-
@simple.
|
|
137
|
-
|
|
138
|
-
"#{self.fname} #{self.lname}"
|
|
139
|
-
end
|
|
146
|
+
@simple.add_extra_method( :full_name ) do |record|
|
|
147
|
+
"#{record.fname} #{record.lname}"
|
|
140
148
|
end
|
|
141
149
|
|
|
142
150
|
assert @simple[0].respond_to?( :full_name )
|
|
@@ -145,6 +153,7 @@ class TestCsvMadness < MadTestCase
|
|
|
145
153
|
|
|
146
154
|
should "return an array of objects when feeding fetch() an array" do
|
|
147
155
|
records = @simple.fetch(:id, ["1","2"])
|
|
156
|
+
|
|
148
157
|
assert_equal records.length, records.compact.length
|
|
149
158
|
assert_equal 2, records.length
|
|
150
159
|
assert_equal "1", records.first.id
|
|
@@ -202,7 +211,7 @@ class TestCsvMadness < MadTestCase
|
|
|
202
211
|
|
|
203
212
|
should "stomp away the nils" do
|
|
204
213
|
@norris = @nilsheet.fetch(:id, "4")
|
|
205
|
-
|
|
214
|
+
assert_nil @norris.born
|
|
206
215
|
assert_equal "Chuck", @norris.fname
|
|
207
216
|
|
|
208
217
|
@nilsheet.nils_are_blank_strings # should turn every nil into a ''
|
|
@@ -244,6 +253,7 @@ class TestCsvMadness < MadTestCase
|
|
|
244
253
|
|
|
245
254
|
should "drop column" do
|
|
246
255
|
load_mary
|
|
256
|
+
|
|
247
257
|
assert @mary.respond_to?(:lname)
|
|
248
258
|
assert_equal "Moore", @mary.lname
|
|
249
259
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class TestIndexSet < MadTestCase
|
|
4
|
+
include CsvMadness
|
|
5
|
+
|
|
6
|
+
context "testing set equality" do
|
|
7
|
+
setup do
|
|
8
|
+
@set0 = IndexSet.new( :even, true )
|
|
9
|
+
@set1 = IndexSet.new( :odd, false )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
should "be unequal when empty" do
|
|
13
|
+
@set0 != @set1
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
should "be unequal when containing the same objects" do
|
|
17
|
+
@set0.add( 0 )
|
|
18
|
+
@set1.add( 0 )
|
|
19
|
+
|
|
20
|
+
@set0 != @set1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
_should "do a thing" do
|
|
24
|
+
1000.times do
|
|
25
|
+
ix = IndexSet.new( :even, :true )
|
|
26
|
+
puts ix.object_id
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class TestIndexer < MadTestCase
|
|
4
|
+
context "absolute basics" do
|
|
5
|
+
setup do
|
|
6
|
+
@ix = CsvMadness::Indexer.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
should "have created an Indexer" do
|
|
10
|
+
assert_kind_of CsvMadness::Indexer, @ix
|
|
11
|
+
|
|
12
|
+
assert_respond_to @ix, :index
|
|
13
|
+
assert_respond_to @ix, :unindex
|
|
14
|
+
assert_respond_to @ix, :lookup
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
should "add items to and retrieve items from an indexer" do
|
|
18
|
+
@ix.index( 5, :even?, 5.even? )
|
|
19
|
+
result = @ix.lookup( :even?, false )
|
|
20
|
+
assert_equal [5], result
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "testing index " do
|
|
25
|
+
setup do
|
|
26
|
+
@ix = CsvMadness::Indexer.new
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
_should "add and remove items, with the lookup staying up-to-date" do
|
|
30
|
+
for i in 0..9
|
|
31
|
+
@ix.index( i, :even?, i.even? )
|
|
32
|
+
@ix.index( i, :odd?, i.odd? )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
assert_equal( [0,2,4,6,8], @ix.lookup( :even?, true ) )
|
|
36
|
+
assert_equal( [1,3,5,7,9], @ix.lookup( :even?, false ) )
|
|
37
|
+
assert_equal( [0,2,4,6,8], @ix.lookup( :odd?, false ) )
|
|
38
|
+
assert_equal( [1,3,5,7,9], @ix.lookup( :odd?, true ) )
|
|
39
|
+
|
|
40
|
+
for i in 0..9
|
|
41
|
+
@ix.unindex( i )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
assert_equal( [], @ix.lookup( :even?, true ) )
|
|
45
|
+
assert_equal( [], @ix.lookup( :even?, false ) )
|
|
46
|
+
assert_equal( [], @ix.lookup( :odd?, true ) )
|
|
47
|
+
assert_equal( [], @ix.lookup( :odd?, false ) )
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -13,9 +13,11 @@ class TestCsvMadness < MadTestCase
|
|
|
13
13
|
assert @darwin.respond_to?(:fname)
|
|
14
14
|
assert @mary.born.is_a?(String)
|
|
15
15
|
|
|
16
|
-
debugger
|
|
17
16
|
muck_up_spreadsheet
|
|
18
|
-
set_person_records
|
|
17
|
+
# set_person_records
|
|
18
|
+
|
|
19
|
+
assert_kind_of CsvMadness::Record, @mary
|
|
20
|
+
assert_kind_of CsvMadness::Record, @darwin
|
|
19
21
|
|
|
20
22
|
assert !@mary.respond_to?(:lname)
|
|
21
23
|
assert !@darwin.respond_to?(:fname)
|
data/test/test_sheet.rb
CHANGED
|
@@ -29,18 +29,21 @@ class TestSheet < MadTestCase
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
context "testing column_types" do
|
|
32
|
-
|
|
33
|
-
load_sheet("test_column_types.csv")
|
|
32
|
+
setup do
|
|
33
|
+
load_sheet("test_column_types.csv")
|
|
34
34
|
|
|
35
|
-
for type
|
|
35
|
+
for type in CsvMadness::ColumnType::COLUMN_TYPE_LOOKUP.keys
|
|
36
36
|
@sheet.set_column_type( type, type )
|
|
37
37
|
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should "gracefully handle empty strings for all column_types" do
|
|
38
41
|
|
|
39
42
|
record = @sheet.records[0]
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
assert_nil record.date
|
|
45
|
+
assert_nil record.number
|
|
46
|
+
assert_nil record.float
|
|
44
47
|
|
|
45
48
|
record = @sheet.records[1]
|
|
46
49
|
assert_equal "12", record.id
|
|
@@ -48,6 +51,15 @@ class TestSheet < MadTestCase
|
|
|
48
51
|
assert_equal 100, record.integer
|
|
49
52
|
assert_equal Time.parse("2013-01-13"), record.date
|
|
50
53
|
end
|
|
54
|
+
|
|
55
|
+
should "convert cells to proper column type when adding record" do
|
|
56
|
+
rec = @sheet.add_record( {:id => 13, :number => "-40.7", :integer => "12", :float => "37.4", :date => "1/31/2017" } )
|
|
57
|
+
|
|
58
|
+
assert_kind_of Float, rec.number
|
|
59
|
+
assert_equal( -40.7, rec.number )
|
|
60
|
+
assert_kind_of Integer, rec.id
|
|
61
|
+
|
|
62
|
+
end
|
|
51
63
|
end
|
|
52
64
|
|
|
53
65
|
context "testing add/remove records" do
|
|
@@ -65,17 +77,38 @@ class TestSheet < MadTestCase
|
|
|
65
77
|
end
|
|
66
78
|
end
|
|
67
79
|
|
|
68
|
-
should "
|
|
80
|
+
should "add record (block form)" do
|
|
81
|
+
count = @sheet.records.length
|
|
82
|
+
|
|
83
|
+
block_ran = false
|
|
84
|
+
|
|
85
|
+
rec = @sheet.add_record( [] ) do |r|
|
|
86
|
+
block_ran = true
|
|
87
|
+
|
|
88
|
+
r.id = "8"
|
|
89
|
+
r.fname = "Omaha"
|
|
90
|
+
r.lname = "Williams"
|
|
91
|
+
r.age = "55"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
assert block_ran, "Block did not run."
|
|
95
|
+
|
|
96
|
+
assert_equal count + 1, @sheet.length
|
|
97
|
+
assert_kind_of CsvMadness::Record, rec
|
|
98
|
+
assert_equal "8", rec.id
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
should "remove_record" do
|
|
69
102
|
count = @sheet.records.length
|
|
70
103
|
record = @sheet.records.last
|
|
71
104
|
record_id = record.id
|
|
72
105
|
|
|
73
|
-
|
|
106
|
+
assert_not_nil @sheet.fetch(:id, record_id)
|
|
74
107
|
|
|
75
108
|
|
|
76
109
|
@sheet.remove_record( record )
|
|
77
110
|
assert_equal (count - 1), @sheet.records.length
|
|
78
|
-
|
|
111
|
+
assert_nil @sheet.fetch(:id, record_id)
|
|
79
112
|
|
|
80
113
|
count = @sheet.records.length
|
|
81
114
|
record = @sheet.records[0]
|
|
@@ -88,38 +121,65 @@ class TestSheet < MadTestCase
|
|
|
88
121
|
end
|
|
89
122
|
|
|
90
123
|
context "testing blanking and splitting of spreadsheet" do
|
|
124
|
+
setup do
|
|
125
|
+
@sheet = CsvMadness.load( "splitter.csv" )
|
|
126
|
+
@blank_sheet = @sheet.blanked
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
teardown do
|
|
130
|
+
self.empty_output_folder
|
|
131
|
+
end
|
|
132
|
+
|
|
91
133
|
should "deliver me a properly blanked spreadsheet (simple)" do
|
|
92
|
-
sheet
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
sheet.length.times do |i|
|
|
96
|
-
blank_sheet.add_record( sheet.remove_record( 0 ) )
|
|
134
|
+
@sheet.length.times do |i|
|
|
135
|
+
@blank_sheet.add_record( @sheet.remove_record( 0 ) )
|
|
97
136
|
end
|
|
98
137
|
|
|
99
|
-
assert_zero sheet.length
|
|
100
|
-
assert_equal 10, blank_sheet.length
|
|
101
|
-
assert_nil blank_sheet.spreadsheet_file
|
|
138
|
+
assert_zero @sheet.length
|
|
139
|
+
assert_equal 10, @blank_sheet.length
|
|
140
|
+
assert_nil @blank_sheet.spreadsheet_file
|
|
102
141
|
end
|
|
103
142
|
|
|
104
143
|
should "deliver me a properly blanked spreadsheet (index)" do
|
|
105
|
-
|
|
106
|
-
blank_sheet
|
|
107
|
-
|
|
108
|
-
assert_zero blank_sheet.length
|
|
109
|
-
assert_includes blank_sheet.index_columns, :id
|
|
144
|
+
assert_zero @blank_sheet.length
|
|
145
|
+
assert_includes( @blank_sheet.index_columns, :id ) if @blank_sheet.indexing_enabled?
|
|
110
146
|
end
|
|
111
147
|
|
|
112
148
|
should "split splitter" do
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
149
|
+
sheets = @sheet.split do |record|
|
|
150
|
+
record.party
|
|
151
|
+
end
|
|
116
152
|
|
|
117
153
|
for party in %w(D I R)
|
|
118
154
|
assert_equal_length sheets[party], @sheet.records.select{|r| r.party == party }
|
|
119
155
|
end
|
|
120
156
|
|
|
121
|
-
|
|
122
|
-
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# assert_includes sheets["D"].index_columns, :id
|
|
160
|
+
# assert_includes sheets["I"].index_columns, :party
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
should "write back a blank sheet to a csv file" do
|
|
164
|
+
outpath = @csv_output_path
|
|
165
|
+
|
|
166
|
+
blankcsv = outpath.join( "blank.csv" )
|
|
167
|
+
onerecord = outpath.join( "onerecord.csv" )
|
|
168
|
+
|
|
169
|
+
@blank_sheet.write_to_file( blankcsv )
|
|
170
|
+
@blank_sheet.add_record( ["1","Mary","Moore","D"] )
|
|
171
|
+
@blank_sheet.write_to_file( onerecord )
|
|
172
|
+
|
|
173
|
+
reloaded = CsvMadness.load( blankcsv )
|
|
174
|
+
assert_length 0, reloaded
|
|
175
|
+
|
|
176
|
+
reloaded = CsvMadness.load( onerecord )
|
|
177
|
+
record = reloaded.records.first
|
|
178
|
+
|
|
179
|
+
assert_length 1, reloaded
|
|
180
|
+
|
|
181
|
+
assert_equal "Mary", record.fname
|
|
182
|
+
assert_equal "1", record.id
|
|
123
183
|
end
|
|
124
184
|
end
|
|
125
185
|
|
|
@@ -130,4 +190,81 @@ class TestSheet < MadTestCase
|
|
|
130
190
|
end
|
|
131
191
|
end
|
|
132
192
|
end
|
|
193
|
+
|
|
194
|
+
context "testing nils in headers" do
|
|
195
|
+
should "load the sheet without errors" do
|
|
196
|
+
ss = CsvMadness.load( "nil_headers.csv" )
|
|
197
|
+
assert_kind_of( CsvMadness::Sheet, ss )
|
|
198
|
+
|
|
199
|
+
expected_columns = [:col0, :fname, :col2, :col3, :col4]
|
|
200
|
+
|
|
201
|
+
for col in expected_columns
|
|
202
|
+
assert_includes( ss.columns, col )
|
|
203
|
+
assert_respond_to( ss[0], col )
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
context "testing sorting" do
|
|
209
|
+
setup do
|
|
210
|
+
load_sheet( "pokemon.csv" )
|
|
211
|
+
@sheet.set_column_type( :id, :integer )
|
|
212
|
+
@sheet.set_column_type( :cp, :integer )
|
|
213
|
+
@sheet.set_column_type( :hp, :integer )
|
|
214
|
+
|
|
215
|
+
@initial_id_result = [1,2,3,4,5,6,7,8]
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
should "successfully load sheet w/ proper results for :id column" do
|
|
219
|
+
assert_equal_length( @initial_id_result, @sheet.column(:id) )
|
|
220
|
+
assert_equal( @initial_id_result, @sheet.column(:id) )
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
should "not alter the order when sorting by ID (already in order)" do
|
|
224
|
+
@sheet.sort( :id )
|
|
225
|
+
assert_equal_length( @initial_id_result, @sheet.column(:id) )
|
|
226
|
+
assert_equal( @initial_id_result, @sheet.column(:id) )
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
should "alter order at other times" do
|
|
230
|
+
flunk
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context "testing add_blank_record" do
|
|
235
|
+
setup do
|
|
236
|
+
load_sheet "simple.csv"
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
should "add_a_blank_record (block form)" do
|
|
240
|
+
rec = @sheet.add_blank_record do |record|
|
|
241
|
+
record.id = "5"
|
|
242
|
+
record.fname = "Larry"
|
|
243
|
+
record.lname = "Wilmore"
|
|
244
|
+
record.age = "55"
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
assert_equal "Larry", @sheet.records.last.fname
|
|
248
|
+
assert_equal "55", rec.age
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
should "add_a_blank_record (no-block)" do
|
|
252
|
+
len = @sheet.length
|
|
253
|
+
rec = @sheet.add_blank_record
|
|
254
|
+
|
|
255
|
+
assert_equal( len + 1, @sheet.length )
|
|
256
|
+
|
|
257
|
+
rec.fname = "Bill"
|
|
258
|
+
assert_equal( "Bill", @sheet.records[len].fname )
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
should "update via apply_update_hash" do
|
|
264
|
+
record = @sheet.add_blank_record
|
|
265
|
+
record.apply_update_hash( :id => "6", :fname => "Teddy", :lname => "Roosevelt", :age => 109 )
|
|
266
|
+
assert_equal 109, record.age
|
|
267
|
+
assert_equal "6", record.id
|
|
268
|
+
end
|
|
269
|
+
end
|
|
133
270
|
end
|
data/test/test_utils.rb
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
class TestUtils < MadTestCase
|
|
4
|
+
include CsvMadness::Utils
|
|
5
|
+
|
|
6
|
+
context "testing for constants" do
|
|
7
|
+
should "have all the constants" do
|
|
8
|
+
assert defined?( CsvMadness )
|
|
9
|
+
assert defined?( CsvMadness::Utils )
|
|
10
|
+
assert defined?( CsvMadness::Utils::Counter )
|
|
11
|
+
assert defined?( CsvMadness::Utils::CounterProc )
|
|
12
|
+
assert defined?( CsvMadness::Utils::ConstProc )
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should "respond to factory methods" do
|
|
16
|
+
assert_respond_to ConstProc, :proc_for
|
|
17
|
+
assert_respond_to CounterProc, :counter
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "testing Counter" do
|
|
22
|
+
context "with a default/zero counter" do
|
|
23
|
+
setup do
|
|
24
|
+
@counter = Counter.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "respond to methods" do
|
|
28
|
+
assert_respond_to @counter, :value
|
|
29
|
+
assert_respond_to @counter, :click
|
|
30
|
+
assert_respond_to @counter, :reset
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should "start at zero" do
|
|
34
|
+
assert_zero @counter.value
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
should "track tick counts" do
|
|
38
|
+
300.times do |i|
|
|
39
|
+
@counter.click
|
|
40
|
+
assert_equal i + 1, @counter.value
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
@counter.reset
|
|
44
|
+
|
|
45
|
+
assert_zero @counter.value
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "when initialized with a positive counter" do
|
|
50
|
+
setup do
|
|
51
|
+
@counter = Counter.new(255)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
should "work okay" do
|
|
55
|
+
assert_equal 255, @counter.value
|
|
56
|
+
assert_equal 256, @counter.click
|
|
57
|
+
assert_equal 256, @counter.value
|
|
58
|
+
assert_equal 257, @counter.click
|
|
59
|
+
assert_equal 258, @counter.click
|
|
60
|
+
assert_equal 255, @counter.reset
|
|
61
|
+
assert_equal 255, @counter.value
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
context "when initialized with a negative counter" do
|
|
67
|
+
setup do
|
|
68
|
+
@counter = Counter.new( -12 )
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
should "work okay" do
|
|
72
|
+
assert_equal( -12, @counter.value )
|
|
73
|
+
assert_equal( -11, @counter.click )
|
|
74
|
+
assert_equal( -11, @counter.value )
|
|
75
|
+
assert_equal( -10, @counter.click )
|
|
76
|
+
assert_equal( -9, @counter.click )
|
|
77
|
+
assert_equal( -12, @counter.reset )
|
|
78
|
+
assert_equal( -12, @counter.value )
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "testing CounterProc" do
|
|
84
|
+
context "with default counter" do
|
|
85
|
+
setup do
|
|
86
|
+
@proc = CounterProc.counter
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should "start at zero and increment each time it's called" do
|
|
90
|
+
assert_zero @proc.call
|
|
91
|
+
assert_one @proc.times_called
|
|
92
|
+
assert_one @proc.call
|
|
93
|
+
assert_equal 2, @proc.times_called
|
|
94
|
+
@proc.reset
|
|
95
|
+
assert_zero @proc.times_called
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: csv_madness
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bryce Anderson
|
|
@@ -10,39 +10,39 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: fun_with_gems
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.0'
|
|
16
19
|
- - ">="
|
|
17
20
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
21
|
+
version: 0.0.6
|
|
19
22
|
type: :runtime
|
|
20
23
|
prerelease: false
|
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
25
|
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.0'
|
|
23
29
|
- - ">="
|
|
24
30
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
31
|
+
version: 0.0.6
|
|
26
32
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
33
|
+
name: csv
|
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
|
29
35
|
requirements:
|
|
30
|
-
- - "~>"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0.0'
|
|
33
36
|
- - ">="
|
|
34
37
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: 0
|
|
38
|
+
version: '0'
|
|
36
39
|
type: :runtime
|
|
37
40
|
prerelease: false
|
|
38
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
42
|
requirements:
|
|
40
|
-
- - "~>"
|
|
41
|
-
- !ruby/object:Gem::Version
|
|
42
|
-
version: '0.0'
|
|
43
43
|
- - ">="
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 0
|
|
45
|
+
version: '0'
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: fun_with_testing
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -67,36 +67,64 @@ extra_rdoc_files:
|
|
|
67
67
|
- LICENSE.txt
|
|
68
68
|
- README.rdoc
|
|
69
69
|
files:
|
|
70
|
-
- "
|
|
71
|
-
- "./lib/csv_madness/builder.rb"
|
|
72
|
-
- "./lib/csv_madness/data_accessor_module.rb"
|
|
73
|
-
- "./lib/csv_madness/exceptions.rb"
|
|
74
|
-
- "./lib/csv_madness/gem_api.rb"
|
|
75
|
-
- "./lib/csv_madness/record.rb"
|
|
76
|
-
- "./lib/csv_madness/sheet.rb"
|
|
77
|
-
- "./lib/csv_madness/sheet_methods/base.rb"
|
|
78
|
-
- "./lib/csv_madness/sheet_methods/class_methods.rb"
|
|
79
|
-
- "./lib/csv_madness/sheet_methods/column_methods.rb"
|
|
80
|
-
- "./lib/csv_madness/sheet_methods/file_methods.rb"
|
|
81
|
-
- "./lib/csv_madness/sheet_methods/indexing.rb"
|
|
82
|
-
- "./lib/csv_madness/sheet_methods/record_methods.rb"
|
|
83
|
-
- "./test/csv/forbidden_column.csv"
|
|
84
|
-
- "./test/csv/simple.csv"
|
|
85
|
-
- "./test/csv/splitter.csv"
|
|
86
|
-
- "./test/csv/test_column_types.csv"
|
|
87
|
-
- "./test/csv/with_nils.csv"
|
|
88
|
-
- "./test/helper.rb"
|
|
89
|
-
- "./test/test_builder.rb"
|
|
90
|
-
- "./test/test_csv_madness.rb"
|
|
91
|
-
- "./test/test_merging_columns.rb"
|
|
92
|
-
- "./test/test_reloading_spreadsheet.rb"
|
|
93
|
-
- "./test/test_sheet.rb"
|
|
70
|
+
- ".document"
|
|
94
71
|
- CHANGELOG.markdown
|
|
95
72
|
- Gemfile
|
|
96
73
|
- LICENSE.txt
|
|
97
74
|
- README.rdoc
|
|
98
75
|
- Rakefile
|
|
99
76
|
- VERSION
|
|
77
|
+
- lib/csv_madness.rb
|
|
78
|
+
- lib/csv_madness/builder.rb
|
|
79
|
+
- lib/csv_madness/column.rb
|
|
80
|
+
- lib/csv_madness/column_methods/core_methods.rb
|
|
81
|
+
- lib/csv_madness/column_methods/default_value_methods.rb
|
|
82
|
+
- lib/csv_madness/column_methods/error_methods.rb
|
|
83
|
+
- lib/csv_madness/column_methods/fetch_methods.rb
|
|
84
|
+
- lib/csv_madness/column_methods/typing_methods.rb
|
|
85
|
+
- lib/csv_madness/column_set.rb
|
|
86
|
+
- lib/csv_madness/column_type.rb
|
|
87
|
+
- lib/csv_madness/column_types/date.rb
|
|
88
|
+
- lib/csv_madness/column_types/float.rb
|
|
89
|
+
- lib/csv_madness/column_types/integer.rb
|
|
90
|
+
- lib/csv_madness/column_types/string.rb
|
|
91
|
+
- lib/csv_madness/data_accessor_module.rb
|
|
92
|
+
- lib/csv_madness/exceptions.rb
|
|
93
|
+
- lib/csv_madness/gem_api.rb
|
|
94
|
+
- lib/csv_madness/index_set.rb
|
|
95
|
+
- lib/csv_madness/indexer.rb
|
|
96
|
+
- lib/csv_madness/record.rb
|
|
97
|
+
- lib/csv_madness/record_filter.rb
|
|
98
|
+
- lib/csv_madness/record_methods/method_methods.rb
|
|
99
|
+
- lib/csv_madness/sheet.rb
|
|
100
|
+
- lib/csv_madness/sheet_methods/base.rb
|
|
101
|
+
- lib/csv_madness/sheet_methods/class_methods.rb
|
|
102
|
+
- lib/csv_madness/sheet_methods/column_methods.rb
|
|
103
|
+
- lib/csv_madness/sheet_methods/file_methods.rb
|
|
104
|
+
- lib/csv_madness/sheet_methods/indexing.rb
|
|
105
|
+
- lib/csv_madness/sheet_methods/record_methods.rb
|
|
106
|
+
- lib/csv_madness/sheet_methods/sorting_methods.rb
|
|
107
|
+
- lib/csv_madness/utils/const_proc.rb
|
|
108
|
+
- lib/csv_madness/utils/counter.rb
|
|
109
|
+
- lib/csv_madness/utils/counter_proc.rb
|
|
110
|
+
- lib/csv_madness/utils/looker_upper.rb
|
|
111
|
+
- test/csv/forbidden_column.csv
|
|
112
|
+
- test/csv/nil_headers.csv
|
|
113
|
+
- test/csv/out/.gitkeep
|
|
114
|
+
- test/csv/pokemon.csv
|
|
115
|
+
- test/csv/simple.csv
|
|
116
|
+
- test/csv/splitter.csv
|
|
117
|
+
- test/csv/test_column_types.csv
|
|
118
|
+
- test/csv/with_nils.csv
|
|
119
|
+
- test/helper.rb
|
|
120
|
+
- test/test_builder.rb
|
|
121
|
+
- test/test_csv_madness.rb
|
|
122
|
+
- test/test_index_set.rb
|
|
123
|
+
- test/test_indexer.rb
|
|
124
|
+
- test/test_merging_columns.rb
|
|
125
|
+
- test/test_reloading_spreadsheet.rb
|
|
126
|
+
- test/test_sheet.rb
|
|
127
|
+
- test/test_utils.rb
|
|
100
128
|
homepage: http://github.com/darthschmoo/csv_madness
|
|
101
129
|
licenses:
|
|
102
130
|
- MIT
|
|
@@ -115,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
115
143
|
- !ruby/object:Gem::Version
|
|
116
144
|
version: '0'
|
|
117
145
|
requirements: []
|
|
118
|
-
rubygems_version:
|
|
146
|
+
rubygems_version: 3.6.9
|
|
119
147
|
specification_version: 4
|
|
120
148
|
summary: CSV Madness turns your CSV rows into happycrazy objects.
|
|
121
149
|
test_files: []
|