csv_schema 0.0.1 → 0.0.2
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.
- data/VERSION +1 -1
- data/csv_schema.gemspec +1 -1
- data/lib/csv_schema.rb +1 -1
- data/spec/csv_schema_spec.rb +22 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/csv_schema.gemspec
CHANGED
data/lib/csv_schema.rb
CHANGED
@@ -18,7 +18,7 @@ class CSVSchema
|
|
18
18
|
field_requirements.each do |field, requirements|
|
19
19
|
@unique_fields[field] = [] if requirements[:unique]
|
20
20
|
@cant_be_nil_fields << field if requirements[:cant_be_nil]
|
21
|
-
@restrict_value_fields[field] = requirements[:restrict_values] if requirements[:restrict_values]
|
21
|
+
@restrict_value_fields[field] = requirements[:restrict_values] << nil if requirements[:restrict_values]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/spec/csv_schema_spec.rb
CHANGED
@@ -153,12 +153,24 @@ describe CSVSchema do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
describe "field_requirements" do
|
156
|
+
|
156
157
|
describe "restrict_values" do
|
158
|
+
it "should raise if referenced column does not exist" do
|
159
|
+
options = {:file => generate_csv_file.path, :field_requirements => {'doesnt_exist' => {:restrict_values => []}}}
|
160
|
+
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should raise_error
|
161
|
+
end
|
162
|
+
|
157
163
|
it "should NOT raise if all field values appear in the RESTRICT_VALUES array for the specified field" do
|
158
164
|
options = {:file => generate_csv_file.path, :field_requirements => {'header_1' => {:restrict_values => ['value_1']}}}
|
159
165
|
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should_not raise_error
|
160
166
|
end
|
161
167
|
|
168
|
+
it "should allow nil values" do
|
169
|
+
@rows << [nil]
|
170
|
+
options = {:file => generate_csv_file.path, :field_requirements => {'header_1' => {:restrict_values => ['value_1']}}}
|
171
|
+
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should_not raise_error
|
172
|
+
end
|
173
|
+
|
162
174
|
it "should raise if any field values do NOT appear in the RESTRICT_VALUES array for the specified field" do
|
163
175
|
options = {:file => generate_csv_file.path, :field_requirements => {'header_1' => {:restrict_values => []}}}
|
164
176
|
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should raise_error(StandardError, /header_1.*value_1.*2/)
|
@@ -166,6 +178,11 @@ describe CSVSchema do
|
|
166
178
|
end
|
167
179
|
|
168
180
|
describe "cant_be_nil" do
|
181
|
+
it "should raise if referenced column does not exist" do
|
182
|
+
options = {:file => generate_csv_file.path, :field_requirements => {'doesnt_exist' => {:cant_be_nil => true}}}
|
183
|
+
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should raise_error
|
184
|
+
end
|
185
|
+
|
169
186
|
it "should NOT raise if all values for the specified field are populated" do
|
170
187
|
options = {:file => generate_csv_file.path, :field_requirements => {'header_1' => {:cant_be_nil => true}}}
|
171
188
|
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should_not raise_error
|
@@ -185,6 +202,11 @@ describe CSVSchema do
|
|
185
202
|
end
|
186
203
|
|
187
204
|
describe 'unique' do
|
205
|
+
it "should raise if referenced column does not exist" do
|
206
|
+
options = {:file => generate_csv_file.path, :field_requirements => {'doesnt_exist' => {:unique => []}}}
|
207
|
+
lambda { CSVSchema.new(@lenient_options.merge(options)).validate }.should raise_error
|
208
|
+
end
|
209
|
+
|
188
210
|
it "should NOT raise if all of the values are unique" do
|
189
211
|
@rows << ['v1']
|
190
212
|
@rows << ['v2']
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- jconley
|