Skip to content

Commit c2a6add

Browse files
author
John Pinto
committed
Added a a changes suggested by @aaronskiba in code review to remove
rendancy and optimise code.
1 parent f236c8b commit c2a6add

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

app/helpers/conditions_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ def answer_remove_list(answer, user = nil)
2323
id_list = []
2424
return id_list unless answer.question.option_based?
2525

26+
chosen = answer.question_option_ids.sort
27+
2628
answer.question.conditions.each do |cond|
2729
opts = cond.option_list.map(&:to_i).sort
2830
action = cond.action_type
29-
chosen = answer.question_option_ids.sort
3031

3132
# If the chosen (options) include the opts (options list) in the condition,
3233
# then we apply the action.

app/models/condition.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def deep_copy(**options)
3939
copy = dup
4040
copy.question_id = options.fetch(:question_id, nil)
4141
# Added to allow options to be passed in for all fields
42-
copy.option_list = options.fetch(:option_list, option_list) if options.key?(:option_list)
43-
copy.remove_data = options.fetch(:remove_data, remove_data) if options.key?(:remove_data)
44-
copy.action_type = options.fetch(:action_type, action_type) if options.key?(:action_type)
45-
copy.webhook_data = options.fetch(:webhook_data, webhook_data) if options.key?(:webhook_data)
42+
copy.option_list = options[:option_list] if options.key?(:option_list)
43+
copy.remove_data = options[:remove_data] if options.key?(:remove_data)
44+
copy.action_type = options[:action_type] if options.key?(:action_type)
45+
copy.webhook_data = options[:webhook_data] if options.key?(:webhook_data)
4646
# TODO: why call validate false here
4747
copy.save!(validate: false) if options.fetch(:save, false)
4848
copy

0 commit comments

Comments
 (0)