Sha256: 53a35be369e864cbc7401bf230fd4f1550a4fb967353d11ee5c661a019968fd2

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require_relative "../test_helper"

class ContactsController < ApplicationController
  def raw
    @contact = new_contact
    render msgpack: @contact
  end
  def serialized
    @contact = new_contact
    render msgpack: @contact.to_msgpack
  end
  private
  def new_contact
    contact = Contact.new
    contact.name = 'Konata Izumi'
    contact.age = 16
    contact.created_at = Time.utc(2006, 8, 1)
    contact.awesome = true
    contact.preferences = { 'shows' => 'anime' }
    contact
  end
end

class RenderingTest < ActionController::TestCase
  tests ContactsController

  def setup
    r = ActionDispatch::Routing::RouteSet.new
    r.draw do
      get ":controller/:action"
    end
    r.finalize!
    @routes = r
  end

  def test_raw
    get :raw, :format => :msgpack
    verify_response
  end

  def test_serialized
    get :serialized, :format => :msgpack
    verify_response
  end

  private

  def verify_response
    assert_response :success

    contact = MessagePack.unpack(response.body)
    assert_equal 'Konata Izumi', contact['name']
    assert_equal 16, contact['age']
    assert_equal Time.utc(2006, 8, 1), contact['created_at']
    assert_equal true, contact['awesome']
    assert_equal({ 'shows' => 'anime' }, contact['preferences'])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
msgpack_rails-0.4.3 test/msgpack_rails/rendering_test.rb