mvcli 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39bb6d037a235e80b610d16a1cff026dd0945134
4
- data.tar.gz: 42a1e909308dea92677bf8e76abb6dcee1d8358f
3
+ metadata.gz: 88557c947ef7dda45f0e854d7c56806e979e75f5
4
+ data.tar.gz: 357ee1d5fd303402b6e538e69f245638b82b1621
5
5
  SHA512:
6
- metadata.gz: 2812db9dc93f3a3ec99d6cfa5b2af883e6ed04af8aea8538404b28b5969234c14c3b71615996011dbd348e7e4343de0ec923e48078487e3d3142a9da6b6b5a8f
7
- data.tar.gz: e2913626bac2de10934365c49a80924365885aac67c7bf23f76764a1ed8ca53fd08792b38dd04dae92aa5c2619385b89b44309552d46216115203bf148b962ab
6
+ metadata.gz: c77eeab72a1f9e1dca58b8910b7dd1dee562b4e412e512911b265cdcb059f8d51fe66d2d9077155d3765f858a295c7e4b1b5f2d583d2f69e4d1d579f5fa776a1
7
+ data.tar.gz: 13187537df716ae571c93eb1df4a9b8b3faf4d71820fd3f9672ccbff5e223ff069c1680fc3d456136fc9c79e1f7e3409387b7816dec342ce1eab50bcc6ea7ded
data/lib/mvcli/erb.rb CHANGED
@@ -15,19 +15,25 @@ module MVCLI
15
15
  Template.new code, enc, filename
16
16
  end
17
17
 
18
+ class Context < BasicObject
19
+ attr_reader :this
20
+ def initialize(this)
21
+ @this = this
22
+ end
23
+ end
24
+
18
25
  class Template
19
26
  def initialize(code, enc, filename)
20
27
  @code, @enc, @filename = code, enc, filename
21
28
  end
22
29
 
23
- def call(context, output)
30
+ def call(this, output)
31
+ context = Context.new this
24
32
  binding = context.instance_eval do
25
33
  @_erbout = output
26
34
  Kernel.binding
27
35
  end
28
36
  eval @code, binding, @filename, 1
29
- ensure
30
- context.remove_instance_variable(:@_erbout)
31
37
  end
32
38
 
33
39
  def to_proc
@@ -172,9 +172,8 @@ module MVCLI::Validatable
172
172
  value, error = read validatable
173
173
  if error
174
174
  errors[@field] << error
175
- elsif value.nil?
176
- return unless !!@options[:nil]
177
175
  else
176
+ return if value.nil? && !@options[:nil]
178
177
  violations[@field] << @message unless @predicate.call value
179
178
  end
180
179
  end
data/lib/mvcli/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MVCLI
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -5,7 +5,7 @@ describe "MVCLI::ERB" do
5
5
  Given(:erb) {MVCLI::ERB.new}
6
6
  context "when I compile a template" do
7
7
  Given(:output) {""}
8
- Given(:template) {erb.compile "name: <%= name %>"}
8
+ Given(:template) {erb.compile "name: <%= this.name %>"}
9
9
  context "and call it with a context" do
10
10
  When {template.call mock(:Context, :name => 'Charles'), output}
11
11
  Then {output.should eql "name: Charles"}
@@ -2,11 +2,14 @@ require "spec_helper"
2
2
  require "mvcli/validatable"
3
3
 
4
4
  describe "a validator" do
5
+ use_natural_assertions
6
+ Given(:object) {Object.new}
5
7
  Given(:validator) {MVCLI::Validatable::Validator.new}
8
+ Given(:validation) { validator.validate object }
6
9
  context "when it validates a field that does not exist on the object" do
7
10
  Given {validator.validates(:does_not_exist, "invalid") {}}
8
- When(:validation) {validator.validate(Object.new)}
9
- Then {validation.errors[:does_not_exist].class < NameError}
11
+ When(:validation) {validator.validate object}
12
+ Then {not validation.errors[:does_not_exist].empty?}
10
13
  Then {not validation.valid?}
11
14
  end
12
15
  describe "validating a child" do
@@ -21,4 +24,17 @@ describe "a validator" do
21
24
  And {not validation.valid?}
22
25
  end
23
26
  end
27
+
28
+ describe "validating a nil field" do
29
+ Given { object.stub(:property) {nil} }
30
+ context "when the validate-on-nil option is passed" do
31
+ When { validator.validates(:property, "check nil", nil: true) {false} }
32
+ Then { not validation.valid? }
33
+ And { not validation.violations[:property].empty? }
34
+ end
35
+ context "when the validate on nil option is not passed" do
36
+ When { validator.validates(:property, "check nil") {false}}
37
+ Then { validation.valid? }
38
+ end
39
+ end
24
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -29,7 +29,7 @@ cert_chain:
29
29
  UgImJlChAzCoDP9zi9tdm6jAr7ttF25R9PPYr11ILb7dYe3qUzlNlM6zJx/nb31b
30
30
  IhdyRVup4qLcqYSTPsm6u7VA
31
31
  -----END CERTIFICATE-----
32
- date: 2013-06-26 00:00:00.000000000 Z
32
+ date: 2013-07-01 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: map