aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2023-12-20 15:22:32 +0000
committerMatthew Lemon <y@yulqen.org>2023-12-20 15:22:32 +0000
commit90b5d0838b14eb2a30206b996260aae4f5049093 (patch)
treeeb76666584ee223096b8261ea0c2774fe6fcc7c1
parent9d4b92824d7b8d7d6ee2eafe3beed66d162e82f7 (diff)
Refactors existing model spec
-rw-r--r--spec/models/event_spec.rb39
1 files changed, 19 insertions, 20 deletions
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index cab2506..d796b8c 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -1,46 +1,45 @@
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
- e = Event.new(name: "")
- expect(e).to_not be_valid
+ subject.name = nil
+ expect(subject).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
+ subject.date = nil
+ expect(subject).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
+ expect(subject).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
+ 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
- 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)
+ 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
- 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)
+ 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
- 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)
+ subject.date = Date.new(2028, 10, 10)
+ expect(subject.month_year_check(2028, 9) ).to eq(false)
end
end
end