Skip to content

Commit 00ee399

Browse files
committed
BUGFIX: Pass values, not observations, to the .diff block
1 parent ffd722f commit 00ee399

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/models/lab_tech/result.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ def record_a_science(scientist_result, diff_with: nil)
5959

6060
record_observation scientist_result.control
6161
scientist_result.candidates.each do |candidate|
62-
diff = diff_with&.call(scientist_result.control, candidate)
62+
diff = nil
63+
if diff_with
64+
# Pass values to the diff block, not the observations themselves
65+
cont = scientist_result.control.value
66+
cand = candidate.value
67+
diff = diff_with&.call(cont, cand)
68+
end
69+
6370
record_observation candidate, diff: diff
6471
end
6572

spec/models/lab_tech/experiment_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ def wtf
100100
e.use { :control }
101101
e.try { :candidate }
102102

103-
e.diff { |control, candidate| "this is a diff" }
103+
e.diff { |control, candidate|
104+
# Make sure we pass values to the diff block, not the observations themselves
105+
raise "nope" if control.is_a?(Scientist::Observation)
106+
raise "nope" if candidate.is_a?(Scientist::Observation)
107+
"this is a diff"
108+
}
104109
end
105110

106111
result = experiment.results.first

0 commit comments

Comments
 (0)