问题
I need to generate a put but I don't know how to pass the parameters to update the name, salary or age from Gem Faker. How to upgrade from GEM faker or any even fixed value? I tried but could not.
require 'HTTParty'
require 'httparty/request'
require 'httparty/response/headers'
#require_relative '../hooks/hook'
class Crud
include HTTParty
base_uri 'http://dummy.restapiexample.com/api/v1'
def create
nome = Faker::Name.unique.first_name
salario = Faker::Number.decimal(l_digits: 4, r_digits: 2)
idade = Faker::Number.number(digits: 2)
body = {name: nome, salary: salario, age: idade }.to_json
headers = {
'Accept' => 'application/vnd.tasksmanager.v2',
'Content-Type' => 'application/json'
}
self.class.post('/create', body: body, headers: headers)
end
def retrieve(id)
self.class.get("/employee/#{ id }")
end
def delete(id)
self.class.delete("/delete/#{ id }")
end
def update(id)
self.class.put("/update/#{ id }")
end
ex.: def retrieve
@response = $manter_user.create
expect($manter_user.create.code).to eq (200)
puts @response.body
@id = JSON.parse(@response)['id']
puts $manter_user.retrieve(@id)
But in def update, I don't know how to pass the value to change.
response = $manter_user.create
expect(@response.code).to eq (200)
puts @response.body
@id = JSON.parse(@response.body)[name][salary][age] --- I don't know what to inform here.
来源:https://stackoverflow.com/questions/59337200/how-can-i-finish-crud-from-api-i-have-questions-on-put