Commit 631b96a015bb5226ecd5bccf956f21e06e8cc9d6

Authored by Rodrigo Souto
1 parent d9680fb6

rails3: fix rss_feed tests

app/models/article.rb
@@ -2,7 +2,7 @@ require 'hpricot' @@ -2,7 +2,7 @@ require 'hpricot'
2 2
3 class Article < ActiveRecord::Base 3 class Article < ActiveRecord::Base
4 4
5 - attr_accessible :name, :body, :abstract, :profile, :tag_list 5 + attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent
6 6
7 SEARCHABLE_FIELDS = { 7 SEARCHABLE_FIELDS = {
8 :name => 10, 8 :name => 10,
app/models/rss_feed.rb
1 class RssFeed < Article 1 class RssFeed < Article
2 2
3 - attr_accessible :limit, :enabled 3 + attr_accessible :limit, :enabled, :language
4 4
5 def self.type_name 5 def self.type_name
6 _('RssFeed') 6 _('RssFeed')
test/unit/rss_feed_test.rb
@@ -29,7 +29,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -29,7 +29,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
29 a2 = profile.articles.build(:name => 'article 2'); a2.save! 29 a2 = profile.articles.build(:name => 'article 2'); a2.save!
30 a3 = profile.articles.build(:name => 'article 3'); a3.save! 30 a3 = profile.articles.build(:name => 'article 3'); a3.save!
31 31
32 - feed = RssFeed.new(:name => 'testfeed') 32 + feed = build(RssFeed, :name => 'testfeed')
33 feed.profile = profile 33 feed.profile = profile
34 feed.save! 34 feed.save!
35 35
@@ -45,7 +45,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -45,7 +45,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
45 a2 = profile.articles.build(:name => 'article 2'); a2.save! 45 a2 = profile.articles.build(:name => 'article 2'); a2.save!
46 a3 = profile.articles.build(:name => 'article 3'); a3.save! 46 a3 = profile.articles.build(:name => 'article 3'); a3.save!
47 47
48 - feed = RssFeed.new(:name => 'testfeed') 48 + feed = build(RssFeed, :name => 'testfeed')
49 feed.profile = profile 49 feed.profile = profile
50 feed.save! 50 feed.save!
51 51
@@ -73,7 +73,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -73,7 +73,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
73 a3_2_1 = a3_2.children.build(:name => 'article 3.2.1', :parent => a3_2, :profile => profile); a3_2_1.save! 73 a3_2_1 = a3_2.children.build(:name => 'article 3.2.1', :parent => a3_2, :profile => profile); a3_2_1.save!
74 74
75 a3.reload 75 a3.reload
76 - feed = RssFeed.new(:name => 'testfeed') 76 + feed = build(RssFeed, :name => 'testfeed')
77 feed.parent = a3 77 feed.parent = a3
78 feed.profile = profile 78 feed.profile = profile
79 feed.include = 'parent_and_children' 79 feed.include = 'parent_and_children'
@@ -91,7 +91,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -91,7 +91,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
91 91
92 should 'list blog posts with more recent first and respecting limit' do 92 should 'list blog posts with more recent first and respecting limit' do
93 profile = create_user('testuser').person 93 profile = create_user('testuser').person
94 - blog = Blog.create!(:name => 'blog-test', :profile => profile) 94 + blog = create(Blog, :name => 'blog-test', :profile => profile)
95 posts = [] 95 posts = []
96 6.times do |i| 96 6.times do |i|
97 posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) 97 posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id)
@@ -105,7 +105,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -105,7 +105,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
105 105
106 should 'list only published posts from blog' do 106 should 'list only published posts from blog' do
107 profile = create_user('testuser').person 107 profile = create_user('testuser').person
108 - blog = Blog.create!(:name => 'blog-test', :profile => profile) 108 + blog = create(Blog, :name => 'blog-test', :profile => profile)
109 posts = [] 109 posts = []
110 5.times do |i| 110 5.times do |i|
111 posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) 111 posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id)
@@ -119,17 +119,17 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -119,17 +119,17 @@ class RssFeedTest &lt; ActiveSupport::TestCase
119 119
120 should 'provide link to profile' do 120 should 'provide link to profile' do
121 profile = create_user('testuser').person 121 profile = create_user('testuser').person
122 - feed = RssFeed.new(:name => 'testfeed') 122 + feed = build(RssFeed, :name => 'testfeed')
123 feed.profile = profile 123 feed.profile = profile
124 feed.save! 124 feed.save!
125 125
126 - assert_match "<link>http://#{profile.environment.default_hostname}/testuser</link>", feed.data 126 + assert_match "<link>http://#{profile.environment.default_hostname}/testuser/homepage</link>", feed.data
127 end 127 end
128 128
129 should 'provide link to each article' do 129 should 'provide link to each article' do
130 profile = create_user('testuser').person 130 profile = create_user('testuser').person
131 art = profile.articles.build(:name => 'myarticle'); art.save! 131 art = profile.articles.build(:name => 'myarticle'); art.save!
132 - feed = RssFeed.new(:name => 'testfeed') 132 + feed = build(RssFeed, :name => 'testfeed')
133 feed.profile = profile 133 feed.profile = profile
134 feed.save! 134 feed.save!
135 135
@@ -144,7 +144,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -144,7 +144,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
144 a2 = profile.articles.build(:name => 'article 2'); a2.save! 144 a2 = profile.articles.build(:name => 'article 2'); a2.save!
145 a3 = profile.articles.build(:name => 'article 3'); a3.save! 145 a3 = profile.articles.build(:name => 'article 3'); a3.save!
146 146
147 - feed = RssFeed.new(:name => 'testfeed') 147 + feed = build(RssFeed, :name => 'testfeed')
148 feed.profile = profile 148 feed.profile = profile
149 feed.save! 149 feed.save!
150 150
@@ -195,13 +195,13 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -195,13 +195,13 @@ class RssFeedTest &lt; ActiveSupport::TestCase
195 195
196 should 'advertise is false before create' do 196 should 'advertise is false before create' do
197 profile = create_user('testuser').person 197 profile = create_user('testuser').person
198 - feed = RssFeed.create!(:name => 'testfeed', :profile => profile) 198 + feed = create(RssFeed, :name => 'testfeed', :profile => profile)
199 assert !feed.advertise? 199 assert !feed.advertise?
200 end 200 end
201 201
202 should 'can display hits' do 202 should 'can display hits' do
203 p = create_user('testuser').person 203 p = create_user('testuser').person
204 - a = RssFeed.create!(:name => 'Test article', :profile => p) 204 + a = create(RssFeed, :name => 'Test article', :profile => p)
205 assert_equal false, a.can_display_hits? 205 assert_equal false, a.can_display_hits?
206 end 206 end
207 207
@@ -209,14 +209,15 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -209,14 +209,15 @@ class RssFeedTest &lt; ActiveSupport::TestCase
209 article = fast_create(TextileArticle, :body => 'This is the content of the Sample Article.', :profile_id => fast_create(Person).id) 209 article = fast_create(TextileArticle, :body => 'This is the content of the Sample Article.', :profile_id => fast_create(Person).id)
210 profile = fast_create(Profile) 210 profile = fast_create(Profile)
211 blog = fast_create(Blog, :profile_id => profile.id) 211 blog = fast_create(Blog, :profile_id => profile.id)
212 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => fast_create(Person)) 212 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => profile, :requestor => fast_create(Person))
  213 + a.requestor.stubs(:notification_emails).returns(['random@example.org'])
