Commit 1eb456dd8c3441050b801c8f2da45d84d992dddc
1 parent
a3b75892
Exists in
master
and in
29 other branches
rails3: fix vote plugin
Showing
7 changed files
with
49 additions
and
49 deletions
Show diff stats
plugins/vote/lib/vote_plugin.rb
... | ... | @@ -33,7 +33,7 @@ class VotePlugin < Noosfero::Plugin |
33 | 33 | def comment_actions(comment) |
34 | 34 | like = vote_partial(comment) |
35 | 35 | dislike = vote_partial(comment, false) |
36 | - lambda do | |
36 | + proc do | |
37 | 37 | [{:link => instance_eval(&dislike), :action_bar => true}, {:link => instance_eval(&like), :action_bar => true}] |
38 | 38 | end |
39 | 39 | end |
... | ... | @@ -41,7 +41,7 @@ class VotePlugin < Noosfero::Plugin |
41 | 41 | def article_header_extra_contents(article) |
42 | 42 | like = vote_partial(article) |
43 | 43 | dislike = vote_partial(article, false) |
44 | - lambda do | |
44 | + proc do | |
45 | 45 | content_tag('div', instance_eval(&dislike) + instance_eval(&like), :class => 'vote-actions') |
46 | 46 | end |
47 | 47 | end | ... | ... |
plugins/vote/lib/vote_plugin_helper.rb
... | ... | @@ -5,7 +5,7 @@ module VotePluginHelper |
5 | 5 | like_action = like ? 'like' : 'dislike' |
6 | 6 | type = target.kind_of?(Article) ? 'article' : target.kind_of?(Comment) ? 'comment' : nil |
7 | 7 | |
8 | - lambda do | |
8 | + proc do | |
9 | 9 | settings = Noosfero::Plugin::Settings.new(environment, VotePlugin) |
10 | 10 | |
11 | 11 | if settings.get_setting("enable_vote_#{type}").include?(vote) |
... | ... | @@ -14,7 +14,7 @@ module VotePluginHelper |
14 | 14 | active = user ? (like ? user.voted_for?(target) : user.voted_against?(target)) : false |
15 | 15 | count = like ? target.votes_for : target.votes_against |
16 | 16 | |
17 | - render(:partial => 'vote/vote.rhtml', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type }) | |
17 | + render(:partial => 'vote/vote', :locals => {:target => target, :active => active, :action => like_action, :count => count, :voters => voters, :vote => vote, :model => type }) | |
18 | 18 | else |
19 | 19 | "" |
20 | 20 | end | ... | ... |
plugins/vote/test/unit/article_test.rb
... | ... | @@ -9,14 +9,14 @@ class ArticleTest < ActiveSupport::TestCase |
9 | 9 | attr_reader :profile |
10 | 10 | |
11 | 11 | should 'vote in a article' do |
12 | - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) | |
12 | + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) | |
13 | 13 | profile.vote(article, 5) |
14 | 14 | assert_equal 1, article.voters_who_voted.length |
15 | 15 | assert_equal 5, article.votes_total |
16 | 16 | end |
17 | 17 | |
18 | 18 | should 'be able to remove a voted article' do |
19 | - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) | |
19 | + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) | |
20 | 20 | profile.vote(article, 5) |
21 | 21 | article.destroy |
22 | 22 | end | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +<% | |
2 | +url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote) | |
3 | +reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote) | |
4 | +%> | |
5 | + | |
6 | +<span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action"> | |
7 | + | |
8 | + <%= link_to_remote content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), :url => url, :html => {:class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'}"} %> | |
9 | + | |
10 | + <% if !voters.blank? %> | |
11 | + <span class="vote-detail"> | |
12 | + <ul> | |
13 | + <% voters.each do |voter| %> | |
14 | + <li> | |
15 | + <%= link_to image_tag(profile_icon(voter, :icon)) + content_tag('span', voter.short_name), | |
16 | + voter.url, :title => voter.short_name %> | |
17 | + </li> | |
18 | + <% end %> | |
19 | + </ul> | |
20 | + </span> | |
21 | + <% end %> | |
22 | +</span> | ... | ... |
plugins/vote/views/vote/_vote.rhtml
... | ... | @@ -1,22 +0,0 @@ |
1 | -<% | |
2 | -url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :vote, :id => target.id, :model => model, :vote => vote) | |
3 | -reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.identifier, :action => :reload_vote, :id => target.id, :model => model, :vote => vote) | |
4 | -%> | |
5 | - | |
6 | -<span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action"> | |
7 | - | |
8 | - <%= link_to_remote content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), :url => url, :html => {:class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'}"} %> | |
9 | - | |
10 | - <% if !voters.blank? %> | |
11 | - <span class="vote-detail"> | |
12 | - <ul> | |
13 | - <% voters.each do |voter| %> | |
14 | - <li> | |
15 | - <%= link_to image_tag(profile_icon(voter, :icon)) + content_tag('span', voter.short_name), | |
16 | - voter.url, :title => voter.short_name %> | |
17 | - </li> | |
18 | - <% end %> | |
19 | - </ul> | |
20 | - </span> | |
21 | - <% end %> | |
22 | -</span> |
... | ... | @@ -0,0 +1,21 @@ |
1 | +<h1><%= _('Vote settings')%></h1> | |
2 | + | |
3 | +<%= form_for(:settings) do |f| %> | |
4 | + | |
5 | + <% ['article', 'comment'].each do |model| %> | |
6 | + <h5><%= _('Enable on %s:' % model) %></h5> | |
7 | + <%= f.check_box("enable_vote_#{model}", {:multiple => true}, 1) + _('Like') %> | |
8 | + <%= f.check_box("enable_vote_#{model}", {:multiple => true}, -1) + _('Dislike') %> | |
9 | + <% end %> | |
10 | + <br/><br/> | |
11 | + | |
12 | + <strong> | |
13 | + <%= labelled_form_field _('Limit of voters to display:'), f.text_field(:voters_limit, :size => 3) %> | |
14 | + </strong> | |
15 | + | |
16 | + <% button_bar do %> | |
17 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | |
18 | + <% end %> | |
19 | + | |
20 | +<% end %> | |
21 | + | ... | ... |
plugins/vote/views/vote_plugin_admin/index.rhtml
... | ... | @@ -1,21 +0,0 @@ |
1 | -<h1><%= _('Vote settings')%></h1> | |
2 | - | |
3 | -<% form_for(:settings) do |f| %> | |
4 | - | |
5 | - <% ['article', 'comment'].each do |model| %> | |
6 | - <h5><%= _('Enable on %s:' % model) %></h5> | |
7 | - <%= f.check_box("enable_vote_#{model}", {:multiple => true}, 1) + _('Like') %> | |
8 | - <%= f.check_box("enable_vote_#{model}", {:multiple => true}, -1) + _('Dislike') %> | |
9 | - <% end %> | |
10 | - <br/><br/> | |
11 | - | |
12 | - <strong> | |
13 | - <%= labelled_form_field _('Limit of voters to display:'), f.text_field(:voters_limit, :size => 3) %> | |
14 | - </strong> | |
15 | - | |
16 | - <% button_bar do %> | |
17 | - <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | |
18 | - <% end %> | |
19 | - | |
20 | -<% end %> | |
21 | - |