Articles tagged 'rails'
-
Page Objects: Where do you put your assertions?
April 12, 2016
I started writing about Page Objects earlier this month, and as soon as you start talking about Page Objects, you need to have an opinion about where to put your assertions. Do you ask the page if it is in the state it expects to be or do you ask the page for values and assert that they are what you expect them to be in the test?
If you look at FluentLenium and Simplelenium on GitHub, you’ll notice that their corresponding
README
s describe the usage of the Page Object pattern. Now, if you take a closer look, you’ll also notice that they have an opinion: they’ve included the assertions in the definition of such Page Objects.Now, my first experience with Page Objects was actually under these conditions. The Page Objects were the main driver…
-
Specifying failure message for RSpec expectations
April 12, 2016
When writing the Unit Testing ActiveRecord eager-loading blog post a couple months ago, I noticed that the test failures I was getting while writing were not very helpful. Initially, I had an assertion that looked like this:
expect(restaurant.association(:reviews)).to be_loaded
Since I was writing the test before the implementation — *cough* TDD isn’t dead *cough* — I got the expected failure when running it. However, the failure message was not that friendly after all:
$ rspec spec/controllers/restaurant_controller_spec.rb Failures: 1) RestaurantsController#index eager loads Failure/Error: expect(restaurant.association(:reviews)).to be_loaded expected `#<ActiveRecord::Associations::HasManyAssociation (...) >.loaded?` to return…
-
Using Page Objects in your Acceptance Tests
April 10, 2016
If you’ve written acceptance tests for web applications in the past (also called feature tests), you might be familiar with tools like Capybara, Simplelenium and FluentLenium. These are great abstractions over the browser (thanks, Selenium!) that provide very nice APIs for testing web applications.
If you’ve done this for a while, you might also have heard of Page Objects. The idea behind them is that your tests should be about the behavior of your application and not about the underlying HTML, since the HTML is an implementation detail and probably not the interesting part of your tests.
Our base acceptance test
Let’s assume that we are working on an application where you can browse and review restaurants and we have an acceptance test…
-
Unit Testing ActiveRecord eager-loading
January 27, 2016
If you’ve worked with relational databases and any ORMs like Java’s Hibernate, .NET’s NHibernate or Rails’
ActiveRecord
in the past, you might be familiar with SELECT N+1 issues. It is a common performance problem in database-dependent applications and, because of this, these ORMs provide a built-in solution to this problem.In
ActiveRecord
,includes
,preload
andeager_load
come to the rescue. Therefore, it is not unusual to find these keywords scattered in different places where your application accesses the database. Hopefully this isn’t a lot of places though - you are using Query Objects, right?An example application
Let’s imagine for a second that we have an application where you can browse restaurants, which in turn have many reviews…
-
Query Objects in the Rails world - A Different Approach
January 26, 2016
If you have worked with Ruby on Rails before then you might be familiar with ActiveRecord
scopes
. Using them, you can achieve what many would consider very readable code. Let’s say that we have an application where we display an inbox where users receive messages.class Message < ActiveRecord::Base end
Now, let’s imagine that after reading a
Message
, it is marked as read, and let’s represent that with aread
column in the database. Additionally, our users can either archive theMessage
or move it to the trash. We’ll represent this concept with alocation
column in themessages
table.Querying the database the Rails way
Let’s say that our users want to have a way to view unread messages in their inbox. Using
ActiveRecord
, you could achieve… -
Pygmentizing your Rails app hosted on Heroku
July 28, 2012
This post was originally published in the Rambling Labs Blog on July 28, 2012.
Last week, I watched Ryan Bates’ Syntax Highlighting RailsCast and wanted to apply what I had just learned right away, using pygments.
As you might have noticed, the jQuery Rambling Slider homepage features the new syntax highlighting styling. I’ve spent great part of the day updating the blog posts to use this new syntax highlighting style, to stop relying on GitHub’s gists, but that’s another story.
Now, there are several ways to do this. There are a couple of gems out there, like the
pygments.rb
mentioned on the RailsCast, that are very helpful. I installed that gem locally and it worked like a charm, but when I tried to upload the changes to Heroku, the… -
The rambling-slider-rails v0.1.0 has been released!
July 22, 2012
This post was originally published in the Rambling Labs Blog on July 22, 2012.
Version 0.1.0 of the
rambling-slider-rails
gem is here! And it includes a major bug fix.The
rambling-slider-rails
gem had an awful bug when running on production mode, causing the SASS to not be compiled. There were a couple of failed attempts before0.1.0
trying to fix this. They were0.0.2
and0.0.3
, which have both been yanked from the RubyGems repository.After fixing the issue and revising the file/directory structure, the version 0.1.0 has been pushed to RubyGems and should now be working correctly on both production and development modes.
See Introducing rambling-slider-rails: Easily include the jQuery Rambling Slider on your rails app and the project…
-
jQuery Rambling Slider new home page
July 22, 2012
This post was originally published in the Rambling Labs Blog on July 22, 2012.
The jQuery Rambling Slider now has its own dedicated section here on ramblinglabs.com. Here’s the link: jQuery Rambling Slider | A CoffeeScript improved version of the Nivo Slider
It features thus far one download page and one description page with a fully functional slider, included on the site with the rambling-slider-rails gem (see Introducing rambling-slider-rails: Easily include the jQuery Rambling Slider on your rails app and The rambling-slider-rails v0.1.0 has been released!. I will be adding an examples page soon, to present the different themes, image resizing support, flash support and other options added.
Go ahead and check it out!
Also, the Rambling…
-
Introducing rambling-slider-rails: Easily include the jQuery Rambling Slider on your rails app
April 27, 2012
This post was originally published in the Rambling Labs Blog on April 27, 2012.
About three weeks ago, I had to use the jQuery Rambling Slider together with the Rails asset pipeline… It was a headache and a total mess… Having to change all the references to the images on the CSS file, as well as the themes was not as smooth as I would like that to be.
So, I automated the process a bit locally and started to think how would be the easiest way to integrate the jQuery Rambling Slider into a Rails app. Then it hit me…
Of course! How about building a gem that includes the necessary adjustments for the asset pipeline on Rails? That would we really cool and will save me from doing the same process over and over again for each new application…
-
Rails - Custom 404 and 500 pages and the exception_notification gem
April 27, 2012
This post was originally published in the Rambling Labs Blog on April 27, 2012.
As I explained before on the Rails 3.1 - Adding custom 404 and 500 error pages post, sometimes you might want to have a custom way to handle your not found and internal server errors. In that case we wanted to show the error with a custom template.
But, what if I have an important site from which I want to be notified if there is any error raised? There are a couple of gems for this. The one I’m most familiar with is
exception_notification
gem, which is easily configured as it is depicted on its README.This gem is added to the rails middleware stack and will capture any raised error and send you an email notifying about it.
However, someone pointed out…