diff --git a/app/helpers/protips_helper.rb b/app/helpers/protips_helper.rb index 4808b9f9..b8a9249d 100644 --- a/app/helpers/protips_helper.rb +++ b/app/helpers/protips_helper.rb @@ -67,8 +67,6 @@ def users_background_image location_image_url_for(@user) elsif @protip && !@protip.new_record? location_image_url_for(@protip.user) - else - location_image_url_for(current_user) end end diff --git a/spec/helpers/protips_helper_spec.rb b/spec/helpers/protips_helper_spec.rb index 98408129..37fbb3a2 100644 --- a/spec/helpers/protips_helper_spec.rb +++ b/spec/helpers/protips_helper_spec.rb @@ -4,4 +4,42 @@ expect(helper.protip_search_results_to_render(nil)).to be_nil end end + + describe '#users_background_image' do + context 'user is logged in' do + it 'returns #location_image_url_for @user' do + assign(:user, 'test_user') + allow(helper).to receive(:location_image_url_for).with('test_user').and_return('image_path') + expect(helper.users_background_image).to eq 'image_path' + end + end + + context 'user is not logged in' do + it 'returns nil' do + assign(:user, nil) + expect(helper.users_background_image).to be_nil + end + end + + context 'protip is set' do + it 'returns #location_image_url_for @protip.user if @protip is not new_record' do + @protip = double('protip', 'user' => 'test_user', 'new_record?' => false) + allow(helper).to receive(:location_image_url_for).with('test_user').and_return('image_path') + expect(helper.users_background_image).to eq 'image_path' + end + + it 'returns nil if @protip is new_record' do + @protip = double('protip', 'user' => 'test_user', 'new_record?' => true) + expect(helper.users_background_image).to be_nil + end + end + + context 'protip is not set' do + it 'returns nil' do + assign(:protip, nil) + expect(helper.users_background_image).to be_nil + end + end + end + end