# frozen_string_literal: true # == Schema Information # # Table name: galleries # # id :integer not null, primary key # description :string default(""), not null # image_count :integer default(0), not null # order_position_asc :boolean default(FALSE), not null # spoiler_warning :string default(""), not null # title :string not null # watcher_count :integer default(0), not null # created_at :datetime not null # updated_at :datetime not null # creator_id :integer not null # thumbnail_id :integer not null # # Indexes # # index_galleries_on_creator_id (creator_id) # index_galleries_on_thumbnail_id (thumbnail_id) # # Foreign Keys # # fk_rails_... (creator_id => users.id) ON DELETE => cascade ON UPDATE => cascade # require 'test_helper' require 'post_loader' class GalleryTest < ActiveSupport::TestCase test 'inserting images creates interactions and updates indexes' do images = gallery_images assert_equal images.size, @gallery.gallery_interactions.size search = search_gallery_images assert_equal images.size, search.size images.each_with_index do |image, i| assert_equal image.id, search.records[i].id end end test 'images can be removed' do images = gallery_images @gallery.remove(images[0]).reload images.delete images[0] assert_equal images.size, @gallery.gallery_interactions.size assert_equal images.size, search_gallery_images.size end test 'gallery is destroyable' do gallery_images @gallery.destroy assert_equal 0, @gallery.gallery_interactions.count assert_equal 0, search_gallery_images.size end def search_gallery_images refresh_index Image PostLoader.new.gallery(@gallery.id).records end def gallery_images @gallery = create(:gallery) images = create_list(:post_skips_validation, 4) images.each { |i| @gallery.add(i) } images.reverse # images are ordered by time added, descending end end