C0 code coverage information
Generated on Fri Aug 25 10:11:27 PDT 2006 with rcov 0.7.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 require 'date'
2 require 'news_parts'
3
4 class SearchController < ApplicationController
5 layout 'site'
6 session :off
7 helper :ads
8 include NewsParts
9
10 def index
11 redirect_to :action=>'main'
12 end
13
14 def record_reviews
15 do_search :record_reviews
16 get_most_read('RecordReview') unless read_fragment(:overwrite_params => {:controller => '/article', :action => 'record_review', :part => 'most_read'})
17
18 @feeds = {
19 :rss => url_for( :controller => 'rss', :action => 'record_reviews' ),
20 :atom => url_for( :controller => 'atom', :action => 'record_reviews' ),
21 }
22
23 @page_title = "Pitchfork: Record Reviews - #{@results_title}"
24 @stylesheets << "pages"
25
26 @is_records = true
27
28 if params[:sub_action] != "query"
29 render :template => "/page/record_review_archive"
30 end
31 true
32 end
33
34 def track_reviews
35 do_search :track_reviews
36 get_most_read('TrackReview') unless read_fragment(:overwrite_params => {:controller => '/article', :action => 'track_review', :part => 'most_read'})
37
38 @feeds = {
39 :rss => url_for( :controller => 'rss', :action => 'track_reviews' ),
40 :atom => url_for( :controller => 'atom', :action => 'track_reviews' ),
41 }
42
43 @page_title = "Pitchfork: Track Reviews - #{@results_title}"
44
45 @stylesheets << "pages"
46
47 @is_tracks = true
48
49 if params[:sub_action] == "date"
50 render :template => "/page/track_review_archive"
51 end
52 true
53 end
54
55 def reviews
56 if params[:query]
57 query = params[:query]
58 else
59 query = params.dup
60 end
61 not_needed = [ :action, :id, :controller, :page, 'action', 'id', 'controller', 'page' ]
62 query.delete_if { |key, value| not_needed.include?(key) }
63
64 criteria = Article.create_search_condition(query)
65 criteria << "AND (type = 'RecordReview' OR type = 'TrackReview')"
66 @results_title = "#{query[:artist]} #{query[:keywords]}"
67 params_array = []
68 query.each do |key, value|
69 params_array << ":#{key} => '#{value}'" if value != ''
70 end
71 @page_parameters = params_array.join(', ')
72
73 @article_pages, @articles = paginate( :article, :order => 'published_at DESC, premiere_position ASC', :per_page => 12, :conditions => criteria)
74
75 get_most_read('RecordReview') unless read_fragment(:overwrite_params => {:controller => '/article', :action => 'record_review', :part => 'most_read'})
76 @stylesheets << "pages"
77 @page_title = "Pitchfork: Reviews - #{@results_title}"
78 true
79 end
80
81 def features
82 do_search :features
83 get_most_read('Feature') unless read_fragment(:overwrite_params => {:controller => '/article', :action => 'feature', :part => 'most_read'})
84
85 @feeds = {
86 :rss => url_for( :controller => 'rss', :action => 'features' ),
87 :atom => url_for( :controller => 'atom', :action => 'features' ),
88 }
89
90 @page_title = "Pitchfork: Features - #{@results_title}"
91 @stylesheets << "pages"
92
93 @is_features = true
94
95 if params[:sub_action] != "query"
96 render :template => "/page/feature_archive"
97 end
98 true
99 end
100
101 def best_new_music
102 end
103
104 def news
105 criteria = []
106 if params[:sub_action] == 'date' or (params[:month] and params[:year])
107 if params[:date]
108 date = params[:date]
109 else
110 date = params
111 end
112 month = date[:month]
113 year = date[:year]
114 first_day, last_day = month_spread(year, month)
115
116 criteria = ["(published_at >= ? AND published_at <= ? ) AND " + NEWS_CONDITION,
117 first_day, last_day]
118 @results_title = "#{Date::MONTHNAMES[month]}, #{year}"
119 elsif params[:sub_action] == 'query'
120 # check and make sure that the query isn't empty.
121 # if it is. Just send them to the news landing page.
122 return false unless criteria = clean_query_params(:news)
123 criteria[0] << " AND (type = \'News\' OR type = \'NewsBlurb\')"
124 @news_pages, @news_articles = paginate( :articles, :per_page => 12, :order => "published_at DESC, premiere_position, created_at DESC", :conditions => criteria)
125 end
126
127 #build up the sidebar data
128 current_news(false)
129
130 # setup the standart page stuff (title, rss, etc...)
131 setup_page
132
133 if params[:sub_action] == 'query'
134 render :template => '/page/news'
135 else
136 render :template => '/page/news_archive'
137 end
138 end
139
140 def downloads
141 do_search :downloads
142 @download_pages = @article_pages
143 @downloads = @articles
144
145 #build up the sidebar data
146 current_news(false)
147
148 @feeds = {
149 :rss => url_for( :controller => 'rss', :action => 'downloads' ),
150 :atom => url_for( :controller => 'atom', :action => 'downloads' ),
151 }
152
153 @page_title = "Pitchfork: Downloads - #{@results_title}"
154 @stylesheets << "pages"
155 render :template => '/page/downloads'
156 end
157
158 def main
159 can_render = true
160
161 case params['article_type']
162 when 'albums'
163 if record_reviews and can_render
164 can_render = false
165 render :action => 'record_reviews'
166 end
167 when 'features'
168 if features and can_render
169 render :action => 'features'
170 end
171 when 'tracks'
172 if track_reviews and can_render
173 render :action => 'track_reviews'
174 can_render = false
175 end
176 when 'news'
177 if can_render and news
178 # news renders its own templates
179 can_render = false
180 end
181 else
182 if can_render and all
183 render :action => 'all'
184 can_render = false
185 end
186 end
187 end
188
189 def all
190 return false unless do_search :articles
191 get_most_read('RecordReview') unless read_fragment(:overwrite_params => {:controller => '/article', :action => 'record_review', :part => 'most_read'})
192 @page_title = "Pitchfork: #{@results_title}"
193 @stylesheets << "pages"
194 end
195
196 private
197
198 def clean_query_params(type)
199 query = nil
200 if params[:query]
201 query = params[:query]
202 else
203 query = params.dup
204 end
205 not_needed = [ :action, :id, :controller, :page, 'action', 'id', 'controller', 'page', 'x', 'y', 'article_type', 'sub_action' ]
206 query.delete_if { |key, value| not_needed.include?(key) or value == "" or value.nil? }
207
208 # check and make sure that the query isn't empty.
209 # if it is. Just send them to the news landing page.
210 if query.size < 1
211 unless type == :articles
212 redirect_to :controller => 'page', :action => type
213 else
214 redirect_to :controller => 'page', :action => 'home'
215 end
216
217 return false
218 end
219
220 criteria = Article.create_search_condition(query)
221 @results_title = "#{query[:artist]} #{query[:keywords]}"
222 params_array = []
223 query.each do |key, value|
224 params_array << ":#{key} => '#{value}'" if value != ''
225 end
226
227 @page_parameters = params_array.join(', ')
228 criteria
229 end
230
231 def do_search(type)
232 criteria = []
233
234 if params[:sub_action] == 'date'
235 # calculate start and end dates to optimize query performance.
236 if params[:date]
237 @date = params[:date]
238 else
239 @date = params
240 end
241 month = @date[:month].to_i
242 year = @date[:year].to_i
243 first_day, last_day = month_spread(year, month)
244
245 criteria = ["(published_at >= ? AND published_at <= ?) AND published_at <= ? AND approved = 1", first_day, last_day, Time.now]
246 @results_title = "#{Date::MONTHNAMES[month]}, #{year}"
247
248 if type == :articles
249 # custom search and sort for an "all" search
250 @article_pages, @articles = paginate(
251 type,
252 :select => "articles.id as id, artist, title, subtitle, abstract, article_pages_data, published_at, record_label, rating, image_id, sub_category_id, author_id, custom_author, source, type, FIND_IN_SET(type, 'RecordReview,News,NewsBlurb,Download,TrackReview,Feature') as sort_column",
253 :joins => "LEFT OUTER JOIN users on users.id = articles.author_id",
254 :order => 'sort_column, published_at DESC, premiere_position ASC',
255 :per_page => 12,
256 :conditions => criteria)
257 else
258 @articles = Object::const_get(Inflector::classify(type.to_s)).find(
259 :all,
260 :select => "articles.id as id, artist, title, subtitle, abstract, article_pages_data, published_at, record_label, rating, image_id, sub_category_id, author_id, custom_author, source",
261 :joins => "LEFT OUTER JOIN users on users.id = articles.author_id",
262 :order => 'published_at DESC, premiere_position ASC',
263 :conditions => criteria )
264 end
265
266 elsif params[:sub_action] == 'query'
267 return false unless criteria = clean_query_params(type)
268
269 if type == :articles
270 # custom search and sort for an "all" search
271 @article_pages, @articles = paginate(
272 type,
273 :select => "articles.id as id, artist, title, subtitle, abstract, article_pages_data, published_at, rating, record_label, image_id, sub_category_id, author_id, custom_author, source, type, FIND_IN_SET(type, 'RecordReview,News,NewsBlurb,Download,TrackReview,Feature') as sort_column",
274 :joins => "LEFT OUTER JOIN users on users.id = articles.author_id",
275 :order => 'sort_column, published_at DESC, premiere_position ASC',
276 :per_page => 12,
277 :conditions => criteria)
278 else
279 @article_pages, @articles = paginate(
280 type,
281 :select => "articles.id as id, artist, title, subtitle, abstract, article_pages_data, published_at, record_label, rating, image_id, sub_category_id, author_id, custom_author, source",
282 :joins => "LEFT OUTER JOIN users on users.id = articles.author_id",
283 :order => 'published_at DESC, premiere_position ASC',
284 :per_page => 12,
285 :conditions => criteria)
286 end
287 end
288
289 end
290 end
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.