Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
getfitter-core / spec / models / core / organisation_spec.rb
Size: Mime:
require 'rails_helper'

RSpec.describe Core::Organisation, type: :model do
  it 'has a valid factory' do
    expect(create(:core_organisation)).to be_valid
  end

  it 'is invalid without a name' do
    expect(build(:core_organisation, name: nil)).to be_invalid
  end

  it 'has an empty venues list' do
    organisation = create(:core_organisation)

    expect(organisation.venues).to eq([])
  end

  it 'can have many events' do
    organisation = create(:core_organisation)
    event = create(:core_event, organisation: organisation)

    expect(organisation.events).to eq([event])
  end

  it 'can have many venues' do
    organisation = create(:core_organisation)
    venue = create(:core_venue, organisations: [organisation])

    expect(organisation.venues).to eq([venue])
  end

  it 'can have passes' do
    organisation = create(:core_organisation)
    pass = create(:core_pass, organisation: organisation)

    expect(organisation.passes).to eq([pass])
  end

  it 'can have an owner' do
    user = create(:core_user)
    organisation = create(:core_organisation, owner: user)

    expect(organisation.owner).to eq(user)
  end

  it 'destroys associated passes on destroy' do
    organisation = create(:core_organisation)
    pass = create(:core_pass, organisation: organisation)

    organisation.destroy

    expect(organisation.destroyed?).to be_truthy

    expect do
      Core::Pass.find(pass.id)
    end.to raise_error(ActiveRecord::RecordNotFound)
  end

  it 'cannot be destroyed if events exist' do
    organisation = create(:core_organisation)
    create(:core_event, organisation: organisation)

    # This shouldn't throw an exception because it isn't expected.
    # But it's a bug in Rails: https://github.com/rails/rails/pull/19773
    #
    # organisation.destroy
    #
    # expect(organisation.destroyed?).to be_falsey

    expect do
      organisation.destroy
    end.to raise_error(ActiveRecord::RecordNotDestroyed)
  end

  it 'destroys associated instructors on destroy' do
    instructor = create(:core_instructor)
    organisation = create(:core_organisation, instructors: [instructor])

    organisation.destroy

    expect(organisation.destroyed?).to be_truthy
    expect do
      Core::Instructor.find(instructor.id)
    end.to raise_error(ActiveRecord::RecordNotFound)
  end

  it 'destroys an associated organisation venue' do
    organisation = create(:core_organisation)
    create(:core_organisation_venue, organisation: organisation)

    organisation.destroy

    expect(organisation.destroyed?).to be_truthy

    ov_where = Core::OrganisationVenue.where(organisation: organisation)
    expect(ov_where).to eq []
  end
end