Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Commit

Permalink
Added view tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostPepperWonton authored and Br3nda committed Dec 10, 2018
1 parent a53fd40 commit c409f5a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -2,6 +2,7 @@

class UsersController < ApplicationController
before_action :set_user, only: %i[destroy]
before_action :set_current_user, only: %i[index]

def index
@users = User.order(:email)
Expand All @@ -14,6 +15,10 @@ def destroy

private

def set_current_user
@current_user = current_user
end

def set_user
@user = User.find(params[:id])
end
Expand Down
26 changes: 14 additions & 12 deletions app/views/users/index.html.haml
Expand Up @@ -5,16 +5,18 @@
= link_to new_user_invitation_path do
Invite new users

%table.pure-table.pure-table-horizontal
%thead
%tr
%th Email

%tbody
- @users.each do |user|
- unless @users.blank?
%table.pure-table.pure-table-horizontal
%thead
%tr
%td= user.email
%td
= link_to user_path(user), method: :delete, data: { confirm: 'Are you sure?' },
class: 'pure-button' do
delete
%th Email

%tbody
- @users.each do |user|
%tr
%td= user.email
%td
- if user != @current_user
= link_to user_path(user), method: :delete, data: { confirm: 'Are you sure?' },
class: 'pure-button' do
delete
25 changes: 25 additions & 0 deletions spec/views/users/index.html.haml_spec.rb
@@ -0,0 +1,25 @@
require 'rails_helper'

RSpec.describe 'users/index', type: :view do
include Devise::Test::ControllerHelpers
describe 'user deletion' do
let(:current_user) { FactoryBot.create :user }
let(:other_user) { FactoryBot.create :user }

before do
assign(:users, [current_user, other_user])
sign_in current_user
end

it 'allows for deletion of users' do
render
expect(rendered).to have_link 'delete'
end

it 'doesn\'t allow for deletion of self' do
assign(:current_user, current_user)
render
expect(rendered).to have_selector('a[data-method="delete"]', count: 1)
end
end
end

0 comments on commit c409f5a

Please sign in to comment.