The Frontier Group - Blog

Ruby on Rails Perth Meetup

February 2nd, 2010, by aaron

Every third Thursday of the month we have a Ruby on Rails meetup at our offices. It’s a bit of a mix of some socialising and some tech sharing. A few of the guys share the same woes in trying to run a small business, or deal with clients, or implement some particular solution so it can sometimes end up being quite a mixing pot for solution finding and solution sharing.

I think in the year 2009 we’ve seen the group grow from a meeting of somewhere around 4-8 people each month to sometimes around 30. In December to celebrate a successful year of growth in the Perth Ruby community we went on a pub crawl down Barrack and Beaufort St, everyone seemed to have a lot of fun and it was good to take the show on the road. Generally we keep the drinking and tomfoolery inside the bounds of our office.

You can find out some more information at the meetup site but generally we get between 15 to 30 people attending and there will be talks ranging from using Capistrano for PHP deployments to Behaviour Driven Testing and a lot in between. In January we had talks on using Sinatra to setup some simple Javascript unit testing, using Sinatra and Rake to setup a simple management interface, and using Soap4R to interface with SOAP APIs.

The meetup is held in Unit 9, 1010 Wellington St from 5pm onwards. Beers and snack food are provided, you just need to bring yourself and a willingness to exchange ideas! The next meeting will be on February 18, 2010.

We are a web development company and this is our blog. We specialize in building web applications with the Ruby on Rails framework. You can read more about our Ruby on Rails development or contact us.


Using RSpec Example Groups for Common Functionality

January 13th, 2010, by aaron

I’m currently getting into using RSpec for testing our controllers on what is turning into a large project. It’s been more than handy because we have a lot of complex scoping to take into account whenever retrieving data. People don’t like to see other peoples’ financial data, mostly because it implies that someone is probably looking at theirs. With this in mind it’s more than important that we know the right data is going to the right places and hence the need for controller testing.

Now most of our controllers require the user to be logged in so writing tests to check this for every controller is annoying and time consuming, more than that it feels dirty. I think this is what some people call a code smell though I’m not up to speed on buzz words. There are also other tasks that are done quite often such as setting up the various types of users we’d like to test as, it would be nice if this were easily put in one place and could be easily pulled in. I guess I was looking for a template of tests that I could share.

It seems that the solution to it is found in Shared Example Groups which I hadn’t heard very much discussion about and it kind of leaves working out how they work to you rather than documenting it too much.

So far I’ve used it simply to make sure that controllers that require are redirecting users appropriately and also for setting up a specific type of user for our system before testing.

I created a directory under /spec/support called example_groups and in there I have a file called login_groups.rb. In that file I have something like the following :

shared_examples_for "customer is logged in" do
  before(:all) do
    @user = Factory(:customer_user)
    @user.customers.push Factory(:customer)
  end

  before(:each) do
    activate_authlogic
    OperatorSession.create(@operator)
  end
end

Now in my spec files when I have a bunch of tests requiring a logged in customer I will include this little snippet :

  it_should_behave_like "customer is logged in"

I get a logged in customer to start playing around with. I have the spec/support/example_groups directory in my include paths for Rspec and so it just all works.

My tests can then start to look like :

describe MerchantsController do
  it_should_behave_like "areas requiring login"

  context "customer logged in" do
    it_should_behave_like "customer is logged in"

    ... insert other tests here ...
  end
end

It means I can swap in another authentication gem/plugin pretty easily and also encapsulates the logic about creating customers, or whatever type of item you want to use, so that if that changes you can swap things in and out with a minimum of fuss.

Just to be clear, example groups aren’t limited to setup tasks or connecting to before/after hooks, you can also include a bunch of tests as well. This allows me to have a bunch of tests to run to make sure that a user does have to be logged in for various controllers and include these tests in on line.

I hope this helps someone, it took a bit of searching and trial and error myself this morning to get it working and find the uses for it that I’ve found. I’m definitely open to better solutions to this sort of issue though.

