Commit 331b9925213373466d6bb0e8f3d775cb6a932bea
1 parent
dfeb7c34
Exists in
master
and in
28 other branches
ActionItem154: creating a home page and a RSS feed for new profiles
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1365 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
12 changed files
with
118 additions
and
44 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -7,7 +7,7 @@ class Article < ActiveRecord::Base |
7 | 7 | |
8 | 8 | belongs_to :last_changed_by, :class_name => Person.name, :foreign_key => 'last_changed_by_id' |
9 | 9 | |
10 | - has_many :comments | |
10 | + has_many :comments, :dependent => :destroy | |
11 | 11 | |
12 | 12 | has_and_belongs_to_many :categories |
13 | 13 | |
... | ... | @@ -29,7 +29,7 @@ class Article < ActiveRecord::Base |
29 | 29 | # retrieves the latest +limit+ articles, sorted from the most recent to the |
30 | 30 | # oldest. |
31 | 31 | def self.recent(limit) |
32 | - options = { :limit => limit, :order => 'created_on' } | |
32 | + options = { :limit => limit, :order => 'created_on desc, articles.id desc' } | |
33 | 33 | self.find(:all, options) |
34 | 34 | end |
35 | 35 | ... | ... |
app/models/environment.rb
... | ... | @@ -31,13 +31,17 @@ class Environment < ActiveRecord::Base |
31 | 31 | 3.times do |
32 | 32 | env.boxes << Box.new |
33 | 33 | end |
34 | + | |
35 | + # main area | |
34 | 36 | env.boxes[0].blocks << MainBlock.new |
35 | 37 | |
38 | + # "left" area | |
39 | + env.boxes[1].blocks << LoginBlock.new | |
36 | 40 | env.boxes[1].blocks << EnvironmentStatisticsBlock.new |
37 | 41 | env.boxes[1].blocks << RecentDocumentsBlock.new |
38 | 42 | |
39 | - env.boxes[2].blocks << LoginBlock.new | |
40 | - | |
43 | + # "right" area | |
44 | + env.boxes[2].blocks << ProfileListBlock.new | |
41 | 45 | end |
42 | 46 | |
43 | 47 | # One Environment can be reached by many domains | ... | ... |
app/models/person.rb
... | ... | @@ -64,12 +64,22 @@ class Person < Profile |
64 | 64 | 3.times do |
65 | 65 | self.boxes << Box.new |
66 | 66 | end |
67 | + | |
68 | + # main area | |
67 | 69 | self.boxes.first.blocks << MainBlock.new |
70 | + | |
71 | + # "left" area | |
72 | + self.boxes[1].blocks << ProfileInfoBlock.new | |
73 | + | |
74 | + # right area | |
75 | + self.boxes[2].blocks << TagsBlock.new | |
76 | + self.boxes[2].blocks << RecentDocumentsBlock.new | |
68 | 77 | |
69 | 78 | true |
70 | 79 | end |
71 | 80 | |
72 | - # FIXME this is *weird*, because this class is not inheriting the callback | |
81 | + # FIXME this is *weird*, because this class is not inheriting the callbacks | |
73 | 82 | before_create :set_default_environment |
83 | + after_create :insert_default_homepage_and_feed | |
74 | 84 | |
75 | 85 | end | ... | ... |
app/models/profile.rb
... | ... | @@ -232,4 +232,16 @@ class Profile < ActiveRecord::Base |
232 | 232 | false |
233 | 233 | end |
234 | 234 | |
235 | + after_create :insert_default_homepage_and_feed | |
236 | + def insert_default_homepage_and_feed | |
237 | + hp = self.articles.build(:name => _('Home page'), :body => _("<h1>%s's home page</h1> <p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % [ self.name, self.name]) | |
238 | + hp.save! | |
239 | + self.home_page = hp | |
240 | + self.save! | |
241 | + | |
242 | + feed = RssFeed.new(:name => 'feed') | |
243 | + self.articles << feed | |
244 | + feed.save! | |
245 | + end | |
246 | + | |
235 | 247 | end | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -145,7 +145,7 @@ class CmsControllerTest < Test::Unit::TestCase |
145 | 145 | should 'be able to create a RSS feed' do |
146 | 146 | login_as(profile.identifier) |
147 | 147 | assert_difference RssFeed, :count do |
148 | - post :new, :type => RssFeed.name, :profile => profile.identifier, :article => { :name => 'feed', :limit => 15, :include => 'all', :feed_item_description => 'body' } | |
148 | + post :new, :type => RssFeed.name, :profile => profile.identifier, :article => { :name => 'new-feed', :limit => 15, :include => 'all', :feed_item_description => 'body' } | |
149 | 149 | assert_response :redirect |
150 | 150 | end |
151 | 151 | end |
... | ... | @@ -171,7 +171,7 @@ class CmsControllerTest < Test::Unit::TestCase |
171 | 171 | should 'be able to update an uploaded file' do |
172 | 172 | post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')} |
173 | 173 | |
174 | - file = profile.articles.find(:first) | |
174 | + file = profile.articles.find_by_path('test.txt') | |
175 | 175 | assert_equal 'test.txt', file.name |
176 | 176 | |
177 | 177 | post :edit, :profile => profile.identifier, :id => file.id, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')} | ... | ... |
test/unit/article_test.rb
... | ... | @@ -133,17 +133,20 @@ class ArticleTest < Test::Unit::TestCase |
133 | 133 | end |
134 | 134 | |
135 | 135 | should 'search for recent documents' do |
136 | + other_profile = create_user('otherpropfile').person | |
137 | + | |
138 | + Article.destroy_all | |
139 | + | |
136 | 140 | first = profile.articles.build(:name => 'first'); first.save! |
137 | 141 | second = profile.articles.build(:name => 'second'); second.save! |
138 | 142 | third = profile.articles.build(:name => 'third'); third.save! |
139 | - forth = profile.articles.build(:name => 'forth'); forth.save! | |
143 | + fourth = profile.articles.build(:name => 'fourth'); fourth.save! | |
140 | 144 | fifth = profile.articles.build(:name => 'fifth'); fifth.save! |
141 | 145 | |
142 | - other_profile = create_user('otherpropfile').person | |
143 | 146 | other_first = other_profile.articles.build(:name => 'first'); other_first.save! |
144 | 147 | |
145 | - assert_equal [first,second,third], Article.recent(3) | |
146 | - assert_equal [first,second,third,forth,fifth,other_first], Article.recent(10) | |
148 | + assert_equal [other_first, fifth, fourth], Article.recent(3) | |
149 | + assert_equal [other_first, fifth, fourth, third, second, first], Article.recent(6) | |
147 | 150 | end |
148 | 151 | |
149 | 152 | should 'provied proper descriptions' do |
... | ... | @@ -190,4 +193,21 @@ class ArticleTest < Test::Unit::TestCase |
190 | 193 | end |
191 | 194 | end |
192 | 195 | |
196 | + should 'remove comments when removing article' do | |
197 | + assert_no_difference Comment, :count do | |
198 | + a = profile.articles.build(:name => 'test article') | |
199 | + a.save! | |
200 | + | |
201 | + assert_difference Comment, :count, 1 do | |
202 | + comment = a.comments.build | |
203 | + comment.author = profile | |
204 | + comment.title = 'test comment' | |
205 | + comment.body = 'you suck!' | |
206 | + comment.save! | |
207 | + end | |
208 | + | |
209 | + a.destroy | |
210 | + end | |
211 | + end | |
212 | + | |
193 | 213 | end | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -55,4 +55,11 @@ class EnterpriseTest < Test::Unit::TestCase |
55 | 55 | end |
56 | 56 | end |
57 | 57 | |
58 | + should 'get a default homepage and RSS feed' do | |
59 | + enterprise = Enterprise.create!(:name => 'my test enterprise', :identifier => 'myenterprise') | |
60 | + | |
61 | + assert_kind_of Article, enterprise.home_page | |
62 | + assert_kind_of RssFeed, enterprise.articles.find_by_path('feed') | |
63 | + end | |
64 | + | |
58 | 65 | end | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -222,22 +222,33 @@ class EnvironmentTest < Test::Unit::TestCase |
222 | 222 | should 'provide recent_documents' do |
223 | 223 | environment = Environment.create(:name => 'a test environment') |
224 | 224 | |
225 | + p1 = environment.profiles.build(:identifier => 'testprofile1', :name => 'test profile 1'); p1.save! | |
226 | + p2 = environment.profiles.build(:identifier => 'testprofile2', :name => 'test profile 2'); p2.save! | |
227 | + | |
228 | + # clear the articles | |
229 | + Article.destroy_all | |
230 | + | |
225 | 231 | # p1 creates one article |
226 | - p1 = environment.profiles.build(:identifier => 'testprofile1', :name => 'test profile 1') | |
227 | - p1.save! | |
228 | 232 | doc1 = p1.articles.build(:name => 'text 1'); doc1.save! |
229 | 233 | |
230 | 234 | # p2 creates two articles |
231 | - p2 = environment.profiles.build(:identifier => 'testprofile2', :name => 'test profile 2') | |
232 | - p2.save! | |
233 | 235 | doc2 = p2.articles.build(:name => 'text 2'); doc2.save! |
234 | 236 | doc3 = p2.articles.build(:name => 'text 3'); doc3.save! |
235 | 237 | |
236 | 238 | # p1 creates another article |
237 | 239 | doc4 = p1.articles.build(:name => 'text 4'); doc4.save! |
238 | 240 | |
239 | - assert_equivalent [doc1,doc2,doc3,doc4], environment.recent_documents | |
240 | - assert_equivalent [doc1,doc2,doc3], environment.recent_documents(3) | |
241 | + all_recent = environment.recent_documents | |
242 | + [doc1,doc2,doc3,doc4].each do |item| | |
243 | + assert_includes all_recent, item | |
244 | + end | |
245 | + | |
246 | + last_three = environment.recent_documents(3) | |
247 | + [doc2, doc3, doc4].each do |item| | |
248 | + assert_includes last_three, item | |
249 | + end | |
250 | + assert_not_includes last_three, doc1 | |
251 | + | |
241 | 252 | end |
242 | 253 | |
243 | 254 | should 'have a description attribute' do | ... | ... |
test/unit/person_test.rb
... | ... | @@ -127,4 +127,11 @@ class PersonTest < Test::Unit::TestCase |
127 | 127 | assert person.blocks.size > 0, 'Person should have blocks upon creation' |
128 | 128 | end |
129 | 129 | |
130 | + should 'get a default home page and a RSS feed' do | |
131 | + person = create_user('mytestuser').person | |
132 | + | |
133 | + assert_kind_of Article, person.home_page | |
134 | + assert_kind_of RssFeed, person.articles.find_by_path('feed') | |
135 | + end | |
136 | + | |
130 | 137 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -72,15 +72,7 @@ class ProfileTest < Test::Unit::TestCase |
72 | 72 | |
73 | 73 | should 'provide access to home page' do |
74 | 74 | profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') |
75 | - assert_nil profile.home_page | |
76 | - | |
77 | - page = profile.articles.build(:name => "My custom home page") | |
78 | - page.save! | |
79 | - | |
80 | - profile.home_page = page | |
81 | - profile.save! | |
82 | - | |
83 | - assert_equal page, profile.home_page | |
75 | + assert_kind_of Article, profile.home_page | |
84 | 76 | end |
85 | 77 | |
86 | 78 | def test_name_should_be_mandatory |
... | ... | @@ -116,9 +108,10 @@ class ProfileTest < Test::Unit::TestCase |
116 | 108 | second = profile.articles.build(:name => 'second'); second.save! |
117 | 109 | third = profile.articles.build(:name => 'third'); third.save! |
118 | 110 | |
119 | - n = Article.count | |
111 | + total = Article.count | |
112 | + mine = profile.articles.count | |
120 | 113 | profile.destroy |
121 | - assert_equal n - 3, Article.count | |
114 | + assert_equal total - mine, Article.count | |
122 | 115 | end |
123 | 116 | |
124 | 117 | def test_should_define_info |
... | ... | @@ -139,12 +132,14 @@ class ProfileTest < Test::Unit::TestCase |
139 | 132 | |
140 | 133 | should 'provide recent documents' do |
141 | 134 | profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') |
135 | + profile.articles.destroy_all | |
136 | + | |
142 | 137 | first = profile.articles.build(:name => 'first'); first.save! |
143 | 138 | second = profile.articles.build(:name => 'second'); second.save! |
144 | 139 | third = profile.articles.build(:name => 'third'); third.save! |
145 | 140 | |
146 | - assert_equal [first,second], profile.recent_documents(2) | |
147 | - assert_equal [first,second,third], profile.recent_documents | |
141 | + assert_equal [third, second], profile.recent_documents(2) | |
142 | + assert_equal [third, second, first], profile.recent_documents | |
148 | 143 | end |
149 | 144 | |
150 | 145 | should 'affiliate and provide a list of the affiliated users' do |
... | ... | @@ -318,6 +313,14 @@ class ProfileTest < Test::Unit::TestCase |
318 | 313 | assert_equal false, Profile.new.has_members? |
319 | 314 | end |
320 | 315 | |
316 | + should 'create a homepage and a feed on creation' do | |
317 | + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
318 | + | |
319 | + assert_kind_of Article, profile.home_page | |
320 | + assert_kind_of RssFeed, profile.articles.find_by_path('feed') | |
321 | + end | |
322 | + | |
323 | + | |
321 | 324 | private |
322 | 325 | |
323 | 326 | def assert_invalid_identifier(id) | ... | ... |
test/unit/recent_documents_block_test.rb
... | ... | @@ -7,7 +7,7 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase |
7 | 7 | profile.articles.build(:name => 'first').save! |
8 | 8 | profile.articles.build(:name => 'second').save! |
9 | 9 | profile.articles.build(:name => 'third').save! |
10 | - profile.articles.build(:name => 'forth').save! | |
10 | + profile.articles.build(:name => 'fourth').save! | |
11 | 11 | profile.articles.build(:name => 'fifth').save! |
12 | 12 | |
13 | 13 | box = Box.create!(:owner => profile) |
... | ... | @@ -26,7 +26,7 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase |
26 | 26 | assert_match /href=.*\/testinguser\/first/, output |
27 | 27 | assert_match /href=.*\/testinguser\/second/, output |
28 | 28 | assert_match /href=.*\/testinguser\/third/, output |
29 | - assert_match /href=.*\/testinguser\/forth/, output | |
29 | + assert_match /href=.*\/testinguser\/fourth/, output | |
30 | 30 | assert_match /href=.*\/testinguser\/fifth/, output |
31 | 31 | end |
32 | 32 | |
... | ... | @@ -35,11 +35,11 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase |
35 | 35 | |
36 | 36 | output = block.content |
37 | 37 | |
38 | - assert_match /href=.*\/testinguser\/first/, output | |
39 | - assert_match /href=.*\/testinguser\/second/, output | |
38 | + assert_match /href=.*\/testinguser\/fifth/, output | |
39 | + assert_match /href=.*\/testinguser\/fourth/, output | |
40 | 40 | assert_match /href=.*\/testinguser\/third/, output |
41 | - assert_no_match /href=.*\/testinguser\/forth/, output | |
42 | - assert_no_match /href=.*\/testinguser\/fifth/, output | |
41 | + assert_no_match /href=.*\/testinguser\/second/, output | |
42 | + assert_no_match /href=.*\/testinguser\/first/, output | |
43 | 43 | end |
44 | 44 | |
45 | 45 | end | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -29,7 +29,7 @@ class RssFeedTest < Test::Unit::TestCase |
29 | 29 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
30 | 30 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
31 | 31 | |
32 | - feed = RssFeed.new(:name => 'feed') | |
32 | + feed = RssFeed.new(:name => 'testfeed') | |
33 | 33 | feed.profile = profile |
34 | 34 | feed.save! |
35 | 35 | |
... | ... | @@ -45,12 +45,12 @@ class RssFeedTest < Test::Unit::TestCase |
45 | 45 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
46 | 46 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
47 | 47 | |
48 | - feed = RssFeed.new(:name => 'feed') | |
48 | + feed = RssFeed.new(:name => 'testfeed') | |
49 | 49 | feed.profile = profile |
50 | 50 | feed.save! |
51 | 51 | |
52 | 52 | rss = feed.data |
53 | - assert_no_match /<item><title>feed<\/title>/, rss | |
53 | + assert_no_match /<item><title>testfeed<\/title>/, rss | |
54 | 54 | end |
55 | 55 | |
56 | 56 | should 'list recent article from parent article' do |
... | ... | @@ -66,7 +66,7 @@ class RssFeedTest < Test::Unit::TestCase |
66 | 66 | profile = create_user('testuser').person |
67 | 67 | a1 = profile.articles.build(:name => 'article 1', 'abstract' => 'my abstract', 'body' => 'my text'); a1.save! |
68 | 68 | |
69 | - feed = RssFeed.new(:name => 'feed') | |
69 | + feed = RssFeed.new(:name => 'testfeed') | |
70 | 70 | feed.profile = profile |
71 | 71 | feed.save! |
72 | 72 | |
... | ... | @@ -90,7 +90,7 @@ class RssFeedTest < Test::Unit::TestCase |
90 | 90 | a3_2 = a3.children.build(:name => 'article 3.2', :parent => a3, :profile => profile); a3_2.save! |
91 | 91 | a3_2_1 = a3_2.children.build(:name => 'article 3.2.1', :parent => a3_2, :profile => profile); a3_2_1.save! |
92 | 92 | |
93 | - feed = RssFeed.new(:name => 'feed') | |
93 | + feed = RssFeed.new(:name => 'testfeed') | |
94 | 94 | feed.parent = a3 |
95 | 95 | feed.profile = profile |
96 | 96 | feed.include = 'parent_and_children' |
... | ... | @@ -108,7 +108,7 @@ class RssFeedTest < Test::Unit::TestCase |
108 | 108 | |
109 | 109 | should 'provide link to profile' do |
110 | 110 | profile = create_user('testuser').person |
111 | - feed = RssFeed.new(:name => 'feed') | |
111 | + feed = RssFeed.new(:name => 'testfeed') | |
112 | 112 | feed.profile = profile |
113 | 113 | feed.save! |
114 | 114 | |
... | ... | @@ -118,7 +118,7 @@ class RssFeedTest < Test::Unit::TestCase |
118 | 118 | should 'provide link to each article' do |
119 | 119 | profile = create_user('testuser').person |
120 | 120 | art = profile.articles.build(:name => 'myarticle'); art.save! |
121 | - feed = RssFeed.new(:name => 'feed') | |
121 | + feed = RssFeed.new(:name => 'testfeed') | |
122 | 122 | feed.profile = profile |
123 | 123 | feed.save! |
124 | 124 | |
... | ... | @@ -133,7 +133,7 @@ class RssFeedTest < Test::Unit::TestCase |
133 | 133 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
134 | 134 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
135 | 135 | |
136 | - feed = RssFeed.new(:name => 'feed') | |
136 | + feed = RssFeed.new(:name => 'testfeed') | |
137 | 137 | feed.profile = profile |
138 | 138 | feed.save! |
139 | 139 | ... | ... |