#havers

Rob Sharp writes online here.

  • Mixing rspec and mislav's will_paginate plugin

    • 11 Jan 2010
    • 0 Responses
    •  views
    • rspec ruby testing will_paginate
    • Edit
    • Delete
    • Tags
    • Autopost

    I didn't find the solution to using will_paginate in rpsec'd views anywhere, so here it is for anyone else searching for the same.

    The solution is to build mock ActiveRecord models as part of an array, which will get you most of the way there. Then you can either the mock in the will_paginate methods, or you can simply call the paginate method on the array itself, as the plugin extends the Array class.

    The code looks a bit like this:

    describe "/items/index.html.erb" do

      before(:each) do
        @items = [
          stub_model(Item,
            :name => "value for name",
            :description => "value for description"
          ),
          stub_model(Item,
            :name => "value for name",
            :description => "value for description"
          )
        ]
        assigns[:items] = @items.paginate({:page => 1, :per_page => 30})
      end

     

    • Tweet
  • Running multiple versions of Ruby on Ubuntu Karmic

    • 1 Sep 2009
    • 1 Response
    •  views
    • mri ree ruby ubuntu
    • Edit
    • Delete
    • Tags
    • Autopost

    UPDATED: For dev, you could also use Ruby Version Manager http://rvm.beginrescueend.com/

    Recently I discovered that Karmic ships with Ruby 1.8.7 - not a problem in itself, but if you're using ActionMailer with Google Mail, there's some big changes between how SMTP/TLS is handled on 1.8.6 vs 1.8.7 that cause things to break.

    I run Ruby Enterprise Edition on my web server - which is currently 1.8.6 - and so the code I had written and tested locally wouldn't run correctly on the server. I can easily install REE locally, but I'd like to hang on to the default ubuntu Ruby too. Thankfully, there's an easy solution

    update-alternatives

    Let's create an alternative path for REE

    sudo update-alternatives --install /usr/local/bin/ruby ruby /opt/ruby-enterprise/bin/ruby 50 --slave /usr/local/bin/erb erb /opt/ruby-enterprise/bin/erb --slave /usr/local/bin/gem gem /opt/ruby-enterprise/bin/gem --slave /usr/local/bin/irb irb /opt/ruby-enterprise/bin/irb --slave /usr/local/bin/rdoc rdoc /opt/ruby-enterprise/bin/rdoc --slave /usr/local/bin/ri ri /opt/ruby-enterprise/bin/ri --slave /usr/local/bin/testrb testrb /opt/ruby-enterprise/bin/testrb --slave /usr/local/bin/rake rake /opt/ruby-enterprise/bin/rake --slave /usr/local/bin/rails rails /opt/ruby-enterprise/bin/rails

    ...and for MRI

    sudo update-alternatives --install /usr/local/bin/ruby ruby /usr/bin/ruby 100 --slave /usr/local/bin/erb erb /usr/bin/erb --slave /usr/local/bin/gem gem /usr/bin/gem --slave /usr/local/bin/irb irb /usr/bin/irb --slave /usr/local/bin/rdoc rdoc /usr/bin/rdoc --slave /usr/local/bin/ri ri /usr/bin/ri --slave /usr/local/bin/testrb testrb /usr/bin/testrb --slave /usr/local/bin/rake rake /usr/bin/rake --slave /usr/local/bin/rails rails /usr/bin/rails

    Oddly, my Karmic install already had an alternative by gems, so I had to remove that first using

    sudo update-alternatives --remove-all gem

    I can now easily switch betwen them using

    sudo update-alternatives --config ruby

    Too easy!

    • Tweet
  • About

    Haggis, neeps and tatties are just a few of my favourite things.

    132885 Views
  • Archive

    • 2010 (19)
      • November (1)
      • June (1)
      • May (4)
      • April (3)
      • March (1)
      • February (4)
      • January (5)
    • 2009 (189)
      • December (4)
      • November (4)
      • October (13)
      • September (5)
      • August (1)
      • July (2)
      • June (18)
      • May (11)
      • April (20)
      • March (59)
      • February (43)
      • January (9)
    • 2008 (355)
      • December (21)
      • November (73)
      • October (52)
      • September (21)
      • August (23)
      • July (37)
      • June (40)
      • May (25)
      • April (30)
      • March (22)
      • February (7)
      • January (4)
    • 2007 (44)
      • December (9)
      • November (18)
      • October (1)
      • September (8)
      • July (7)
      • May (1)

    Get Updates

    Subscribe via RSS
    TwitterFlickr