csv_schema 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/csv_schema.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{csv_schema}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jconley"]
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
 
@@ -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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - jconley