-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeclaration_input_spec.rb
More file actions
68 lines (52 loc) · 2.71 KB
/
declaration_input_spec.rb
File metadata and controls
68 lines (52 loc) · 2.71 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "rails_helper"
RSpec.describe Forms::DeclarationInput, type: :model do
describe "validations" do
describe "Character length" do
it "is valid if less than 2000 characters" do
declaration_input = described_class.new(declaration_markdown: "a", mark_complete: true)
expect(declaration_input).to be_valid
end
it "is valid if 2000 characters" do
declaration_input = described_class.new(declaration_markdown: "a" * 2000, mark_complete: true)
expect(declaration_input).to be_valid
end
it "is strips carriage returns before calculating the length" do
declaration_markdown = "#{'a' * 1000}\r\n#{'a' * 999}"
declaration_input = described_class.new(declaration_markdown:, mark_complete: true)
expect(declaration_input).to be_valid
end
it "is invalid if more than 2000 characters" do
declaration_input = described_class.new(declaration_markdown: "a" * 2001, mark_complete: true)
error_message = I18n.t("activemodel.errors.models.forms/declaration_input.attributes.declaration_markdown.too_long")
expect(declaration_input).not_to be_valid
declaration_input.validate(:declaration_markdown)
expect(declaration_input.errors.full_messages_for(:declaration_markdown)).to include(
"Declaration markdown #{error_message}",
)
end
end
it "is valid if declaration text is blank" do
declaration_input = described_class.new(declaration_markdown: "", mark_complete: true)
expect(declaration_input).to be_valid
end
it "is not valid if mark complete is blank" do
declaration_input = described_class.new(mark_complete: nil)
expect(declaration_input).not_to be_valid
expect(declaration_input.errors.full_messages_for(:mark_complete)).to include "Mark complete #{I18n.t('activemodel.errors.models.forms/declaration_input.attributes.mark_complete.blank')}"
end
end
describe "#submit" do
it "returns false if the data is invalid" do
form = OpenStruct.new(declaration_markdown: "", name: "Apply for a juggling licence")
declaration_input = described_class.new(declaration_markdown: ("abc" * 2001), form:)
expect(declaration_input.submit).to be false
end
it "sets the form's attribute values" do
form = OpenStruct.new(declaration_markdown: "abc", declaration_section_completed: "false")
declaration_input = described_class.new(form:, declaration_markdown: "new declaration text", mark_complete: "true")
declaration_input.submit
expect(declaration_input.form.declaration_markdown).to eq "new declaration text"
expect(declaration_input.form.declaration_section_completed).to eq "true"
end
end
end