4523: Merge branch '4523-search-index' of git.curoverse.com:arvados into 4523-search...
authorTom Clegg <tom@curoverse.com>
Mon, 5 Jan 2015 15:05:57 +0000 (10:05 -0500)
committerTom Clegg <tom@curoverse.com>
Mon, 5 Jan 2015 15:05:57 +0000 (10:05 -0500)
Conflicts:
services/api/test/unit/arvados_model_test.rb

1  2 
services/api/test/unit/arvados_model_test.rb

index 4d8e00398d72164d295d2cf2c9d76bf2c567f237,63b47731f0e40e8effdf474926ffeb4f41eb6934..a8175d373525a14a406ba66e1ef376bb69d24a81
@@@ -87,54 -87,26 +87,37 @@@ class ArvadosModelTest < ActiveSupport:
      end
    end
  
-   test "unique uuid index exists on all models with the column uuid" do
-     tables = ActiveRecord::Base.connection.tables
-     tables.each do |table|
-       columns = ActiveRecord::Base.connection.columns(table)
-       uuid_column = columns.select do |column|
-         column.name == 'uuid'
-       end
-       if !uuid_column.empty?
-         indexes = ActiveRecord::Base.connection.indexes(table)
-         uuid_index = indexes.select do |index|
-           index.columns == ['uuid'] and index.unique == true
-         end
-         assert !uuid_index.empty?, "#{table} does not have unique uuid index"
-       end
-     end
-   end
-   test "owner uuid index exists on all models with the owner_uuid column" do
-     all_tables = ActiveRecord::Base.connection.tables
-     all_tables.each do |table|
-       columns = ActiveRecord::Base.connection.columns(table)
-       uuid_column = columns.select do |column|
-         column.name == 'owner_uuid'
-       end
-       if !uuid_column.empty?
-         indexes = ActiveRecord::Base.connection.indexes(table)
-         owner_uuid_index = indexes.select do |index|
-           index.columns == ['owner_uuid']
 +  test "store long string" do
 +    set_user_from_auth :active
 +    longstring = "a"
 +    while longstring.length < 2**28
 +      longstring = longstring + longstring
 +    end
 +    g = Group.create! name: 'Has a long description', description: longstring
 +    g = Group.find_by_uuid g.uuid
 +    assert_equal g.description, longstring
 +  end
 +
+   [['uuid', {unique: true}],
+    ['owner_uuid', {}]].each do |the_column, requires|
+     test "unique index on all models with #{the_column}" do
+       checked = 0
+       ActiveRecord::Base.connection.tables.each do |table|
+         columns = ActiveRecord::Base.connection.columns(table)
+         next unless columns.collect(&:name).include? the_column
+         indexes = ActiveRecord::Base.connection.indexes(table).reject do |index|
+           requires.map do |key, val|
+             index.send(key) == val
+           end.include? false
          end
-         assert !owner_uuid_index.empty?, "#{table} does not have owner_uuid index"
+         assert_includes indexes.collect(&:columns), [the_column], 'no index'
+         checked += 1
        end
+       # Sanity check: make sure we didn't just systematically miss everything.
+       assert_operator(10, :<, checked,
+                       "Only #{checked} tables have a #{the_column}?!")
      end
    end