I’m working on a plugin that adds a model. I am trying to write specs that test that the model (and controller?) are behaving as expected.
This code in an ansible library, is successfully PUT
ting to this path and updating a field in the model/record:
headers = {
'Api-Key': discourse_api_key,
'Api-Username': discourse_api_username,
}
payload = {
"server[request_status]": status
}
url = "%spfaffmanager/servers/%s" % (discourse_url, server_id)
# raise Exception(url)
result = requests.put(url, data=payload, headers=headers)
This is the spec that I am trying to write that tests updates to that path. I’m confused because I have a zillion puts
in the controller and none of them are printing, though puts
in the model (e.g., in a function called by before_save
) are showing up in the stuff I see in the rake autospec
.
My best guess is that I’m screwing up the
# frozen_string_literal: true
require 'rails_helper'
describe Pfaffmanager::ServersController do
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
fab!(:another_user) { Fabricate(:user) }
fab!(:trust_level_2) { Fabricate(:user, trust_level: TrustLevel[2]) }
before do
Jobs.run_immediately!
end
it 'can update status' do
request_status = 'new status'
sign_in(admin)
s=Pfaffmanager::Server.createServerFromParams(user_id: user.id,
hostname: 'bogus.invalid' , request_status: 'not updated')
puts "can update status created server id: #{s.id}"
params = {server: {request_status: request_status}}
expect {
put "/pfaffmanager/servers/#{s.id}", params: params
}.to change { s.request_status }
expect(response.status).to eq(200)
expect(s.request_status).to eq('new status')
end
end
I spent pretty much all day on this yesterday and would appreciate any hints on solutions or techniques for debugging.