Running an individual shoulda context test

By kenglish

I’m suffering from serious CRS. Yesterday, I was wondering how to run my shoulda tests individually. My co-worker said “Just google for it.” I entered a google search term and the 4th or 5th result was a post by ME to the shoulda google group. This was the post: Can you controller context test just one test via the -n flag?

To reinforce the lesson, you can run a single context using a regular expression.

context "on GET to :show for first record" do
  setup do
    get :show, :id => 1
  end
 
  should_assign_to :sweater
  should_respond_with :success
  should_render_template :show
end

Although, you need to put quotes around the regular expression or the command line interpreter mistaked the spaces for separate arguments:

ruby test/functional/sweater_controller_test.rb -n "/show for first record/"

categoriaProgramming, Tech commentoNo Comments dataFebruary 25th, 2009
Read All

Handle 404 Errors with Errorlytics

By kenglish

There’s a cool Mashable writeup about this service called Errorlytics. This site is written in Rails and seems pretty cool. It allows you to customize responses for 404 errors.

categoriaTech, Uncategorized commentoNo Comments dataJanuary 27th, 2009
Read All

Aloha on Rails

By kenglish

Here’s a pre-preview but Aloha on Rails is coming

categoriaTech commentoNo Comments dataJanuary 21st, 2009
Read All

Apache SSL with 2 IPs and 2 Certificates

By admin

Yesterday we had to set up Apache to host 2 SSL certificates for 2 different IPs. There’s all kind of crackheads on the internet who think you can install 2 SSL certificates for 1 IP but it simply can’t be done. So, here’s what I did:

There’s info on the Apache VirtaulHost Examples site. The best examples are “Mixed name-based and IP-based vhosts” and “Mixed port-based and ip-based virtual hosts.”

Let’s say we have 2 domains: mauka.com and makai.com.

We change our DNS so that the IP xx.xx.xx.1 points to mauka.com and xx.xx.xx.2 points to makai.com points to xx.xx.xx.2. This means the server has to be set up with 2 IPs.

Before we change anything in Apache, we need to generate 2 ssl certificates. We will make these wildcard certificates for the names *.mauka.com and *.makai.com. There’s plenty of information out there about how to generate the key, this site has some good stuff: http://www.madboa.com/geek/openssl/
So, we generate our keys and certs and place them in /etc/pki/tls/private/wildcard-makai.key, /etc/pki/tls/certs/wildcard-makai.crt, /etc/pki/tls/certs/wildcard-mauka.crt and /etc/pki/tls/private/wildcard-mauka.key.

Here’s what the set up will look like for our domain to configure the following urls. :

http://www.mauka.com
http://www2.mauka.com
https://www.mauka.com
https://www2.mauka.com

http://www.makai.com
http://www2.makai.com
https://www.makai.com
https://www2.makai.com

in the main http.conf

NameVirtualHost xx.xx.xx.1:80
NameVirtualHost xx.xx.xx.2:80

Add after our mod_ssl setup, for us it is a file ssl.conf

DocumentRoot /www/www.mauka.com
ServerName www.mauka.com
DocumentRoot /www/www2.mauka.com
ServerName www2.mauka.com
DocumentRoot /www/www.makai.com
ServerName www.makai.com
DocumentRoot /www/www2.makai.com
ServerName www2.makai.com

SSL Configurations
Add after our mod_ssl setup, for us it is a file ssl.conf

NameVirtualHost xx.xx.xx.1:443
NameVirtualHost xx.xx.xx.2:433
DocumentRoot /www/www.mauka.com
ServerName www.mauka.com

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
SSLCertificateFile /etc/pki/tls/certs/wildcard-mauka.crt
SSLCertificateKeyFile /etc/pki/tls/private/wildcard-mauka.key
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
DocumentRoot /www/www2.mauka.com
ServerName www2.mauka.com

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
SSLCertificateFile /etc/pki/tls/certs/wildcard-mauka.crt
SSLCertificateKeyFile /etc/pki/tls/private/wildcard-mauka.key
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
DocumentRoot /www/www.makai.com
ServerName www.makai.com

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
SSLCertificateFile /etc/pki/tls/certs/wildcard-makai.crt
SSLCertificateKeyFile /etc/pki/tls/private/wildcard-makai.key
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
DocumentRoot /www/www2.makai.com
ServerName www2.makai.com

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
SSLCertificateFile /etc/pki/tls/certs/wildcard-makai.crt
SSLCertificateKeyFile /etc/pki/tls/private/wildcard-makai.key
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire

