2023-02-08 13:21:39 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
RSpec.describe FormTemplate, type: :model do
|
|
|
|
it "can't have duplicate names" do
|
2023-03-01 13:07:13 -06:00
|
|
|
Fabricate(:form_template, name: "Bug Report", template: "- type: input")
|
|
|
|
t = Fabricate.build(:form_template, name: "Bug Report", template: "- type: input")
|
2023-02-08 13:21:39 -06:00
|
|
|
expect(t.save).to eq(false)
|
2023-03-01 13:07:13 -06:00
|
|
|
t = Fabricate.build(:form_template, name: "Bug Report", template: "- type: input")
|
2023-02-08 13:21:39 -06:00
|
|
|
expect(t.save).to eq(false)
|
|
|
|
expect(described_class.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can't have an invalid yaml template" do
|
2023-03-01 13:07:13 -06:00
|
|
|
template = "- type: checkbox\nattributes; bad"
|
2023-02-08 13:21:39 -06:00
|
|
|
t = Fabricate.build(:form_template, name: "Feature Request", template: template)
|
|
|
|
expect(t.save).to eq(false)
|
|
|
|
end
|
2023-03-01 13:07:13 -06:00
|
|
|
|
|
|
|
it "must have a supported type" do
|
|
|
|
template = "- type: fancy"
|
|
|
|
t = Fabricate.build(:form_template, name: "Fancy Template", template: template)
|
|
|
|
expect(t.save).to eq(false)
|
|
|
|
end
|
|
|
|
|
2023-06-13 15:02:21 -05:00
|
|
|
it "must have a type property" do
|
2023-03-01 13:07:13 -06:00
|
|
|
template = "- hello: world"
|
|
|
|
t = Fabricate.build(:form_template, name: "Basic Template", template: template)
|
|
|
|
expect(t.save).to eq(false)
|
|
|
|
end
|
2023-02-08 13:21:39 -06:00
|
|
|
end
|