1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
require 'rails_helper'
require 'date'
RSpec.describe Event, type: :model do
it "is invalid without a name" do
e = Event.new(name: "")
expect(e).to_not be_valid
end
describe "validations" do
it "is invalid without a date" do
e = Event.new(date: nil, name: "Sludge")
expect(e).to_not be_valid
end
it "is valid with valid attributes" do
d = Date.new(2023, 1, 1)
e = Event.new(date: d, name: "Slish")
expect(e).to be_valid
end
it "is invalid with a name longer than 50 chars" do
d = Date.new(2023, 1, 1)
str = "a" * 51
e = Event.new(date: d, name: str)
expect(e).to_not be_valid
end
end
describe "events by month" do
it "knows it is a january 2024 event" do
d = Date.new(2024, 1, 10)
e = Event.new(date: d, name: "Nice January event")
expect(e.month_year_check(2024, 1) ).to eq(true)
end
it "knows it is a September 2028 event" do
d = Date.new(2028, 9, 10)
e = Event.new(date: d, name: "Nice September event")
expect(e.month_year_check(2028, 9) ).to eq(true)
end
it "knows it is not a September 2028 event" do
d = Date.new(2028, 10, 10)
e = Event.new(date: d, name: "Not a nice September event")
expect(e.month_year_check(2028, 9) ).to eq(false)
end
end
end
|