Skip to content

Commit

Permalink
Tests for .parse_birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
lortza committed Sep 3, 2018
1 parent 87e821a commit 6b0f066
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 7 additions & 3 deletions app/models/movie_person_profile.rb
Expand Up @@ -30,12 +30,9 @@ def parse_result(result)
)
end

def self.display_birthday_and_age(date)
return "Not available" unless date
def parse_bio(biography)
return 'Bio not available.' if biography.blank?

"#{date.stamp('January 1st, 2018')} (Age: #{DateAndTimeHelper.years_since_date(date)})"
standardize_wikipedia_credit(biography)
biography.gsub(/(?:\n\r?|\r\n?)/, '<br>').html_safe
end
Expand All @@ -51,5 +48,12 @@ def standardize_wikipedia_credit(bio)
def wikipedia_credit?(bio)
bio.include?(WIKIPEDIA_CREDIT[:starting]) || bio.include?(WIKIPEDIA_CREDIT[:trailing])
end

def parse_birthday(birthday)
return 'Not available' unless birthday

date = Date.parse(birthday)
"#{date.stamp('January 1st, 2018')} (Age: #{DateAndTimeHelper.years_since_date(date)})"
end
end
end
26 changes: 23 additions & 3 deletions spec/models/movie_person_profile_spec.rb
Expand Up @@ -159,15 +159,12 @@
end
end

describe '.display_birthday_and_age' do
xit 'returns "Not available" if there is no Date' do
describe '.wikipedia_credit?' do
it 'returns true if a starting Wikipedia credit exists' do
bio = "#{MoviePersonProfile::WIKIPEDIA_CREDIT[:starting]} Bio Goes here."
expect(MoviePersonProfile.wikipedia_credit?(bio)).to be true
end

xit 'returns a string with the birthdate and Age' do
it 'returns true if a trailing Wikipedia credit exists' do
bio = "Bio Goes here. #{MoviePersonProfile::WIKIPEDIA_CREDIT[:trailing]}"
expect(MoviePersonProfile.wikipedia_credit?(bio)).to be true
Expand All @@ -178,6 +175,29 @@
expect(MoviePersonProfile.wikipedia_credit?(bio)).to be false
end
end

describe '.parse_birthday' do
it 'returns "Not available" message if there is no date provided' do
birthday = nil
parsed_birthday = MoviePersonProfile.parse_birthday(birthday)
message = 'not available'

expect(parsed_birthday.downcase.include?(message)).to be true
end

it 'includes the word version of the birthdate in the returned string' do
birthday = '2000-01-28'
parsed_birthday = MoviePersonProfile.parse_birthday(birthday)

expect(parsed_birthday.include?('January')).to be true
end

it "includes the person's current age in the returned string" do
birthday = '2000-01-28'
current_age = DateAndTimeHelper.years_since_date(birthday.to_date).to_s
parsed_birthday = MoviePersonProfile.parse_birthday(birthday)

expect(parsed_birthday.include?(current_age)).to be true
end
end
end

0 comments on commit 6b0f066

Please sign in to comment.