aboutsummaryrefslogblamecommitdiffstats
path: root/spec/models/event_spec.rb
blob: d796b8c1b6811f9c7d43cb9856e0d38561bccf24 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                     



                                                           
                                    

                                   



                                     

                                     
       

                                          
                                 


                                                       

                                     




                                            

                                                            
       
 
                                              

                                                            
       
 
                                                  

                                                             
       

     
require 'rails_helper'

RSpec.describe Event, type: :model do
  subject { described_class.new(name: "Cleish Event", \
                                date: Date.new(2023, 1, 1))
  }

  it "is invalid without a name" do 
    subject.name = nil
    expect(subject).to_not be_valid
  end

  describe "validations" do
    it "is invalid without a date" do
      subject.date = nil
      expect(subject).to_not be_valid
    end

    it "is valid with valid attributes" do
      expect(subject).to be_valid
    end

    it "is invalid with a name longer than 50 chars" do
      subject.name = "a" * 51
      expect(subject).to_not be_valid
    end
  end

  describe "events by month" do
    it "knows it is a january 2024 event" do
      subject.date = Date.new(2024, 1, 10)
      expect(subject.month_year_check(2024, 1) ).to eq(true)
    end

    it "knows it is a September 2028 event" do
      subject.date = Date.new(2028, 9, 10)
      expect(subject.month_year_check(2028, 9) ).to eq(true)
    end

    it "knows it is not a September 2028 event" do
      subject.date = Date.new(2028, 10, 10)
      expect(subject.month_year_check(2028, 9) ).to eq(false)
    end
  end
end