Commit bdd5ef3ed49b917e287d8fbf9c6b5b75029641b2
Committed by
Evandro Junior
1 parent
5c115a98
Exists in
master
and in
29 other branches
Implents most relevant block plugin
Showing
10 changed files
with
648 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,194 @@ | @@ -0,0 +1,194 @@ | ||
1 | +require_dependency 'article' | ||
2 | + | ||
3 | +class Article | ||
4 | + | ||
5 | + named_scope :relevant_content, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] | ||
6 | + | ||
7 | + def self.most_accessed(owner, limit = nil) | ||
8 | + if owner.kind_of?(Environment) | ||
9 | + result = Article.relevant_content.find( | ||
10 | + :all, | ||
11 | + :order => 'hits desc', | ||
12 | + :limit => limit, | ||
13 | + :conditions => ["hits > 0"] | ||
14 | + ) | ||
15 | + result.paginate({:page => 1, :per_page => limit}) | ||
16 | + else | ||
17 | + #Owner is a profile | ||
18 | + result = Article.relevant_content.find( | ||
19 | + :all, | ||
20 | + :order => 'hits desc', | ||
21 | + :limit => limit, | ||
22 | + :conditions => ["profile_id = ? and hits > 0", owner.id] | ||
23 | + ) | ||
24 | + result.paginate({:page => 1, :per_page => limit}) | ||
25 | + end | ||
26 | + end | ||
27 | + | ||
28 | + def self.most_commented_relevant_content(owner, limit) | ||
29 | + | ||
30 | + if owner.kind_of?(Environment) | ||
31 | + result = Article.relevant_content.find( | ||
32 | + :all, | ||
33 | + :order => 'comments_count desc', | ||
34 | + :limit => limit, | ||
35 | + :conditions => ["comments_count > 0"] | ||
36 | + ) | ||
37 | + result.paginate({:page => 1, :per_page => limit}) | ||
38 | + else | ||
39 | + #Owner is a profile | ||
40 | + result = Article.relevant_content.find( | ||
41 | + :all, | ||
42 | + :order => 'comments_count desc', | ||
43 | + :limit => limit, | ||
44 | + :conditions => ["profile_id = ? and comments_count > 0", owner.id] | ||
45 | + ) | ||
46 | + result.paginate({:page => 1, :per_page => limit}) | ||
47 | + end | ||
48 | + end | ||
49 | + | ||
50 | + def self.articles_columns | ||
51 | + Article.column_names.map {|c| "articles.#{c}"} .join(",") | ||
52 | + end | ||
53 | + | ||
54 | + def self.more_positive_votes(owner, limit = nil) | ||
55 | + if owner.kind_of?(Environment) | ||
56 | + result = Article.find( | ||
57 | + :all, | ||
58 | + :select => articles_columns, | ||
59 | + :order => 'sum(vote) desc', | ||
60 | + :group => 'voteable_id, ' + articles_columns, | ||
61 | + :limit => limit, | ||
62 | + :having => ['sum(vote) > 0'], | ||
63 | + :conditions => {'votes.voteable_type' => 'Article'}, | ||
64 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id' | ||
65 | + ) | ||
66 | + result.paginate({:page => 1, :per_page => limit}) | ||
67 | + else | ||
68 | + #Owner is a profile | ||
69 | + result = Article.find( | ||
70 | + :all, | ||
71 | + :select => articles_columns, | ||
72 | + :order => 'sum(vote) desc', | ||
73 | + :group => 'voteable_id, ' + articles_columns, | ||
74 | + :limit => limit, | ||
75 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
76 | + :having => ['sum(vote) > 0'], | ||
77 | + :conditions => ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article'] | ||
78 | + ) | ||
79 | + result.paginate({:page => 1, :per_page => limit}) | ||
80 | + end | ||
81 | + end | ||
82 | + | ||
83 | + def self.more_negative_votes(owner, limit = nil) | ||
84 | + if owner.kind_of?(Environment) | ||
85 | + result = Article.find( | ||
86 | + :all, | ||
87 | + :select => articles_columns, | ||
88 | + :order => 'sum(vote) asc', | ||
89 | + :group => 'voteable_id, ' + articles_columns, | ||
90 | + :limit => limit, | ||
91 | + :having => ['sum(vote) < 0'], | ||
92 | + :conditions => {'votes.voteable_type' => 'Article'}, | ||
93 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id' | ||
94 | + ) | ||
95 | + result.paginate({:page => 1, :per_page => limit}) | ||
96 | + else | ||
97 | + #Owner is a profile | ||
98 | + result = Article.find( | ||
99 | + :all, | ||
100 | + :select => articles_columns, | ||
101 | + :order => 'sum(vote) asc', | ||
102 | + :group => 'voteable_id, ' + articles_columns, | ||
103 | + :limit => limit, | ||
104 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
105 | + :having => ['sum(vote) < 0'], | ||
106 | + :conditions => ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id] | ||
107 | + ) | ||
108 | + result.paginate({:page => 1, :per_page => limit}) | ||
109 | + end | ||
110 | + end | ||
111 | + | ||
112 | + def self.most_liked(owner, limit = nil) | ||
113 | + if owner.kind_of?(Environment) | ||
114 | + result = Article.find( | ||
115 | + :all, | ||
116 | + :select => articles_columns, | ||
117 | + :order => 'count(voteable_id) desc', | ||
118 | + :group => 'voteable_id, ' + articles_columns, | ||
119 | + :limit => limit, | ||
120 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
121 | + :conditions => ["votes.voteable_type = 'Article' and vote > 0"] | ||
122 | + ) | ||
123 | + result.paginate({:page => 1, :per_page => limit}) | ||
124 | + else | ||
125 | + #Owner is a profile | ||
126 | + result = Article.find( | ||
127 | + :all, | ||
128 | + :select => articles_columns, | ||
129 | + :order => 'count(voteable_id) desc', | ||
130 | + :group => 'voteable_id, ' + articles_columns, | ||
131 | + :limit => limit, | ||
132 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
133 | + :conditions => ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id] | ||
134 | + ) | ||
135 | + result.paginate({:page => 1, :per_page => limit}) | ||
136 | + end | ||
137 | + end | ||
138 | + | ||
139 | + def self.most_disliked(owner, limit = nil) | ||
140 | + if owner.kind_of?(Environment) | ||
141 | + result = Article.find( | ||
142 | + :all, | ||
143 | + :order => 'count(voteable_id) desc', | ||
144 | + :group => 'voteable_id, ' + articles_columns, | ||
145 | + :limit => limit, | ||
146 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
147 | + :conditions => ["votes.voteable_type = 'Article' and vote < 0"] | ||
148 | + ) | ||
149 | + result.paginate({:page => 1, :per_page => limit}) | ||
150 | + else | ||
151 | + #Owner is a profile | ||
152 | + result = Article.find( | ||
153 | + :all, | ||
154 | + :order => 'count(voteable_id) desc', | ||
155 | + :group => 'voteable_id, ' + articles_columns, | ||
156 | + :limit => limit, | ||
157 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
158 | + :conditions => ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id] | ||
159 | + ) | ||
160 | + result.paginate({:page => 1, :per_page => limit}) | ||
161 | + end | ||
162 | + end | ||
163 | + | ||
164 | + def self.most_voted(owner, limit = nil) | ||
165 | + if owner.kind_of?(Environment) | ||
166 | + result = Article.find( | ||
167 | + :all, | ||
168 | + :select => articles_columns, | ||
169 | + :order => 'count(voteable_id) desc', | ||
170 | + :group => 'voteable_id, ' + articles_columns, | ||
171 | + :limit => limit, | ||
172 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
173 | + :conditions => ["votes.voteable_type = 'Article'"] | ||
174 | + ) | ||
175 | + result.paginate({:page => 1, :per_page => limit}) | ||
176 | + else | ||
177 | + #Owner is a profile | ||
178 | + result = Article.find( | ||
179 | + :all, | ||
180 | + :select => articles_columns, | ||
181 | + :order => 'count(voteable_id) desc', | ||
182 | + :group => 'voteable_id, ' + articles_columns, | ||
183 | + :limit => limit, | ||
184 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | ||
185 | + :conditions => ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id] | ||
186 | + ) | ||
187 | + result.paginate({:page => 1, :per_page => limit}) | ||
188 | + end | ||
189 | + end | ||
190 | + | ||
191 | + | ||
192 | + | ||
193 | + | ||
194 | +end | ||
0 | \ No newline at end of file | 195 | \ No newline at end of file |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +class RelevantContentPlugin < Noosfero::Plugin | ||
2 | + | ||
3 | + def self.plugin_name | ||
4 | + "Relevant Content Plugin" | ||
5 | + end | ||
6 | + | ||
7 | + def self.plugin_description | ||
8 | + _("A plugin that lists the most accessed, most commented, most liked and most disliked contents.") | ||
9 | + end | ||
10 | + | ||
11 | + def self.extra_blocks | ||
12 | + { | ||
13 | + RelevantContentPlugin::RelevantContentBlock => {:position => ['1','2','3'] } | ||
14 | + } | ||
15 | + end | ||
16 | + | ||
17 | + def stylesheet? | ||
18 | + true | ||
19 | + end | ||
20 | + | ||
21 | +end |
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
0 → 100644
@@ -0,0 +1,93 @@ | @@ -0,0 +1,93 @@ | ||
1 | +class RelevantContentPlugin::RelevantContentBlock < Block | ||
2 | + def self.description | ||
3 | + _('Relevant content') | ||
4 | + end | ||
5 | + | ||
6 | + def default_title | ||
7 | + _('Relevant content') | ||
8 | + end | ||
9 | + | ||
10 | + def help | ||
11 | + _('This block lists the most popular content.') | ||
12 | + end | ||
13 | + | ||
14 | + settings_items :limit, :type => :integer, :default => 5 | ||
15 | + settings_items :show_most_read, :type => :integer, :default => 1 | ||
16 | + settings_items :show_most_commented, :type => :integer, :default => 1 | ||
17 | + settings_items :show_most_liked, :type => :integer, :default => 1 | ||
18 | + settings_items :show_most_disliked, :type => :integer, :default => 0 | ||
19 | + settings_items :show_most_voted, :type => :integer, :default => 1 | ||
20 | + | ||
21 | + include ActionController::UrlWriter | ||
22 | + def content(args={}) | ||
23 | + | ||
24 | + content = block_title(title) | ||
25 | + | ||
26 | + if self.show_most_read != 0 | ||
27 | + docs = Article.most_accessed(owner, self.limit) | ||
28 | + if !docs.blank? | ||
29 | + subcontent = "" | ||
30 | + subcontent += content_tag(:span, _("Most read articles"), :class=>"title mread") + "\n" | ||
31 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
32 | + content += content_tag(:div, subcontent, :class=>"block mread") + "\n" | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
36 | + if self.show_most_commented != 0 | ||
37 | + docs = Article.most_commented_relevant_content(owner, self.limit) | ||
38 | + if !docs.blank? | ||
39 | + subcontent = "" | ||
40 | + subcontent += content_tag(:span, _("Most commented articles"), :class=>"title mcommented") + "\n" | ||
41 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
42 | + content += content_tag(:div, subcontent, :class=>"block mcommented") + "\n" | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
46 | + if owner.kind_of?(Environment) | ||
47 | + env = owner | ||
48 | + else | ||
49 | + env = owner.environment | ||
50 | + end | ||
51 | + | ||
52 | + if env.plugin_enabled?(VotePlugin) | ||
53 | + if self.show_most_liked != 0 | ||
54 | + docs = Article.more_positive_votes(owner, self.limit) | ||
55 | + if !docs.blank? | ||
56 | + subcontent = "" | ||
57 | + subcontent += content_tag(:span, _("Most liked articles"), :class=>"title mliked") + "\n" | ||
58 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
59 | + content += content_tag(:div, subcontent, :class=>"block mliked") + "\n" | ||
60 | + end | ||
61 | + end | ||
62 | + if self.show_most_disliked != 0 | ||
63 | + docs = Article.more_negative_votes(owner, self.limit) | ||
64 | + if !docs.blank? | ||
65 | + subcontent = "" | ||
66 | + subcontent += content_tag(:span, _("Most disliked articles"), :class=>"title mdisliked") + "\n" | ||
67 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
68 | + content += content_tag(:div, subcontent, :class=>"block mdisliked") + "\n" | ||
69 | + end | ||
70 | + end | ||
71 | + | ||
72 | + if self.show_most_voted != 0 | ||
73 | + docs = Article.most_voted(owner, self.limit) | ||
74 | + if !docs.blank? | ||
75 | + subcontent = "" | ||
76 | + subcontent += content_tag(:span, _("Most voted articles"), :class=>"title mvoted") + "\n" | ||
77 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
78 | + content += content_tag(:div, subcontent, :class=>"block mvoted") + "\n" | ||
79 | + end | ||
80 | + end | ||
81 | + end | ||
82 | + return content | ||
83 | + end | ||
84 | + | ||
85 | + def timeout | ||
86 | + 4.hours | ||
87 | + end | ||
88 | + | ||
89 | + def self.expire_on | ||
90 | + { :profile => [:article], :environment => [:article] } | ||
91 | + end | ||
92 | + | ||
93 | +end | ||
0 | \ No newline at end of file | 94 | \ No newline at end of file |
@@ -0,0 +1,79 @@ | @@ -0,0 +1,79 @@ | ||
1 | +#content .relevant-content-plugin_relevant-content-block { | ||
2 | + padding: 10px 0px 10px 10px; | ||
3 | + word-wrap: break-word; | ||
4 | +} | ||
5 | + | ||
6 | +.relevant-content-plugin_relevant-content-block ul { | ||
7 | + margin: 0px; | ||
8 | + padding: 0px 0px 0px 20px; | ||
9 | +} | ||
10 | +.relevant-content-plugin_relevant-content-block li { | ||
11 | + margin: 0px; | ||
12 | + padding: 0px; | ||
13 | + list-style: none | ||
14 | +} | ||
15 | +.relevant-content-plugin_relevant-content-block a { | ||
16 | + text-decoration: none; | ||
17 | +} | ||
18 | +.relevant-content-plugin_relevant-content-block .block-footer-content { | ||
19 | + font-size: 10px; | ||
20 | +} | ||
21 | +.relevant-content-plugin_relevant-content-block .block-footer-content a:hover { | ||
22 | + text-decoration: underline; | ||
23 | +} | ||
24 | + | ||
25 | +.relevant-content-plugin_relevant-content-block p { | ||
26 | + text-align:center; | ||
27 | +} | ||
28 | + | ||
29 | +.relevant-content-plugin_relevant-content-block p.like{ | ||
30 | + background-image: url('images/positive-hand.png'); | ||
31 | + background-repeat: no-repeat; | ||
32 | + min-width: 50px; | ||
33 | + text-align:center; | ||
34 | +} | ||
35 | + | ||
36 | +.relevant-content-plugin_relevant-content-block p.dislike{ | ||
37 | + background-image: url('images/negative-hand.png'); | ||
38 | + background-repeat: no-repeat; | ||
39 | + min-width: 50px; | ||
40 | + text-align:center; | ||
41 | +} | ||
42 | + | ||
43 | + | ||
44 | +.relevant-content-plugin_relevant-content-block { | ||
45 | + //overflow: hidden; | ||
46 | + display: block; | ||
47 | + width: 100%; | ||
48 | +} | ||
49 | + | ||
50 | + | ||
51 | +.relevant-content-cover img { | ||
52 | + width: 100%; | ||
53 | +} | ||
54 | + | ||
55 | +.relevant-content-plugin_relevant-content-block span.title { | ||
56 | + display: block; | ||
57 | + margin: 20px 0px 0px; | ||
58 | + padding: 0px 0px 0px 20px; | ||
59 | +} | ||
60 | + | ||
61 | +.relevant-content-plugin_relevant-content-block span.title.mread { | ||
62 | + | ||
63 | +} | ||
64 | + | ||
65 | +.relevant-content-plugin_relevant-content-block span.title.mcommented { | ||
66 | + | ||
67 | +} | ||
68 | + | ||
69 | +.relevant-content-plugin_relevant-content-block span.title.mliked { | ||
70 | + | ||
71 | +} | ||
72 | + | ||
73 | +.relevant-content-plugin_relevant-content-block span.title.mdisliked { | ||
74 | + | ||
75 | +} | ||
76 | + | ||
77 | +.relevant-content-plugin_relevant-content-block span.title.mvoted { | ||
78 | + | ||
79 | +} |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' |
plugins/relevant_content/test/unit/relevant_content_block_test.rb
0 → 100644
@@ -0,0 +1,217 @@ | @@ -0,0 +1,217 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +require 'comment_controller' | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class CommentController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class RelevantContentBlockTest < ActiveSupport::TestCase | ||
8 | + | ||
9 | + include AuthenticatedTestHelper | ||
10 | + fixtures :users, :environments | ||
11 | + | ||
12 | + def setup | ||
13 | + @controller = CommentController.new | ||
14 | + @request = ActionController::TestRequest.new | ||
15 | + @response = ActionController::TestResponse.new | ||
16 | + | ||
17 | + @profile = create_user('testinguser').person | ||
18 | + @environment = @profile.environment | ||
19 | + end | ||
20 | + attr_reader :profile, :environment | ||
21 | + | ||
22 | + | ||
23 | + | ||
24 | + should 'have a default title' do | ||
25 | + relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new | ||
26 | + block = Block.new | ||
27 | + assert_not_equal block.default_title, relevant_content_block.default_title | ||
28 | + end | ||
29 | + | ||
30 | + should 'have a help tooltip' do | ||
31 | + relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new | ||
32 | + block = Block.new | ||
33 | + assert_not_equal "", relevant_content_block.help | ||
34 | + end | ||
35 | + | ||
36 | + should 'describe itself' do | ||
37 | + assert_not_equal Block.description, RelevantContentPlugin::RelevantContentBlock.description | ||
38 | + end | ||
39 | + | ||
40 | + should 'is editable' do | ||
41 | + block = RelevantContentPlugin::RelevantContentBlock.new | ||
42 | + assert block.editable? | ||
43 | + end | ||
44 | + | ||
45 | + should 'expire' do | ||
46 | + assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]} | ||
47 | + end | ||
48 | + | ||
49 | + should 'not raise an exception when finding the most accessed content' do | ||
50 | + assert_nothing_raised{ | ||
51 | + Article.most_accessed(Environment.default, 5) | ||
52 | + } | ||
53 | + end | ||
54 | + | ||
55 | + should 'not raise an exception when finding the most commented content' do | ||
56 | + assert_nothing_raised{ | ||
57 | + Article.most_commented_relevant_content(Environment.default, 5) | ||
58 | + } | ||
59 | + end | ||
60 | + | ||
61 | + should 'not raise an exception when finding the most liked content' do | ||
62 | + begin | ||
63 | + Environment.default.enable_plugin(:vote) | ||
64 | + rescue | ||
65 | + puts "Unable to activate vote plugin" | ||
66 | + end | ||
67 | + if Environment.default.plugin_enabled?(:vote) | ||
68 | + assert_nothing_raised{ | ||
69 | + Article.most_liked(Environment.default, 5) | ||
70 | + } | ||
71 | + end | ||
72 | + end | ||
73 | + | ||
74 | + should 'not raise an exception when finding the most disliked content' do | ||
75 | + begin | ||
76 | + Environment.default.enable_plugin(:vote) | ||
77 | + rescue | ||
78 | + puts "Unable to activate vote plugin" | ||
79 | + end | ||
80 | + if Environment.default.plugin_enabled?(:vote) | ||
81 | + assert_nothing_raised{ | ||
82 | + Article.most_disliked(Environment.default, 5) | ||
83 | + } | ||
84 | + end | ||
85 | + end | ||
86 | + | ||
87 | + | ||
88 | + should 'not raise an exception when finding the more positive votes' do | ||
89 | + begin | ||
90 | + Environment.default.enable_plugin(:vote) | ||
91 | + rescue | ||
92 | + puts "Unable to activate vote plugin" | ||
93 | + end | ||
94 | + if Environment.default.plugin_enabled?(:vote) | ||
95 | + assert_nothing_raised{ | ||
96 | + Article.more_positive_votes(Environment.default, 5) | ||
97 | + } | ||
98 | + end | ||
99 | + end | ||
100 | + | ||
101 | + should 'not raise an exception when finding the most voted' do | ||
102 | + begin | ||
103 | + Environment.default.enable_plugin(:vote) | ||
104 | + rescue | ||
105 | + puts "Unable to activate vote plugin" | ||
106 | + end | ||
107 | + if Environment.default.plugin_enabled?(:vote) | ||
108 | + assert_nothing_raised{ | ||
109 | + Article.most_voted(Environment.default, 5) | ||
110 | + } | ||
111 | + end | ||
112 | + end | ||
113 | + | ||
114 | + should 'find the most voted' do | ||
115 | + | ||
116 | + article = fast_create(Article, {:name=>'2 votes'}) | ||
117 | + for i in 0..2 | ||
118 | + person = fast_create(Person) | ||
119 | + person.vote_for(article) | ||
120 | + end | ||
121 | + | ||
122 | + article = fast_create(Article, {:name=>'10 votes'}) | ||
123 | + for i in 0..10 | ||
124 | + person = fast_create(Person) | ||
125 | + person.vote_for(article) | ||
126 | + end | ||
127 | + | ||
128 | + article = fast_create(Article, {:name=>'5 votes'}) | ||
129 | + for i in 0..5 | ||
130 | + person = fast_create(Person) | ||
131 | + person.vote_for(article) | ||
132 | + end | ||
133 | + | ||
134 | + articles = Article.most_voted(Environment.default, 5) | ||
135 | + assert_equal '10 votes', articles.first.name | ||
136 | + assert_equal '2 votes', articles.last.name | ||
137 | + end | ||
138 | + | ||
139 | + should 'list the most postive' do | ||
140 | + | ||
141 | + article = fast_create(Article, {:name=>'23 votes for 20 votes against'}) | ||
142 | + for i in 0..20 | ||
143 | + person = fast_create(Person) | ||
144 | + person.vote_against(article) | ||
145 | + end | ||
146 | + for i in 0..23 | ||
147 | + person = fast_create(Person) | ||
148 | + person.vote_for(article) | ||
149 | + end | ||
150 | + | ||
151 | + article = fast_create(Article, {:name=>'10 votes for 5 votes against'}) | ||
152 | + for i in 0..10 | ||
153 | + person = fast_create(Person) | ||
154 | + person.vote_for(article) | ||
155 | + end | ||
156 | + for i in 0..5 | ||
157 | + person = fast_create(Person) | ||
158 | + person.vote_against(article) | ||
159 | + end | ||
160 | + | ||
161 | + article = fast_create(Article, {:name=>'2 votes against'}) | ||
162 | + for i in 0..2 | ||
163 | + person = fast_create(Person) | ||
164 | + person.vote_against(article) | ||
165 | + end | ||
166 | + | ||
167 | + article = fast_create(Article, {:name=>'7 votes for'}) | ||
168 | + for i in 0..7 | ||
169 | + person = fast_create(Person) | ||
170 | + person.vote_for(article) | ||
171 | + end | ||
172 | + | ||
173 | + articles = Article.more_positive_votes(Environment.default, 5) | ||
174 | + assert_equal '7 votes for', articles.first.name | ||
175 | + assert_equal '23 votes for 20 votes against', articles.last.name | ||
176 | + end | ||
177 | + | ||
178 | + should 'list the most negative' do | ||
179 | + | ||
180 | + article = fast_create(Article, {:name=>'23 votes for 29 votes against'}) | ||
181 | + for i in 0..29 | ||
182 | + person = fast_create(Person) | ||
183 | + person.vote_against(article) | ||
184 | + end | ||
185 | + for i in 0..23 | ||
186 | + person = fast_create(Person) | ||
187 | + person.vote_for(article) | ||
188 | + end | ||
189 | + | ||
190 | + article = fast_create(Article, {:name=>'10 votes for 15 votes against'}) | ||
191 | + for i in 0..10 | ||
192 | + person = fast_create(Person) | ||
193 | + person.vote_for(article) | ||
194 | + end | ||
195 | + for i in 0..15 | ||
196 | + person = fast_create(Person) | ||
197 | + person.vote_against(article) | ||
198 | + end | ||
199 | + | ||
200 | + article = fast_create(Article, {:name=>'2 votes against'}) | ||
201 | + for i in 0..2 | ||
202 | + person = fast_create(Person) | ||
203 | + person.vote_against(article) | ||
204 | + end | ||
205 | + | ||
206 | + article = fast_create(Article, {:name=>'7 votes for'}) | ||
207 | + for i in 0..7 | ||
208 | + person = fast_create(Person) | ||
209 | + person.vote_for(article) | ||
210 | + end | ||
211 | + | ||
212 | + articles = Article.more_negative_votes(Environment.default, 5) | ||
213 | + assert_equal '23 votes for 29 votes against', articles.first.name | ||
214 | + assert_equal '2 votes against', articles.last.name | ||
215 | + end | ||
216 | + | ||
217 | +end |
plugins/relevant_content/test/unit/relevant_content_plugin_test.rb
0 → 100644
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class RelevantContentPluginTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @plugin = RelevantContentPlugin.new | ||
7 | + end | ||
8 | + | ||
9 | + should 'be a noosfero plugin' do | ||
10 | + assert_kind_of Noosfero::Plugin, @plugin | ||
11 | + end | ||
12 | + | ||
13 | + should 'have name' do | ||
14 | + assert_equal 'Relevant Content Plugin', RelevantContentPlugin.plugin_name | ||
15 | + end | ||
16 | + | ||
17 | + should 'have description' do | ||
18 | + assert_equal _("A plugin that lists the most accessed, most commented, most liked and most disliked contents."), RelevantContentPlugin.plugin_description | ||
19 | + end | ||
20 | + | ||
21 | + should 'have stylesheet' do | ||
22 | + assert @plugin.stylesheet? | ||
23 | + end | ||
24 | + | ||
25 | + should "return RelevantContentBlock in extra_blocks class method" do | ||
26 | + assert RelevantContentPlugin.extra_blocks.keys.include?(RelevantContentPlugin::RelevantContentBlock) | ||
27 | + end | ||
28 | + | ||
29 | +end |
plugins/relevant_content/views/box_organizer/relevant_content_plugin/_relevant_content_block.rhtml
0 → 100644
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<div id='edit-relevant-content-block'> | ||
2 | + <%= labelled_form_field _('Limit of items per category'), text_field(:block, :limit, :size => 3) %> | ||
3 | + <%= labelled_check_box _('Display most accessed content'), "block[show_most_read]", 1 ,@block.show_most_read != 0 %><BR> | ||
4 | + <%= labelled_check_box _('Display most commented content'), "block[show_most_commented]", 1 ,@block.show_most_commented != 0 %><BR> | ||
5 | + <%= labelled_check_box _('Display most liked content'), "block[show_most_liked]", 1 ,@block.show_most_liked != 0 %><BR> | ||
6 | + <%= labelled_check_box _('Display most voted content'), "block[show_most_voted]", 1 ,@block.show_most_voted != 0 %><BR> | ||
7 | + <%= labelled_check_box _('Display most disliked content'), "block[show_most_disliked]", 1 , @block.show_most_disliked != 0 %><BR> | ||
8 | +</div> | ||
9 | + | ||
10 | + | ||
11 | + | ||
12 | + |
plugins/relevant_content/views/environment_design/relevant_content_plugin
0 → 120000
plugins/relevant_content/views/profile_design/relevant_content_plugin
0 → 120000