lib/zendesk2/client/requests/update_user.rb in zendesk2-0.1.1 vs lib/zendesk2/client/requests/update_user.rb in zendesk2-0.1.2
- old
+ new
@@ -12,13 +12,14 @@
)
end
end
class Mock
def update_user(params={})
- id = params.delete("id")
- path = "/users/#{id}.json"
- if params["email"] && self.data[:users].find{|k,u| u["email"] == params["email"] && k != id}
+ user_id = params.delete("id")
+ path = "/users/#{user_id}.json"
+
+ if (email = params["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
response(
:method => :put,
:path => path,
:status => 422,
:body => {
@@ -29,10 +30,25 @@
} ]
}
}
)
else
- body = self.data[:users][id].merge!(params)
+ user_identity_id = self.class.new_id # ugh
+
+ user_identity = {
+ "id" => user_identity_id,
+ "url" => url_for("/users/#{user_id}/identities/#{user_identity_id}.json"),
+ "created_at" => Time.now.iso8601,
+ "updated_at" => Time.now.iso8601,
+ "type" => "email",
+ "value" => params["email"],
+ "verified" => false,
+ "primary" => false,
+ "user_id" => user_id,
+ }
+
+ self.data[:identities][user_identity_id] = user_identity
+ body = self.data[:users][user_id].merge!(params)
response(
:method => :put,
:path => path,
:body => {
"user" => body