DEV: Rename controller methods.

DEV: Rename controller methods.
From 580ae90fcc140fa84ca99c5010c4a3156f2dded7 Mon Sep 17 00:00:00 2001
From: Dan Ungureanu <dan@ungureanu.me>
Date: Wed, 5 Dec 2018 11:04:24 +0200
Subject: [PATCH] DEV: Rename controller methods.


diff --git a/plugin.rb b/plugin.rb
index 35cd0d6..e06b234 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -43,7 +43,7 @@ after_initialize do
       # +public_key+::  Serialized public key. This parameter is optional when
       #                 the private key is updated (changed passphrase).
       # +private_key+:: Serialized private key.
-      def keys_put
+      def update_keys
         public_key  = params.require(:public_key)
         private_key = params.require(:private_key)
         salt        = params.require(:salt)
@@ -68,7 +68,7 @@ after_initialize do
       # +usernames+::   Array of usernames.
       #
       # Returns a hash of usernames and public keys.
-      def user_get
+      def show_user
         usernames = params.require(:usernames)
 
         keys = Hash[User.where(username: usernames).map { |u| [u.username, u.custom_fields['encrypt_public_key']] }]
@@ -84,7 +84,7 @@ after_initialize do
       #               topic custom field.
       # +keys+::      Hash of usernames and keys to be saved in plugin's store.
       #               This parameter is optional when editing a topic's title.
-      def topic_put
+      def update_topic
         topic_id = params.require(:topic_id)
 
         topic = Topic.find_by(id: topic_id)
@@ -111,7 +111,7 @@ after_initialize do
       #
       # Params:
       # +usernames+::   Array of usernames.
-      def topic_delete
+      def destroy_topic
         topic_id = params.require(:topic_id)
         usernames = params.require(:usernames)
 
@@ -225,10 +225,10 @@ after_initialize do
   end
 
   DiscourseEncrypt::Engine.routes.draw do
-    put    '/encrypt/keys'  => 'encrypt#keys_put'
-    get    '/encrypt/user'  => 'encrypt#user_get'
-    put    '/encrypt/topic' => 'encrypt#topic_put'
-    delete '/encrypt/topic' => 'encrypt#topic_delete'
+    put    '/encrypt/keys'  => 'encrypt#update_keys'
+    get    '/encrypt/user'  => 'encrypt#show_user'
+    put    '/encrypt/topic' => 'encrypt#update_topic'
+    delete '/encrypt/topic' => 'encrypt#destroy_topic'
   end
 
   Discourse::Application.routes.append do
diff --git a/spec/requests/encrypt_controller_spec.rb b/spec/requests/encrypt_controller_spec.rb
index 75db55b..7b4c70f 100644
--- a/spec/requests/encrypt_controller_spec.rb
+++ b/spec/requests/encrypt_controller_spec.rb
@@ -38,7 +38,7 @@ describe ::DiscourseEncrypt::EncryptController do
     store.set("key_#{topic.id}_#{user2.id}", '-- the key of user2 --')
   end
 
-  context '#keys_put' do
+  context '#update_keys' do
     it 'does not work when not logged in' do
       put '/encrypt/keys', params: {
         public_key: '-- the public key --',
@@ -97,7 +97,7 @@ describe ::DiscourseEncrypt::EncryptController do
     end
   end
 
-  context '#user_get' do
+  context '#show_user' do
     it 'does not work when not logged in' do
       get '/encrypt/user', params: { usernames: [ 'user', 'user2', 'other' ] }
       expect(response.status).to eq(404)
@@ -117,7 +117,7 @@ describe ::DiscourseEncrypt::EncryptController do
     end
   end
 
-  context '#topic_put' do
+  context '#update_topic' do
     it 'does not work when not logged in' do
       put '/encrypt/topic', params: {
         topic_id: topic.id,
@@ -202,7 +202,7 @@ describe ::DiscourseEncrypt::EncryptController do
     end
   end
 
-  context '#topic_delete' do
+  context '#destroy_topic' do
     it 'does not work when not logged in' do
       delete '/encrypt/topic', params: { topic_id: topic.id, usernames: [ 'user' ] }

GitHub

2 Likes