If you follow the Devise Wiki on setting up Rspec and Devise you may end up wanting to set an expecatation on the currently signed in user. Don’t fall into the trap of setting it on the original user model as your specs will still fail: user.should_receive(:blah).once # Won't work Rather, you should set it on the controller’s current_user: subject.current_user.should_receive(:blah).once # Will work!
One slightly annoying thing about Postgres over MySQL is that trying to reset a database with rake db:migrate:reset fails if there are connected clients and as I use Pow for development, killing the process doesn’t always free up the connections. To get around this you can quickly kill all connections with this command: [crayon-5f9777c12499c988701699/]
I thought I’d have a look at the SpotifyAPI to see what it’s like. Pretty nice that everything is just HTML + JS. I knocked up a small app which simply provides search links for the currently playing track. It also changes as the player’s track changes. The source is on Github.
I’ve been working on a templating engine recently and had the need to substitute some variables on the page with the result of an slightly expensive remote API call. The first iteration was just a simple replace on the page: [crayon-5f9777c124d1d763248942/] This “worked” but the problem is the call would be made even if the variable that needed replacing wasn’t on the page. The easy fix is to check it exists before making the substitution: […]
Some bosses make the mistake of thinking that if the result of someone’s work is easy to use, the work itself must be easy. A guy goes in to consult for a company and runs across a bug. He raises the issue and the boss says “Oh boy – another ‘Bob bug’ – Bob created a lot of bugs.” (Bob has moved on by now). After the guy was there for a while he comes […]
I’m generating PDFs with PDFkit/wkhtmltopdf on a current project. While the output is fine in the browser, £ (pound) signs in the generated PDF were showing up incorrectly as: [crayon-5f9777c124d97544003380/] The fix was relatively easy as PDFs have their own view layout, so all I had to do was add an extra meta tag to the head: [crayon-5f9777c124d9b483629062/]
My current project www.viewshound.com requires different users to have different scopes for their Facebook authentication. Warden supports dynamic providers out of the box. To get it working with Devise was pretty easy, just a couple of minor changes were needed especially to support Facebook. First up was creating the new route. As I’m using a controller called Omniauth and not Session, the :to attribute is different. The other thing to note is I’m matching /users/auth/facebook/setup, […]
I just realised that my NERDTree directory colour wasn’t inline with my Vim theme, and I couldn’t help but be bugged by it. Seems it’s a simple change. To change colour you need to use the treeDir highlight group. [crayon-5f9777c124e78568093837/] To keep it synced with the ir_black theme I use, I just added the following to my colour scheme file. [crayon-5f9777c124e7c553481479/]
Recently I’ve been coding some iPhone and iPad apps with multiple targets, all sharing the same codebase. Previously I had been using Preprocessor Macros to get the job done, but that soon turns messy and hard to maintain. I’ve since moved to just storing target specific values in each apps related plist file. Retrieving a value is as simple as: [crayon-5f9777c124ecc808086845/]
Installing the intermediate certificates on our server gave me the following error while trying to start up nginx again: [crayon-5f9777c124f12660903526/] The end of the file looked fine, but the problem was half way through it. Somehow the concatenation had joined two lines together: [crayon-5f9777c124f15122241494/] This just needed a line break to fix: [crayon-5f9777c124f18634268498/]
A current requirement is that assets uploaded to Amazon S3 must be accessed via SSL and use an expiring URL. Using an expiring url with Paperclip is extremely easy. [crayon-5f9777c124f84942689557/] The problem is expiring_url doesn’t let you choose a style and doesn’t use https, which breaks our SSL site. To add the behaviour was an easy “hack”. I added the file /config/initializers/paperclip.rb with the following code: [crayon-5f9777c124f88872818457/] Now calling my expiring image URL with a […]
First let me state how much I dislike developing for the Facebook platform. It’s just one constant headache. Things are always changing and breaking things. Anyways, I’ve been banging my head against the wall all day trying to get some FBJS running on a canvas application that’s embedded on a Fan Page tab. No matter what I did, I kept getting the error: [crayon-5f9777c124ff9176870014/] Even using Facebook’s own FBJS examples left my tab in a […]
Recently the discussion of code quality has come up with a couple of different people. With the main question: “If the app does what it’s supposed to do, why does code quality matter?” In one instance an application that was bringing in over a £1m in revenues a month had one of the worst code bases a friend had ever seen. And I totally agree that there is no correlation between code quality and the […]
To get webby using HAML/SASS’ SCSS rendering engine I added the following to my Sitefile. No doubt there’s a cleaner and quicker way of getting it working, but this works. [crayon-5f9777c12504f146493202/]
Autotest would constantly run my tests even though I hadn’t modified anything. Which made it impossible to actually use. Creating the following in a file called .autotest in my application’s root solved the problem for me. This is on Rails 3 RC, RSpec 2 beta 19 and Cucumber 0.8.5. [crayon-5f9777c125094939514481/] [crayon-5f9777c125098866840060/]