about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorShuhei Kitagawa <shuheiktgw@users.noreply.github.com>2018-05-11 20:14:33 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-11 13:14:33 +0200
commit50491e0d92acea90e7a83d2ab0e9a1b271daa8a8 (patch)
treeb1f3e9ef27fea9bfbcfb0cba5d7867975f514964 /app
parent1337ca837b8de992945413a7f4f4b0aecd89dc9c (diff)
Add tests for invites controller (#7441)
* Add tests for invites controller

* Small refactoring and fix for invites controller
Diffstat (limited to 'app')
-rw-r--r--app/controllers/invites_controller.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 38d6c8d73..8e87c63cf 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -8,9 +8,9 @@ class InvitesController < ApplicationController
   before_action :authenticate_user!
 
   def index
-    authorize :invite, :create?
+    authorize :invite, :index?
 
-    @invites = Invite.where(user: current_user)
+    @invites = invites
     @invite  = Invite.new(expires_in: 1.day.to_i)
   end
 
@@ -23,13 +23,13 @@ class InvitesController < ApplicationController
     if @invite.save
       redirect_to invites_path
     else
-      @invites = Invite.where(user: current_user)
+      @invites = invites
       render :index
     end
   end
 
   def destroy
-    @invite = Invite.where(user: current_user).find(params[:id])
+    @invite = invites.find(params[:id])
     authorize @invite, :destroy?
     @invite.expire!
     redirect_to invites_path
@@ -37,6 +37,10 @@ class InvitesController < ApplicationController
 
   private
 
+  def invites
+    Invite.where(user: current_user)
+  end
+
   def resource_params
     params.require(:invite).permit(:max_uses, :expires_in)
   end