Commit 967cac32b6f332384dd124773a7a4408d798d014
1 parent
37fbb823
Exists in
master
and in
29 other branches
ActionItem194: fixed criteria used to list or not articles in 'recent documents'
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1667 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
80 additions
and
16 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -19,7 +19,11 @@ class Article < ActiveRecord::Base |
19 | 19 | acts_as_versioned |
20 | 20 | |
21 | 21 | acts_as_searchable :fields => [ :name, :abstract, :body, :tag_list ] |
22 | - | |
22 | + | |
23 | + before_update do |article| | |
24 | + article.advertise = true | |
25 | + end | |
26 | + | |
23 | 27 | # retrieves all articles belonging to the given +profile+ that are not |
24 | 28 | # sub-articles of any other article. |
25 | 29 | def self.top_level_for(profile) | ... | ... |
app/models/profile.rb
... | ... | @@ -260,14 +260,13 @@ class Profile < ActiveRecord::Base |
260 | 260 | |
261 | 261 | hacked_after_create :insert_default_homepage_and_feed |
262 | 262 | def insert_default_homepage_and_feed |
263 | - hp = self.articles.build(:name => _("%s's home page") % self.name, :body => _("<p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % self.name) | |
263 | + hp = self.articles.build(:name => _("%s's home page") % self.name, :body => _("<p>This is a default homepage created for %s. It can be changed though the control panel.</p>") % self.name, :advertise => false) | |
264 | 264 | hp.save! |
265 | 265 | self.home_page = hp |
266 | 266 | self.save! |
267 | 267 | |
268 | 268 | feed = RssFeed.new(:name => 'feed') |
269 | 269 | self.articles << feed |
270 | - feed.save! | |
271 | 270 | end |
272 | 271 | |
273 | 272 | # Adds a person as member of this Profile. | ... | ... |
app/models/recent_documents_block.rb
... | ... | @@ -8,14 +8,9 @@ class RecentDocumentsBlock < Block |
8 | 8 | |
9 | 9 | include ActionController::UrlWriter |
10 | 10 | def content |
11 | - docs = | |
12 | - if self.limit.nil? | |
13 | - owner.recent_documents | |
14 | - else | |
15 | - owner.recent_documents(self.limit) | |
16 | - end | |
11 | + docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit) | |
17 | 12 | |
18 | - docs = docs.select{|d| d.kind_of?(TextArticle)} | |
13 | + docs.delete_if{|d| d.kind_of?(Article) and !d.advertise?} | |
19 | 14 | |
20 | 15 | block_title(_('Recent content')) + |
21 | 16 | content_tag('ul', docs.map {|item| content_tag('li', link_to(item.title, item.url))}.join("\n")) | ... | ... |
app/models/rss_feed.rb
db/migrate/007_create_articles.rb
... | ... | @@ -35,6 +35,10 @@ class CreateArticles < ActiveRecord::Migration |
35 | 35 | # attachment_fu data for images |
36 | 36 | t.column :height, :integer # in pixels |
37 | 37 | t.column :width, :integer # in pixels |
38 | + | |
39 | + # show in recent content? | |
40 | + t.column :advertise, :boolean, :default => true | |
41 | + | |
38 | 42 | end |
39 | 43 | |
40 | 44 | Article.create_versioned_table | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -88,4 +88,26 @@ class ProfileControllerTest < Test::Unit::TestCase |
88 | 88 | assert_tag :tag => 'a', :content => 'Friends', :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } |
89 | 89 | end |
90 | 90 | |
91 | + should 'not show homepage and feed automatically created on recent content' do | |
92 | + person = create_user('person_1').person | |
93 | + get :index, :profile => person.identifier | |
94 | + assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => '' } | |
95 | + end | |
96 | + | |
97 | + should 'show homepage on recent content after update' do | |
98 | + person = create_user('person_1').person | |
99 | + person.home_page.name = 'Changed name' | |
100 | + assert person.home_page.save! | |
101 | + get :index, :profile => person.identifier | |
102 | + assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.home_page.name}/ } | |
103 | + end | |
104 | + | |
105 | + should 'show feed on recent content after update' do | |
106 | + person = create_user('person_1').person | |
107 | + person.articles.find_by_path('feed').name = 'Changed name' | |
108 | + assert person.articles.find_by_path('feed').save! | |
109 | + get :index, :profile => person.identifier | |
110 | + assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.articles.find_by_path('feed').name}/ } | |
111 | + end | |
112 | + | |
91 | 113 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -410,6 +410,28 @@ class ProfileTest < Test::Unit::TestCase |
410 | 410 | assert_equal [p3,p2], Profile.recent(2) |
411 | 411 | end |
412 | 412 | |
413 | + should 'advertise false to homepage and feed on creation' do | |
414 | + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
415 | + assert !profile.home_page.advertise? | |
416 | + assert !profile.articles.find_by_path('feed').advertise? | |
417 | + end | |
418 | + | |
419 | + should 'advertise true to homepage after update' do | |
420 | + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
421 | + assert !profile.home_page.advertise? | |
422 | + profile.home_page.name = 'Changed name' | |
423 | + assert profile.home_page.save! | |
424 | + assert profile.home_page.advertise? | |
425 | + end | |
426 | + | |
427 | + should 'advertise true to feed after update' do | |
428 | + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
429 | + assert !profile.articles.find_by_path('feed').advertise? | |
430 | + profile.articles.find_by_path('feed').name = 'Changed name' | |
431 | + assert profile.articles.find_by_path('feed').save! | |
432 | + assert profile.articles.find_by_path('feed').advertise? | |
433 | + end | |
434 | + | |
413 | 435 | private |
414 | 436 | |
415 | 437 | def assert_invalid_identifier(id) |
... | ... | @@ -417,4 +439,5 @@ class ProfileTest < Test::Unit::TestCase |
417 | 439 | assert !profile.valid? |
418 | 440 | assert profile.errors.invalid?(:identifier) |
419 | 441 | end |
442 | + | |
420 | 443 | end | ... | ... |
test/unit/recent_documents_block_test.rb
... | ... | @@ -40,14 +40,19 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase |
40 | 40 | assert_no_match /href=.*\/testinguser\/first/, output |
41 | 41 | end |
42 | 42 | |
43 | - should 'not list rss feed articles' do | |
44 | - profile.articles << RssFeed.create(:name => 'sixth') | |
45 | - profile.save! | |
46 | - | |
43 | + should 'not list rss feed articles automatically created' do | |
44 | + assert_equal 'feed', profile.articles.find_by_path('feed').name | |
47 | 45 | output = block.content |
46 | + assert_match /href=.*\/testinguser\/first/, output | |
47 | + assert_no_match /href=.*\/testinguser\/feed/, output | |
48 | + end | |
48 | 49 | |
50 | + should 'list rss feed articles after update' do | |
51 | + profile.articles.find_by_path('feed').name = 'chaged name' | |
52 | + assert profile.articles.find_by_path('feed').save! | |
53 | + output = block.content | |
49 | 54 | assert_match /href=.*\/testinguser\/first/, output |
50 | - assert_no_match /href=.*\/testinguser\/sixth/, output | |
55 | + assert_match /href=.*\/testinguser\/feed/, output | |
51 | 56 | end |
52 | 57 | |
53 | 58 | end | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -201,4 +201,10 @@ class RssFeedTest < Test::Unit::TestCase |
201 | 201 | assert_equal 'rss-feed', RssFeed.new.icon_name |
202 | 202 | end |
203 | 203 | |
204 | + should 'advertise is false before create' do | |
205 | + profile = create_user('testuser').person | |
206 | + feed = RssFeed.create!(:name => 'testfeed', :profile => profile) | |
207 | + assert !feed.advertise? | |
208 | + end | |
209 | + | |
204 | 210 | end | ... | ... |