Title / Description
Code # frozen_string_literal: true class Scheduler def self.needs_updating_ids # TODO: Add your resolution here movies = Movie.where(needs_update: true) response = Faraday.get('https://imdb-remote-api.com/') # response.body response_body = JSON.parse(response.body) response_body movies_for_update = [] movies.each do |movie| api_movie = response_body.find{ |var| var["id"] == movie.id } movies_for_update << movie.id if check_current_label(api_movie, movie) end movies_for_update end def self.schedule # TODO: Add your resolution here [] end def self.check_current_label(hash_movie, movie) current_label_value = get_label_value(hash_movie["rating"].to_f) current_label_value != movie.label end def self.get_label_value(label_value) case label_value when 0..1.99 'Poor' when 2..3.99 'Below Average' when 4..5.99 'Average' when 6..7.99 'Good' when 8..10 'Excellent' end end end # frozen_string_literal: true RSpec.describe Scheduler do before do # Seed database File.read(scenario_file).each_line do |line| id, name, label, needs_update = line.gsub("\n","").split(",") Movie.create!(id: id, name: name, label: label, needs_update: needs_update) end end context "scenario 1", vcr: { cassette_name: "scenario1" } do let(:scenario_file) { "./spec/db/scenario1.txt" } let(:needs_updating) { [1,4] } it "finds the IDs that need updating" do result = Scheduler.needs_updating_ids expect(result).to match_array needs_updating end it "creates the update schedule" do scheduled = Scheduler.schedule expect(scheduled).to eq([]) # replace this array with the correct batches schedule end end context "scenario 2", vcr: { cassette_name: "scenario2" } do let(:scenario_file) { "./spec/db/scenario2.txt" } let(:needs_updating) { [1,2,5,6,8] } it "finds the IDs that need updating" do result = Scheduler.needs_updating_ids # replace this with your result expect(result).to match_array needs_updating end it "creates the update schedule" do scheduled = Scheduler.schedule expect(scheduled).to eq([]) # replace this array with the correct batches schedule end end context "scenario 3", vcr: { cassette_name: "scenario3" } do let(:scenario_file) { "spec/db/scenario3.txt" } let(:needs_updating) { File.read("spec/db/scenario3-updates.txt").split.map(&:to_i) } it "finds the IDs that need updating" do result = Scheduler.needs_updating_ids # replace this with your result expect(result).to match_array needs_updating end it "creates the update schedule" end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code