How to test Web Service in Ruby on Rails

0

I'm having the following question, I'm doing a server with my application , I'm using gem wash-out , I understood how it works and managed to get my web-service to run, but I'd like to know how to test my server, I've already tried several tutorials and none helped me.

For example:

 soap_action "novo_cadastro",
      :args   => {:titulo => :string, :descricao => :string },
      :return => :xml

  def novo_cadastro
    cad = Cadastro.new(titulo: params[:titulo], descricao: params[:descricao])
    if cad.save
      render xml: cad
    else
      render :soap => nil
    end
  end

How to test this?

Thank you.

    
asked by anonymous 05.06.2014 / 15:55

1 answer

1

An example of the WashOut page:

require 'test_helper'
require 'savon'

class NovoCadastroTeste < ActiveSupport::TestCase

    test "cadastro com sucesso" do

        cliente = Savon::Client.new(wsdl: "http://localhost:3000/novo_cadastro/wsdl")

        cliente.operations # Retorna operações possíveis.

        resultado = client.call(:novo_cadastro, message: { :titulo => "titulo", :descricao => "descricao" })

        # Verifique se a resposta está correta.

        resultado = resultado.to_hash

        assert resultado[:sucesso]
    end
end

You should import the gem of the savon into your Gemfile, like this:

gem 'savon'
    
17.07.2014 / 21:18