{"action":"created","comment":{"url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/comments/44583317","id":44583317,"diff_hunk":"@@ -0,0 +1,98 @@\n+require 'yahoo_finance.rb'\n+require 'test_helper'\n+\n+class YahooFinanceTest < ActiveSupport::TestCase\n+  test 'Check caching stock data' do\n+    # Cache miss\n+    start_miss = Time.now\n+    finance_miss = Finance.get_quotes('AAPL', 0)\n+    end_miss = Time.now\n+    time_miss = end_miss - start_miss\n+\n+    # Cache hit\n+    start_hit = Time.now\n+    finance_hit = Finance.get_quotes('AAPL', 0)\n+    end_hit = Time.now\n+    time_hit = end_hit - start_hit\n+\n+    # Compare quotes\n+    assert_equal(finance_hit['name'], finance_miss['name'],\n+                 'Symbol names differ between fresh and cached')\n+    assert_equal(finance_hit['open'], finance_miss['open'], \n+                 'Opening prices differ between fresh and cached')\n+    assert(time_hit < time_miss, 'Cache hit no faster than cache miss')\n+  end\n+\n+  test 'Check only one record of each type for a company' do\n+    # Querying for AAPL twice to check for multiple cache attempts\n+    Finance.get_quotes('AAPL', 0)\n+    Finance.get_quotes('AAPL', 0)\n+    Finance.get_quotes('AAPL', 1)\n+    Finance.get_quotes('AAPL', 1)\n+    company = Company.find_by(symbol: 'AAPL')\n+    count_hist_entries = FinanceCache.where(company_id: company.id,\n+                                            category: 0).count\n+    count_curr_entries = FinanceCache.where(company_id: company.id,\n+                                            category: 1).count\n+    assert_equal(1, count_hist_entries, \n+                 'Cache is adding too many historical records or not enough.')\n+    assert_equal(1, count_curr_entries, \n+                 'Cache is adding too many current records or not enough.')\n+  end\n+  \n+  test 'Check cache expiration' do\n+    # Cache miss\n+    start_miss = Time.now\n+    Finance.get_quotes('AAPL', 0)\n+    Finance.get_quotes('AAPL', 1)\n+    end_miss = Time.now\n+    time_miss = end_miss - start_miss\n+\n+    # Cache hit\n+    start_hit = Time.now\n+    Finance.get_quotes('AAPL', 0)\n+    Finance.get_quotes('AAPL', 1)\n+    end_hit = Time.now\n+    time_hit = end_hit - start_hit\n+\n+    # Cache expired\n+    # First, expire the caches for both curr and hist records\n+    company = Company.find_by(symbol: 'AAPL')\n+    cached_hist = FinanceCache.find_by(company_id: company.id, category: 1)\n+    cached_curr = FinanceCache.find_by(company_id: company.id, category: 0)\n+    assert_not_nil(cached_hist, 'Couldn\\'t find cached history quotes.')\n+    assert_not_nil(cached_curr, 'Couldn\\'t find cached current quotes.')\n+    cached_hist.created_at = cached_hist.created_at - 1.day - 1.hour\n+    cached_curr.created_at = cached_curr.created_at - 30.minutes\n+    cached_hist.save\n+    cached_curr.save\n+\n+    # Second, make sure this request takes longer than a cache hit\n+    start_expired = Time.now\n+    Finance.get_quotes('AAPL', 1)\n+    end_expired = Time.now\n+    time_expired = end_expired - start_expired\n+    puts \"Time expired: #{time_expired}\"\n+    puts \"Time miss: #{time_miss}\"\n+    puts \"Time hit: #{time_hit}\"\n+\n+    # Compare results\n+    assert(time_hit < time_miss, 'Cache doesn\\'t take less time')\n+    assert(time_hit < time_expired, 'Cache didn\\'t expire')\n+    assert(time_expired - time_miss < time_expired - time_hit,","path":"test/lib/yahoo_finance_test.rb","position":82,"original_position":82,"commit_id":"4140e6655c9b1db001e00caf52c203df0b79246c","original_commit_id":"4140e6655c9b1db001e00caf52c203df0b79246c","user":{"login":"chriskonstad","id":1539144,"avatar_url":"https://avatars.githubusercontent.com/u/1539144?v=3","gravatar_id":"","url":"https://api.github.com/users/chriskonstad","html_url":"https://github.com/chriskonstad","followers_url":"https://api.github.com/users/chriskonstad/followers","following_url":"https://api.github.com/users/chriskonstad/following{/other_user}","gists_url":"https://api.github.com/users/chriskonstad/gists{/gist_id}","starred_url":"https://api.github.com/users/chriskonstad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chriskonstad/subscriptions","organizations_url":"https://api.github.com/users/chriskonstad/orgs","repos_url":"https://api.github.com/users/chriskonstad/repos","events_url":"https://api.github.com/users/chriskonstad/events{/privacy}","received_events_url":"https://api.github.com/users/chriskonstad/received_events","type":"User","site_admin":false},"body":"Should be comparing absolute values, I think?","created_at":"2015-11-11T20:42:13Z","updated_at":"2015-11-11T20:42:13Z","html_url":"https://github.com/scalableinternetservices/ABCs/pull/49#discussion_r44583317","pull_request_url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49","_links":{"self":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/comments/44583317"},"html":{"href":"https://github.com/scalableinternetservices/ABCs/pull/49#discussion_r44583317"},"pull_request":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49"}}},"pull_request":{"url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49","id":49929167,"html_url":"https://github.com/scalableinternetservices/ABCs/pull/49","diff_url":"https://github.com/scalableinternetservices/ABCs/pull/49.diff","patch_url":"https://github.com/scalableinternetservices/ABCs/pull/49.patch","issue_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/49","number":49,"state":"open","locked":false,"title":"Financecache","user":{"login":"apfong","id":7343409,"avatar_url":"https://avatars.githubusercontent.com/u/7343409?v=3","gravatar_id":"","url":"https://api.github.com/users/apfong","html_url":"https://github.com/apfong","followers_url":"https://api.github.com/users/apfong/followers","following_url":"https://api.github.com/users/apfong/following{/other_user}","gists_url":"https://api.github.com/users/apfong/gists{/gist_id}","starred_url":"https://api.github.com/users/apfong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apfong/subscriptions","organizations_url":"https://api.github.com/users/apfong/orgs","repos_url":"https://api.github.com/users/apfong/repos","events_url":"https://api.github.com/users/apfong/events{/privacy}","received_events_url":"https://api.github.com/users/apfong/received_events","type":"User","site_admin":false},"body":"Historical data is cached for 1 day.\r\nCurrent data is cached for 15 minutes.","created_at":"2015-11-06T08:54:38Z","updated_at":"2015-11-11T20:42:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88a8e638f26cd3867f5cd68ba3ec0592a7af3786","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49/commits","review_comments_url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49/comments","review_comment_url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/49/comments","statuses_url":"https://api.github.com/repos/scalableinternetservices/ABCs/statuses/4140e6655c9b1db001e00caf52c203df0b79246c","head":{"label":"scalableinternetservices:financecache","ref":"financecache","sha":"4140e6655c9b1db001e00caf52c203df0b79246c","user":{"login":"scalableinternetservices","id":8645121,"avatar_url":"https://avatars.githubusercontent.com/u/8645121?v=3","gravatar_id":"","url":"https://api.github.com/users/scalableinternetservices","html_url":"https://github.com/scalableinternetservices","followers_url":"https://api.github.com/users/scalableinternetservices/followers","following_url":"https://api.github.com/users/scalableinternetservices/following{/other_user}","gists_url":"https://api.github.com/users/scalableinternetservices/gists{/gist_id}","starred_url":"https://api.github.com/users/scalableinternetservices/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalableinternetservices/subscriptions","organizations_url":"https://api.github.com/users/scalableinternetservices/orgs","repos_url":"https://api.github.com/users/scalableinternetservices/repos","events_url":"https://api.github.com/users/scalableinternetservices/events{/privacy}","received_events_url":"https://api.github.com/users/scalableinternetservices/received_events","type":"Organization","site_admin":false},"repo":{"id":43981551,"name":"ABCs","full_name":"scalableinternetservices/ABCs","owner":{"login":"scalableinternetservices","id":8645121,"avatar_url":"https://avatars.githubusercontent.com/u/8645121?v=3","gravatar_id":"","url":"https://api.github.com/users/scalableinternetservices","html_url":"https://github.com/scalableinternetservices","followers_url":"https://api.github.com/users/scalableinternetservices/followers","following_url":"https://api.github.com/users/scalableinternetservices/following{/other_user}","gists_url":"https://api.github.com/users/scalableinternetservices/gists{/gist_id}","starred_url":"https://api.github.com/users/scalableinternetservices/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalableinternetservices/subscriptions","organizations_url":"https://api.github.com/users/scalableinternetservices/orgs","repos_url":"https://api.github.com/users/scalableinternetservices/repos","events_url":"https://api.github.com/users/scalableinternetservices/events{/privacy}","received_events_url":"https://api.github.com/users/scalableinternetservices/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scalableinternetservices/ABCs","description":"[UCLA] A stock recommender based on tweet sentiments.","fork":false,"url":"https://api.github.com/repos/scalableinternetservices/ABCs","forks_url":"https://api.github.com/repos/scalableinternetservices/ABCs/forks","keys_url":"https://api.github.com/repos/scalableinternetservices/ABCs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scalableinternetservices/ABCs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scalableinternetservices/ABCs/teams","hooks_url":"https://api.github.com/repos/scalableinternetservices/ABCs/hooks","issue_events_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/events{/number}","events_url":"https://api.github.com/repos/scalableinternetservices/ABCs/events","assignees_url":"https://api.github.com/repos/scalableinternetservices/ABCs/assignees{/user}","branches_url":"https://api.github.com/repos/scalableinternetservices/ABCs/branches{/branch}","tags_url":"https://api.github.com/repos/scalableinternetservices/ABCs/tags","blobs_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/refs{/sha}","trees_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scalableinternetservices/ABCs/statuses/{sha}","languages_url":"https://api.github.com/repos/scalableinternetservices/ABCs/languages","stargazers_url":"https://api.github.com/repos/scalableinternetservices/ABCs/stargazers","contributors_url":"https://api.github.com/repos/scalableinternetservices/ABCs/contributors","subscribers_url":"https://api.github.com/repos/scalableinternetservices/ABCs/subscribers","subscription_url":"https://api.github.com/repos/scalableinternetservices/ABCs/subscription","commits_url":"https://api.github.com/repos/scalableinternetservices/ABCs/commits{/sha}","git_commits_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/commits{/sha}","comments_url":"https://api.github.com/repos/scalableinternetservices/ABCs/comments{/number}","issue_comment_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/comments{/number}","contents_url":"https://api.github.com/repos/scalableinternetservices/ABCs/contents/{+path}","compare_url":"https://api.github.com/repos/scalableinternetservices/ABCs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scalableinternetservices/ABCs/merges","archive_url":"https://api.github.com/repos/scalableinternetservices/ABCs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scalableinternetservices/ABCs/downloads","issues_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues{/number}","pulls_url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls{/number}","milestones_url":"https://api.github.com/repos/scalableinternetservices/ABCs/milestones{/number}","notifications_url":"https://api.github.com/repos/scalableinternetservices/ABCs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scalableinternetservices/ABCs/labels{/name}","releases_url":"https://api.github.com/repos/scalableinternetservices/ABCs/releases{/id}","created_at":"2015-10-09T21:42:17Z","updated_at":"2015-11-09T20:06:52Z","pushed_at":"2015-11-11T20:15:52Z","git_url":"git://github.com/scalableinternetservices/ABCs.git","ssh_url":"git@github.com:scalableinternetservices/ABCs.git","clone_url":"https://github.com/scalableinternetservices/ABCs.git","svn_url":"https://github.com/scalableinternetservices/ABCs","homepage":"","size":8552,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":4,"default_branch":"master"}},"base":{"label":"scalableinternetservices:master","ref":"master","sha":"1f2fe2a6dcf28e0fbeba461dfda92a5318dc7c10","user":{"login":"scalableinternetservices","id":8645121,"avatar_url":"https://avatars.githubusercontent.com/u/8645121?v=3","gravatar_id":"","url":"https://api.github.com/users/scalableinternetservices","html_url":"https://github.com/scalableinternetservices","followers_url":"https://api.github.com/users/scalableinternetservices/followers","following_url":"https://api.github.com/users/scalableinternetservices/following{/other_user}","gists_url":"https://api.github.com/users/scalableinternetservices/gists{/gist_id}","starred_url":"https://api.github.com/users/scalableinternetservices/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalableinternetservices/subscriptions","organizations_url":"https://api.github.com/users/scalableinternetservices/orgs","repos_url":"https://api.github.com/users/scalableinternetservices/repos","events_url":"https://api.github.com/users/scalableinternetservices/events{/privacy}","received_events_url":"https://api.github.com/users/scalableinternetservices/received_events","type":"Organization","site_admin":false},"repo":{"id":43981551,"name":"ABCs","full_name":"scalableinternetservices/ABCs","owner":{"login":"scalableinternetservices","id":8645121,"avatar_url":"https://avatars.githubusercontent.com/u/8645121?v=3","gravatar_id":"","url":"https://api.github.com/users/scalableinternetservices","html_url":"https://github.com/scalableinternetservices","followers_url":"https://api.github.com/users/scalableinternetservices/followers","following_url":"https://api.github.com/users/scalableinternetservices/following{/other_user}","gists_url":"https://api.github.com/users/scalableinternetservices/gists{/gist_id}","starred_url":"https://api.github.com/users/scalableinternetservices/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalableinternetservices/subscriptions","organizations_url":"https://api.github.com/users/scalableinternetservices/orgs","repos_url":"https://api.github.com/users/scalableinternetservices/repos","events_url":"https://api.github.com/users/scalableinternetservices/events{/privacy}","received_events_url":"https://api.github.com/users/scalableinternetservices/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scalableinternetservices/ABCs","description":"[UCLA] A stock recommender based on tweet sentiments.","fork":false,"url":"https://api.github.com/repos/scalableinternetservices/ABCs","forks_url":"https://api.github.com/repos/scalableinternetservices/ABCs/forks","keys_url":"https://api.github.com/repos/scalableinternetservices/ABCs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scalableinternetservices/ABCs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scalableinternetservices/ABCs/teams","hooks_url":"https://api.github.com/repos/scalableinternetservices/ABCs/hooks","issue_events_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/events{/number}","events_url":"https://api.github.com/repos/scalableinternetservices/ABCs/events","assignees_url":"https://api.github.com/repos/scalableinternetservices/ABCs/assignees{/user}","branches_url":"https://api.github.com/repos/scalableinternetservices/ABCs/branches{/branch}","tags_url":"https://api.github.com/repos/scalableinternetservices/ABCs/tags","blobs_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/refs{/sha}","trees_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scalableinternetservices/ABCs/statuses/{sha}","languages_url":"https://api.github.com/repos/scalableinternetservices/ABCs/languages","stargazers_url":"https://api.github.com/repos/scalableinternetservices/ABCs/stargazers","contributors_url":"https://api.github.com/repos/scalableinternetservices/ABCs/contributors","subscribers_url":"https://api.github.com/repos/scalableinternetservices/ABCs/subscribers","subscription_url":"https://api.github.com/repos/scalableinternetservices/ABCs/subscription","commits_url":"https://api.github.com/repos/scalableinternetservices/ABCs/commits{/sha}","git_commits_url":"https://api.github.com/repos/scalableinternetservices/ABCs/git/commits{/sha}","comments_url":"https://api.github.com/repos/scalableinternetservices/ABCs/comments{/number}","issue_comment_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/comments{/number}","contents_url":"https://api.github.com/repos/scalableinternetservices/ABCs/contents/{+path}","compare_url":"https://api.github.com/repos/scalableinternetservices/ABCs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scalableinternetservices/ABCs/merges","archive_url":"https://api.github.com/repos/scalableinternetservices/ABCs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scalableinternetservices/ABCs/downloads","issues_url":"https://api.github.com/repos/scalableinternetservices/ABCs/issues{/number}","pulls_url":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls{/number}","milestones_url":"https://api.github.com/repos/scalableinternetservices/ABCs/milestones{/number}","notifications_url":"https://api.github.com/repos/scalableinternetservices/ABCs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scalableinternetservices/ABCs/labels{/name}","releases_url":"https://api.github.com/repos/scalableinternetservices/ABCs/releases{/id}","created_at":"2015-10-09T21:42:17Z","updated_at":"2015-11-09T20:06:52Z","pushed_at":"2015-11-11T20:15:52Z","git_url":"git://github.com/scalableinternetservices/ABCs.git","ssh_url":"git@github.com:scalableinternetservices/ABCs.git","clone_url":"https://github.com/scalableinternetservices/ABCs.git","svn_url":"https://github.com/scalableinternetservices/ABCs","homepage":"","size":8552,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49"},"html":{"href":"https://github.com/scalableinternetservices/ABCs/pull/49"},"issue":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/49"},"comments":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/issues/49/comments"},"review_comments":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49/comments"},"review_comment":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/pulls/49/commits"},"statuses":{"href":"https://api.github.com/repos/scalableinternetservices/ABCs/statuses/4140e6655c9b1db001e00caf52c203df0b79246c"}}}}