heroku/databasedotcom — Issue #33: PATCH verb not allowed
Author: vzmind
Created: 2011-11-08 09:22:19+00:00
State: open

Hello,

I have established a connection to SFDC using databasedotcom gem. I have materalized Case and use them for index and show. Everything works fine but when I perform I try to update I got a HTTP Method 'PATCH' not allowed. here is the controller#action failing:

@sfdc.materialize("Case")
@case = Case.find(params['Id'])
@case.update_attributes('Description' => params[:case]['Description'])

Here is the full error:

```
Databasedotcom::SalesForceError in CasesController#update

HTTP Method 'PATCH' not allowed. Allowed are HEAD,GET,POST

Rails.root: /Users/vzmind/rails/apps/ev-demo
Application Trace | Framework Trace | Full Trace

databasedotcom (1.2.3) lib/databasedotcom/client.rb:376:in `ensure_expected_response'
databasedotcom (1.2.3) lib/databasedotcom/client.rb:334:in `with_encoded_path_and_checked_response'
databasedotcom (1.2.3) lib/databasedotcom/client.rb:316:in `http_patch'
databasedotcom (1.2.3) lib/databasedotcom/client.rb:250:in `update'
databasedotcom (1.2.3) lib/databasedotcom/sobject/sobject.rb:69:in `update_attributes'
app/controllers/cases_controller.rb:33:in `update'
```

As this is working on console, I thought may be ActionDispatch might restrict the verb used from the application. But PATCH verb as been added already one year https://github.com/rails/rails/commit/d446392f76c063d9f04396a1d3ca9e314a521671

Then I have tried to understand what could be failing at lib/databasedotcom/client.rb:376 but I am not sure to really understand what could cause such error:

def ensure_expected_response(expected_result_class)
response = yield

unless response.is_a?(expected_result_class || Net::HTTPSuccess)
if response.is_a?(Net::HTTPUnauthorized)
if self.refresh_token
response = with_encoded_path_and_checked_response("/services/oauth2/token", { :grant_type => "refresh_token", :refresh_token => self.refresh_token, :client_id => self.client_id, :client_secret => self.client_secret}, :host => self.host) do |encoded_path|
response = https_request(self.host).post(encoded_path, nil)
if response.is_a?(Net::HTTPOK)
parse_auth_response(response.body)
end
response
end
elsif self.username && self.password
response = with_encoded_path_and_checked_response("/services/oauth2/token", { :grant_type => "password", :username => self.username, :password => self.password, :client_id => self.client_id, :client_secret => self.client_secret}, :host => self.host) do |encoded_path|
response = https_request(self.host).post(encoded_path, nil)
if response.is_a?(Net::HTTPOK)
parse_auth_response(response.body)
end
response
end
end

if response.is_a?(Net::HTTPSuccess)
response = yield
end
end

raise SalesForceError.new(response) unless response.is_a?(expected_result_class || Net::HTTPSuccess)
end

response
end
Anybody already exposed to such behavior?