From 3c1e8ba1236679f14fc2df2d025f9803c15cf4e7 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Tue, 11 Sep 2018 14:46:10 +0800 Subject: [PATCH] Modify SQL in RecentView factory to support MySQL --- spec/factories/recent_view.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/factories/recent_view.rb b/spec/factories/recent_view.rb index 8ef6d159c..29889a35c 100644 --- a/spec/factories/recent_view.rb +++ b/spec/factories/recent_view.rb @@ -9,7 +9,14 @@ FactoryBot.define do # select a random record of the given object class o_id do - type.to_s.camelcase.constantize.order('RANDOM()').first.id + random_function = case ActiveRecord::Base.connection_config[:adapter] + when 'mysql2' + 'RAND' + when 'postgresql' + 'RANDOM' + end + + type.to_s.camelcase.constantize.order("#{random_function}()").first.id end # assign to an existing user, if possible