View shock.rb
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 |
View ajax.js
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 = |
View vcr_setup.rb
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, |
View mock_clock.js
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 () { |
View a_foreign_key_constraint_association.rb
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 |
View names_for_let_object.rb
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 |
View results.txt
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: "user1@example.com", ...a bunch of attributes...>] | |
actual collection contained: [#<User id: 1, email: "user1@example.com", ...a bunch of attributes...>, | |
#<User id: 2, email: "user2@example.com", ...a bunch of attributes...>] |
View car.rb
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 |
View spec_example.rb
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 |
View original.rb
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
describe Sweeper do | |
context 'a subscription is expired' do | |
let(:bob) { double(active?: true, paid_at: 2.months.ago) } | |
let(:users) { [bob] } | |
before { allow(User).to receive(:all).and_return(users) } | |
it 'emails the user' do | |
expect(UserMailer).to receive(:billing_problem).with(bob) | |
described_class.sweep | |
end |