Skip to content

Commit

Permalink
Merge branch 'main' into jonny5/permissions-creation-163
Browse files Browse the repository at this point in the history
  • Loading branch information
abachman authored Jun 1, 2024
2 parents e9429c9 + c77adf7 commit 582c53d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 17 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ on:
types: ['opened', 'reopened', 'synchronize', 'unlocked']

jobs:
ruby-lint:
name: Ruby Lint
runs-on: ubuntu-latest
# NOTE: @abachman
# In order to move a little faster for the Ruby for Good weekend event, I'm
# commenting out the ruby-lint job. We can re-enable it after the event
# once we've had a chance to let the dust settle and run `standardrb --fix`
# on everything.
# ruby-lint:
# name: Ruby Lint
# runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/[email protected]
with:
ruby-version: '3.2.3'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
# - name: Set up Ruby
# uses: ruby/[email protected]
# with:
# ruby-version: '3.2.3'
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Ruby Lint
run: bundle exec standardrb --parallel -f github
# - name: Ruby Lint
# run: bundle exec standardrb --parallel -f github

rails-test:
name: Rails Test
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
!/app/assets/builds/.keep

/node_modules
.vscode/
.vscode/
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ end
group :test do
gem "capybara"
gem "selenium-webdriver"
gem "webmock"
end

gem "pundit", "~> 2.3"
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
cssbundling-rails (1.4.0)
railties (>= 6.0.0)
Expand All @@ -132,6 +135,7 @@ GEM
ffi (1.16.3)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.0)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
Expand Down Expand Up @@ -350,6 +354,10 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.6)
Expand Down Expand Up @@ -393,6 +401,7 @@ DEPENDENCIES
turbo-rails
tzinfo-data
web-console
webmock

RUBY VERSION
ruby 3.2.3p157
Expand Down
13 changes: 13 additions & 0 deletions app/jobs/stock_prices_update_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@ class StockPricesUpdateJob < ApplicationJob
def perform(*args)
# For each stock symbol, request the latest closing cost
# update the stocks table with each new closing cost
stock_symbols = ["KO", "SNE", "TWX", "DIS", "SIRI", "F", "EA", "FB", "UA", "LUV", "GPS"]
stock_symbols.each do |symbol|
api_request(symbol)
stock_db = Stock.find_by(ticker: symbol)
end
end

private

def api_request(symbol)
url = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=#{symbol}&apikey=#{API_KEY}"
uri = URI.parse(url)
print Net::HTTP.get(uri)
end
end
1 change: 1 addition & 0 deletions config/initializers/api_keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY = ENV.fetch("STOCKS_API_KEY", "test-api-key")
42 changes: 39 additions & 3 deletions test/jobs/stock_prices_update_job_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
require "test_helper"

class StockPricesUpdateJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
STOCK_URL_MATCHER = %r{https://www\.alphavantage\.co/query\?apikey=[^&]+&function=GLOBAL_QUOTE&symbol=[A-Z]+}
STOCK_SYMBOLS = ["KO", "SNE", "TWX", "DIS", "SIRI", "F", "EA", "FB", "UA", "LUV", "GPS"]

setup do
stub_request(:get, STOCK_URL_MATCHER)
.with(
headers: {
"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Host" => "www.alphavantage.co",
"User-Agent" => "Ruby"
}
)
.to_return(status: 200, body: "", headers: {})
end

test "makes API calls" do
StockPricesUpdateJob.perform_now
assert_requested :get, STOCK_URL_MATCHER, times: 11
end

test "creates Stock records" do
skip("waiting for implementation")

assert_difference("Stock.count", 11) do
StockPricesUpdateJob.perform_now
end
end

test "sets Stock ticker and price" do
skip("waiting for implementation")

StockPricesUpdateJob.perform_now
STOCK_SYMBOLS.each do |ticker|
stock = Stock.find_by(ticker: ticker)
assert stock.present?
assert stock.price.present?
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
require "webmock/minitest"

module ActiveSupport
class TestCase
Expand Down

0 comments on commit 582c53d

Please sign in to comment.