Skip to content

Commit

Permalink
Modify SQL in RecentView factory to support MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
rlue authored and Ryan Lue committed Sep 11, 2018
1 parent d51d222 commit 3c1e8ba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion spec/factories/recent_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

# 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
Expand Down

0 comments on commit 3c1e8ba

Please sign in to comment.