This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shock_cost_class_map = { | |
front: FrontShockCost, | |
lefty: LeftyShockCost, | |
rear: RearSHockCost, | |
} | |
shock_cost_class = shock_cost_class_map.fetch(type, ShockCost) | |
shock_cost_class.new.compute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://www.youtube.com/watch?v=f5I1iyso29U&t=23m44s | |
class Shock | |
def cost(type) | |
case type | |
when :front | |
FrontShockCost.new.compute | |
when :rear | |
RearShockCost.new.compute | |
when :lefty | |
LeftyShockCost.new.compute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.testHelpers.stubAjaxRequestWithData = function (requestURL, data, status) { | |
jasmine.Ajax.stubRequest(requestURL) | |
.andReturn({ | |
status: status, | |
responseText: data, | |
contentType: 'text/html', | |
}); | |
}; | |
App.testHelpers.stubSuccessfulAjaxRequestWithData = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require('vcr') | |
VCR.configure do |config| | |
config.cassette_library_dir = 'spec/cassettes' | |
config.hook_into :webmock | |
config.configure_rspec_metadata! | |
config.ignore_localhost = true | |
# Don't change this here! Instead, to record an initial cassette, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
beforeEach(function () { | |
jasmine.clock().install(); | |
jasmine.clock().mockDate( | |
new Date(2015, 4, 20) | |
); | |
}); | |
afterEach(function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.shared_examples('a foreign_key constraint association') do | |
specify do | |
expect do | |
build(described_model, "#{association}_id" => 0).save(validate: false) | |
end.to raise_error(ActiveRecord::InvalidForeignKey) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NamesForLetObject | |
def names_for_let_objects(objects) | |
objects.map { |object| name_for_let_object(object) } | |
end | |
def name_for_let_object(object) | |
__memoized.instance_variable_get(:@memoized).key(object) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expected collection contained: [#<User id: 1, email: "[email protected]", ...a bunch of attributes...>] | |
actual collection contained: [#<User id: 1, email: "[email protected]", ...a bunch of attributes...>, | |
#<User id: 2, email: "[email protected]", ...a bunch of attributes...>] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car < ActiveRecord::Base | |
attr_accessor(:skip_association_presence_validations) | |
validates(:driver, presence: true, unless: :skip_association_presence_validations) | |
# creates driver_license_number method | |
delegate(:license_number, to: :driver, prefix: true) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('uses the client time zone') do | |
allow(described_class).to receive(:delete_cache) do | |
fail unless Time.zone == client_time_zone | |
end | |
allow(described_class).to receive(:create_cache) do | |
fail unless Time.zone == client_time_zone | |
end | |
update_for_year | |
end |