Note: This is very general, there’s a lot of other options that are missing here. This is to give you an idea of what it looks like.

categoriaTech commentoNo Comments dataOctober 17th, 2008
Read All

git: Get a single file from another repository

By admin

This is so easy it's almost stupid. Let's say want to copy a single file from b0 to another branch, b1, without doing a merge and all that crap. all you do is this:

# change to b1
get-checkout b1
# checkout the single file
git-checkout b0 path/to/file

Then you can do something like to see the differences:

git-diff HEAD path/to/file

and when you are done:

git-commit -m “Commit it, baby” path/to/file

“Commit it, baby” as a comment is mandatory.

categoriaTech commentoNo Comments dataSeptember 25th, 2008
Read All

Make irb remember your history with the irbrc

By admin

I always forget this one too. To make ruby's irb remember commands you entered in the last session(s), you need to add the following lines to /home/kenglish/.irbrc:

require 'irb/completion'
require 'irb/ext/save-history'

IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = “#{ENV['HOME']}/.irb-save-history”
IRB.conf[:PROMPT_MODE] = :SIMPLE

Isn't IRB-RC an awesome name for a file?

isn't Camber First

categoriaTech commentoNo Comments dataSeptember 17th, 2008
Read All

git – adding e-mail alerts & hooks

By admin

Before you do anything, you may want to back up the file .git/hooks/post-receive in your project directory or at least view it to make sure that there's nothing in it.

Now, get a copy of the git source code:

git clone git://git.kernel.org/pub/scm/git/git.git

Overwrite the post-receive in your hook folder with the file git/contrib/hooks/post-receive-email :

cp git/contrib/hooks/post-receive-email /var/data/repos/myproject/.git/hooks/post-receive

Now, go to your project home and add the git-config variable:

cd /var/data/repos/myproject/
git-config hooks.mailinglist “kenglish@someweakdomain.org”
git-config hooks.mailinglist “[GIT-MYPROJECT] “

Now test it out, do a git-commit -a on your repository and push it to the master. Should send an e-mail about the checkin.

BONUS:
By default, the script will just e-mail you that files have checked in. If you want to Email the diffs of the files themselves, basically, copy the diff of from that guys post into your post-receive file. THen set hooks.emailprefix=1

with:
git-config hooks.emailprefix 1

categoriaTech commentoNo Comments dataSeptember 15th, 2008
Read All

Ignoring local changes

By admin

If You have something checked into the repository that you will change locally but never want to check back in, you can do this:

git update-index –assume-unchanged config/initializers/ruby_inline.rb

categoriaTech commentoNo Comments dataSeptember 11th, 2008
Read All

/etc/cron.hourly/ and run-parts

By admin

My co-worker found out the hard way what run-parts is all about.
He was trying to run an hourly cron job so he put his script file in /etc/cron.hourly/ .

The file was named something like 'launch-nuclear-attack.sh'. However,the script didn't run hourly and the nuclear holocaust never took place. He dug deep and found out that the cron.hourly files are run by a program called 'run-parts'. In the run-parts man page it says:

“names must consist entirely of upper and lower case letters, digits, under‐scores, and hyphens”

This means that 'launch-nuclear-attack.sh' was an invalid filename since it contains a period. He renamed his file to 'go_for_world_peace', and it worked fine. Also, we're all in a lot better shape to boot.

categoriaTech commentoNo Comments dataAugust 25th, 2008
Read All

Replace text string in many files at once

By admin

So my boss says that he doesn't like the word “Admin” and wants it replaced with Administration in all the menus. Here's how to do it:

perl -p -i -e “s/'Admin'/'Administration'/g” *.rb

Perl rocks. Let's see you do that in Java!
Options explain:

-p assume loop like -n but print line also, like sed
-i edit <> files in place (makes backup if extension supplied)
-e one line of program (several -e's allowed, omit programfile)

Fortunately, with my case, the word “Admin” was surrounded by single quotes. If you have just the naked work Admin and you did:

perl -p -i -e “s/Admin/Administration/g” *.rb

two times in a row, you would end up with AdminAdministration, three times would give you AdminAdminAdministration…

categoriaTech commento1 Comment dataAugust 25th, 2008
Read All