Skip to content

Instantly share code, notes, and snippets.

Augusts Bautra Epigene

Block or report user

Report or block Epigene

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Epigene / bout4.rb
Created Oct 14, 2017
Build VS create
View bout4.rb
describe " VS FactoryGirl.create" do
subject {! }
bout4_number_of = 200
context "when setting up with" do
let(:book) { build(:book) }
bout4_number_of.times do
it "triggers ApplicationRecord.class in callback" do
Epigene / book.rb
Created Oct 14, 2017
Matching author and publisher names?
View book.rb
def with_characteristics?(characteristics_hash) == characteristics_hash[:author_name] && == characteristics_hash[:publisher_name]
Epigene / bout3.rb
Created Oct 14, 2017
FC.build_stubbed vs other FC strategies
View bout3.rb
describe "FactoryGirl.build_stubbed VS [, FactoryGirl.create]" do
subject { book.with_characteristics?(options) }
let(:options) { {author_name:, publisher_name:} }
bout3_number_of = 200
context "when setting up with FactoryGirl.build_stubbed" do
let(:book) { build_stubbed(:book) }
Epigene / bout2.rb
Created Oct 14, 2017
#build_stubbed vs FactoryGirl strategies
View bout2.rb
describe "#instance_double VS FactoryGirl.build_stubbed,, and FactoryGirl.create" do
subject { book.by_bce_autor? }
bout2_number_of = 200
context "when setting up with #instance_double" do
let(:book) { build_stubbed(:book) }
let(:author) { instance_double("Author", bce?: true) }
before { allow(book).to receive(:author).and_return(author) }
Epigene / book.rb
Created Oct 14, 2017
Ancient author?
View book.rb
def by_bce_autor?
Epigene / bout1.rb
Created Oct 14, 2017
#new VS all other setup strategies
View bout1.rb
describe "#new VS all others when testing Book#vampire_title?" do
subject { book.vampire_title? }
bout1_number_of = 200
context "when setting up with #new" do
bout1_number_of.times do
let(:book) { "Vampire Literature, a Historical Perspective") }
it { eq(true) }
Epigene / book.rb
Created Oct 14, 2017
Book about vampires?
View book.rb
def vampire_title?
View Pure SQL.rb
# from
# Uses LEFT JOIN to join the posts table with itself in a clever manner - on id AND the relevant, :created_at row.
# The check on created_at makes it so that the last records have NULLs in t2 rows, so we use WHERE to select those and done.
scope :users_last_posts, -> {
query = <<~HEREDOC
FROM post t1
ON t1.author_id = t2.author_id AND
View the ok.rb
last_post_ids ="MAX(id) AS last_post_id").group(:user_id)
last_posts = Post.where(id: last_post_ids).order(created_at: :desc)
View get a query object.rb
last_post_ids = []
User.where(id: Post.all.distinct.pluck(:user_id)).find_each |user|
last_post_ids << user.posts.order(created_at: :desc).limit(1).pluck(:id).last
last_posts = Post.where(id: last_post_ids).order(created_at: :desc)
You can’t perform that action at this time.