213 a.finish 214 a.finish
214 215
215 published_article = article.class.last 216 published_article = article.class.last
216 published_article.parent = blog 217 published_article.parent = blog
217 published_article.save 218 published_article.save
218 219
219 - feed = RssFeed.new(:parent => blog, :profile => profile) 220 + feed = build(RssFeed, :parent => blog, :profile => profile)
220 221
221 assert_match "This is the content of the Sample Article", feed.data 222 assert_match "This is the content of the Sample Article", feed.data
222 end 223 end
@@ -229,7 +230,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -229,7 +230,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
229 a2 = profile.articles.build(:name => 'article 2'); a2.save! 230 a2 = profile.articles.build(:name => 'article 2'); a2.save!
230 a3 = profile.articles.build(:name => 'article 3'); a3.save! 231 a3 = profile.articles.build(:name => 'article 3'); a3.save!
231 232
232 - feed = RssFeed.new(:name => 'testfeed') 233 + feed = build(RssFeed, :name => 'testfeed')
233 feed.profile = profile 234 feed.profile = profile
234 feed.save! 235 feed.save!
235 236
@@ -245,7 +246,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -245,7 +246,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
245 246
246 should 'include posts from all languages' do 247 should 'include posts from all languages' do
247 profile = create_user('testuser').person 248 profile = create_user('testuser').person
248 - blog = Blog.create!(:name => 'blog-test', :profile => profile, :language => nil) 249 + blog = create(Blog, :name => 'blog-test', :profile => profile, :language => nil)
249 blog.posts << en_post = fast_create(TextArticle, :name => "English", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'en') 250 blog.posts << en_post = fast_create(TextArticle, :name => "English", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'en')
250 blog.posts << es_post = fast_create(TextArticle, :name => "Spanish", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'es') 251 blog.posts << es_post = fast_create(TextArticle, :name => "Spanish", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'es')
251 252
@@ -255,7 +256,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase @@ -255,7 +256,7 @@ class RssFeedTest &lt; ActiveSupport::TestCase
255 256
256 should 'include only posts from some language' do 257 should 'include only posts from some language' do
257 profile = create_user('testuser').person 258 profile = create_user('testuser').person
258 - blog = Blog.create!(:name => 'blog-test', :profile => profile) 259 + blog = create(Blog, :name => 'blog-test', :profile => profile)
259 blog.feed.update_attributes! :language => 'es' 260 blog.feed.update_attributes! :language => 'es'
260 blog.posts << en_post = fast_create(TextArticle, :name => "English", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'en') 261 blog.posts << en_post = fast_create(TextArticle, :name => "English", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'en')
261 blog.posts << es_post = fast_create(TextArticle, :name => "Spanish", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'es') 262 blog.posts << es_post = fast_create(TextArticle, :name => "Spanish", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'es')