Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
Get test with two months since published days to pass, assume fractio…
Browse files Browse the repository at this point in the history
…nal views don't mean anything
  • Loading branch information
edgenard committed May 13, 2018
1 parent 76fbc77 commit 53c30c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion refactoring_external_service/youtube_video_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def video_list
def monthlyViews(views, publishing_date)
days_available = Date.today - Date.parse(publishing_date)
return views if days_available < 30
views * 365.0 / days_available / 12
(views * 365 / days_available / 12).to_i
end
end
8 changes: 5 additions & 3 deletions refactoring_external_service/youtube_video_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_when_views_unchanged_for_one_month
expected = video_repo_response
assert_equal(expected[0]['youtubeID'], actual[0]['youtubeID'])
assert_equal(expected[0]['views'], actual[0]['views'])
assert_in_delta(expected[0]['monthlyViews'], actual[0]['monthlyViews'], 0.1)
assert_equal(expected[0]['monthlyViews'], actual[0]['monthlyViews'])
end

def test_when_less_than_thirty_days_have_passed
Expand Down Expand Up @@ -87,7 +87,9 @@ def test_when_sixty_days_have_passed_since_publishing
video_client: YoutubeVideoClientStub.new(youtube_client_response)
)
actual = JSON.parse(video_service.video_list)
assert_equal(10, actual[0]['views'])
assert_equal(5, actual[0]['monthlyViews'])
assert_equal(10, actual[0]['views'], 'Total Views')
# I'm making another assumption here that fractional views don't really count for anything

This comment has been minimized.

Copy link
@medwards1771

medwards1771 May 15, 2018

Contributor

Fair assumption

# So monthly views should always be integers.
assert_equal(5, actual[0]['monthlyViews'], 'Monthly Views')
end
end

0 comments on commit 53c30c0

Please sign in to comment.