+
+ test "Stringify symbols coming from serialized attribute in database" do
+ set_user_from_auth :admin_trustedclient
+ fixed = Link.find_by_uuid(links(:has_symbol_keys_in_database_somehow).uuid)
+ assert_equal(["baz", "foo"], fixed.properties.keys.sort,
+ "Hash symbol keys from DB did not get stringified.")
+ assert_equal(['waz', 'waz', 'waz', 1, nil, false, true],
+ fixed.properties['baz'],
+ "Array symbol values from DB did not get stringified.")
+ assert_equal true, fixed.save, "Failed to save fixed model back to db."
+ end
+
+ test "No HashWithIndifferentAccess in database" do
+ set_user_from_auth :admin_trustedclient
+ assert_raises ActiveRecord::RecordInvalid do
+ Link.create!(link_class: 'test',
+ properties: {'foo' => 'bar'}.with_indifferent_access)
+ 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']
+ end
+ assert !owner_uuid_index.empty?, "#{table} does not have owner_uuid index"
+ end
+ end
+ end
+
+ test "search index exists on models that go into projects" do
+ all_tables = ActiveRecord::Base.connection.tables
+ all_tables.delete 'schema_migrations'
+
+ all_tables.each do |table|
+ table_class = table.classify.constantize
+ if table_class.respond_to?('searchable_columns')
+ search_index_columns = table_class.searchable_columns('ilike')
+
+ indexes = ActiveRecord::Base.connection.indexes(table)
+ search_index = indexes.select do |index|
+ index.columns == search_index_columns
+ end
+ assert !search_index.empty?, "#{table} does not have search index with all searchable columns #{search_index_columns}"
+ end
+ end
+ end