Sha256: 3f2c3d7228ff0fa4537565ea4d9c424bee2b29e3a655e3833ff21bd813c77ce5

Contents?: true

Size: 1.91 KB

Versions: 105

Compression:

Stored size: 1.91 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'net/http_multipart_post'

class HttpMulitpartPostTest < Test::Unit::TestCase
  def setup
    super
  end
  
  def fixture(string)
    File.open(File.dirname(__FILE__) + "/../fixtures/#{string}.txt").read
  end
  
  def test_multipart_post_with_only_parameters
    params = add_sample_facebook_params({})
    post = Net::HTTP::MultipartPost.new("uri", params)
    assert_equal fixture("multipart_post_body_with_only_parameters"), post.send(:body)
  end
  
  def test_multipart_post_with_a_single_file
    params = add_sample_facebook_params({})
    params[:file] = Net::HTTP::MultipartPostFile.new
    params[:file].filename = "somefilename.jpg"
    params[:file].content_type = "image/jpg"
    params[:file].data = "[Raw file data here]"
    post = Net::HTTP::MultipartPost.new("uri", params)
    assert_equal fixture("multipart_post_body_with_single_file"), post.send(:body)
  end
  
  def test_multipart_post_with_a_single_file_parameter_that_has_nil_key
    params = add_sample_facebook_params({})
    params[nil] = Net::HTTP::MultipartPostFile.new("somefilename.jpg", "image/jpg", "[Raw file data here]")
    post = Net::HTTP::MultipartPost.new("uri", params)
    assert_equal fixture("multipart_post_body_with_single_file_that_has_nil_key"), post.send(:body)
  end
  
  def test_multipart_post_should_have_correct_content_type
    post = Net::HTTP::MultipartPost.new("uri", {})
    assert post.send(:content_type) =~ /multipart\/form-data; boundary=/
  end
  
  def add_sample_facebook_params(hash)
    hash[:method] = "facebook.photos.upload"
    hash[:v] = "1.0"
    hash[:api_key] = "77a52842357422fadd912a2600e6e53c"
    hash[:session_key] = "489727d0ab2efc6e8003018c-i2LLkn8BDb2s."
    hash[:call_id] = "1172623588.023010"
    hash[:caption] = "Under the sunset"
    hash[:aid] = "940915667462717"
    hash[:sig] = "dfa724b8a5cd97d9df4baf2b60d3484c"
    hash
  end
end

Version data entries

105 entries across 105 versions & 23 rubygems

Version Path
corey-facebooker-1.0.28.1 test/net/http_multipart_post_test.rb
fs-facebooker-1.0.37 test/net/http_multipart_post_test.rb
mborromeo-facebooker-1.0.28 test/net/http_multipart_post_test.rb
mborromeo-facebooker-1.0.29 test/net/http_multipart_post_test.rb
mborromeo-facebooker-1.0.30 test/net/http_multipart_post_test.rb
mborromeo-facebooker-1.0.31 test/net/http_multipart_post_test.rb
micahwedemeyer-facebooker-1.0.50 test/net/http_multipart_post_test.rb
micahwedemeyer-facebooker-1.0.51 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.16 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.19 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.20 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.21 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.22 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.23 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.24 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.25 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.26 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.27 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.28 test/net/http_multipart_post_test.rb
mmangino-facebooker-1.0.29 test/net/http_multipart_post_test.rb