chozo 0.2.2 → 0.2.3

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.
@@ -61,15 +61,17 @@ module Chozo
61
61
  end
62
62
  end
63
63
 
64
+ # Validate that the attribute on the given model has a non-nil value assigned
65
+ #
64
66
  # @param [VariaModel] model
65
67
  # @param [String] key
66
68
  #
67
69
  # @return [Array]
68
70
  def validate_required(model, key)
69
- if model.attributes.dig(key).present?
70
- [ :ok, "" ]
71
- else
71
+ if model.attributes.dig(key).nil?
72
72
  [ :error, "A value is required for attribute: '#{key}'" ]
73
+ else
74
+ [ :ok, "" ]
73
75
  end
74
76
  end
75
77
 
@@ -1,3 +1,3 @@
1
1
  module Chozo
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -206,6 +206,24 @@ describe Chozo::VariaModel do
206
206
  subject.validate_required(model, key).should be_a(Array)
207
207
  end
208
208
 
209
+ it "fails validation if the value of the attribute is nil" do
210
+ model.set_attribute(key, nil)
211
+
212
+ subject.validate_required(model, key).first.should eql(:error)
213
+ end
214
+
215
+ it "passes validation if the value of the attribute is false", focus: true do
216
+ model.set_attribute(key, false)
217
+
218
+ subject.validate_required(model, key).first.should eql(:ok)
219
+ end
220
+
221
+ it "passes validation if the value of the attribute is not nil" do
222
+ model.set_attribute(key, 'some_value')
223
+
224
+ subject.validate_required(model, key).first.should eql(:ok)
225
+ end
226
+
209
227
  context "failure" do
210
228
  before(:each) do
211
229
  model.nested.one = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chozo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-06 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: -257548737276151229
123
+ hash: 23954185641818190
124
124
  requirements: []
125
125
  rubyforge_project:
126
126
  rubygems_version: 1.8.23