test/fake_server.rb in roar-0.8.3 vs test/fake_server.rb in roar-0.9.0

- old
+ new

@@ -1,32 +1,11 @@ require "bundler/setup" require 'sinatra/base' require 'sinatra/reloader' -require 'roar/representer/xml' -# Usually shared in a gem between service and clients. -module BandRepresenter - include Roar::Representer::XML - property :name - property :label -end - -Band = Struct.new(:name, :label) -Band.class_eval do - include Roar::Representer::XML - include BandRepresenter -end - -class FakeServer < Sinatra::Base - BANDS = {"belvedere" => Band.new("Belvedere", "canadian maple")} - - get "/bands/:id" do - BANDS[params[:id]].to_xml - end - - +class FakeServer < Sinatra::Base get "/method" do "<method>get</method>" end post "/method" do @@ -43,24 +22,21 @@ #patch "/method" do # "<method>patch</method>" #end - post "/band" do - if request.content_type =~ /xml/ - %{<band><label>n/a</label><name>Strung Out</name> - <link href="http://search" rel="search" /> - <link href="http://band/strungout" rel="self" /> - </band>} - else - '{"band": {"label": "n/a", "name": "Strung Out", "links": [{"href":"http://search", "rel": "search"}, {"href":"http://band/strungout", "rel": "self"}]}}' - end + post "/bands" do + #if request.content_type =~ /xml/ + '{"label": "n/a", "name": "Strung Out", "links": [{"href":"http://search", "rel": "search"}, {"href":"http://band/strungout", "rel": "self"}]}' end - put "/band/strungout" do - %{<band><label>Fat Wreck</label><name>Strung Out</name></band>} + put "/bands/strungout" do + {:name => "Strung Out", :label => "Fat Wreck"}.to_json end + get "/bands/slayer" do + {:name => "Slayer", :label => "Canadian Maple"}.to_json + end require Dir.pwd + '/order_representers' JSON::Order.class_eval do def items_url