Permalink
Browse files

Use the right variable scope

  • Loading branch information...
1 parent 00d74a5 commit fc5f26a3b989992be5e3157725ff6f39e7602c16 @jhchabran jhchabran committed Jul 24, 2012
Showing with 61 additions and 7 deletions.
  1. +2 −2 lib/vintner/collection_representer.rb
  2. +5 −5 lib/vintner/representer.rb
  3. +54 −0 spec/vintner/representer_spec.rb
@@ -15,10 +15,10 @@ def to_json
module ClassMethods
- mattr_reader :collection
+ attr_reader :collection
def representer representer_klass
- @@collection = Collection.new(name, representer_klass)
+ @collection = Collection.new(name, representer_klass)
end
def representation &block
View
@@ -18,18 +18,18 @@ def from_json json
end
module ClassMethods
- mattr_reader :properties, :collections
+ attr_reader :properties, :collections
def property name, &block
- @@properties ||= {}
+ @properties ||= {}
- @@properties[name] = Property.new(name, &block)
+ @properties[name] = Property.new(name, &block)
end
def collection name, representer, &block
- @@collections ||= {}
+ @collections ||= {}
- @@collections[name] = Collection.new(name, representer, &block)
+ @collections[name] = Collection.new(name, representer, &block)
end
def representation &block
@@ -333,4 +333,58 @@ class DummyCollection
DummyCollection.new(@collection).to_json.should ==(@hash.to_json)
end
end
+
+ describe "Issue" do
+ before :each do
+ @model_klass = Struct.new(:foo)
+ @another_klass = Struct.new(:bar)
+
+ class Dummy
+ include Vintner::Representer
+
+ property :foo
+ representation do |json|
+ json.meta do |meta|
+ meta.property :foo
+ end
+ end
+ end
+
+ class Another
+ include Vintner::Representer
+
+ property :bar
+ representation do |json|
+ json.meta do |meta|
+ meta.property :bar
+ end
+ end
+ end
+
+ class DummyCollection
+ include Vintner::CollectionRepresenter
+
+ representer Dummy
+
+ representation do |json|
+ json.collection :dummies
+ end
+ end
+
+ class AnotherCollection
+ include Vintner::CollectionRepresenter
+
+ representer Another
+
+ representation do |json|
+ json.collection :anothers
+ end
+ end
+ end
+
+ it "should not share representer" do
+ DummyCollection.new([@model_klass.new("test"), @model_klass.new("test2")]).to_json
+ AnotherCollection.new([@another_klass.new("another"), @another_klass.new("another2")]).to_json
+ end
+ end
end

0 comments on commit fc5f26a

Please sign in to comment.