Commit 3c2de986d2eba190314b40e2961d7be7ac6327d4
1 parent
356ed1a3
Exists in
master
and in
26 other branches
Validate article type in SuggestArticle
Showing
2 changed files
with
17 additions
and
1 deletions
Show diff stats
app/models/suggest_article.rb
@@ -36,7 +36,11 @@ class SuggestArticle < Task | @@ -36,7 +36,11 @@ class SuggestArticle < Task | ||
36 | end | 36 | end |
37 | 37 | ||
38 | def article_type | 38 | def article_type |
39 | - (article[:type] || 'TinyMceArticle').constantize | 39 | + if article[:type].present? |
40 | + type = article[:type].constantize | ||
41 | + return type if type < Article | ||
42 | + end | ||
43 | + TinyMceArticle | ||
40 | end | 44 | end |
41 | 45 | ||
42 | def perform | 46 | def perform |
test/unit/suggest_article_test.rb
@@ -230,4 +230,16 @@ class SuggestArticleTest < ActiveSupport::TestCase | @@ -230,4 +230,16 @@ class SuggestArticleTest < ActiveSupport::TestCase | ||
230 | end | 230 | end |
231 | end | 231 | end |
232 | 232 | ||
233 | + should 'accept article type parameter' do | ||
234 | + t = SuggestArticle.new | ||
235 | + t.article = {:name => 'name', :body => 'body', :type => 'TextArticle'} | ||
236 | + t.article_type == TextArticle | ||
237 | + end | ||
238 | + | ||
239 | + should 'fallback to tinymce when type parameter is invalid' do | ||
240 | + t = SuggestArticle.new | ||
241 | + t.article = {:name => 'name', :body => 'body', :type => 'Comment'} | ||
242 | + t.article_type == TinyMceArticle | ||
243 | + end | ||
244 | + | ||
233 | end | 245 | end |