Find out if attributes are identical
You could try the appropriately named #all? method:

reference = tests.first.result
if tests.all? { |test| test.result == reference }
  reference
else
  'mixed'
end


Edit: As tokland points out, you'll want to check if tests is empty before any of this. Otherwise, tests.first will of course be nil.

But you could also do the check in the database layer with something like:

if Test.select(:result).distinct.count &gt; 1
  'mixed'
else
  Test.first.try(:result)
end


Obviously you'll want to scope the query more specifically.

Also note that here, an empty collection returns a nil (because if Test.first is nil, then .try(:result) will also be nil).