Commit e4a49c3b743b2e07c5f15ca100c34e8ffdb0f9eb

Authored by AntonioTerceiro
1 parent 132c1fdd

ActionItem23: refactoring: transformed settings in attributes



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1129 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/rss_feed.rb
@@ -8,6 +8,27 @@ class RssFeed < Article @@ -8,6 +8,27 @@ class RssFeed < Article
8 end 8 end
9 alias :settings :body 9 alias :settings :body
10 10
  11 + def limit
  12 + settings[:limit]
  13 + end
  14 + def limit=(value)
  15 + settings[:limit] = value
  16 + end
  17 +
  18 + def include
  19 + settings[:include]
  20 + end
  21 + def include=(value)
  22 + settings[:include] = value
  23 + end
  24 +
  25 + def feed_item_description
  26 + settings[:feed_item_description]
  27 + end
  28 + def feed_item_description=(value)
  29 + settings[:feed_item_description] = value
  30 + end
  31 +
11 # TODO 32 # TODO
12 def to_html 33 def to_html
13 end 34 end
@@ -20,10 +41,10 @@ class RssFeed < Article @@ -20,10 +41,10 @@ class RssFeed < Article
20 # FIXME feed real data into the RSS feed 41 # FIXME feed real data into the RSS feed
21 def data 42 def data
22 articles = 43 articles =
23 - if (self.settings[:include] == :parent_and_children) && self.parent 44 + if (self.include == :parent_and_children) && self.parent
24 self.parent.map_traversal 45 self.parent.map_traversal
25 else 46 else
26 - profile.recent_documents(self.settings[:limit] || 10) 47 + profile.recent_documents(self.limit || 10)
27 end 48 end
28 49
29 50
@@ -41,7 +62,7 @@ class RssFeed < Article @@ -41,7 +62,7 @@ class RssFeed < Article
41 unless self == article 62 unless self == article
42 xml.item do 63 xml.item do
43 xml.title(article.name) 64 xml.title(article.name)
44 - if self.settings[:description] == :body 65 + if self.feed_item_description == :body
45 xml.description(article.body) 66 xml.description(article.body)
46 else 67 else
47 xml.description(article.abstract) 68 xml.description(article.abstract)
test/unit/rss_feed_test.rb
@@ -11,7 +11,7 @@ class RssFeedTest < Test::Unit::TestCase @@ -11,7 +11,7 @@ class RssFeedTest < Test::Unit::TestCase
11 assert_kind_of Hash, feed.body 11 assert_kind_of Hash, feed.body
12 12
13 feed.body = { 13 feed.body = {
14 - :description => :abstract, 14 + :feed_item_description => :abstract,
15 :search => :parent_and_children, 15 :search => :parent_and_children,
16 } 16 }
17 feed.valid? 17 feed.valid?
@@ -74,7 +74,7 @@ class RssFeedTest < Test::Unit::TestCase @@ -74,7 +74,7 @@ class RssFeedTest < Test::Unit::TestCase
74 assert_match /<description>my abstract<\/description>/, rss 74 assert_match /<description>my abstract<\/description>/, rss
75 assert_no_match /<description>my text<\/description>/, rss 75 assert_no_match /<description>my text<\/description>/, rss
76 76
77 - feed.settings[:description] = :body 77 + feed.feed_item_description = :body
78 rss = feed.data 78 rss = feed.data
79 assert_match /<description>my text<\/description>/, rss 79 assert_match /<description>my text<\/description>/, rss
80 assert_no_match /<description>my abstract<\/description>/, rss 80 assert_no_match /<description>my abstract<\/description>/, rss
@@ -93,7 +93,7 @@ class RssFeedTest &lt; Test::Unit::TestCase @@ -93,7 +93,7 @@ class RssFeedTest &lt; Test::Unit::TestCase
93 feed = RssFeed.new(:name => 'feed') 93 feed = RssFeed.new(:name => 'feed')
94 feed.parent = a3 94 feed.parent = a3
95 feed.profile = profile 95 feed.profile = profile
96 - feed.settings[:include] = :parent_and_children 96 + feed.include = :parent_and_children
97 feed.save! 97 feed.save!
98 98
99 rss = feed.data 99 rss = feed.data
@@ -119,7 +119,7 @@ class RssFeedTest &lt; Test::Unit::TestCase @@ -119,7 +119,7 @@ class RssFeedTest &lt; Test::Unit::TestCase
119 feed.profile.expects(:recent_documents).with(10).returns([]).once 119 feed.profile.expects(:recent_documents).with(10).returns([]).once
120 feed.data 120 feed.data
121 121
122 - feed.settings[:limit] = 5 122 + feed.limit = 5
123 feed.profile.expects(:recent_documents).with(5).returns([]).once 123 feed.profile.expects(:recent_documents).with(5).returns([]).once
124 feed.data 124 feed.data
125 end 125 end