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

Commit 53c30c0

Browse files
committed
Get test with two months since published days to pass, assume fractional views don't mean anything
1 parent 76fbc77 commit 53c30c0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

refactoring_external_service/youtube_video_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def video_list
5151
def monthlyViews(views, publishing_date)
5252
days_available = Date.today - Date.parse(publishing_date)
5353
return views if days_available < 30
54-
views * 365.0 / days_available / 12
54+
(views * 365 / days_available / 12).to_i
5555
end
5656
end

refactoring_external_service/youtube_video_list_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_when_views_unchanged_for_one_month
4646
expected = video_repo_response
4747
assert_equal(expected[0]['youtubeID'], actual[0]['youtubeID'])
4848
assert_equal(expected[0]['views'], actual[0]['views'])
49-
assert_in_delta(expected[0]['monthlyViews'], actual[0]['monthlyViews'], 0.1)
49+
assert_equal(expected[0]['monthlyViews'], actual[0]['monthlyViews'])
5050
end
5151

5252
def test_when_less_than_thirty_days_have_passed
@@ -87,7 +87,9 @@ def test_when_sixty_days_have_passed_since_publishing
8787
video_client: YoutubeVideoClientStub.new(youtube_client_response)
8888
)
8989
actual = JSON.parse(video_service.video_list)
90-
assert_equal(10, actual[0]['views'])
91-
assert_equal(5, actual[0]['monthlyViews'])
90+
assert_equal(10, actual[0]['views'], 'Total Views')
91+
# I'm making another assumption here that fractional views don't really count for anything
92+
# So monthly views should always be integers.
93+
assert_equal(5, actual[0]['monthlyViews'], 'Monthly Views')
9294
end
9395
end

0 commit comments

Comments
 (0)