From 1cd24e451b445c5f5d3921c9092ab9c11632af87 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 20 Jan 2009 10:46:16 -0800 Subject: [PATCH] Sorting the Project column by project name now * Including projects in Rate.history_for_user * Moved the valid sort options to a constant on the RatesController * Changed the ValidSortOptions to use the Project name for project_id * Updated admin view to use RatesController::ValidSortOptions instead of a duplicated string. #1915 --- app/controllers/rates_controller.rb | 4 +++- app/models/rate.rb | 3 ++- app/views/users/_rates.html.erb | 2 +- spec/controllers/rates_controller_spec.rb | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/rates_controller.rb b/app/controllers/rates_controller.rb index f403342..fb8bc43 100644 --- a/app/controllers/rates_controller.rb +++ b/app/controllers/rates_controller.rb @@ -7,11 +7,13 @@ class RatesController < ApplicationController before_filter :require_user_id, :only => [:index, :new] before_filter :set_back_url, :only => [:new, :edit] + ValidSortOptions = {'date_in_effect' => "#{Rate.table_name}.date_in_effect", 'project_id' => "#{Project.table_name}.name"} + # GET /rates?user_id=1 # GET /rates.xml?user_id=1 def index sort_init "#{Rate.table_name}.date_in_effect", "desc" - sort_update ['date_in_effect', 'project_id'] + sort_update ValidSortOptions @rates = Rate.history_for_user(@user, sort_clause) diff --git a/app/models/rate.rb b/app/models/rate.rb index d247121..33a1e2f 100644 --- a/app/models/rate.rb +++ b/app/models/rate.rb @@ -14,7 +14,8 @@ class Rate < ActiveRecord::Base named_scope :history_for_user, lambda { |user, order| { :conditions => { :user_id => user.id }, - :order => order + :order => order, + :include => :project } } diff --git a/app/views/users/_rates.html.erb b/app/views/users/_rates.html.erb index ce6ec62..ff4c706 100644 --- a/app/views/users/_rates.html.erb +++ b/app/views/users/_rates.html.erb @@ -9,7 +9,7 @@ <%# TODO: Refactor out of the view once there is a hook in the controller (Post 0.8.0). %> <%# Can't expect everyone to upgrade at the moment %> <% sort_init "#{Rate.table_name}.date_in_effect", "desc" %> -<% sort_update ['date_in_effect', 'project_id'] %> +<% sort_update RatesController::ValidSortOptions %> <% @rates = Rate.history_for_user(@user, "#{Rate.table_name}.date_in_effect desc") %> diff --git a/spec/controllers/rates_controller_spec.rb b/spec/controllers/rates_controller_spec.rb index c79250c..efe6a61 100644 --- a/spec/controllers/rates_controller_spec.rb +++ b/spec/controllers/rates_controller_spec.rb @@ -161,6 +161,7 @@ describe RatesController, "as an administrator" do before(:each) do User.stub!(:find).with(@user.id.to_s).and_return(@user) @default_sort = "#{Rate.table_name}.date_in_effect desc" + controller.stub!(:sort_clause).and_return(@default_sort) end it "should expose all historic rates for the user as @rates" do