Sha256: eec5da38fa7ae1535a080540a69267b3ca5f7efac5b6a248193b0b9c0de3e996

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Medie::Json::Driver do
  
  context "when looking up the handler" do
  
    it "should accept pure application/json" do
      Medie::Json::Driver.new.can_handle?("application/json").should be_true
    end

    it "should not accept anything else" do
      Medie::Json::Driver.new.can_handle?("application/json2").should be_false
    end

    it "should accept profiles and options" do
      Medie::Json::Driver.new.can_handle?("application/json;profile=client").should be_true
    end

  end
  
  context "when unmarshalling" do
    
    it "should return an empty hash if its empty" do
      result = Medie::Json::Driver.new.unmarshal(nil)
      result.should be_empty
      result.should be_kind_of(Hash)
      result.should be_kind_of(Methodize)
      result.should be_kind_of(Medie::Linked)
      result.links.should be_kind_of(Medie::Json::Links)
    end
    
    it "should return the unmarshalled json hash enhanced" do
      result = Medie::Json::Driver.new.unmarshal({"name" => "guilherme"}.to_json)
      result.should == {"name" => "guilherme"}
      result.should be_kind_of(Hash)
      result.should be_kind_of(Methodize)
      result.should be_kind_of(Medie::Linked)
      result.links.should be_kind_of(Medie::Json::Links)
    end
    
  end
  
  context "when marshalling" do
    
    it "should return itself if its a string" do
      result = Medie::Json::Driver.new.marshal("guilherme", nil)
      result.should == "guilherme"
    end
    
    it "should return the unmarshalled json hash enhanced" do
      result = Medie::Json::Driver.new.marshal({"name" => "guilherme"}, nil)
      result.should == {"name" => "guilherme"}.to_json
    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
medie-1.0.0 spec/medie/json/driver_spec.rb
medie-1.0.0.beta4 spec/medie/json/driver_spec.rb
medie-1.0.0.beta3 spec/medie/json/driver_spec.rb