Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fetch_profile_photo_spec.rb « workers « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 66106b27859a18b4e382b626de5f2f79d0fb0eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
describe Workers::FetchProfilePhoto do
  before do
   @user = alice
   @service = FactoryGirl.build(:service, :user => alice)

   @url = "https://service.com/user/profile_image"

   allow(@service).to receive(:profile_photo_url).and_return(@url)
   allow(@user).to receive(:update_profile)

   allow(User).to receive(:find).and_return(@user)
   allow(Service).to receive(:find).and_return(@service)

    @photo_double = double
    allow(@photo_double).to receive(:save!).and_return(true)
    allow(@photo_double).to receive(:url).and_return("image.jpg")
  end

  it 'saves the profile image' do
    expect(@photo_double).to receive(:save!).and_return(true)
    expect(Photo).to receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_double)

    Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
  end

  context "service does not have a profile_photo_url" do
    it "does nothing without fallback" do
      allow(@service).to receive(:profile_photo_url).and_return(nil)
      expect(Photo).not_to receive(:diaspora_initialize)

      Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
    end

    it "fetches fallback if it's provided" do
      expect(@photo_double).to receive(:save!).and_return(true)
      allow(@service).to receive(:profile_photo_url).and_return(nil)
      expect(Photo).to receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_double)

      Workers::FetchProfilePhoto.new.perform(@user.id, @service.id, "https://service.com/fallback_lowres.jpg")
    end
  end


  it 'updates the profile' do
    allow(@photo_double).to receive(:url).and_return("large.jpg", "medium.jpg", "small.jpg")

    expect(Photo).to receive(:diaspora_initialize).and_return(@photo_double)
    expect(@user).to receive(:update_profile).with(hash_including({
                                               :image_url => "large.jpg",
                                               :image_url_medium => "medium.jpg",
                                               :image_url_small  => "small.jpg"
                                            }))

    Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
  end
end