Sha256: a7c9b7d8133c0cc8b4d442cefbe8a24aa27d01959ea253ffecbe7622e846d0df

Contents?: true

Size: 799 Bytes

Versions: 2

Compression:

Stored size: 799 Bytes

Contents

require File.expand_path('../test_helper', __FILE__)
require 'ostruct'

class EmulateTest < UnitTest
  class App < Sinatra::Base
    register Sinatra::RestAPI
    disable :show_exceptions
    enable :raise_errors

    rest_resource("/api/:id") { |id| FauxModel.new }
  end

  def app() App; end

  setup do
    header 'Accept', 'application/json, */*'
  end

  test "emulate json and emulate http" do
    FauxModel.any_instance.expects(:two=).times(1).returns(true)
    FauxModel.any_instance.expects(:save).times(1).returns(true)
    FauxModel.any_instance.expects(:valid?).times(1).returns(true)
    FauxModel.any_instance.expects(:to_hash).times(1).returns('a' => 'b')

    post "/api/2", :model => { :two => 2 }.to_json
    assert json_response == { 'a' => 'b' }
  end
end

class FauxModel
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sinatra-backbone-2-0.1.1 test/emulate_test.rb
sinatra-backbone-0.1.1 test/emulate_test.rb