Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dc5003
commit ad86d48
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |