Commit 19ac13ef93744d1089346dbfb74f6bd0ee2c6a67
1 parent
e4a49c3b
Exists in
master
and in
29 other branches
ActionItem23: adding validations to RSS feed
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1130 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
54 additions
and
0 deletions
Show diff stats
app/models/rss_feed.rb
... | ... | @@ -8,6 +8,7 @@ class RssFeed < Article |
8 | 8 | end |
9 | 9 | alias :settings :body |
10 | 10 | |
11 | + # The maximum number of articles to be displayed in the RSS feed. | |
11 | 12 | def limit |
12 | 13 | settings[:limit] |
13 | 14 | end |
... | ... | @@ -15,19 +16,32 @@ class RssFeed < Article |
15 | 16 | settings[:limit] = value |
16 | 17 | end |
17 | 18 | |
19 | + # FIXME this should be validates_numericality_of, but Rails 1.2.6 does not | |
20 | + # support validates_numericality_of with virtual attributes | |
21 | + validates_format_of :limit, :with => /^[0-9]+$/, :if => :limit | |
22 | + | |
23 | + # determinates what to include in the feed. Possible values are +:all+ | |
24 | + # (include everything from the profile) and :parent_and_children (include | |
25 | + # only articles that are siblings of the feed). | |
26 | + # | |
27 | + # The feed itself is never included. | |
18 | 28 | def include |
19 | 29 | settings[:include] |
20 | 30 | end |
21 | 31 | def include=(value) |
22 | 32 | settings[:include] = value |
23 | 33 | end |
34 | + validates_inclusion_of :include, :in => [ :all, :parent_and_children ], :if => :include | |
24 | 35 | |
36 | + # determinates what to include in the feed as items' description. Possible | |
37 | + # values are +:body+ (default) and +:abstract+. | |
25 | 38 | def feed_item_description |
26 | 39 | settings[:feed_item_description] |
27 | 40 | end |
28 | 41 | def feed_item_description=(value) |
29 | 42 | settings[:feed_item_description] = value |
30 | 43 | end |
44 | + validates_inclusion_of :feed_item_description, :in => [ :body, :abstract ], :if => :feed_item_description | |
31 | 45 | |
32 | 46 | # TODO |
33 | 47 | def to_html | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -124,6 +124,46 @@ class RssFeedTest < Test::Unit::TestCase |
124 | 124 | feed.data |
125 | 125 | end |
126 | 126 | |
127 | + should 'limit should only accept integers' do | |
128 | + feed = RssFeed.new | |
129 | + feed.limit = 'text' | |
130 | + feed.valid? | |
131 | + assert feed.errors.invalid?(:limit) | |
132 | + feed.limit = 10 | |
133 | + feed.valid? | |
134 | + assert !feed.errors.invalid?(:limit) | |
135 | + end | |
136 | + | |
137 | + should 'allow only :parent_and_children and :all as include setting' do | |
138 | + feed = RssFeed.new | |
139 | + feed.include = :something_else | |
140 | + feed.valid? | |
141 | + assert feed.errors.invalid?(:include) | |
142 | + | |
143 | + feed.include = :parent_and_children | |
144 | + feed.valid? | |
145 | + assert !feed.errors.invalid?(:include) | |
146 | + | |
147 | + feed.include = :all | |
148 | + feed.valid? | |
149 | + assert !feed.errors.invalid?(:include) | |
150 | + end | |
151 | + | |
152 | + should 'allow only :body and :abstract as feed_item_description' do | |
153 | + feed = RssFeed.new | |
154 | + feed.feed_item_description = :something_else | |
155 | + feed.valid? | |
156 | + assert feed.errors.invalid?(:feed_item_description) | |
157 | + | |
158 | + feed.feed_item_description = :body | |
159 | + feed.valid? | |
160 | + assert !feed.errors.invalid?(:feed_item_description) | |
161 | + | |
162 | + feed.feed_item_description = :abstract | |
163 | + feed.valid? | |
164 | + assert !feed.errors.invalid?(:feed_item_description) | |
165 | + end | |
166 | + | |
127 | 167 | should 'provide proper short description' do |
128 | 168 | RssFeed.expects(:==).with(Article).returns(true).at_least_once |
129 | 169 | assert_not_equal Article.short_description, RssFeed.short_description | ... | ... |