We are a web development company and this is our blog. We specialize in building web applications with the Ruby on Rails framework. You can read more about our Ruby on Rails development or contact us.


Database Transactions in Cucumber Breaking Selenium

October 8th, 2009, by aaron

We’ve been using Selenium, Webrat, Cucumber and any number of other gems together for quite a while with very few problems. Just recently our Selenium tests just stopped working on the login step, and given our application requires users to login to do anything, it meant out test suite was basically broken from step one.

Given that we thought very little of any consequence had changed it was annoying trying to troubleshoot the problem. Typically you start off thinking it’s something you did, then maybe it’s something someone you know did, then you start to branch out and think that maybe, just maybe, it was a bug elsewhere!

I initially started to check the logs and they seemed perfect, but it wasn’t finding the user record in the database. So I loaded the database in sqlite and lo-and-behold there were no user records to be found. I started a debug session and it reported that the user had in fact been created. I thought it had to be something to do with transactions being used. Trying to insert a record into the database and being told the database was locked confirmed this.

I turned out that the Cucumber gem writer determined that there should be no more global setting for turning on or off transaction support when running tests. Previously transactions were turned off by default in Cucumber, and you’d generally turn them back on if you needed them. This change is annoying because a good chunk of our suite uses Selnium for testing and it requires transactions to be turned off. It’s also a bit odd to reverse a default option and have no way to enable it at all.

Apparently the work around is to tag all the features and scenarios that rely on non-transactional database operations with this new tag of @no-txn. After implementing this, we’ve found it does work and so our tests are back to usual condition.

So if you’re running into problems with your Selenium tests using Cucumber with Rails and your database isn’t updating within a test then check out the ‘@no-txn’ tag and see what happens after you use that.

We are a web development company and this is our blog. We specialize in building web applications with the Ruby on Rails framework. You can read more about our Ruby on Rails development or contact us.


The Ruby Manor

February 4th, 2009, by aaron

I got sucked into the Ruby Manor site (in a good way) because of a presentation about the Rack spec and how it works. The Rack talk was quite short and to the point, but had some great examples of how to use Rack for micro-applications.

It’s a bit of a pain that the speaker didn’t repeat the questions in the Q&A section for the internet audience because for the latter third of the talk I had no idea what was being talked about. However the talk piqued my interest in learning a bit more about Rack and how it can be utilised when writing Ruby applications. I thought it might pique other peoples’ interest too!

We are a web development company and this is our blog. We specialize in building web applications with the Ruby on Rails framework. You can read more about our Ruby on Rails development or contact us.


Understanding Ruby Blocks, Procs and Lambdas

January 7th, 2009, by aaron

I thought that I understood Ruby a little bit, but after reading Robert Sosinski’s article on Blocks, Procs and Lamdas in Ruby I felt a little humbled. To take such a small part of a language and express such detail and give some very useful examples really impressed me. The similarities between some of the ways I do things using Javascript and his examples really surprised me too.

I’d recommend giving it a good read to really understand how things work with these constructs and it may even give you a few new ideas on how to approach some problems you’ve encountered along the way.

We are a web development company and this is our blog. We specialize in building web applications with the Ruby on Rails framework. You can read more about our Ruby on Rails development or contact us.


Follow Us

Stay in the Loop

  • Enter your email address to subscribe to our mailing list. You'll get updates about our products, specials and bonus offers, and general behind the scenes news from our team.

Twitter

Newsletters

Alexa Rank

Testimonial

The boys at The Frontier Group are amazing! For such a relaxed and personable organisation, they have phenomenal technical ability and a rampant professionalism. They have customisable solutions for all of my IT needs and they always deliver, on time and beyond expectation.

They fix problems other service providers can't and they helped me get a critical section of my web site up and running 10 minutes after I emailed the request!

Alex Hyndman, Nexus Car Share.

Featured Project

Case Study - Caudo Group - www.caudo.com.au

Website

www.caudo.com.au

Caudo Machinery

Caudo Group engaged our services to redesign their outdated website. We sent our photographer on-site to capture the essence of their business and turned it into a stunning web design.