diff --git a/lib/honeybadger/backend/base.rb b/lib/honeybadger/backend/base.rb index 7016902b..c2c692f0 100644 --- a/lib/honeybadger/backend/base.rb +++ b/lib/honeybadger/backend/base.rb @@ -4,7 +4,7 @@ require 'honeybadger/logging' -require 'honeybadger/checkin' +require 'honeybadger/check_in' module Honeybadger module Backend @@ -111,59 +111,59 @@ def track_deployment(payload) notify(:deploys, payload) end - # Get checkin by id + # Get check_in by id # @example - # backend.get_checkin('1234', 'ajdja") + # backend.get_check_in('1234', 'ajdja") # # @param [String] project_id The unique project id # @param [String] id The unique check_in id # @raise NotImplementedError - def get_checkin(project_id, id) + def get_check_in(project_id, id) raise NotImplementedError, 'must define #get_checkin on subclass' end # Get checkins by project # @example - # backend.get_checkins('1234') + # backend.get_check_ins('1234') # # @param [String] project_id The unique project id # @raise NotImplementedError - def get_checkins(project_id) + def get_check_ins(project_id) raise NotImplementedError, 'must define #get_checkins on subclass' end - # Create checkin on project + # Create check_in on project # @example - # backend.create_checkin('1234', checkin) + # backend.create_check_in('1234', check_in) # # @param [String] project_id The unique project id - # @param [Checkin] data A Checkin object encapsulating the config + # @param [CheckIn] data A CheckIn object encapsulating the config # @raise NotImplementedError - def create_checkin(project_id, data) - raise NotImplementedError, 'must define #create_checkin on subclass' + def create_check_in(project_id, data) + raise NotImplementedError, 'must define #create_check_in on subclass' end - # Update checkin on project + # Update check_in on project # @example - # backend.update_checkin('1234', 'eajaj', checkin) + # backend.update_check_in('1234', 'eajaj', check_in) # # @param [String] project_id The unique project id # @param [String] id The unique check_in id - # @param [Checkin] data A Checkin object encapsulating the config + # @param [CheckIn] data A CheckIn object encapsulating the config # @raise NotImplementedError - def update_checkin(project_id, id, data) - raise NotImplementedError, 'must define #update_checkin on subclass' + def update_check_in(project_id, id, data) + raise NotImplementedError, 'must define #update_check_in on subclass' end - # Delete checkin + # Delete check_in # @example - # backend.delete_checkin('1234', 'eajaj') + # backend.delete_check_in('1234', 'eajaj') # # @param [String] project_id The unique project id # @param [String] id The unique check_in id # @raise NotImplementedError - def delete_checkin(project_id, id) - raise NotImplementedError, 'must define #delete_checkin on subclass' + def delete_check_in(project_id, id) + raise NotImplementedError, 'must define #delete_check_in on subclass' end private diff --git a/lib/honeybadger/backend/server.rb b/lib/honeybadger/backend/server.rb index 182a1887..93f86ea4 100644 --- a/lib/honeybadger/backend/server.rb +++ b/lib/honeybadger/backend/server.rb @@ -16,12 +16,11 @@ class Server < Base CHECK_IN_ENDPOINT = '/v1/check_in'.freeze - HTTP_ERRORS = Util::HTTP::ERRORS def initialize(config) @http = Util::HTTP.new(config) - # for checkin config sync + # for check_in config sync @personal_auth_token = config.get(:personal_auth_token) super end @@ -52,93 +51,93 @@ def check_in(id) # - ##### Checkin Crud methods + ##### CheckIn Crud methods # - # Get checkin by id + # Get check_in by id # @example - # backend.get_checkin('1234', 'ajdja") + # backend.get_check_in('1234', 'ajdja") # # @param [String] project_id The unique project id # @param [String] id The unique check_in id - # @returns [Checkin] or nil if checkin is not found - # @raises CheckinSyncError on error + # @returns [CheckIn] or nil if check_in is not found + # @raises CheckInSyncError on error - def get_checkin(project_id, id) + def get_check_in(project_id, id) response = Response.new(@http.get("/v2/projects/#{project_id}/check_ins/#{id}", personal_auth_headers)) if response.success? - return Checkin.from_remote(project_id, JSON.parse(response.body)) + return CheckIn.from_remote(project_id, JSON.parse(response.body)) else if response.code == 404 return nil end end - raise CheckinSyncError.new "Fetching Checkin failed (Code: #{response.code}) #{response.body}" + raise CheckInSyncError.new "Fetching CheckIn failed (Code: #{response.code}) #{response.body}" end - # Get checkins by project + # Get check_ins by project # @example - # backend.get_checkins('1234') + # backend.get_check_ins('1234') # # @param [String] project_id The unique project id - # @returns [Array] All checkins for this project - # @raises CheckinSyncError on error - def get_checkins(project_id) + # @returns [Array] All checkins for this project + # @raises CheckInSyncError on error + def get_check_ins(project_id) response = Response.new(@http.get("/v2/projects/#{project_id}/check_ins", personal_auth_headers)) if response.success? - all_checkins = JSON.parse(response.body)["results"] - return all_checkins.map{|cfg| Checkin.from_remote(project_id, cfg) } + all_check_ins = JSON.parse(response.body)["results"] + return all_check_ins.map{|cfg| CheckIn.from_remote(project_id, cfg) } end - raise CheckinSyncError.new "Fetching Checkins failed (Code: #{response.code}) #{response.body}" + raise CheckInSyncError.new "Fetching CheckIns failed (Code: #{response.code}) #{response.body}" end - # Create checkin on project + # Create check_in on project # @example - # backend.create_checkin('1234', checkin) + # backend.create_check_in('1234', check_in) # # @param [String] project_id The unique project id - # @param [Checkin] data A Checkin object encapsulating the config - # @returns [Checkin] A checkin object containing the id - # @raises CheckinSyncError on error - def create_checkin(project_id, data) - response = Response.new(@http.post("/v2/projects/#{project_id}/check_ins", data.to_json, personal_auth_headers)) + # @param [CheckIn] check_in_config A CheckIn object encapsulating the config + # @returns [CheckIn] A CheckIn object additionally containing the id + # @raises CheckInSyncError on error + def create_check_in(project_id, check_in_config) + response = Response.new(@http.post("/v2/projects/#{project_id}/check_ins", check_in_config.to_json, personal_auth_headers)) if response.success? - return Checkin.from_remote(project_id, JSON.parse(response.body)) + return CheckIn.from_remote(project_id, JSON.parse(response.body)) end - raise CheckinSyncError.new "Creating Checkin failed (Code: #{response.code}) #{response.body}" + raise CheckInSyncError.new "Creating CheckIn failed (Code: #{response.code}) #{response.body}" end - # Update checkin on project + # Update check_in on project # @example - # backend.update_checkin('1234', 'eajaj', checkin) + # backend.update_check_in('1234', 'eajaj', check_in) # # @param [String] project_id The unique project id # @param [String] id The unique check_in id - # @param [Checkin] data A Checkin object encapsulating the config - # @returns [Checkin] updated Checkin object - # @raises CheckinSyncError on error - def update_checkin(project_id, id, data) - response = Response.new(@http.put("/v2/projects/#{project_id}/check_ins/#{id}", data.to_json, personal_auth_headers)) + # @param [CheckIn] check_in_config A CheckIn object encapsulating the config + # @returns [CheckIn] updated CheckIn object + # @raises CheckInSyncError on error + def update_check_in(project_id, id, check_in_config) + response = Response.new(@http.put("/v2/projects/#{project_id}/check_ins/#{id}", check_in_config.to_json, personal_auth_headers)) if response.success? - return Checkin.from_remote(project_id, JSON.parse(response.body)) + return CheckIn.from_remote(project_id, JSON.parse(response.body)) end - raise CheckinSyncError.new "Updating Checkin failed (Code: #{response.code}) #{response.body}" + raise CheckInSyncError.new "Updating CheckIn failed (Code: #{response.code}) #{response.body}" end - # Delete checkin + # Delete check_in # @example - # backend.delete_checkin('1234', 'eajaj') + # backend.delete_check_in('1234', 'eajaj') # # @param [String] project_id The unique project id # @param [String] id The unique check_in id # @returns [Boolean] true if deletion was successful - # @raises CheckinSyncError on error - def delete_checkin(project_id, id) + # @raises CheckInSyncError on error + def delete_check_in(project_id, id) response = Response.new(@http.delete("/v2/projects/#{project_id}/check_ins/#{id}", personal_auth_headers)) if response.success? return true end - raise CheckinSyncError.new "Deleting Checkin failed (Code: #{response.code}) #{response.body}" + raise CheckInSyncError.new "Deleting CheckIn failed (Code: #{response.code}) #{response.body}" end private diff --git a/lib/honeybadger/backend/test.rb b/lib/honeybadger/backend/test.rb index e3911d70..da561616 100644 --- a/lib/honeybadger/backend/test.rb +++ b/lib/honeybadger/backend/test.rb @@ -42,102 +42,102 @@ def check_in(id) super end - def self.checkin_configs - @checkin_configs ||= {} + def self.check_in_configs + @check_in_configs ||= {} end - def checkin_configs - self.class.checkin_configs + def check_in_configs + self.class.check_in_configs end - # Set checkin by id, only for use in tests + # Set check_in by id, only for use in tests # @example - # backend.set_checkin('1234', 'ajdja', checkin) + # backend.set_checkin('1234', 'ajdja', check_in) # # @param [String] project_id The unique project id # @param [String] id The unique check_in id - # @param [Checkin] data Checkin object with config + # @param [CheckIn] data CheckIn object with config def set_checkin(project_id, id, data) - self.checkin_configs[project_id] = self.checkin_configs[project_id] || {} - self.checkin_configs[project_id][id] = data + self.check_in_configs[project_id] = self.check_in_configs[project_id] || {} + self.check_in_configs[project_id][id] = data end - # Get checkin by id + # Get check_in by id # @example - # backend.get_checkin('1234', 'ajdja") + # backend.get_check_in('1234', 'ajdja") # # @param [String] project_id The unique project id # @param [String] id The unique check_in id - # @returns [Checkin] or nil if checkin is not found - def get_checkin(project_id, id) - self.checkin_configs ||= {} - self.checkin_configs[project_id]&.[](id) + # @returns [CheckIn] or nil if check_in is not found + def get_check_in(project_id, id) + self.check_in_configs ||= {} + self.check_in_configs[project_id]&.[](id) end # Get checkins by project # @example - # backend.get_checkins('1234') + # backend.get_check_ins('1234') # # @param [String] project_id The unique project id - # @returns [Array] All checkins for this project - def get_checkins(project_id) - self.checkin_configs ||= {} - self.checkin_configs[project_id] = self.checkin_configs[project_id] || {} - return [] if self.checkin_configs[project_id].empty? - self.checkin_configs[project_id].values + # @returns [Array] All checkins for this project + def get_check_ins(project_id) + self.check_in_configs ||= {} + self.check_in_configs[project_id] = self.check_in_configs[project_id] || {} + return [] if self.check_in_configs[project_id].empty? + self.check_in_configs[project_id].values end - # Create checkin on project + # Create check_in on project # @example - # backend.create_checkin('1234', checkin) + # backend.create_check_in('1234', check_in) # # @param [String] project_id The unique project id - # @param [Checkin] data A Checkin object encapsulating the config - # @returns [Checkin] A checkin object containing the id - def create_checkin(project_id, data) - self.checkin_configs ||= {} - self.checkin_configs[project_id] = self.checkin_configs[project_id] || {} - id = self.checkin_configs[project_id].length + 1 + # @param [CheckIn] data A CheckIn object encapsulating the config + # @returns [CheckIn] A check_in object containing the id + def create_check_in(project_id, data) + self.check_in_configs ||= {} + self.check_in_configs[project_id] = self.check_in_configs[project_id] || {} + id = self.check_in_configs[project_id].length + 1 loop do - break unless self.checkin_configs[project_id].has_key?(id) + break unless self.check_in_configs[project_id].has_key?(id) id += 1 end id = id.to_s data.id = id - self.checkin_configs[project_id][id] = data + self.check_in_configs[project_id][id] = data data end - # Update checkin on project + # Update check_in on project # @example - # backend.update_checkin('1234', 'eajaj', checkin) + # backend.update_check_in('1234', 'eajaj', check_in) # # @param [String] project_id The unique project id # @param [String] id The unique check_in id - # @param [Checkin] data A Checkin object encapsulating the config - # @returns [Checkin] updated Checkin object - def update_checkin(project_id, id, data) - self.checkin_configs ||= {} - if self.checkin_configs[project_id]&.[](id) - self.checkin_configs[project_id][id] = data + # @param [CheckIn] data A CheckIn object encapsulating the config + # @returns [CheckIn] updated CheckIn object + def update_check_in(project_id, id, data) + self.check_in_configs ||= {} + if self.check_in_configs[project_id]&.[](id) + self.check_in_configs[project_id][id] = data return data else raise "Update failed" end end - # Delete checkin + # Delete check_in # @example - # backend.delete_checkin('1234', 'eajaj') + # backend.delete_check_in('1234', 'eajaj') # # @param [String] project_id The unique project id # @param [String] id The unique check_in id # @returns [Boolean] true if deletion was successful - # @raises CheckinSyncError on error - def delete_checkin(project_id, id) - self.checkin_configs ||= {} - if self.checkin_configs[project_id]&.[](id) - self.checkin_configs[project_id].delete(id) + # @raises CheckInSyncError on error + def delete_check_in(project_id, id) + self.check_in_configs ||= {} + if self.check_in_configs[project_id]&.[](id) + self.check_in_configs[project_id].delete(id) else raise "Delete failed" end diff --git a/lib/honeybadger/checkin.rb b/lib/honeybadger/check_in.rb similarity index 59% rename from lib/honeybadger/checkin.rb rename to lib/honeybadger/check_in.rb index 010d27b3..fad57c1f 100644 --- a/lib/honeybadger/checkin.rb +++ b/lib/honeybadger/check_in.rb @@ -1,34 +1,34 @@ module Honeybadger class InvalidCheckinConfig < StandardError; end - class CheckinSyncError < StandardError; end + class CheckInSyncError < StandardError; end - class Checkin + class CheckIn attr_reader :project_id attr_accessor :name, :slug, :schedule_type, :report_period, :grace_period, :cron_schedule, :cron_timezone, :deleted, :id def self.from_config(config_entry) c = config_entry.transform_keys {|k| k.to_s } - checkin = self.new(c["project_id"], c["id"]) - checkin.name = c["name"] - checkin.slug = c["slug"] - checkin.schedule_type = c["schedule_type"] - checkin.report_period = c["report_period"] - checkin.grace_period = c["grace_period"] - checkin.cron_schedule = c["cron_schedule"] - checkin.cron_timezone = c["cron_timezone"] - checkin + check_in = self.new(c["project_id"], c["id"]) + check_in.name = c["name"] + check_in.slug = c["slug"] + check_in.schedule_type = c["schedule_type"] + check_in.report_period = c["report_period"] + check_in.grace_period = c["grace_period"] + check_in.cron_schedule = c["cron_schedule"] + check_in.cron_timezone = c["cron_timezone"] + check_in end def self.from_remote(project_id, data) - checkin = self.new(project_id, data["id"]) - checkin.name = data["name"] - checkin.slug = data["slug"] - checkin.schedule_type = data["schedule_type"] - checkin.report_period = data["report_period"] - checkin.grace_period = data["grace_period"] - checkin.cron_schedule = data["cron_schedule"] - checkin.cron_timezone = data["cron_timezone"] - checkin + check_in = self.new(project_id, data["id"]) + check_in.name = data["name"] + check_in.slug = data["slug"] + check_in.schedule_type = data["schedule_type"] + check_in.report_period = data["report_period"] + check_in.grace_period = data["grace_period"] + check_in.cron_schedule = data["cron_schedule"] + check_in.cron_timezone = data["cron_timezone"] + check_in end def initialize(project_id, id = nil) @@ -60,8 +60,8 @@ def blank?(str) end def validate! - raise InvalidCheckinConfig.new('project_id is required for each checkin') if blank?(project_id) - raise InvalidCheckinConfig.new('name is required for each checkin') if blank?(name) + raise InvalidCheckinConfig.new('project_id is required for each check_in') if blank?(project_id) + raise InvalidCheckinConfig.new('name is required for each check_in') if blank?(name) raise InvalidCheckinConfig.new("#{name} schedule_type must be either 'simple' or 'cron'") unless ['simple', 'cron'].include? schedule_type if schedule_type == 'simple' raise InvalidCheckinConfig.new("#{name} report_period is required for simple checkins") if blank?(report_period) @@ -70,14 +70,14 @@ def validate! end end - def update_from(checkin) - self.name = checkin.name - self.slug = checkin.slug - self.schedule_type = checkin.schedule_type - self.report_period = checkin.report_period - self.grace_period = checkin.grace_period - self.cron_schedule = checkin.cron_schedule - self.cron_timezone = checkin.cron_timezone + def update_from(check_in) + self.name = check_in.name + self.slug = check_in.slug + self.schedule_type = check_in.schedule_type + self.report_period = check_in.report_period + self.grace_period = check_in.grace_period + self.cron_schedule = check_in.cron_schedule + self.cron_timezone = check_in.cron_timezone end def deleted? diff --git a/lib/honeybadger/cli/checkins.rb b/lib/honeybadger/cli/check_ins.rb similarity index 93% rename from lib/honeybadger/cli/checkins.rb rename to lib/honeybadger/cli/check_ins.rb index 021e135d..8039a211 100644 --- a/lib/honeybadger/cli/checkins.rb +++ b/lib/honeybadger/cli/check_ins.rb @@ -19,7 +19,7 @@ def initialize(options, args, config) def run config_sync_service = ConfigSyncService.new(@config) result = config_sync_service.sync_checkins - say("Checkin config synced", :green) + say("CheckIn config synced", :green) end private diff --git a/lib/honeybadger/cli/main.rb b/lib/honeybadger/cli/main.rb index 5a81beaf..56d3a7ca 100644 --- a/lib/honeybadger/cli/main.rb +++ b/lib/honeybadger/cli/main.rb @@ -4,7 +4,7 @@ require 'honeybadger/cli/install' require 'honeybadger/cli/notify' require 'honeybadger/cli/test' -require 'honeybadger/cli/checkins' +require 'honeybadger/cli/check_ins' require 'honeybadger/config' require 'honeybadger/config/defaults' require 'honeybadger/ruby' diff --git a/lib/honeybadger/config_sync_service.rb b/lib/honeybadger/config_sync_service.rb index 79d6054e..2bb41a44 100644 --- a/lib/honeybadger/config_sync_service.rb +++ b/lib/honeybadger/config_sync_service.rb @@ -1,9 +1,9 @@ -require 'honeybadger/checkin' +require 'honeybadger/check_in' module Honeybadger class ConfigSyncService def initialize(config) @config = config - @checkins_cache = nil + @check_ins_cache = nil end def sync_checkins @@ -11,9 +11,9 @@ def sync_checkins return [] if checkin_configs.empty? checkins = checkin_configs.map do |cfg| - checkin = Checkin.from_config(cfg) - checkin.validate! - checkin + check_in = CheckIn.from_config(cfg) + check_in.validate! + check_in end created_or_updated = sync_existing_checkins(checkins) removed = sync_removed_checkins(checkins) @@ -24,25 +24,25 @@ def sync_checkins private def get_checkin_by_name(project_id, name) - @checkins_cache ||= @config.backend.get_checkins(project_id) - @checkins_cache.find {|c| c.name == name } + @check_ins_cache ||= @config.backend.get_check_ins(project_id) + @check_ins_cache.find {|c| c.name == name } end def sync_existing_checkins(checkins = []) return [] if checkins.empty? result = [] - checkins.each do |checkin| - remote_checkin = if checkin.id - @config.backend.get_checkin(checkin.project_id, checkin.id) + checkins.each do |check_in| + remote_checkin = if check_in.id + @config.backend.get_check_in(check_in.project_id, check_in.id) else - get_checkin_by_name(checkin.project_id, checkin.name) + get_checkin_by_name(check_in.project_id, check_in.name) end if remote_checkin - unless remote_checkin == checkin - result << @config.backend.update_checkin(checkin.project_id, remote_checkin.id, checkin) + unless remote_checkin == check_in + result << @config.backend.update_check_in(check_in.project_id, remote_checkin.id, check_in) end else - result << @config.backend.create_checkin(checkin.project_id, checkin) + result << @config.backend.create_check_in(check_in.project_id, check_in) end end result @@ -53,17 +53,17 @@ def sync_removed_checkins(checkins) result = [] project_ids = checkins.map{|ch| ch.project_id }.uniq project_ids.each do |prj_id| - @checkins_cache ||= @config.backend.get_checkins(prj_id) + @check_ins_cache ||= @config.backend.get_check_ins(prj_id) local_project_checkins = checkins.select {|c| c.project_id == prj_id } - to_remove = @checkins_cache.reject do |pc| + to_remove = @check_ins_cache.reject do |pc| local_project_checkins.find{|c| c.id == pc.id || c.name == pc.name } end to_remove.each do |ch| if ch.id.nil? ch = get_checkin_by_name(prj_id, ch.name) end - @config.backend.delete_checkin(prj_id, ch.id) + @config.backend.delete_check_in(prj_id, ch.id) ch.deleted = true result << ch end diff --git a/spec/features/checkins_spec.rb b/spec/features/check_ins_spec.rb similarity index 85% rename from spec/features/checkins_spec.rb rename to spec/features/check_ins_spec.rb index 32ef8684..db532722 100644 --- a/spec/features/checkins_spec.rb +++ b/spec/features/check_ins_spec.rb @@ -1,14 +1,14 @@ require 'honeybadger' -feature "Running the checkins cli command" do - scenario "sync checkins" do +feature "Running the check_ins cli command" do + scenario "sync check ins" do context "with config file" do let(:config_file_contents) { { checkins: [ { project_id: 'abcd', - name: "worker checkin", + name: "worker check in", schedule_type: "simple", report_period: "1 hour" } @@ -25,7 +25,7 @@ after { File.unlink(config_file) } - it "syncs checkin configuration" do + it "syncs check in configuration" do expect(run_command("honeybadger sync_checkins --personal-auth-token=abcd")).to be_successfully_executed end end @@ -45,7 +45,7 @@ after { File.unlink(config_file) } - it "does not sync checkin configuration if checkins are not configured in config file" do + it "does not sync check_in configuration if checkins are not configured in config file" do expect(run_command("honeybadger sync_checkins --personal-auth-token=abcd")).to_not be_successfully_executed expect(all_output).to match(/No checkins provided in config file/) end diff --git a/spec/unit/honeybadger/backend/base_spec.rb b/spec/unit/honeybadger/backend/base_spec.rb index 548706f0..eec9e33d 100644 --- a/spec/unit/honeybadger/backend/base_spec.rb +++ b/spec/unit/honeybadger/backend/base_spec.rb @@ -64,34 +64,34 @@ end end - describe "checkin API methods" do + describe "check_in API methods" do describe "#get_checkin" do it "raises NotImplementedError" do - expect { subject.get_checkin('abcd', 'efgh') }.to raise_error NotImplementedError + expect { subject.get_check_in('abcd', 'efgh') }.to raise_error NotImplementedError end end describe "#get_checkins" do it "raises NotImplementedError" do - expect { subject.get_checkins('abcd') }.to raise_error NotImplementedError + expect { subject.get_check_ins('abcd') }.to raise_error NotImplementedError end end - describe "#create_checkin" do + describe "#create_check_in" do it "raises NotImplementedError" do - expect { subject.create_checkin('abcd', {}) }.to raise_error NotImplementedError + expect { subject.create_check_in('abcd', {}) }.to raise_error NotImplementedError end end - describe "#update_checkin" do + describe "#update_check_in" do it "raises NotImplementedError" do - expect { subject.update_checkin('abcd', 'efgh', {}) }.to raise_error NotImplementedError + expect { subject.update_check_in('abcd', 'efgh', {}) }.to raise_error NotImplementedError end end - describe "#delete_checkin" do + describe "#delete_check_in" do it "raises NotImplementedError" do - expect { subject.delete_checkin('abcd', 'efgh') }.to raise_error NotImplementedError + expect { subject.delete_check_in('abcd', 'efgh') }.to raise_error NotImplementedError end end end diff --git a/spec/unit/honeybadger/backend/server_spec.rb b/spec/unit/honeybadger/backend/server_spec.rb index d3ba9268..14ed4805 100644 --- a/spec/unit/honeybadger/backend/server_spec.rb +++ b/spec/unit/honeybadger/backend/server_spec.rb @@ -89,7 +89,7 @@ def notify_backend get_one = stub_request(:get, "https://api.honeybadger.io/v2/projects/1234/check_ins/5678").to_return({ status: 200, body: { - name: "Test Checkin", + name: "Test CheckIn", slug: nil, schedule_type: "simple", report_period: "1 day", @@ -99,25 +99,25 @@ def notify_backend id: "5678" }.to_json }) - checkin = subject.get_checkin("1234", "5678") - expect(checkin).to be_a(Honeybadger::Checkin) + check_in = subject.get_check_in("1234", "5678") + expect(check_in).to be_a(Honeybadger::CheckIn) expect(get_one).to have_been_made end it "should return nil if it gets a 404" do get_one = stub_request(:get, "https://api.honeybadger.io/v2/projects/1234/check_ins/5678").to_return({status: 404}) - checkin = subject.get_checkin("1234", "5678") - expect(checkin).to be_nil + check_in = subject.get_check_in("1234", "5678") + expect(check_in).to be_nil expect(get_one).to have_been_made end end - + describe "#get_checkins" do it "should return an array of check ins" do get_all = stub_request(:get, "https://api.honeybadger.io/v2/projects/1234/check_ins").to_return({ status: 200, body: {results: [{ - name: "Test Checkin", + name: "Test CheckIn", slug: nil, schedule_type: "simple", report_period: "1 day", @@ -127,20 +127,20 @@ def notify_backend id: "5678" }]}.to_json }) - checkins = subject.get_checkins("1234") + checkins = subject.get_check_ins("1234") expect(checkins).to be_a(Array) expect(checkins.length).to eq(1) - expect(checkins.first).to be_a(Honeybadger::Checkin) + expect(checkins.first).to be_a(Honeybadger::CheckIn) expect(get_all).to have_been_made end end - describe "#create_checkin" do - it "should return checkin" do + describe "#create_check_in" do + it "should return check_in" do post_one = stub_request(:post, "https://api.honeybadger.io/v2/projects/1234/check_ins").to_return({ status: 200, body: { - name: "Test Checkin", + name: "Test CheckIn", slug: nil, schedule_type: "simple", report_period: "1 day", @@ -150,24 +150,24 @@ def notify_backend id: "5678" }.to_json }) - checkin = Honeybadger::Checkin.from_config({ - name: "Test Checkin", + check_in = Honeybadger::CheckIn.from_config({ + name: "Test CheckIn", schedule_type: "simple", report_period: "1 day", grace_period: "3 hours" }) - result = subject.create_checkin("1234", checkin) - expect(result).to be_a(Honeybadger::Checkin) + result = subject.create_check_in("1234", check_in) + expect(result).to be_a(Honeybadger::CheckIn) expect(post_one).to have_been_made end end - describe "#update_checkin" do - it "should return checkin" do + describe "#update_check_in" do + it "should return check_in" do put_one = stub_request(:put, "https://api.honeybadger.io/v2/projects/1234/check_ins/5678").to_return({ status: 200, body: { - name: "Test Checkin", + name: "Test CheckIn", slug: nil, schedule_type: "simple", report_period: "2 days", @@ -177,22 +177,22 @@ def notify_backend id: "5678" }.to_json }) - checkin = Honeybadger::Checkin.from_config({ - name: "Test Checkin", + check_in = Honeybadger::CheckIn.from_config({ + name: "Test CheckIn", schedule_type: "simple", report_period: "2 days", grace_period: "3 hours" }) - result = subject.update_checkin("1234", "5678", checkin) - expect(result).to be_a(Honeybadger::Checkin) + result = subject.update_check_in("1234", "5678", check_in) + expect(result).to be_a(Honeybadger::CheckIn) expect(put_one).to have_been_made end end - describe "#delete_checkin" do + describe "#delete_check_in" do it "should accept a delete" do delete_one = stub_request(:delete, "https://api.honeybadger.io/v2/projects/1234/check_ins/5678").to_return(status: 200) - result = subject.delete_checkin("1234", "5678") + result = subject.delete_check_in("1234", "5678") expect(result).to be_truthy expect(delete_one).to have_been_made end diff --git a/spec/unit/honeybadger/backend/test_spec.rb b/spec/unit/honeybadger/backend/test_spec.rb index 2af63b48..026b38a4 100644 --- a/spec/unit/honeybadger/backend/test_spec.rb +++ b/spec/unit/honeybadger/backend/test_spec.rb @@ -1,6 +1,6 @@ require 'honeybadger/backend/test' require 'honeybadger/config' -require 'honeybadger/checkin' +require 'honeybadger/check_in' describe Honeybadger::Backend::Test do @@ -48,107 +48,107 @@ end end - context "checkin sync crud methods" do + context "check_in sync crud methods" do before do - Honeybadger::Backend::Test.checkin_configs.clear + Honeybadger::Backend::Test.check_in_configs.clear end describe "#set_checkin" do it "should set object on class" do - checkin = Honeybadger::Checkin.from_config({ + check_in = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "1 hour" }) - subject.set_checkin("1234", "5678", checkin) - expect(subject.checkin_configs["1234"]["5678"]).to eq(checkin) + subject.set_checkin("1234", "5678", check_in) + expect(subject.check_in_configs["1234"]["5678"]).to eq(check_in) end end describe "#get_checkin" do - it "should return nil if checkin does not exist" do - expect(subject.get_checkin("1234", "5678")).to be_nil + it "should return nil if check_in does not exist" do + expect(subject.get_check_in("1234", "5678")).to be_nil end - it "should return checkin if it exists" do - checkin = Honeybadger::Checkin.from_config({ + it "should return check_in if it exists" do + check_in = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "1 hour" }) - subject.set_checkin("1234", "5678", checkin) - expect(subject.get_checkin("1234", "5678")).to eq(checkin) + subject.set_checkin("1234", "5678", check_in) + expect(subject.get_check_in("1234", "5678")).to eq(check_in) end end describe "#get_checkins" do - it "should return empty array if no checkin exists" do - expect(subject.get_checkins("1234")).to be_empty + it "should return empty array if no check_in exists" do + expect(subject.get_check_ins("1234")).to be_empty end - it "should return array if checkin exists" do - checkin = Honeybadger::Checkin.from_config({ + it "should return array if check_in exists" do + check_in = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "1 hour" }) - subject.set_checkin("1234", "5678", checkin) - expect(subject.get_checkins("1234").first).to eq(checkin) + subject.set_checkin("1234", "5678", check_in) + expect(subject.get_check_ins("1234").first).to eq(check_in) end end - describe "#create_checkin" do - it "should create checkin and return it" do - checkin = Honeybadger::Checkin.from_config({ + describe "#create_check_in" do + it "should create check_in and return it" do + check_in = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "1 hour" }) - created = subject.create_checkin("1234", checkin) + created = subject.create_check_in("1234", check_in) expect(created.id).to_not be_nil - expect(subject.checkin_configs["1234"][created.id]).to_not be_nil + expect(subject.check_in_configs["1234"][created.id]).to_not be_nil end end - describe "#update_checkin" do - it "should update checkin and return it" do - checkin = Honeybadger::Checkin.from_config({ + describe "#update_check_in" do + it "should update check_in and return it" do + check_in = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "1 hour" }) - checkin_update = Honeybadger::Checkin.from_config({ + checkin_update = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "2 hours" }) - subject.set_checkin("1234", "5678", checkin) - updated = subject.update_checkin("1234", "5678", checkin_update) + subject.set_checkin("1234", "5678", check_in) + updated = subject.update_check_in("1234", "5678", checkin_update) expect(updated.report_period).to eq("2 hours") - expect(subject.checkin_configs["1234"]["5678"].report_period).to eq("2 hours") + expect(subject.check_in_configs["1234"]["5678"].report_period).to eq("2 hours") end end - describe "#delete_checkin" do - it "should update checkin and return it" do - checkin = Honeybadger::Checkin.from_config({ + describe "#delete_check_in" do + it "should update check_in and return it" do + check_in = Honeybadger::CheckIn.from_config({ project_id: "1234", - name: "Test checkin", + name: "Test check_in", schedule_type: "simple", report_period: "1 hour" }) - subject.set_checkin("1234", "5678", checkin) - expect(subject.checkin_configs["1234"]["5678"]).to_not be_nil + subject.set_checkin("1234", "5678", check_in) + expect(subject.check_in_configs["1234"]["5678"]).to_not be_nil - expect(subject.delete_checkin("1234", "5678")).to be_truthy - expect(subject.checkin_configs["1234"]["5678"]).to be_nil + expect(subject.delete_check_in("1234", "5678")).to be_truthy + expect(subject.check_in_configs["1234"]["5678"]).to be_nil end end end diff --git a/spec/unit/honeybadger/config_sync_service_spec.rb b/spec/unit/honeybadger/config_sync_service_spec.rb index bbf49a16..d00a2bbd 100644 --- a/spec/unit/honeybadger/config_sync_service_spec.rb +++ b/spec/unit/honeybadger/config_sync_service_spec.rb @@ -2,7 +2,7 @@ require 'honeybadger/backend/server' require 'honeybadger/config' require 'honeybadger/config_sync_service' -require 'honeybadger/checkin' +require 'honeybadger/check_in' describe Honeybadger::ConfigSyncService do let(:config) { Honeybadger::Config.new(logger: NULL_LOGGER, api_key: 'abc123', backend: 'test') } @@ -10,10 +10,10 @@ subject { described_class.new(config) } - context "sync checkin configs" do + context "sync check_in configs" do before { - config.backend.checkin_configs.clear + config.backend.check_in_configs.clear } it "syncs with empty array" do @@ -22,34 +22,34 @@ expect(result).to be_empty end - it "syncs with good checkin by id, unchanged" do - config.set(:checkins, [{project_id: '1234', id: '5678', name: 'Main Web App Checkin', schedule_type: 'simple', report_period: '1 hour'}]) - config.backend.set_checkin("1234", "5678", Honeybadger::Checkin.from_config({ + it "syncs with good check_in by id, unchanged" do + config.set(:checkins, [{project_id: '1234', id: '5678', name: 'Main Web App CheckIn', schedule_type: 'simple', report_period: '1 hour'}]) + config.backend.set_checkin("1234", "5678", Honeybadger::CheckIn.from_config({ project_id: "1234", id: "5678", - name: "Main Web App Checkin", schedule_type: "simple", report_period: "1 hour", + name: "Main Web App CheckIn", schedule_type: "simple", report_period: "1 hour", })) result = subject.sync_checkins expect(result).to be_empty end - it "syncs with good checkin by name, unchanged" do - config.set(:checkins, [{project_id: '1234', name: 'Main Web App Checkin', schedule_type: 'simple', report_period: '1 hour'}]) - config.backend.set_checkin("1234", "5678", Honeybadger::Checkin.from_config({ + it "syncs with good check_in by name, unchanged" do + config.set(:checkins, [{project_id: '1234', name: 'Main Web App CheckIn', schedule_type: 'simple', report_period: '1 hour'}]) + config.backend.set_checkin("1234", "5678", Honeybadger::CheckIn.from_config({ project_id: "1234", id: "5678", - name: "Main Web App Checkin", slug: nil, schedule_type: "simple", report_period: "1 hour", + name: "Main Web App CheckIn", slug: nil, schedule_type: "simple", report_period: "1 hour", })) result = subject.sync_checkins expect(result).to be_empty end - it "syncs with good checkin by id, with changes" do - config.set(:checkins, [{project_id: '1234', id: '5678', name: 'Main Web App Checkin', schedule_type: 'simple', report_period: '2 hours'}]) - config.backend.set_checkin("1234", "5678", Honeybadger::Checkin.from_config({ + it "syncs with good check_in by id, with changes" do + config.set(:checkins, [{project_id: '1234', id: '5678', name: 'Main Web App CheckIn', schedule_type: 'simple', report_period: '2 hours'}]) + config.backend.set_checkin("1234", "5678", Honeybadger::CheckIn.from_config({ project_id: "1234", id: "5678", - name: "Main Web App Checkin", slug: nil, schedule_type: "simple", report_period: "1 hour", + name: "Main Web App CheckIn", slug: nil, schedule_type: "simple", report_period: "1 hour", })) result = subject.sync_checkins @@ -57,8 +57,8 @@ expect(result.first.id).to eq("5678") end - it "syncs with new checkin" do - new_project = {project_id: '1234', name: 'Main Web App Checkin', schedule_type: 'simple', report_period: '1 hour'} + it "syncs with new check_in" do + new_project = {project_id: '1234', name: 'Main Web App CheckIn', schedule_type: 'simple', report_period: '1 hour'} config.set(:checkins, [new_project]) result = subject.sync_checkins @@ -68,13 +68,13 @@ end it "syncs with removed checkins" do - config.set(:checkins, [{project_id: '1234', id: "5678", name: 'Main Web App Checkin', schedule_type: 'simple', report_period: '1 hour'}]) - config.backend.set_checkin("1234", "5678", Honeybadger::Checkin.from_config({ + config.set(:checkins, [{project_id: '1234', id: "5678", name: 'Main Web App CheckIn', schedule_type: 'simple', report_period: '1 hour'}]) + config.backend.set_checkin("1234", "5678", Honeybadger::CheckIn.from_config({ project_id: "1234", id: "5678", - name: "Main Web App Checkin", slug: nil, schedule_type: "simple", report_period: "1 hour", + name: "Main Web App CheckIn", slug: nil, schedule_type: "simple", report_period: "1 hour", })) - config.backend.set_checkin("1234", "dele", Honeybadger::Checkin.from_config({ + config.backend.set_checkin("1234", "dele", Honeybadger::CheckIn.from_config({ project_id: "1234", id: "dele", name: "to be deleted", slug: nil, schedule_type: "simple", report_period: "1 hour",