Skip to content

Instantly share code, notes, and snippets.

@patrick99e99
Created February 18, 2010 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrick99e99/307464 to your computer and use it in GitHub Desktop.
Save patrick99e99/307464 to your computer and use it in GitHub Desktop.
# controller action
def result_list
type = (params[:newsletter_id].to_i.zero? ? 'PdfList' : 'Newsletter').constantize
result_list = type.find(params[:result_list_id])
unless result_list.in_progress?
call_rake :result_list, :function => params[:submit_button],
:result_list_id => result_list.id,
:search => (params[:search].blank? ? nil : params[:search].strip),
:search_scope => params[:search_scope],
:type => type.to_s.downcase,
:item_ids => (params[:item_ids].join(",") if params[:item_ids])
end
respond_to do |format|
format.html { redirect_to contacts_path(params) }
format.js { render :nothing => true }
end
end
require 'spec_helper'
describe ContactsController do
before do
@params = { "item_ids"=>["1", "2", "3"],
"action"=>"result_list",
"_method"=>"put",
"authenticity_token"=>"SH8gm6L3C5V0mnfMsXSSQYZexMBPJ2G9hrbIBF7F718=",
"order"=>"contacts.first_name",
"submit_button"=>"check all",
"page"=>"1",
"display"=>"",
"result_list_id"=>"1",
"controller"=>"contacts",
"per_page"=>"5",
"direction"=>"0",
"search_scope"=>"",
"search"=>""
}
end
def do_put
put :result_list, :params => @params
end
describe "calling result_list action for rake task" do
it "should be a mailing list when there is a newsletter_id param" do
end
it "should be a pdf list when there is no newsletter_id param"
it "should not call rake if the result list is in process" do
pdf_list = mock_model(PdfList, :save => true, :id => "1", :rake_finish => Time.now)
newsletter = mock_model(Newsletter, :save => true, :id => "1", :rake_finish => Time.now)
# and here I should be doing something like:
# pdf_list.in_progress?.should be_false
# newsletter.in_progress?.should be_false
end
it "should redirect to the contacts path when called via http"
it "should render nothing when called via ajax"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment