https://remoteindian.com/ logo
#random
Title
# random
q

quaint-farmer-12353

01/18/2022, 11:57 AM
Any ROR developers here? need your help. I am having trouble in identifying how to run controller test in sequence or with transaction lock..๐Ÿงต
message has been deleted
I know i can assign created record to a variable and assert the result with variable, but I want to figure out if there is a way to run test in synchronous or in transactional mode ( records created by one test doesn't interfere with another )
w

wide-twilight-82330

01/18/2022, 12:06 PM
Use databasecleaner
๐Ÿ‘€ 1
โž• 2
q

quaint-farmer-12353

01/18/2022, 12:14 PM
Thanks @wide-twilight-82330 let me dig into this
f

freezing-whale-32835

01/18/2022, 3:13 PM
For the first test above, does
@response.body
return the newly created SellerCompany's ID? If it does, then using that id to get the object instead of
SellerCompany.last
might work
a

adventurous-fireman-74405

01/18/2022, 3:20 PM
One straight forwards solution would be, instead of using
SellerCompany.last
, use
SellerCompany.find_by(name: '')
q

quaint-farmer-12353

01/19/2022, 1:15 AM
@freezing-whale-32835 @adventurous-fireman-74405 that would work, but I was curious to know why it
SellerCompany.last
does not works and wether it is an issue with parallel controller test or fixtures. finally found out that sorting goes for a toss when using uuids as the primary keys
Update: Issue was due to usage of uuids as the primary key which breaks the implicit sorting; uuids are not sequential, Fixed it by overriding,
self.implicit_order_column = :created_at
w

wide-twilight-82330

01/19/2022, 2:21 AM
@quaint-farmer-12353 IMO, not a good idea to rely on timestamp unless that's part of the behaviour you're designing. I don't know which test framework is that but I have used transactional fixtures in rspec, until I was blocked by limitations of the transactional fixtures due to multiple dbs - so switched to databasecleaner.