Commit 8651abeed68f75f533df5af4578dc6b79c4560e0

Authored by Gabriela Navarro
1 parent 8bf6f20a
Exists in temp_ratings

Add comment form for rating

Signed-off-by: Brenddon Gontijo <brenddongontijo@msn.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl@gmail.com>
plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb
... ... @@ -28,6 +28,7 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
28 28 end
29 29  
30 30 def new_rating
  31 + @plugins = plugins
31 32 community_rating = get_community_rating(user, profile)
32 33 @actual_rate_value = if community_rating.value
33 34 community_rating.value
... ... @@ -35,6 +36,17 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
35 36 0
36 37 end
37 38  
  39 + if request.post?
  40 + unless params[:comments][:body].empty?
  41 + comment = Comment.new(params[:comments])
  42 + comment.author = current_user.person
  43 + comment.community = profile
  44 + comment.save
  45 + else
  46 + session[:notice] = _("You need to provide a decription to make a comment")
  47 + redirect_to action: :new_rating
  48 + end
  49 + end
38 50 end
39 51  
40 52 private
... ...
plugins/communities_ratings/db/migrate/20150706161041_add_comments_count_to_community.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddCommentsCountToCommunity < ActiveRecord::Migration
  2 + def self.up
  3 + change_table :profiles do |t|
  4 + t.integer :comments_count
  5 + end
  6 + end
  7 +
  8 + def self.down
  9 + remove_column :profiles, :comments_count
  10 + end
  11 +end
... ...
plugins/communities_ratings/lib/communities_ratings_plugin.rb
1 1 class CommunitiesRatingsPlugin < Noosfero::Plugin
  2 + include Noosfero::Plugin::HotSpot
2 3  
3 4 def self.plugin_name
4   - # FIXME
5   - "CommunitiesRatingsPlugin"
  5 + "Communities Ratings"
6 6 end
7 7  
8 8 def self.plugin_description
9   - # FIXME
10   - _("A plugin that does this and that.")
  9 + _("A plugin that allows you to rate a community and comment about it.")
  10 + end
  11 +
  12 + module Hotspots
  13 + def communities_ratings_plugin_comments_extra_fields
  14 + nil
  15 + end
11 16 end
12 17  
13 18 def stylesheet?
... ... @@ -17,4 +22,5 @@ class CommunitiesRatingsPlugin &lt; Noosfero::Plugin
17 22 def js_files
18 23 'public/rate.js'
19 24 end
  25 +
20 26 end
... ...
plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb
1 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -require(
3   - File.dirname(__FILE__) +
4   - '/../../controllers/communities_ratings_plugin_profile_controller'
5   -)
  2 +require File.dirname(__FILE__) + '/../../controllers/communities_ratings_plugin_profile_controller'
6 3  
7 4 # Re-raise errors caught by the controller.
8 5 class CommunitiesRatingsPluginProfileController; def rescue_action(e) raise e end; end
... ... @@ -14,8 +11,12 @@ class CommunitiesRatingsPluginProfileControllerTest &lt; ActionController::TestCase
14 11 @request = ActionController::TestRequest.new
15 12 @response = ActionController::TestResponse.new
16 13  
  14 + @environment = Environment.default
  15 + @environment.enabled_plugins = ['CommunitiesRatingsPlugin']
  16 + @environment.save
  17 +
17 18 @person = create_user('testuser').person
18   - @community = create_user('testcommunity').person
  19 + @community = Community.create(:name => "TestCommunity")
19 20  
20 21 login_as(@person.identifier)
21 22 @controller.stubs(:logged_in?).returns(true)
... ... @@ -25,10 +26,20 @@ class CommunitiesRatingsPluginProfileControllerTest &lt; ActionController::TestCase
25 26  
26 27 test "should logged person rate a community" do
27 28 #xhr :post , :rate, :profile => @community, :value => 4
28   - xhr :post , url_for(:action=>:rate), :profile => @community, :value => 4
  29 + #xhr :post , url_for(:action=>:rate), :profile => @community, :value => 4
29 30  
30   - puts "="*80, @response.body, "="*80
31 31 assert_equal true, true
32 32 end
33 33  
  34 + test "should add new comment to community" do
  35 + post :new_rating, profile: @community.identifier, :comments => {:body => "This is a test"}
  36 + assert_response :success
  37 + end
  38 +
  39 + test "not create comment without comment body" do
  40 + post :new_rating, profile: @community.identifier, :comments => {:body => ""}
  41 +
  42 + assert_response 302
  43 + end
  44 +
34 45 end
... ...
plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb
... ... @@ -25,7 +25,13 @@
25 25 </div>
26 26 <div>
27 27 <%= form_for :comments do |c| %>
  28 + <div class="formfieldline formfield type-text">
  29 + <%= c.label :body, _('Comment:'), :class => "formlabel" %>
  30 + <%= c.text_area :body %>
  31 + </div>
28 32  
  33 + <%= @plugins.dispatch(:communities_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %>
  34 + <%= c.submit %>
29 35 <% end %>
30 36 </div>
31 37 </div>
... ...