This commit is contained in:
Gopesh Tulsyan 2014-08-04 09:35:58 +00:00
commit 1729faac05
5 changed files with 13 additions and 9 deletions

View file

@ -36,6 +36,7 @@ module Admin
def destroy def destroy
@user = User.find(params[:id]) @user = User.find(params[:id])
@user.events.destroy_all
@user.destroy @user.destroy
redirect_to admin_users_path, notice: 'User got deleted' redirect_to admin_users_path, notice: 'User got deleted'
end end

View file

@ -16,7 +16,7 @@ class User < ActiveRecord::Base
:name, :email_public, :biography, :nickname, :affiliation :name, :email_public, :biography, :nickname, :affiliation
has_many :event_users, dependent: :destroy has_many :event_users, dependent: :destroy
has_many :events, -> { uniq }, through: :event_users has_many :events, -> { uniq }, through: :event_users, dependent: :destroy
has_many :registrations, dependent: :destroy has_many :registrations, dependent: :destroy
has_many :votes, dependent: :destroy has_many :votes, dependent: :destroy
has_many :voted_events, through: :votes, source: :events has_many :voted_events, through: :votes, source: :events

View file

@ -70,7 +70,7 @@
- if current_user.id == user.id or user.role_ids.include? 3 - if current_user.id == user.id or user.role_ids.include? 3
=link_to 'Delete',admin_user_path(user), :method => :delete , :data => {:confirm => 'Are you sure ?'}, :disabled => true,:class => "btn btn-primary disabled btn-danger",:role => "button" =link_to 'Delete',admin_user_path(user), :method => :delete , :data => {:confirm => 'Are you sure ?'}, :disabled => true,:class => "btn btn-primary disabled btn-danger",:role => "button"
- else - else
=link_to 'Delete',admin_user_path(user), :method=> :delete , :data=> {:confirm => 'Are you sure ?'},:class => "btn btn-primary btn-danger" =link_to 'Delete',admin_user_path(user), :method=> :delete , :data=> {:confirm => 'Are you sure ?'},:class => "btn btn-primary btn-danger", id: "user-delete-#{user.id}"
:javascript :javascript

View file

@ -9,15 +9,13 @@ feature User do
shared_examples 'admin ability' do shared_examples 'admin ability' do
scenario 'deletes a user', feature: true, js: true do scenario 'deletes a user', feature: true, js: true do
sign_in(admin) sign_in(admin)
@user = create(:user)
visit admin_users_path visit admin_users_path
expected_count = User.count - 1 expected_count = User.count - 1
page.all('btn btn-primary btn-danger') do find("#user-delete-#{@user.id}").click
click_link 'Delete'
page.evaluate_script('window.confirm = function() { return true; }') page.evaluate_script('window.confirm = function() { return true; }')
page.click('OK')
expect(flash).to eq('User got deleted') expect(flash).to eq('User got deleted')
expect(User.count).to eq(expected_count) expect(User.count).to eq(expected_count)
end
sign_out sign_out
end end
scenario 'can modify roles', feature: true, js: true do scenario 'can modify roles', feature: true, js: true do

View file

@ -26,6 +26,11 @@ describe User do
expect(user_with_all_roles.roles[2]).to eq(admin_role) expect(user_with_all_roles.roles[2]).to eq(admin_role)
end end
it { should have_many(:events).dependent(:destroy) }
it { should have_many(:event_users).dependent(:destroy) }
it { should have_many(:registrations).dependent(:destroy) }
it { should have_many(:votes).dependent(:destroy) }
describe '#role?' do describe '#role?' do
shared_examples '#role?' do |user, role, expected| shared_examples '#role?' do |user, role, expected|
it "returns #{expected} for #{role}" do it "returns #{expected} for #{role}" do