|
18 | 18 |
|
19 | 19 | context 'when person has profile_image_url method' do |
20 | 20 | before do |
21 | | - allow(person).to receive(:respond_to?).with(:profile_image).and_return(true) |
22 | | - allow(person).to receive(:respond_to?).with(:profile_image, anything).and_return(true) |
23 | | - allow(person).to receive(:respond_to?).with(:profile_image_url).and_return(true) |
24 | | - allow(person).to receive(:respond_to?).with(:profile_image_url, anything).and_return(true) |
25 | | - |
26 | 21 | # Mock profile_image.attached? to return true |
27 | 22 | profile_image_double = double('profile_image', attached?: true) # rubocop:todo RSpec/VerifiedDoubles |
28 | | - allow(person).to receive_messages(respond_to?: false, profile_image_url: 'http://example.com/optimized.jpg', |
29 | | - profile_image: profile_image_double) |
| 23 | + allow(person).to receive(:profile_image).and_return(profile_image_double) |
| 24 | + |
| 25 | + # Stub the profile_image_url method to return our test URL |
| 26 | + allow(person).to receive(:profile_image_url).and_return('http://example.com/optimized.jpg') |
30 | 27 | end |
31 | 28 |
|
32 | 29 | it 'uses the optimized profile_image_url method' do |
33 | | - expect(person).to receive(:profile_image_url).with(size: 300) |
| 30 | + expect(person).to receive(:profile_image_url).with(size: 300).and_return('http://example.com/optimized.jpg') |
34 | 31 | result = profile_image_tag(person) |
35 | 32 | expect(result).to include('src="http://example.com/optimized.jpg"') |
36 | 33 | expect(result).to include('class="profile-image rounded-circle') |
37 | 34 | end |
38 | 35 |
|
39 | 36 | it 'respects custom size parameter' do |
40 | | - expect(person).to receive(:profile_image_url).with(size: 150) |
| 37 | + expect(person).to receive(:profile_image_url).with(size: 150).and_return('http://example.com/optimized.jpg') |
41 | 38 | profile_image_tag(person, size: 150) |
42 | 39 | end |
43 | 40 | end |
|
0 commit comments