Skip to content

Commit

Permalink
Merge pull request #219 from razeware/WEB-6508
Browse files Browse the repository at this point in the history
WEB-6508: Validate presence of ref in text lesson
  • Loading branch information
KapilSachdev authored Oct 4, 2023
2 parents 55a0c36 + f3116c9 commit 01750b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit 01750b4

Please sign in to comment.