mediator 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mediator/registry.rb +6 -0
- data/mediator.gemspec +1 -1
- data/test/mediator_renderer_test.rb +16 -0
- metadata +2 -2
data/lib/mediator/registry.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "mediator/errors"
|
2
|
+
require "ostruct"
|
2
3
|
|
3
4
|
class Mediator
|
4
5
|
module Registry
|
@@ -31,6 +32,11 @@ class Mediator
|
|
31
32
|
# registry - optional registry map to use instead of default
|
32
33
|
|
33
34
|
def for subject, opts = {}
|
35
|
+
# Return a dummy mediator is subject is nil
|
36
|
+
# (can happen with r.one :foo, empty: true)
|
37
|
+
|
38
|
+
return OpenStruct.new render: nil if subject == nil
|
39
|
+
|
34
40
|
context = opts[:context]
|
35
41
|
|
36
42
|
reg = registry(opts[:registry] || context)
|
data/mediator.gemspec
CHANGED
@@ -356,5 +356,21 @@ describe Mediator::Renderer do
|
|
356
356
|
|
357
357
|
assert_equal e, d
|
358
358
|
end
|
359
|
+
|
360
|
+
it "does not barf if associated object is nil and empty is true" do
|
361
|
+
c = Class.new Mediator do
|
362
|
+
def render! r
|
363
|
+
r.one :foo, empty: true
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
s = OpenStruct.new foo: nil
|
368
|
+
|
369
|
+
m = c.new s
|
370
|
+
d = m.render
|
371
|
+
e = {foo: nil}
|
372
|
+
|
373
|
+
assert_equal e, d
|
374
|
+
end
|
359
375
|
end
|
360
376
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
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: 2013-
|
12
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A go-between for models.
|
15
15
|
email:
|