live coder seeding - completes #16
This commit is contained in:
@ -31,7 +31,9 @@ class AnswerFormatValidator < ActiveModel::EachValidator
|
||||
end
|
||||
|
||||
def live_code record, attribute, value
|
||||
return unless value.nil? || value.values.join.blank?
|
||||
seed = (Question.find_by(id: record.question_id) || Question.new).input_options
|
||||
|
||||
return unless value.nil? || value.values.join.blank? || !match_seed?(value, seed)
|
||||
|
||||
record.errors[attribute] << (options[:message] || live_code_error_message(value))
|
||||
end
|
||||
@ -44,4 +46,16 @@ class AnswerFormatValidator < ActiveModel::EachValidator
|
||||
end
|
||||
"You must write comments or code in one of the textareas to progress."
|
||||
end
|
||||
|
||||
def match_seed? value, seed
|
||||
s_value = value.stringify_keys
|
||||
s_seed = seed.stringify_keys
|
||||
keys = s_value.merge(s_seed).keys.uniq
|
||||
|
||||
matches = keys.inject([]) do |memo, k|
|
||||
memo << (s_value[k].to_s.strip == s_seed[k].to_s.strip)
|
||||
end
|
||||
|
||||
matches.include? false
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user