Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEB-6508: Validate presence of ref in text lesson #219

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/lessons_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def check_unique_refs(record, attribute, value)
lesson.segments.each { |segment| ref_counts[segment.ref] += 1 }
non_unique_refs = ref_counts.select { |_, count| count > 1 }.keys

non_unique_refs.each { |ref| record.errors.add(attribute, "segment ref #{ref} is not unique") }
non_unique_refs.each { |ref| record.errors.add(attribute, "(#{lesson.title}) segment ref #{ref} is not unique") }
end
end
end
6 changes: 5 additions & 1 deletion app/models/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class Text
attr_accessor :title, :ordinal, :ref, :description, :authors, :markdown_file, :root_path, :free, :kind

attr_markdown :body, source: :markdown_file, file: true, wrapper_class: :wrapper_class
validates :title, :ordinal, :markdown_file, presence: true
validates :title, :ordinal, :ref, :markdown_file, presence: true
validate do |text|
# Check the ref is a string
errors.add(:ref, 'must be a string') unless text.ref.is_a?(String)
end

def initialize(attributes = {})
super
Expand Down