Browse Source

crystal|lucky update test fix (#6128)

Matthew McGarvey 4 years ago
parent
commit
002c97f38a
1 changed files with 8 additions and 1 deletions
  1. 8 1
      frameworks/Crystal/lucky/src/actions/updates/index.cr

+ 8 - 1
frameworks/Crystal/lucky/src/actions/updates/index.cr

@@ -4,7 +4,14 @@ class Updates::Index < BaseAction
   get "/updates" do
     results = (1..queries_param).map do
       world = WorldQuery.find(rand(1..ID_MAXIMUM))
-      world = SaveWorld.update!(world, randomnumber: rand(1..ID_MAXIMUM))
+      # Avram does not perform the update operation if no value has changed
+      # so we have to keep generating random numbers until we
+      # get one that is different than the currently set one
+      random_number = rand(1..ID_MAXIMUM)
+      while random_number == world.randomnumber
+        random_number = rand(1..ID_MAXIMUM)
+      end
+      world = SaveWorld.update!(world, randomnumber: random_number)
       WorldSerializer.new(world)
     end