users: add anonymize as an option (#241)

users: add anonymize as an option (#241)

  • add def for anonymize

  • add anonymize to users_spec

  • refine spec

diff --git a/lib/discourse_api/api/users.rb b/lib/discourse_api/api/users.rb
index fefd79a..07c699e 100644
--- a/lib/discourse_api/api/users.rb
+++ b/lib/discourse_api/api/users.rb
@@ -102,6 +102,10 @@ module DiscourseApi
         put("/admin/users/#{user_id}/unsuspend")
       end
 
+      def anonymize(user_id)
+        put("/admin/users/#{user_id}/anonymize")
+      end
+
       def delete_user(user_id, delete_posts = false)
         delete("/admin/users/#{user_id}.json?delete_posts=#{delete_posts}")
       end
diff --git a/spec/discourse_api/api/users_spec.rb b/spec/discourse_api/api/users_spec.rb
index 10c9043..c265c1f 100644
--- a/spec/discourse_api/api/users_spec.rb
+++ b/spec/discourse_api/api/users_spec.rb
@@ -306,6 +306,20 @@ describe DiscourseApi::API::Users do
     end
   end
 
+  describe "#anonymize" do
+    before do
+      url = "#{host}/admin/users/11/anonymize"
+      stub_put(url).to_return(body: '', status: 200)
+    end
+
+    it "makes the correct put request" do
+      result = subject.anonymize(11)
+      url = "#{host}/admin/users/11/anonymize"
+      expect(a_put(url)).to have_been_made
+      expect(result.status).to eq(200)
+    end
+  end
+
   describe "#delete_user" do
     before do
       url = "#{host}/admin/users/11.json?delete_posts=true"

GitHub sha: c6bd7aa6d85f5b6ae261744105a83a2138e85124

This commit appears in #241 which was approved by eviltrout. It was merged by eviltrout.