Skip to content

Instantly share code, notes, and snippets.

View thatrubylove's full-sized avatar

Jim OKelly thatrubylove

View GitHub Profile
@thatrubylove
thatrubylove / example-9.rb
Created April 16, 2014 05:08
a-faux-o-deck-of-cards-example-9
blackjack_deck = Deck.new(8)
poker_deck = Deck.new
@thatrubylove
thatrubylove / example-1.rb
Created April 17, 2014 20:21
an-exercise-in-refactoring-large-methods-in-ruby-2
...
def update
if (params[:user][:password].blank? && params[:user][:password_confirmation].blank?)
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
if params[:user][:photo_attributes]
Photos::Manipulation.update_resource_photo(current_user.photo || Photo, params[:user][:photo_attributes], current_user)
current_user.photo.try(:reload)
@thatrubylove
thatrubylove / example-2.rb
Created April 17, 2014 20:22
an-exercise-in-refactoring-large-methods-in-ruby-2-example-2
if (params[:user][:password].blank? && params[:user][:password_confirmation].blank?)
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
@thatrubylove
thatrubylove / example-3.rb
Created April 17, 2014 20:23
an-exercise-in-refactoring-large-methods-in-ruby-2-example-3
module UserPasswordHashCleaner
extend self
end
@thatrubylove
thatrubylove / example-4.rb
Created April 17, 2014 20:24
an-exercise-in-refactoring-large-methods-in-ruby-2-example-4
module UserPasswordHashCleaner
extend self
end
require 'minitest/autorun'
describe UserPasswordHashCleaner do
subject { UserPasswordHashCleaner }
describe "call(params)" do
@thatrubylove
thatrubylove / example-5.rb
Created April 17, 2014 20:25
an-exercise-in-refactoring-large-methods-in-ruby-2-example-5
module UserPasswordHashCleaner
extend self
def call(params)
return {} if params.nil?
end
end
require 'minitest/autorun'
@thatrubylove
thatrubylove / example-6.md
Created April 17, 2014 20:26
an-exercise-in-refactoring-large-methods-in-ruby-2-example-6

require 'minitest/autorun'

describe UserPasswordHashCleaner do subject { UserPasswordHashCleaner } describe "call(params)" do it "will return the hash as is if it has a password && password_confirmation" do params = { user: { password: "ok", password_confirmation: "ok", admin: true } }

@thatrubylove
thatrubylove / example-7.rb
Created April 17, 2014 20:27
an-exercise-in-refactoring-large-methods-in-ruby-2-example-7
module UserPasswordHashCleaner
extend self
def call(params)
...
return params if hash_has_password_info?(params)
end
protected
@thatrubylove
thatrubylove / example-8.rb
Created April 17, 2014 20:31
an-exercise-in-refactoring-large-methods-in-ruby-2-example-8
require 'minitest/autorun'
describe UserPasswordHashCleaner do
subject { UserPasswordHashCleaner }
describe "call(params)" do
it "will return a hash without the password key if it it's value is blank" do
params = { user: { password: "", admin: true } }
subject.call(params).must_equal({ user: { admin: true } })
end
@thatrubylove
thatrubylove / example-9.rb
Created April 17, 2014 20:32
an-exercise-in-refactoring-large-methods-in-ruby-2-example-9
module UserPasswordHashCleaner
extend self
def call(params)
...
strip_password_keys_from_hash(params)
end
protected