Skip to content

Instantly share code, notes, and snippets.

View neilmarion's full-sized avatar

Neil Marion dela Cruz neilmarion

View GitHub Profile
@neilmarion
neilmarion / metaprogramming.rb
Created February 19, 2014 16:10
metaprogramming
def calculate_till
self.cash_in_till = type.nil? ? cash_on_hand :
send("calculate_#{type.gsub(/-/,"_")}")
calculated_value
end
@neilmarion
neilmarion / requiring_gem_development.rb
Created February 28, 2014 05:41
requiring a gem during development
require 'lib/my_gem'
#http://stackoverflow.com/questions/4493114/developing-gems-and-testing
#http://stackoverflow.com/questions/4487948/how-can-i-specify-a-local-gem-in-my-gemfile
@neilmarion
neilmarion / build_gem
Created March 3, 2014 02:36
building a gem locally
gem build hola.gemspec
@neilmarion
neilmarion / minibufexpl.sh
Last active August 29, 2015 14:08
minibufexpl (Mini-buffer explorer)
# https://github.com/fholgado/minibufexpl.vim
# ':edit' --> to open another file in vim and creating a new buffer
# ':new' --> to open another file in vim and creating an empty
# ':b2' --> to open a buffer with label '2'
# Commnad ':MBEbd', ':MBEbw' or ':MBEbun' could be used to delete/wipeout/unload buffers just as ':bd', ':bw' or ':bun', but the window that previously holding them will be preserved.
@neilmarion
neilmarion / search_spec.rb
Created April 8, 2013 21:52
Seems like spec/features have some issue with shared methods... This does not proceed to visit root_path at all. spec/features/search_spec.rb
require 'spec_helper'
describe "Searching" do
before(:each) do
visit root_path
end
before(:all) do
load_test_posts
end
@neilmarion
neilmarion / search_spec.rb
Created April 12, 2013 21:50
Since capybara, without using selenium driver, does not have a way to detect a return value '\n' or i.e. 'Enter' key press, I created a hack on rspec test using rspec-mock
#Testing my full-text-search function. I do not have a submit button to submit my #query field but instead I only have the enter key press for it.
describe "will be successful" do
it "after the #query field is submitted by return button and the relevance of the value in the #query search_field_input is > 0%" do
result = Post.text_search(@question.title)
#fill_in 'query', with: "#{@question.title}\n"
Post.should_receive(:text_search).at_least(:once){ result }
visit root_path
page.should have_content @question.title
page.should have_css(".post-row", count: 1)
@neilmarion
neilmarion / replacing_occurrences
Last active December 16, 2015 10:59
I use the I18n#t helpers as my parameters for matching strings in my specs. And in my views I use the relative path for the locales. That is why whenever a view file was transferred to another directory, the locale relative path would change and specs will fail. So I wrote a command to change all the occurrences of the changed translation. The '…
find -wholename '*spec.rb' | xargs sed -i 's/shared.navbar.sign_in_with_fb_link.sign_in_with_facebook/shared.navbar.user_links.sign_in_with_fb_link.sign_in_with_facebook/g
find -wholename '*[rb][haml]&' | xargs sed -i 's/status_circle/status_indicator/g'
@neilmarion
neilmarion / rspec_mocks_parent_children_spec.rb
Created April 24, 2013 14:04
RSpec::Mocks methods will fail if compared to instance of the parent class or vice versa (title not helpful, just see example)
#i.e you have Question object that has parent class Post
#say for example Post::SomeMethod returns true by default
@question = Question.create
#will fail
Post.any_instance.should_receive(:some_method).and_return false
@question.some_method.should eq false
@neilmarion
neilmarion / find.sh
Last active December 17, 2015 03:49
Finding a Particular Source File
//Assume that the code base is really large. Say thousands of files. And you wanted to write on files involved to http://www.some.domain.com/membership/index.php
//This would be useful
find -name "index.htm" | ack-grep "membership"
find -name "index.php" | ack-grep "membership"
//Apply reg expressions to be more effective