Sha256: 4c7334e17d0ec92f02adc1b53f233d5bfeb946ae69e8f62dd43716221546663e
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
module Spree class Foo include Spree::Model define_model_attributes :id, :name end module API class Foo extend Spree::API::Query end end end describe Spree::API::Query do extend WebStub::SpecHelpers before do disable_network_access! end describe "#collection_query" do before do @uri = "http://example.com/api/foos" @data = { foos: [{ id: "1", name: "Foo 1" }, { id: "2", name: "Foo 2" }] } stub_request(:get, @uri). to_return(json: @data) Spree::API::Foo.collection_query("foos", Spree::Foo, @uri) do |f| @foos = f resume end # Wait for the BW::HTTP Thread wait_max 1 { @foos } end it "maps received data to objects of the specified class" do @foos.each_with_index do |f, i| f.is_a?(Spree::Foo).should.be.true f.id.should.equal @data[:foos][i][:id] f.name.should.equal @data[:foos][i][:name] end end end describe "#object_query" do before do @uri = "http://example.com/api/foos/1" @data = { id: "1", name: "Foo 1" } stub_request(:get, @uri). to_return(json: @data) Spree::API::Foo.object_query(Spree::Foo, @uri) do |f| @foo = f resume end # Wait for the BW::HTTP Thread wait_max 1 { @foo } end it "maps received data to an object of the specified class" do @foo.is_a?(Spree::Foo).should.be.true @foo.id.should.equal @data[:id] @foo.name.should.equal @data[:name] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spree-wrap-0.0.2 | spec/spree/api/query_spec.rb |