Created
April 17, 2012 18:55
-
-
Save jhigginbotham/2408242 to your computer and use it in GitHub Desktop.
Representable: Typed Property Missing Spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'json' | |
require 'roar/representer/json' | |
require 'rspec' | |
class User | |
attr_accessor :login, :address | |
end | |
class Address | |
attr_accessor :street | |
end | |
module AddressRepresenter | |
include Roar::Representer::JSON | |
property :street | |
end | |
module UserRepresenter | |
include Roar::Representer::JSON | |
self.representation_wrap = true | |
property :login | |
property :address, :class=>Address, :extend=>AddressRepresenter | |
end | |
describe "Typed Property Missing" do | |
before :each do | |
@user = User.new.extend(UserRepresenter) | |
end | |
it "should generate valid json" do | |
puts @user.to_json | |
end | |
it "should parse valid json" do | |
json = "{\"user\":{}}" | |
@user.from_json(json) # undefined method `[]' for nil:NilClass | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment