Permalink
Browse files

[#77745832] Searchers see fewer duplicate/similar images in results

- Improve test coverage
  • Loading branch information...
loren committed Sep 17, 2014
1 parent b12eb19 commit f6ab91539efa965325dbe02b6c67ff68a7dff431
@@ -0,0 +1,38 @@
require 'rails_helper'
describe AlbumDetectionPhotoIterator, "run" do
before do
5.times do |x|
i = x + 1
FlickrPhoto.create(id: "photo #{i}", owner: "owner1", profile_type: 'user',
tags: ['alpha', 'bravo', 'charlie', i.ordinalize],
title: "#{i.ordinalize} presidential visit to Mars",
description: "#{i.ordinalize} title from unverified data provided by the Bain News Service on the negatives or caption cards",
taken_at: Date.parse("2014-09-16"), popularity: 100+i, url: "http://photo#{i}", thumbnail_url: "http://photo_thumbnail#{i}",
album: "photo #{i}")
end
FlickrPhoto.refresh_index!
end
let(:iterator) { AlbumDetectionPhotoIterator.new(FlickrPhoto, PhotoFilter.new('owner', 'owner1').query_body) }
it 'should run the album detector on each photo' do
expect(AlbumDetector).to receive(:detect_albums!).exactly(5).times { [] }
iterator.run
end
describe "assigning a default album" do
context 'when there is a version conflict during the update' do
let(:photo) { FlickrPhoto.create(id: "photo1", owner: "owner1", profile_type: 'user', tags: [], title: "title1 earth", description: "desc 1", taken_at: Date.current, popularity: 100, url: "http://photo1", thumbnail_url: "http://photo_thumbnail1", album: 'album1') }
before do
expect(photo).to receive(:update).and_raise Elasticsearch::Transport::Transport::Errors::Conflict
end
it 'should log a warning and continue' do
expect(Rails.logger).to receive(:warn)
AlbumDetector.detect_albums! photo
end
end
end
end
@@ -0,0 +1,18 @@
require 'rails_helper'
describe AlbumDetector do
describe "assigning a default album" do
context 'when there is a version conflict during the update' do
let(:photo) { FlickrPhoto.create(id: "photo1", owner: "owner1", profile_type: 'user', tags: [], title: "title1 earth", description: "desc 1", taken_at: Date.current, popularity: 100, url: "http://photo1", thumbnail_url: "http://photo_thumbnail1", album: 'album1') }
before do
expect(photo).to receive(:update).and_raise Elasticsearch::Transport::Transport::Errors::Conflict
end
it 'should log a warning and continue' do
expect(Rails.logger).to receive(:warn)
AlbumDetector.detect_albums! photo
end
end
end
end
@@ -0,0 +1,28 @@
require 'rails_helper'
describe FlickrAlbumDetector do
context 'when 4 or more other Flickr photos are sufficiently similar in their tags, title, and description fields' do
before do
5.times do |x|
i = x + 1
FlickrPhoto.create(id: "photo #{i}", owner: "owner1", profile_type: 'user',
tags: ['alpha', 'bravo', 'charlie', i.ordinalize],
title: "#{i.ordinalize} presidential visit to Mars",
description: "#{i.ordinalize} title from unverified data provided by the Bain News Service on the negatives or caption cards",
taken_at: Date.parse("2014-09-16"), popularity: 100+i, url: "http://photo#{i}", thumbnail_url: "http://photo_thumbnail#{i}",
album: "photo #{i}")
end
FlickrPhoto.refresh_index!
end
let(:photo) { FlickrPhoto.find "photo 1" }
it 'should assign them all to the same album' do
AlbumDetector.detect_albums! photo
5.times do |x|
i = x + 1
expect(FlickrPhoto.find("photo #{i}").album).to eq("owner1:2014-09-16:photo 1")
end
end
end
end
@@ -0,0 +1,27 @@
require 'rails_helper'
describe InstagramAlbumDetector do
context 'when 4 or more other Instagram photos are sufficiently similar in their tags and caption fields' do
before do
5.times do |x|
i = x + 1
InstagramPhoto.create(id: "photo #{i}", username: "username1",
tags: ['alpha', 'bravo', 'charlie', i.ordinalize],
caption: "#{i.ordinalize} title from unverified data provided by the Bain News Service on the negatives or caption cards",
taken_at: Date.parse("2014-09-16"), popularity: 100+i, url: "http://photo#{i}", thumbnail_url: "http://photo_thumbnail#{i}",
album: "photo #{i}")
end
InstagramPhoto.refresh_index!
end
let(:photo) { InstagramPhoto.find "photo 1" }
it 'should assign them all to the same album' do
AlbumDetector.detect_albums! photo
5.times do |x|
i = x + 1
expect(InstagramPhoto.find("photo #{i}").album).to eq("username1:2014-09-16:photo 1")
end
end
end
end

0 comments on commit f6ab915

Please sign in to comment.