Sha256: ead65b83648586e219b1efd53e696d472bbf2189d48f85e6edce58142bd91bca

Contents?: true

Size: 1.49 KB

Versions: 12

Compression:

Stored size: 1.49 KB

Contents

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

module Loquor
  class HttpAction::PostTest < HttpAction::Test
    def test_post_should_call_new
      url = "foobar"
      payload = {y: false}
      deps = {x: true}
      HttpAction::Post.expects(:new).with(url, payload, deps).returns(mock(post: nil))
      HttpAction::Post.post(url, payload, deps)
    end

    def test_post_should_call_post
      HttpAction::Post.any_instance.expects(:post)
      HttpAction::Post.post("foobar", {}, {})
    end

    def test_post_returns_response
      output = {'foo' => 'bar'}
      json = output.to_json
      post = HttpAction::Post.new("", {}, deps)
      response = post.expects(signed_request: mock(execute: json))
      assert_equal output, post.post
    end

    def test_request_is_generated_correctly
      url = "/foobar"
      payload = {foo: true, bar: false}
      full_url = "#{@endpoint}#{url}"

      RestClient::Request.expects(:new).with(
        url: full_url,
        accept: :json,
        payload: payload.to_json,
        headers: {'Content-type' => 'application/json'},
        method: :post
      )
      HttpAction::Post.new(url, payload, deps).send(:request)
    end

    def test_request_is_signed_correctly
      posts = HttpAction::Post.new("", {}, deps)
      request = RestClient::Request.new(url: "http://localhost:3000", method: :post)
      posts.expects(request: request)
      ApiAuth.expects(:sign!).with(request, @access_id, @secret_key)
      posts.send(:signed_request)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
loquor-1.13.0 test/http_actions/post_test.rb
loquor-1.12.0 test/http_actions/post_test.rb
loquor-1.11.0 test/http_actions/post_test.rb
loquor-1.10.0 test/http_actions/post_test.rb
loquor-1.9.0 test/http_actions/post_test.rb
loquor-1.8.0 test/http_actions/post_test.rb
loquor-1.7.0 test/http_actions/post_test.rb
loquor-1.6.0 test/http_actions/post_test.rb
loquor-1.5.0 test/http_actions/post_test.rb
loquor-1.4.0 test/http_actions/post_test.rb
loquor-1.3.0 test/http_actions/post_test.rb
loquor-1.2.1 test/http_actions/post_test.rb