Showing posts with label urls. Show all posts
Showing posts with label urls. Show all posts

Monday, 9 June 2008

Rails Gotchas: Missing host error in unit tests

I finally got around to adding nice "and if you'd like to see your newly-created report, go to the URL: BLAH" links into my notification emails... a tiny nice-to-have that wasn't high on the priority list.

Suddenly my unit tests started spewing errors of the form:
ActionView::TemplateError: Missing host to link to! Please provide :host parameter or set default_url_options[:host]

The doco on default_url_options says you can add the "host" param on ActionController::Base, but no amount of monkey-patching in config/environment.rb seemed to do the trick.

Googling found a link talking about re-writing your URLs and it mentioned the problem is mainly seen in unit testing, and gave a couple of lines for a fix (as below)... but didn't say where to put them.

  include ActionController::UrlWriter
  default_url_options[:host] = 'localhost'

Experimentation showed that if you put them in your Notifer model (eg user_notifier.rb) they work just fine. Otherwise it just doesn't get into ActionMailer. :P

Friday, 22 December 2006

PayPal helldesk

I like text-only emails. It's a great way to avoid link-jack phishing spam, virii and annoying flashing ads. It's also a great way to get your email through an ssh connection. However, dealing with long URLs can sometimes be annoying. It doesn't seem to matter that I've set all of my settings to *not* use wrap-characters. When a link comes through it will, more-often-than-not, have a '+' sign squidged into it when it breaks onto a newline.

This is not a big problem. I've grown accustomed to copy/pasting (ok, highlight and middle-clicking) into my browser window, searching for the <CR> and a spurious '+' and removing it before hitting "Go".

This does not work for PayPal URLs

PayPal text-based email is that hideous abomination that comes sprinkled with MicoSoft proprietary characters. Lines end in '=' and there is a smattering of '?', "=20" and other random wierdness, just to make life more challenging...

I spent hours yesterday morning trying to get back into an old paypal account of mine. I did the "forgotten password email" thing. I clicked on the URL. I removed the <CR> and the clearly spurious '=' wrap-character - no go. I tried it while leaving in the '=' - no go. I tried copy/pasting the inidividual halves of the URL into my browser - no go.

I then spent an hour or more on the phone with their help-desk trying to be polite while they went through their script:
"Hi there, I'm having trouble with the forgotten-password URL. I have tried copy/pasting it into my browser, I removed the line-wrap symbol and the carriage-return, and it still doesn't work."
"Have you gone to the forgotten password page and clicked the link to send you a reminder email?"
"Yes, I've done that - I've got the email, I've clicked on the link and it doesn't work. I tried to copy the link into my browser, but that doesn't work either."
"Have you tried to copy/paste the URL into your browser?"
<sigh> <<find me somebody that understands linux... or at least somebody that knows how to *listen*!>>.

Finally he agreed that it really wasn't working for me! But their technical desk had gone home by that stage so all they could do was open a trouble-ticket with me and I would need to call them tomorrow.

I played a wild-card and tried creating an account with the email for my old company. I was coming in for some final work this morning. I used Evolution there so I could look at the URL and compare. I wasn't sure if it'd help - but figured it was a better shot than fretting about the next level of helldesk support.

Example URL from Evolution: https://developer.paypal.com/devscr?cmd=_signup-el&ac=Uqht43A9suP7A-qEw=
Wi6tvquhPE8gVgEPX5Rr7vBWrMTj8uOWmJ2eh6wavzjhIQWjjkrfCT8x4rJvA

Example from mutt: https://developer.paypal.com/devscr?cmd=3D_signup-el&ac=3DKiXOj6ebBnR5sJZhj=
xP1NKTMTbq6pyy7COF6tQRj-BkZjbnAvkAjAwLMiTalSVT94OmHniMPIMI9Iw

Note the "3D" after each of the (real) '=' signs. I have no idea what character PayPal's text-email generator thinks they are supposed to represent - or why Evolution seems to gloss over them, but removing them makes it all work.