If you want to test that that an exception is raised and then test the message that is easily accomplished with assert_raise:
If you’re working on an older Rails project (pre Rails 2.1) you will be missing config.gem for Gem dependency management. If you have multiple versions of gems on the machine you can still load a specific version by using rubygems:
Rails doesn’t check authenticity tokens on GET requests and doesn’t
ever check them in the functional tests. More info on Rails
authenticity token
here.
A couple weeks ago I sat down at my computer after dinner to do a little
bit of work and was greeted with a very, very sluggish machine. This
isn’t normal with my Macbook so I tried shutting down a few applications
and pull up Activity Monitor to see what was chewing up the cycles. This
seemed to be too much for the machine and it completely locked up, what
next? Well, the only thing I could do, hold down the power button until
it shut off and try turning it back on (did you try turning it off and
on
again?).
At this point I wasn’t too worried, and sat waiting for OS X to load.
Waiting. And Waiting. And Waiting. It just sat there spinning away. This
is quite the dilemma. I hopped onto my iPhone and Goggled to see if
there was a way to start up to a command prompt. I found this
link which had a bunch of
information, including holding command-s to boot to single user mode.
Off and On again, this time booting to single user mode and the command
prompt. The same link mentioned running ‘/sbin/fsck’ (file system check)
to fix any problems with the file system. I ran it. A billion errors,
half a billion couldn’t be fixed. Great… Well, it says you may need to
run it multiple times to fix everything, so I run it again. And again.
And again. Shit.
Maybe I should try reseting the PRAM like this link
says. Off and On again. Kernel
Panic. Off and On. Kernel Panic. Shit. (Kernel Panic is the OS X
equivalent to a Windows Blue Screen. They are rare so it is likely you
have never seen one, but you can check it out
here)
Well, now I’m screwed. At least I have Apple Care, into the Mac shop it
goes.
“Did you try turning it Off and On again?”, she asks.
“Yep. I tried running the file system check, I tried reseting the PRAM
and I turned it Off and On a dozen times,” I told her.
“Well, I’ll just try reseting the PRAM,” she said. “Oh, ya, Kernel
Panic. That’s not good. We’ll take a look and let you know what we can
do.”
Later that day, the Mac Store calls. “You need a new hard drive, we’ll
be sending your old one to Apple and probably get a new one in 3-5
business days.”
“You don’t have them in stock?” I asked.
“No, we don’t stock the brand Apple uses and to keep it covered by the
warranty we have to use one of theirs,” the girl from The Mac Store
says.
Four days later and I’m bringing my Macbook home with it’s fresh new
hard drive. I pop in my Snow Leopard disk and watch some TV while OS X
reinstalls. Once it finishes I’m asked if I want to import user settings
or restore from a Time Machine backup. Hell Yes, I’ll restore from the
Time Machine backups I started doing ONE WEEK EARLIER! A couple hours
later and I could barely remember that my hard drive had failed and I
had a new one in my machine. All my Applications were restored. All my
settings. Heck, even my desktop wallpaper came back.
The only thing that I had to reinstall was parallels, and that’s because
I ignored the folder where the Windows VM was saved (it seems like it
wouldn’t have worked from a restore anyways). The moral of the story is
spend $60 on a 500 gig hard drive and USE Time Machine. I’ve ignored a
number of places on my machine to keep the backup a little smaller and
taking less time, you can do the same (with my setup it is PROVEN that
you can still restore and get everything back):
Currently I have 20 days of backups and 300 gigs remaining on the drive.
Do it.
I have to note that my little dialog with the girl at the Mac shop was a
little contrived. They were actually really helpful and did a great job
bringing my Macbook (and me) back to life.
Ran into an issue calling to_json on a an object that has a carrierwave attachment and have commented on an issue for it. I am running Rails3 RC2 and using FileSystem storage. To get around this I’m simply excluding the file attachment from the to_json:
Well, I’ve been slacking again, here’s the learnings from a couple weeks
ago.
IE must “haveLayout for opacity”:http://joseph.randomnetworks.com/archives/2006/08/16/css-opacity-in-internet-explorer-ie/ (alpha filter) to work. You can use the IE zoom rule to give an element layout if needed:
To add custom Date/Time formats in Rails:
Don’t forget to add your custom formats to Date as well, they use a different hash. This can then be used like so:
When using Paypal buttons you can change the Currency that is used by “adding a hidden field”:https://www.paypal.com/us/cgi-bin/webscr?cmd=p/sell/mc/mc_wa-outside:
The Rails Request object has a number of useful methods for “finding the url that was used for the request”:http://programming-tut.blogspot.com/2010/06/ruby-on-rails-request-url.html:
This past week I had learnings all over the place; javascript, rails,
oracle, css and probably more that I’ve already forgotten.
Interesting post by Remy Sharp on “Throttling Javascript Function Calls”:http://remysharp.com/2010/07/21/throttling-function-calls/
Usage:
This will require there to be 250ms between a keypress before it will
execute the given function. Useful for things like Autocomplete where
you don’t want an AJAX request to fire until the person stops typing.
To access the Host machine from a VirtualBox Windows VM
‘\\vboxsvr\share’ . You can also turn on Windows filesharing and
access the VM from the Host.
When Rails (as of 2.3.5) runs the ‘environment’ Rake task it sets
the global variable $rails_rake_task = true. Since most tasks
depend on the environment you can use this to do slightly different
behavior if your code is running within a Rake task.
IE has a property ‘hasLayout’ that determines “how to draw and bound elements”:http://www.satzansatz.de/cssd/onhavinglayout.html. Some elements “have layout by default”:http://www.satzansatz.de/cssd/onhavinglayout.html#wherefrom and others do not. Sometimes when an element does not have layout you can see odd behavior, like lists being numbered incorrectly or margins collapsing. To fix this you can “add certain css properties”:http://www.satzansatz.de/cssd/onhavinglayout.html#prop to elements so that they will gain layout.
Height is a property that will have an element gain layout but sometimes
you might still want the element to auto expand. Setting the height to
1% will give the element layout as well as allowing it to expand with
its content. This is known as the Holly Hack. **Note: hasLayout may
not be an issue anymore as of IE8.
SQLServer compatibility mode doesn’t make the server behave exactly
what is specified, rather, it pulls in any functionality that may
have been deprecated in the later releases (I think)
SendGrid, Google
Apps,
AuthSMTP are paid services that can be
used for sending email so you don’t need to do it through your own
server (or if you’re on EC2 and can’t reliably send mail from your
server)
Late again, I know, but here’s my learnings from a couple weeks ago.
If you need to use the Rails url helpers within a model or even script/console you just need these two lines:
Alternatively within script/console you can use the “‘app’ or ‘helper’ variables to interact with the application”:http://stackoverflow.com/questions/151030/how-do-i-call-controller-view-methods-from-the-console-in-rails
If you want some piece of code to run after each request you can use
a ‘config.to_prepare’
block.
This might be useful if you have classes reloading in development
and want to set settings after they have reloaded.
Git can sometimes consider text files to be binary if they have Null characters at the end. You can still diff these files with this command:
Git interactive rebase can reorder commits (just reorder them in the
file)
“No such device eth0” after cloning VMWare Image
run ‘sudo mv /etc/udev/rules.d/70-persistent-net.rules
/etc/udev/rules.d/70-persistent-net.rules.old’ and then restart
the machine to fix the problem. Found
here.
type some characters then ctrl-N or ctrl-P (next or previous
match)
EngineYard App Cloud
makes a lot of mundane server admin tasks very simple and still
allowing complete customization with chef scripts or with root
access on the server.
Many EC2 IPs are on Spam blacklists. Use a thirdparty such as gmail
to do the emailing for you.
Checking if a javascript function exists in the page:
typeof functionName == ‘function’
Tig
a simple command-line yet visual interface to Git
Filename completion in Vim with ctrl-x then ctrl-f
Had issues with parts of the page not redrawing correctly, the
culprit was a position: relative - not really sure why.
jQuery delegate method is the ‘new’ way to do live events, cleaner
syntax and promotes using a context so the events don’t have to
bubble all the way up the DOM. Learning
JQuery
has a pretty good explanation.