# frozen_string_literal: true require "rails_helper" module MrCommon RSpec.describe MrCommon::Reminder, type: :model do describe "#slug" do it "parameterizes the value before validation" do reminder = build(:reminder) reminder.slug = "a test_slug" reminder.validate expect(reminder.slug).to eq("a-test-slug") end end describe "#to_ical" do it "renders to a calendar string" do reminder = build(:reminder) expect(reminder.to_ical).to start_with "BEGIN:VCALENDAR\r\n" expect(reminder.to_ical).to end_with "END:VCALENDAR\r\n" end it "renders to a calendar string when text is missing" do reminder = build(:reminder) reminder.location = "" reminder.summary = "" reminder.description = "" expect(reminder.to_ical).to start_with "BEGIN:VCALENDAR\r\n" expect(reminder.to_ical).to end_with "END:VCALENDAR\r\n" end describe "when event has a duration" do it "start time is tagged with a tzid" do reminder = build(:reminder, all_day: false) reminder.time_zone = "Europe/Madrid" expect(reminder.to_ical).to include "DTSTART;TZID=Europe/Madrid" end it "end_time is tagged with a tzid" do reminder = build(:reminder, all_day: false) reminder.time_zone = "Europe/Madrid" expect(reminder.to_ical).to include "DTEND;TZID=Europe/Madrid" end end describe "when event is all day long" do it "start_time is just a date" do reminder = build(:reminder, all_day: true) reminder.time_zone = "Europe/Madrid" expect(reminder.to_ical).to include "DTSTART;VALUE=DATE:" end it "end_time is just a date" do reminder = build(:reminder, all_day: true) reminder.time_zone = "Europe/Madrid" expect(reminder.to_ical).to include "DTEND;VALUE=DATE:" end end end describe "#time_zone" do it "must be a value compatible with ActiveSupport::TimeZone" do reminder = build(:reminder) reminder.time_zone = "asdf/ohno" expect(reminder.errors[:job_title]).to_not be :empty? end it "can be blank" do reminder = build(:reminder) reminder.time_zone = "" expect(reminder.valid?).to eq true end end describe ".time_zone_options" do it "is an alias to ActiveSupport::TimeZone::MAPPING.values.sort" do expected = ActiveSupport::TimeZone::MAPPING.values.sort actual = MrCommon::Reminder.time_zone_options expect(actual).to eq expected end end end end