mediator 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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)
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.test_files = `git ls-files -- test/*`.split "\n"
10
10
  gem.name = "mediator"
11
11
  gem.require_paths = ["lib"]
12
- gem.version = "0.4.1"
12
+ gem.version = "0.4.2"
13
13
 
14
14
  gem.required_ruby_version = ">= 1.9.2"
15
15
  end
@@ -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.1
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-03-07 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A go-between for models.
15
15
  email: