Hi TDD Fans,

I'm pretty new to Ruby / RSpec / Rails but not to TDD.

This is more of a general 'how do you do good design in a rails app' question than an rspec-specific question. I'm asking it here because I know this list is read by lots of people who care about good design, but please feel free to point me somewhere else if you think it's not relevant to this list.

Probably through my inexperience with the language / framework, I'm finding that I'm tending to clutter my controllers with SQL-specific stuff.

e.g.

    def get_cities

City.paginate(:all, get_find_params.merge!( :page => params [:page] ))

    end

    def get_find_params

      find_params = { :order => get_order_clause }

      if params[:name] || params[:last_24]
        find_params.merge! :conditions => get_conditions
      end

      return find_params

    end

    def get_conditions
"name like '%#{params[:name]}%'" + (params[:last_24] ? " AND created_at >= '#{DateTime.now - 1.days}'" : "")
    end

    def get_order_clause
      (params[:sort] ? 'created_at DESC, ' : "") + 'name ASC'
    end

This is obviously horribly brittle to write specs for, but I'm not really sure what I should do instead...

How do I get my models to encapsulate this stuff, especially given I'm using the will_paginate plug-in?

Any tips / pointers greatly appreciated.

cheers,
Matt

http://blog.mattwynne.net
http://songkick.com

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to