Generalize get_logo helper for all classes

This commit is contained in:
James Mason 2017-11-26 20:34:27 -08:00
parent aee1f58607
commit b2e1eb5fa9
4 changed files with 58 additions and 53 deletions

View file

@ -181,4 +181,19 @@ module ApplicationHelper
title: 'Open Source Event Manager'
)
end
# returns the url to be used for logo on basis of sponsorship level position
def get_logo(object)
if object.try(:sponsorship_level)
if object.sponsorship_level.position == 1
object.picture.first.url
elsif object.sponsorship_level.position == 2
object.picture.second.url
else
object.picture.others.url
end
else
object.picture.large.url
end
end
end

View file

@ -1,12 +0,0 @@
module SponsorsHelper
# returns the url to be used for logo on basis of sponsorship level position
def get_logo(sponsor)
if sponsor.sponsorship_level.position == 1
sponsor.picture.first.url
elsif sponsor.sponsorship_level.position == 2
sponsor.picture.second.url
else
sponsor.picture.others.url
end
end
end

View file

@ -1,8 +1,9 @@
require 'spec_helper'
describe ApplicationHelper, type: :helper do
let(:conference) { create(:conference) }
let(:conference) { create(:full_conference) }
let(:event) { create(:event, program: conference.program) }
let(:sponsor) { create(:sponsor) }
describe '#date_string' do
it 'when conference lasts 1 day' do
@ -75,4 +76,45 @@ describe ApplicationHelper, type: :helper do
end
end
end
describe '#get_logo' do
context 'first sponsorship_level' do
before do
first_sponsorship_level = create(:sponsorship_level, position: 1)
sponsor.update_attributes(sponsorship_level: first_sponsorship_level)
end
it 'returns correct url' do
expect(get_logo(sponsor)).to match %r{.*(\bfirst/#{sponsor.logo_file_name}\b)}
end
end
context 'second sponsorship_level' do
before do
second_sponsorship_level = create(:sponsorship_level, position: 2)
sponsor.update_attributes(sponsorship_level: second_sponsorship_level)
end
it 'returns correct url' do
expect(get_logo(sponsor)).to match %r{.*(\bsecond/#{sponsor.logo_file_name}\b)}
end
end
context 'other sponsorship_level' do
before do
other_sponsorship_level = create(:sponsorship_level, position: 3)
sponsor.update_attributes(sponsorship_level: other_sponsorship_level)
end
it 'returns correct url' do
expect(get_logo(sponsor)).to match %r{.*(\bothers/#{sponsor.logo_file_name}\b)}
end
end
context 'non-sponsor' do
it 'returns correct url' do
expect(get_logo(conference)).to match %r{.*(\blarge/#{conference.logo_file_name}\b)}
end
end
end
end

View file

@ -1,40 +0,0 @@
require 'spec_helper'
describe SponsorsHelper, type: :helper do
let(:sponsor) { create(:sponsor) }
describe '#get_logo' do
context 'first sponsorship_level' do
before do
first_sponsorship_level = create(:sponsorship_level, position: 1)
sponsor.update_attributes(sponsorship_level: first_sponsorship_level)
end
it 'returns correct url' do
expect(get_logo(sponsor)).to match %r{.*(\bfirst/#{sponsor.logo_file_name}\b)}
end
end
context 'second sponsorship_level' do
before do
second_sponsorship_level = create(:sponsorship_level, position: 2)
sponsor.update_attributes(sponsorship_level: second_sponsorship_level)
end
it 'returns correct url' do
expect(get_logo(sponsor)).to match %r{.*(\bsecond/#{sponsor.logo_file_name}\b)}
end
end
context 'other sponsorship_level' do
before do
other_sponsorship_level = create(:sponsorship_level, position: 3)
sponsor.update_attributes(sponsorship_level: other_sponsorship_level)
end
it 'returns correct url' do
expect(get_logo(sponsor)).to match %r{.*(\bothers/#{sponsor.logo_file_name}\b)}
end
end
end
end