Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Add dependencies removal for the user entity #193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/casino/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
class CASino::User < ActiveRecord::Base
serialize :extra_attributes, Hash

has_many :ticket_granting_tickets
has_many :two_factor_authenticators
has_many :login_attempts
has_many :ticket_granting_tickets, dependent: :destroy
has_many :two_factor_authenticators, dependent: :destroy
has_many :login_attempts, dependent: :destroy

def active_two_factor_authenticator
self.two_factor_authenticators.where(active: true).first
Expand Down
35 changes: 35 additions & 0 deletions spec/model/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe CASino::User do
let(:user) { FactoryGirl.create :user }

let!(:ticket_granting_ticket) { FactoryGirl.create :ticket_granting_ticket, user: user }
let!(:two_factor_authenticator) { FactoryGirl.create :two_factor_authenticator, user: user }
let!(:login_attempt) { FactoryGirl.create :login_attempt, user: user }

subject { user }

describe '#destroy' do
before(:each) do
CASino::ServiceTicket::SingleSignOutNotifier.any_instance.stub(:notify).and_return(false)
end

it 'deletes depending ticket-granting-ticket' do
lambda {
user.destroy
}.should change(CASino::TicketGrantingTicket, :count).by(-1)
end

it 'deletes depending two-factor-authenticator' do
lambda {
user.destroy
}.should change(CASino::TwoFactorAuthenticator, :count).by(-1)
end

it 'deletes depending login-attempt' do
lambda {
user.destroy
}.should change(CASino::LoginAttempt, :count).by(-1)
end
end
end