• Rambling Trie 1.0.0 released!

    January 23, 2017

    It’s been a while since I last wrote anything about Rambling Trie (or anything at all really), but I wanted to take the time to talk about all the changes and performance improvements that I’ve made to the gem lately and that culminated in the release of version 1.0.0.

    The changes worth highlighting are:

    NEW: Ability to dump and load tries from disk

    It takes a relatively long time to load all the words from a large dictionary into a new trie in memory. This becomes especially annoying when you have to do this full process every time you restart your application, even though you know that the trie is going to remain constant over time.

    To sort this out, you can now use the Rambling::Trie.load and Rambling::Trie.dump methods! Like this...

    Continue Reading →

  • 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
      1) RestaurantsController#index eager loads
         Failure/Error: expect(restaurant.association(:reviews)).to be_loaded
           expected `#<ActiveRecord::Associations::HasManyAssociation (...) >.loaded?` to return...

    Continue Reading →

  • 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 READMEs 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...

    Continue Reading →

  • 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...

    Continue Reading →

  • 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 and eager_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...

    Continue Reading →

  • 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

    Now, let’s imagine that after reading a Message, it is marked as read, and let’s represent that with a read column in the database. Additionally, our users can either archive the Message or move it to the trash. We’ll represent this concept with a location column in the messages 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...

    Continue Reading →

  • Installing MacVim with Lua enabled through Homebrew

    January 11, 2016

    If you’re like me, you like to have control over the plugins that you have installed in your editor setup. However, staying up to date with the different plugins can be a little bit of a hassle from time to time, so lately, I’ve been using YADR, a set of community maintained dotfiles.

    A great autocompletion plugin that YADR comes with is neocomplete.vim, which “provides a keyword completion system by maintaining a cache of keywords in the current buffer”. Unfortunately, for it to work, it needs MacVim with Lua enabled.

    Now, I already had MacVim installed through Caskroom:

    which mvim
    # /usr/local/bin/mvim
    ls -l $(which mvim)
    # /usr/local/bin/mvim -> /opt/homebrew-cask/Caskroom/macvim/7.4-84/mvim

    But this version was installed without Lua...

    Continue Reading →

  • New homepage for Rambling Trie

    July 28, 2012

    This post was originally published in the Rambling Labs Blog on July 28, 2012.

    As done with the jQuery Rambling Slider previously on this week, and as I promised on that post as well, the Rambling Trie now has its own homepage on ramblinglabs.com! Here’s the link:

    Rambling Trie | A Ruby implementation of the Trie data structure

    It features installation and usage steps as well as a contributing page, and includes the badges from various cool GitHub services (more on that later). It also has a brand new logo, inspired on the trie data structure (and other tree data structures) concept.

    Go ahead and check it out!

    Still pending:

    • Examples page for jQuery Rambling Slider
    • Examples page for Rambling Trie
    • Examples page for Rambling Slider...

    Continue Reading →

  • 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,...

    Continue Reading →

  • Version 0.4.2 of the Rambling Trie has been released!

    July 28, 2012

    This post was originally published in the Rambling Labs Blog on July 28, 2012.

    The Rambling Trie has reached its 0.4.2 version. This one includes the before mentioned changes for the trie instance to behave as an Enumerable.

    This means that having this:

    trie = Rambling::Trie.create
    (%w(some words and other stuff)).each |word|
      trie << word

    You can do something like this:

    trie.each do |word|
      puts "#{word} is included!"

    As well as:

    trie.any? { |word| word.include? 'x' }
    trie.all? { |word| word.length > 0 }

    And any other method included in Ruby core’s Enumerable module. Isn’t that cool!?