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 / 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
[07/Aug/2013 21:02:07] DEBUG [tastyapi.slum:13] Using slumber with user test, pointed at http://localhost:8000
[07/Aug/2013 21:02:07] INFO [core.management.commands.update_repos:65] Building Pip
[07/Aug/2013 21:02:07] INFO [requests.packages.urllib3.connectionpool:191] Starting new HTTP connection (1): localhost
Traceback (most recent call last):
File "./manage.py", line 5, in <module>
execute_manager(settings.sqlite)
File "/home/deployer/apps/rtd/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 459, in execute_manager
utility.execute()
File "/home/deployer/apps/rtd/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
@neilmarion
neilmarion / .vimrc
Created September 4, 2013 02:07
Show tab numbers in Vim tabs
set tabline=%!MyTabLine() " custom tab pages line
function MyTabLine()
let s = '' " complete tabline goes here
" loop through each tab page
for t in range(tabpagenr('$'))
" set highlight
if t + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
@neilmarion
neilmarion / styles.css
Last active December 22, 2015 12:38
railman theme change
div.entry {
padding: 60px 90px 40px;
background: #fff;
}
div.published,
div.published a {
color: #aaa;
font-size: 12px;
}
@neilmarion
neilmarion / resque_run_workers.sh
Last active December 26, 2015 16:09
Running Resque
QUEUE=* RAILS_ENV=production bundle exec rake resque:work &
rake resque:work QUEUE='*'
RAILS_ENV=development rake resque:workers QUEUE=send_feddit_newsletters COUNT='3'
QUEUE=send_feddit_newsletters RAILS_ENV=production bundle exec rake resque:work COUNT='5' &
RAILS_ENV=production rake resque:workers QUEUE=send_feddit_newsletters COUNT='3'