Skip to content

Instantly share code, notes, and snippets.

View Bartuz's full-sized avatar
⛑️

Filip Bartuzi Bartuz

⛑️
View GitHub Profile
class NestedAttributesForStrategy
def association(runner)
runner.run
end
def result(evaluation)
evaluation.object.tap do |instance|
evaluation.notify(:after_build, instance)
return attributes(instance)
end
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@Bartuz
Bartuz / .vimrc
Last active August 29, 2015 14:06 — forked from jandudulski/.vimrc
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
endif

its isn't core to RSpec. One the of the focuses of RSpec is on the documentation aspects of tests. Unfortunately, its often leads to documentation output that is essentially lies. Consider this spec:

User = Struct.new(:name, :email)

describe User do
  subject { User.new("bob") }
  its(:name) { should == "bob" }
end
@Bartuz
Bartuz / file.rb
Created September 19, 2014 11:59
Ruby: Compare 2 hashes
class Hash
def diff(other)
(self.keys + other.keys).uniq.inject({}) do |memo, key|
unless self[key] == other[key]
if self[key].kind_of?(Hash) && other[key].kind_of?(Hash)
memo[key] = self[key].diff(other[key])
else
memo[key] = [self[key], other[key]]
end
end
@Bartuz
Bartuz / global-hook
Last active August 29, 2015 14:06 — forked from proapi/gitconfig
1. Enable git templates:
git config --global init.templatedir '~/.git-templates'
This tells git to copy everything in ~/.git-templates to your per-project .git/ directory when you run git init
2. Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
3. Write your hooks in ~/.git-templates/hooks
4. Make sure the hook is executable.
@Bartuz
Bartuz / application_controller_spec.rb
Created October 23, 2015 16:37
before/after filters/actions rspec testing. Credits to: http://stackoverflow.com/a/20776916/2047418
# spec/controllers/application_controller_spec.rb
require 'spec_helper'
describe ApplicationController do
describe 'class' do
it { has_before_filters(:authenticate_user) }
end
end
@Bartuz
Bartuz / alias_matchers.md
Created November 9, 2015 11:29 — forked from JunichiIto/alias_matchers.md
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@Bartuz
Bartuz / Plea.markdown
Created November 11, 2015 09:52 — forked from justinko/Plea.markdown
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this: