require 'test_helper'

class RecentChangesTest < ActionDispatch::IntegrationTest
  setup do
    @conference = create(:conference)
    @user = create(:user, role: 'admin')
    @tmp_user = create(:user, role: 'admin')
  end

  teardown do
    PaperTrail.enabled = false
  end

  test 'home page still displays after event with person has been deleted' do
    sign_in(@user)
    event = create(:event, conference: @conference)
    create(:event_person, event: event)
    PaperTrail.enabled = true
    assert_difference 'Event.count', -1 do
      delete "/#{@conference.acronym}/events/#{event.id}"
    end
    get '/', params: { conference_acronym: @conference.acronym }
    assert_response :success
  end

  test 'home page still displays after initiator of change has been deleted' do
    sign_in(@tmp_user)
    PaperTrail.enabled = true
    event = create(:event, conference: @conference)
    create(:event_person, event: event)
    delete "/#{@conference.acronym}/people/#{@tmp_user.person.id}"
    @tmp_user.delete
    sign_in(@user)
    get '/', params: { conference_acronym: @conference.acronym }
    assert_response :success
  end
end
