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
# IO#read should return a string with ASCII-8BIT encoding | |
# http://www.ruby-doc.org/core-2.1.1/IO.html#method-i-read | |
irb(main):001:0> RUBY_VERSION | |
=> "2.1.1" | |
irb(main):002:0> File.write('test', 'abcdefg') | |
=> 7 | |
irb(main):003:0> File.read('test').encoding | |
=> #<Encoding:UTF-8> |
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
# Always logs to passed-in logger | |
# Logs to $stderr when in console | |
class TeeLogger | |
def initialize(ruby_logger) | |
@logger = ruby_logger | |
end | |
private | |
def logger |
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
= simple_form_for [:admin, @basic_po], as: :purchase_order, | |
url: basic_po_admin_purchase_orders_path, | |
html: { class: 'form-horizontal' } do |f| | |
.form_controls | |
= f.input :vendor_id, label: 'Vendor Id', placeholder: '3231' | |
= f.input :brand_title, as: :select, label: 'Brand', | |
collection: UpcMaster.all_brand_titles | |
= f.input :terms, as: :select, label: 'Terms', | |
collection: Erp::PurchaseOrder::PO_TERMS.to_a |
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
# spec: | |
it "calls TrackShipment#track_delivery for the PurchaseReturnShipment" do | |
track_shipment = instance_double('Ops::Returns::TrackShipment') | |
expect(track_shipment).to receive(:foo) | |
track_shipment_class = class_double('Ops::Returns::TrackShipment').as_stubbed_const | |
expect(track_shipment_class).to receive(:new).with(prs).and_return(track_shipment) | |
tracker.detect_events | |
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
# Spec: | |
it "calls TrackShipment#track_delivery for the PurchaseReturnShipment" do | |
track_shipment_class = class_double('Ops::Returns::TrackShipment').as_stubbed_const | |
expect(track_shipment_class).to receive(:foo).with(prs) | |
tracker.detect_events | |
end | |
# Code under test | |
class Ops::Returns::TrackBatchShipments |
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
# Ruby VIPS Memory Test | |
# Instructions: `bundle exec ruby memory_test3.rb` | |
require 'vips' | |
def mem_usage | |
`ps -o rss -p #{$$}`.strip.split.last.to_i | |
end | |
include VIPS |
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
# Instructions: `bundle exec ruby memory_test2.rb` | |
# Variations: | |
# 1. `include CarrierWave::Vips` (default) | |
# 2. `include CarrierWave::MiniMagic` - first need to disable 'newrelic-carrierwave' gem | |
require 'carrierwave' | |
require 'carrierwave-vips' | |
# Memory test 2 |
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
# require 'spec_helper' | |
class InMemoryArel | |
attr_accessor :collection | |
def initialize(collection) | |
self.collection = collection | |
end | |
def all |
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
househappy_test=# create table my_nulls (id integer not null, first_name character varying(255) default 'foo', last_name character varying(255) default 'bar'); | |
CREATE TABLE | |
househappy_test=# create sequence my_nulls_id_seq start with 1 increment by 1 no minvalue no maxvalue cache 1; | |
CREATE SEQUENCE | |
househappy_test=# alter table only my_nulls alter column id set default nextval('my_nulls_id_seq'::regclass); | |
ALTER TABLE | |
househappy_test=# insert into my_nulls (first_name) values (null); | |
INSERT 0 1 | |
househappy_test=# select * from my_nulls where first_name is null; | |
id | first_name | last_name |
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
[1] website » class MyNull < ActiveRecord::Base | |
» end | |
=> nil | |
[2] website » my_null = MyNull.new | |
=> #<MyNull:0x007fc89cedd430> { | |
:id => nil, | |
:first_name => "foo", | |
:last_name => "bar" | |
} | |
[3] website » my_null.save! |