Sha256: c74424da570bf527d387402fdbd63cc93b186b24a72bd9f3ce3906fc3a8881eb

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'rails_helper'

RSpec.describe Event, folder: :models do
  include_context 'loaded site'

  describe 'Model' do
    # Rolify Gem
    it { should have_many(:roles) }

    # Schedulable Gem
    it { should have_one(:schedule) }

    # Validations
    it { should validate_presence_of(:name) }
    it { should validate_presence_of(:slug) }
    it { should validate_presence_of(:calendar) }

    # Relationships
    it { should belong_to(:calendar) }

    # Nested Attributes
    it { should accept_nested_attributes_for :schedule }
  end

  describe 'Class' do
    subject { Event }
    # FriendlyId Gem
    it { should respond_to(:friendly) }
  end

  describe 'Scopes and Methods' do
    describe '#ending_after' do
      subject { Event.ending_after(Time.zone.now) }
      it { should include tomorrows_event }
      it { should_not include yesterdays_event }
    end
    describe '#starting_before' do
      subject { Event.starting_before(Time.zone.now) }
      it { should include yesterdays_event }
      it { should_not include tomorrows_event }
    end
    describe '#to_list' do
      subject { Event.all.to_list }
      its(:first) { should be_a ::Hash }
      it { should have_at_least(3).items }
    end
    describe '.schedule' do
      describe 'with a new record' do
        subject { Event.new }
        its(:schedule) { should be_a_new Schedule }
      end
      describe 'with a saved record' do
        subject { monday_event }
        its(:schedule) { should be_a Schedule }
        its(:schedule) { should_not be_a_new Schedule }
      end
    end
    describe '.next_occurrence' do
      subject { tomorrows_event.next_occurrence }
      its(:start_date) { should be > Time.now }
    end
    describe '.previous_occurrence' do
      subject { yesterdays_event.previous_occurrence }
      its(:end_date) { should be < Time.now }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
date_book-0.0.5 spec/models/event_spec.rb
date_book-0.0.3 spec/models/event_spec.rb
date_book-0.0.2 spec/models/event_spec.rb
date_book-0.0.1 spec/models/event_spec.rb