C0 code coverage information

Generated on Tue Dec 04 22:06:26 -0500 2007 with rcov 0.8.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.
Name Total lines Lines of code Total coverage Code coverage
app/controllers/meals_controller.rb 166 117
100.0% 
100.0% 
  1 #####
  2 #
  3 # Copyright 2007 Chris Strom, Robin Strom
  4 #
  5 # This file is part of EEE Code.
  6 #
  7 # EEE Code is free software: you can redistribute it and/or modify
  8 # it under the terms of the GNU General Public License as published by
  9 # the Free Software Foundation, either version 3 of the License, or
 10 # (at your option) any later version.
 11 #
 12 # EEE Code is distributed in the hope that it will be useful,
 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 # GNU General Public License for more details.
 16 #
 17 # You should have received a copy of the GNU General Public License
 18 # along with EEE Code.  If not, see <http://www.gnu.org/licenses/>.
 19 #
 20 class MealsController < ApplicationController
 21   before_filter :login_required, :only => [ :edit, :update, :new, :create ]
 22 
 23   after_filter :destroy_cache_with_flash, :only => [:show]
 24 
 25   layout 'master'
 26 
 27   caches_action :mini_calendar, :show, :rss
 28 
 29   cache_sweeper :meal_sweeper, :only => [ :create, :update, :delete ]
 30 
 31   def initialize
 32     @title = 'Meal'
 33     super
 34   end
 35 
 36   def index
 37     redirect_to :controller => 'home'
 38   end
 39 
 40   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
 41   verify :method => :post, :only => [ :destroy, :create, :update ],
 42          :redirect_to => { :controller => 'home', :action => 'index' }
 43 
 44   def mini_calendar
 45     @first_month = Meal.oldest && Meal.oldest.date.to_time.beginning_of_month.to_date
 46     @last_month = (Meal.newest ? Meal.newest.date : Date.today).to_time.beginning_of_month.to_date
 47     @date = Date.new((params[:year] && params[:year].to_i) || @last_month.year,
 48                      (params[:month] && params[:month].to_i) || @last_month.month, 1)
 49 
 50     if @date > @last_month.to_time.years_since(2).to_date
 51       redirect_to(:action => 'mini_calendar', :year => @last_month.year, :month => @last_month.month)
 52       return
 53     elsif @date < @first_month.to_time.years_ago(2).to_date
 54       redirect_to(:action => 'mini_calendar', :year => @first_month.year, :month => @first_month.month)
 55       return
 56     end
 57 
 58     render :layout => 'frame'
 59   end
 60 
 61   def show
 62     @show_recipe_search = true
 63     @meal = params.include?(:id) ? Meal.find(params[:id]) : Meal.find_by_ymd(params)
 64 
 65     if @meal.nil?
 66       flash[:notice] = 'Unable to locate the requested meal.'
 67       redirect_to :controller => 'home', :action => 'interstitial'
 68       return
 69     end
 70 
 71     @title = @meal.title + ' (Meal)'
 72     @tags = @meal.tags
 73   end
 74 
 75   def new
 76     @meal = Meal.new
 77   end
 78 
 79   def create
 80     @meal = Meal.new(params[:meal])
 81     @meal.current_user = current_user
 82 
 83     Meal.transaction do
 84       @meal.save!
 85       (params[:new_menu_item] || []).each do |attr|
 86         @meal.menu_items.create(attr) if !attr[:name].blank?
 87       end
 88     end
 89 
 90     flash[:notice] = "Meal created successfully."
 91     if params[:commit] && params[:commit] == "Create"
 92       redirect_to '/meals/' + @meal.uri
 93     else
 94       redirect_to :action => 'edit', :id => @meal.id
 95     end
 96   rescue ActiveRecord::RecordInvalid => e
 97     render(:action => 'new')
 98   end
 99 
100   def edit
101     @meal = Meal.find(params[:id])
102   end
103 
104   def update
105     @meal = Meal.find(params[:id])
106     @meal.current_user = current_user
107 
108     Meal.transaction do
109       @meal.update_attributes!(params[:meal])
110       (params[:menu_item] || {}).each_pair do |id, attr|
111         if attr[:name].blank?
112           MenuItem.delete(id)
113         else
114           MenuItem.update(id, attr)
115         end
116       end
117       (params[:new_menu_item] || []).each do |attr|
118         @meal.menu_items.create(attr) if !attr[:name].blank?
119       end
120     end
121 
122     flash[:notice] = "Meal updated successfully."
123     if params[:commit] && params[:commit].downcase == "save changes"
124       redirect_to '/meals/' + @meal.uri
125     else
126       redirect_to :action => 'edit', :id => @meal.id
127     end
128 
129   rescue ActiveRecord::RecordInvalid => e
130     render(:action => 'edit')
131   end
132 
133   def show_month
134     @month = Date.new(params[:year].to_i, params[:month].to_i)
135 
136     if @month > (date_newest = Meal.newest.date)
137       redirect_to(:action => 'show_month', :year => date_newest.year, :month => date_newest.month)
138       return
139     elsif (date_oldest = Meal.oldest.date) > @month.to_time.next_month.to_date
140       redirect_to(:action => 'show_month', :year => date_oldest.year, :month => date_oldest.month)
141       return
142     end
143 
144     @meals = Meal.find_all_from_month(@month)
145   end
146 
147   def show_year
148     @meals = Meal.find_all_from_year(params[:year])
149   end
150 
151   def rss
152     @meals = Meal.newest(10)
153     render :layout =>  false
154   end
155 
156   protected
157   def destroy_cache_with_flash
158     if @meal && !flash.empty?
159       expire_action("/meals/#{@meal.uri}")
160     end
161   end
162 
163   def authorized?
164     current_user.author?
165   end
166 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.

Valid XHTML 1.0! Valid CSS!