representable 1.1.0 → 1.1.1

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.
@@ -1,3 +1,7 @@
1
+ h2. 1.1.1
2
+
3
+ * When a representer module is extended we no longer set the <code>@representable_attrs</code> ivar directly but use a setter. This makes it work with mongoid and fixes https://github.com/apotonick/roar/issues/10.
4
+
1
5
  h2. 1.1.0
2
6
 
3
7
  * Added `JSON::Collection` to have plain list representations. And `JSON::Hash` for hashes.
@@ -25,6 +25,8 @@ require 'representable/definition'
25
25
  #
26
26
  # hero.extend(HeroRepresenter).to_json
27
27
  module Representable
28
+ attr_writer :representable_attrs
29
+
28
30
  def self.included(base)
29
31
  base.class_eval do
30
32
  extend ClassMethods
@@ -37,10 +39,7 @@ module Representable
37
39
 
38
40
  # Copies the representable_attrs to the extended object.
39
41
  def self.extended(object)
40
- attrs = representable_attrs
41
- object.instance_eval do
42
- @representable_attrs = attrs
43
- end
42
+ object.representable_attrs=(representable_attrs)
44
43
  end
45
44
  end
46
45
  end
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency "test_xml"
27
27
  s.add_development_dependency "minitest", ">= 2.8.1"
28
28
  s.add_development_dependency "mocha"
29
+ s.add_development_dependency "mongoid"
29
30
  end
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'representable/json'
3
2
 
4
3
  class JSONBindingTest < MiniTest::Spec
5
4
  module SongRepresenter
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'representable/json'
3
2
 
4
3
  module JsonTest
5
4
  class APITest < MiniTest::Spec
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+ require 'mongoid'
3
+ require 'mongoid/document'
4
+
5
+ class MongoidTest < MiniTest::Spec
6
+ describe "Mongoid compatibility" do
7
+ it "allows #to_json" do
8
+ class Profile
9
+ include Mongoid::Document
10
+ field :name
11
+ end
12
+
13
+ class Dude
14
+ include Mongoid::Document
15
+ embeds_one :profile, :class_name => "MongoidTest::Profile"
16
+ end
17
+
18
+ module ProfileRepresenter
19
+ include Representable::JSON
20
+
21
+ property :name
22
+ end
23
+
24
+ dude = Dude.new
25
+ dude.profile = Profile.new
26
+ dude.profile.name = "Kofi"
27
+
28
+ assert_equal "{\"name\":\"Kofi\"}", dude.profile.extend(ProfileRepresenter).to_json
29
+ end
30
+ end
31
+ end
@@ -56,7 +56,6 @@ class RepresentableTest < MiniTest::Spec
56
56
  end
57
57
 
58
58
  it "allows including the concrete representer module later" do
59
- require 'representable/json'
60
59
  vd = class VD
61
60
  attr_accessor :name, :street_cred
62
61
  include Representable::JSON
@@ -199,7 +198,7 @@ class RepresentableTest < MiniTest::Spec
199
198
  end
200
199
 
201
200
 
202
- require 'representable/json' # DISCUSS: i don't like the JSON requirement here, what about some generic test module?
201
+ # DISCUSS: i don't like the JSON requirement here, what about some generic test module?
203
202
  class PopBand
204
203
  include Representable::JSON
205
204
  property :name
@@ -293,6 +292,6 @@ class RepresentableTest < MiniTest::Spec
293
292
  it "allows mapping formats to representers" do
294
293
  assert_equal :whatever, @class.representer[:json]
295
294
  assert_equal :special, @class.representer["application/order-json"]
296
- end
295
+ end
297
296
  end
298
297
  end
@@ -3,6 +3,7 @@ Bundler.setup
3
3
 
4
4
  gem 'minitest'
5
5
  require 'representable'
6
+ require 'representable/json'
6
7
  require 'test/unit'
7
8
  require 'minitest/spec'
8
9
  require 'minitest/autorun'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 0
9
- version: 1.1.0
8
+ - 1
9
+ version: 1.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-02-03 00:00:00 +01:00
17
+ date: 2012-02-06 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -97,6 +97,19 @@ dependencies:
97
97
  version: "0"
98
98
  type: :development
99
99
  version_requirements: *id006
100
+ - !ruby/object:Gem::Dependency
101
+ name: mongoid
102
+ prerelease: false
103
+ requirement: &id007 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ type: :development
112
+ version_requirements: *id007
100
113
  description: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties, collections and compositions.
101
114
  email:
102
115
  - apotonick@gmail.com
@@ -131,6 +144,7 @@ files:
131
144
  - test/definition_test.rb
132
145
  - test/json_bindings_test.rb
133
146
  - test/json_test.rb
147
+ - test/mongoid_test.rb
134
148
  - test/polymorphic_test.rb
135
149
  - test/representable_test.rb
136
150
  - test/test_helper.rb