|
|
|
@ -137,19 +137,25 @@ class BulkUpload::Lettings::RowParser |
|
|
|
attribute :field_133, :integer |
|
|
|
attribute :field_133, :integer |
|
|
|
attribute :field_134, :integer |
|
|
|
attribute :field_134, :integer |
|
|
|
|
|
|
|
|
|
|
|
validates :field_1, presence: true, numericality: { in: (1..12) } |
|
|
|
def valid? |
|
|
|
validates :field_4, numericality: { in: (1..999), allow_blank: true } |
|
|
|
log.valid? |
|
|
|
validates :field_4, presence: true, if: :field_4_presence_check |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validate :validate_possible_answers |
|
|
|
errors.clear |
|
|
|
|
|
|
|
|
|
|
|
# delegate :valid?, to: :native_object |
|
|
|
log.errors.each do |error| |
|
|
|
# delegate :errors, to: :native_object |
|
|
|
field = field_for_attribute(error.attribute) |
|
|
|
|
|
|
|
errors.add(field, error.type) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
def native_object |
|
|
|
def log |
|
|
|
@native_object ||= LettingsLog.new(attributes_for_log) |
|
|
|
@log ||= LettingsLog.new(attributes_for_log) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def field_for_attribute(attribute) |
|
|
|
|
|
|
|
field_mapping.invert[attribute] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def field_mapping |
|
|
|
def field_mapping |
|
|
|
@ -158,16 +164,6 @@ private |
|
|
|
} |
|
|
|
} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def validate_possible_answers |
|
|
|
|
|
|
|
field_mapping.each do |field, attribute| |
|
|
|
|
|
|
|
possible_answers = FormHandler.instance.current_lettings_form.questions.find { |q| q.id == attribute.to_s }.answer_options.keys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unless possible_answers.include?(public_send(field)) |
|
|
|
|
|
|
|
errors.add(field, "Value supplied is not one of the permitted values") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def attributes_for_log |
|
|
|
def attributes_for_log |
|
|
|
hash = field_mapping.invert |
|
|
|
hash = field_mapping.invert |
|
|
|
attributes = {} |
|
|
|
attributes = {} |
|
|
|
@ -178,8 +174,4 @@ private |
|
|
|
|
|
|
|
|
|
|
|
attributes |
|
|
|
attributes |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def field_4_presence_check |
|
|
|
|
|
|
|
[1, 3, 5, 7, 9, 11].include?(field_1) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|