Skip to content

Commit

Permalink
integration specs for json
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Dec 29, 2010
1 parent 7dc5003 commit ad86d48
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
46 changes: 46 additions & 0 deletions spec/integration/full_json.js
@@ -0,0 +1,46 @@
{
"articles": {
"link": [
{
"rel": "self",
"href": "http://another.place.com",
"type": "text/json",
"charset": "utf-8"
},
{
"rel": "search",
"href": "http://search.place.com",
"type": "application/opensearchdescription+xml",
"charset": "utf-8"
}
],
"size": 2,
"freezed": null,
"article": [
{
"link": {
"rel": "self",
"href": "http://a.link.com",
"type": "text/json",
"profile": "article",
"charset": "utf-8"
},
"title": "a awesome title",
"subtitle": "Article subtitle",
"author": "John Maclane"
},
{
"link": {
"rel": "self",
"href": "http://a.link.com",
"type": "text/json",
"profile": "article",
"charset": "utf-8"
},
"title": "a awesome title",
"subtitle": "Article subtitle",
"author": "John Maclane"
}
]
}
}
40 changes: 40 additions & 0 deletions spec/integration/json_spec.rb
@@ -0,0 +1,40 @@
require 'spec_helper'

describe Medie::Json do

before :all do
full_json = IO.read(File.dirname(__FILE__) + '/full_json.js')
@json = Medie::Json::Driver.new.unmarshal(full_json)
end

describe "JSON read" do

it "should be able to read a JSON object in many ways" do

@json["articles"]["link"].first["type"].should == "text/json"
@json.articles.link.first.type.should == "text/json"

@json.articles.links.search.href.should == "http://search.place.com"
@json.articles.links.unknow_rel.should == nil
end

end

describe "JSON write" do

it "should be able to write a JSON object in many ways" do
@json["articles"]["size"] = 10
@json["articles"]["size"].should == 10

@json.articles.link << {"href" => "http://dont.panic.com", "rel" => "towel"}
@json.articles.link.last.href.should == "http://dont.panic.com"
@json.articles.link.last.rel.should == "towel"
@json.articles.link.size.should == 3

@json.articles.link.last.type = "application/json"
@json.articles.link.last.type.should == "application/json"
end

end

end

0 comments on commit ad86d48

Please sign in to comment.