C0 code coverage information
Generated on Tue May 30 23:34:43 CEST 2006 with rcov 0.5.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 'uri'
2 require 'net/http'
3 require 'md5'
4
5 class Article < ActiveRecord::Base
6 has_many :pings, :dependent => true, :order => "created_at ASC"
7 has_many :comments, :dependent => true, :order => "created_at ASC"
8 has_many :trackbacks, :dependent => true, :order => "created_at ASC"
9
10 has_and_belongs_to_many :categories
11 belongs_to :user
12
13 def stripped_title
14 self.title.to_url
15 end
16
17 def send_pings(articleurl, urllist)
18
19 # we need to transform the body now
20 # because we need to sent out an except based on the html representation
21 transform_body
22
23 urllist.to_a.each do |url|
24 begin
25 unless pings.collect { |p| p.url }.include?(url.strip)
26 ping = pings.build("url" => url)
27
28 ping.send_ping(articleurl)
29 ping.save
30 end
31
32 rescue
33 # in case the remote server doesn't respond or gives an error,
34 # we should throw an xmlrpc error here.
35 end
36 end
37 end
38
39 # Count articles on a certain date
40 def self.count_by_date(year, month = nil, day = nil, limit = nil)
41 from, to = self.time_delta(year, month, day)
42 Article.count(["articles.created_at BETWEEN ? AND ? AND articles.published != 0", from, to])
43 end
44
45 # Find all articles on a certain date
46 def self.find_all_by_date(year, month = nil, day = nil)
47 from, to = self.time_delta(year, month, day)
48 Article.find(:all, :conditions => ["articles.created_at BETWEEN ? AND ? AND articles.published != 0", from, to], :order => 'articles.created_at DESC', :include => [:categories, :trackbacks, :comments])
49 end
50
51 # Find one article on a certain date
52 def self.find_by_date(year, month, day)
53 find_all_by_date(year, month, day).first
54 end
55
56 # Finds one article which was posted on a certain date and matches the supplied dashed-title
57 def self.find_by_permalink(year, month, day, title)
58 from, to = self.time_delta(year, month, day)
59 find(:first, :conditions => [ %{
60 permalink = ?
61 AND articles.created_at BETWEEN ? AND ?
62 AND articles.published != 0
63 }, title, from, to ])
64 end
65
66 # Fulltext searches the body of published articles
67 def self.search(query)
68 if !query.to_s.strip.empty?
69 tokens = query.split.collect {|c| "%#{c.downcase}%"}
70 find_by_sql(["SELECT * from articles WHERE articles.published != 0 AND #{ (["(LOWER(body) LIKE ? OR LOWER(extended) LIKE ? OR LOWER(title) LIKE ?)"] * tokens.size).join(" AND ") } AND published != 0 ORDER by created_at DESC", *tokens.collect { |token| [token] * 3 }.flatten])
71 else
72 []
73 end
74 end
75
76 # Get the full html body
77 def full_html
78 "#{body_html}\n\n#{extended_html}"
79 end
80
81 protected
82
83 before_save :set_defaults, :transform_body
84
85 def set_defaults
86 self.published ||= 1
87 self.text_filter = config['text_filter'] if self.text_filter.blank?
88 self.permalink = self.stripped_title if self.attributes.include?("permalink") and self.permalink.blank?
89 self.guid = Digest::MD5.new(self.body.to_s+self.extended.to_s+self.title.to_s+self.permalink.to_s+self.author.to_s+Time.now.to_f.to_s).to_s if self.guid.blank?
90 end
91
92 def transform_body
93 self.body_html = HtmlEngine.transform(body, self.text_filter)
94 self.extended_html = HtmlEngine.transform(extended, self.text_filter)
95 end
96
97 def self.time_delta(year, month = nil, day = nil)
98 from = Time.mktime(year, month || 1, day || 1)
99
100 to = from + 1.year
101 to = from + 1.month unless month.blank?
102 to = from + 1.day unless day.blank?
103 to = to.tomorrow unless month.blank?
104 return [from, to]
105 end
106
107 validates_uniqueness_of :guid
108 validates_presence_of :title
109 end
Generated using the rcov code coverage analysis tool for Ruby version 0.5.0.