Posts tagged activeresource

Breadboard.yml is to ActiveResource as Database.yml is to ActiveRecord

One of the problems we were having with ActiveResource at work was that we have multiple versions of services. We needed development services, “preview” services for the editorial team to test new articles and of course the production services. Developers only really want to see the development services but our designers need to see the preview content to make sure the stylesheets and javascript will work prior to going live. This gets sticky whenever there are multiple people editing the self.site variable in a model and can cause a headache when merging if values are getting overwritten all over the place.

I can’t quite understand why this isn’t a default feature of ActiveResource, but wouldn’t one think that developers would need to have at least two different environment services like development and production?

My co-worker, Matt Parker (@moonmaster9000,) imagined a better way to handle services and ta-da, Breadboard was born!

When I was implementing Breadboard on our front-end code, I quickly found that there were a few bugs that needed to be weeded out before it could be widely used by the team. For one thing, whenever you were inheriting site settings from parent classes, that would automatically be set for you, but with Breadboard it wasn’t checking if the parent class was assigned a proper site service and would automatically fall back to the default service value. I made a patch that performed the necessary checks on parent classes before the fallback to the default service.

Another interesting bug that we found was that sometimes the services were not getting set. It ended up being that when an ActiveResource model set self.site, it also set @connection equal to nil which was a key component missing the Breadboard gem that was causing some inconsistencies. A quick method write solved the problem and we were able to get Breadboard out into the workflow of the Online team.

ActiveResource, Cucumber and Dupe

At my job at American Express Publishing in New York City, I’m doing Ruby on Rails development and I was hired to help with the redesign of FoodAndWine.com. The production site is currently running Cold Fusion and MS SQL and the team is employed with the task of creating a Service Oriented Architecture (SOA) Ruby on Rails web site to replace the legacy code. How this works is that the legacy Cold Fusion site will serve up services for our site, we’ll make requests to get that information and then display that on our Ruby on Rails front end.

This is all nice and dandy because of Ruby on Rail’s ActiveResource that’s built right in. The tricky part comes in with testing. At American Express Publishing in our web development department, we’re really big into Test Driven Development (TDD) and Behavioral Driven Development (BDD). There are tools out there already made to do TDD and BDD for Ruby on Rails, Rspec and Cucumber, respectively. These tools work great when using ActiveRecord but since we don’t utilize a database, Rspec and Cucumber have a hard time working with ActiveResource and mocking service data.

This is where Dupe comes in. My co-worker Matt Parker came up with a ruby gem to mock service calls for use within Cucumber and Rspec so that we can write the appropriate tests for our code. With Dupe, you can write expected service returns and run tests against them. For the initial pages we’ve written we’ve only needed GET requests. When I started cuking and spec’ing some of the flat pages on Food and Wine we found that there was a (probably underused) polls section of the site that we needed to pull over. Because it needs user input to add to the poll, we would need to add a way for Dupe to mock POST requests.

This is the first time I’ve really programmed a gem let alone worked on someone else’s. I’ve spent a lot of time today researching HTTP requests and GETs, POSTs, PUTs and DELETEs. I also looked up the difference between blocks, lambdas and procs and found this neat, well-written blog post about them that helped straighten me out.

I’m still figuring out the appropriate way to set all this up but hopefully I can update the blog with a success story by tomorrow!

Go to Top