Commit 53ef4b9015a78e895d869c755b2ab202fa266e4a

Authored by Gabriel Silva
Committed by Thiago Ribeiro
1 parent f50cbb93

Software Communities plugin rating improvements

- Move software statistics from blocks table to softwares table
- Update methods called on view to display software statistics
- Software now automagically sums saved_resources and benefited people  when the task is accepted
- Adds one hotspot to insert content on ratings task and another one to ratings container (used on
ratings page and ratings block)
- Removes statistic block fields that are no longer used
- Adds number_to_human method to get better visualization for numbers
- Makes the software tasks page closer to the prototype (changes in the divs, sizes and aligns).
- Fixed broken tests on software_profile_editor_controller

Signed-off-by: Dylan Guedes <djmgguedes@gmail.com>
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
Showing 50 changed files with 434 additions and 118 deletions   Show diff stats
src/noosfero-spb/noosfero-spb-theme/css/software-pages.css
@@ -630,3 +630,106 @@ @@ -630,3 +630,106 @@
630 } 630 }
631 631
632 /*** end fo software internal pages ***/ 632 /*** end fo software internal pages ***/
  633 +
  634 +/*** organization-rating review page (tasks of software) ***/
  635 +
  636 +.task-list .task_boxes{
  637 + font-family: Arial;
  638 +}
  639 +
  640 +.task-list .task_boxes .task_box .task_date{
  641 + position: absolute;
  642 + left: 80px;
  643 +}
  644 +
  645 +.task_boxes .task_box .task_title{
  646 + position: absolute;
  647 + left: 80px;
  648 + font-weight: 500;
  649 + margin-top: 10px;
  650 +}
  651 +
  652 +.task_boxes .task_box .task_responsible{
  653 + text-align: right;
  654 +}
  655 +
  656 +.task_boxes .task_box .task_responsible span select{
  657 + padding: 4px 15px 1px 4px;
  658 +}
  659 +
  660 +.task_boxes .task_box .task_decisions{
  661 + float: right;
  662 + padding-right: 5px;
  663 +}
  664 +
  665 +.task_boxes .task_box .task_information{
  666 + margin-top: 40px;
  667 +}
  668 +
  669 +.task_boxes .task_box .organization-rating-comment-body .aditional-informations .comments-people-benefited{
  670 + float: left;
  671 + font-weight: 900;
  672 +}
  673 +
  674 +.task_boxes .task_box .organization-rating-comment-body .aditional-informations .comments-saved-value{
  675 + font-weight: 900;
  676 + margin-left: 160px;
  677 +}
  678 +
  679 +.task_boxes .task_box .organization-rating-comment-body .aditional-informations{
  680 + margin-top: 10px;
  681 + margin-bottom: 10px;
  682 + border-bottom: 1px solid #CDCDCD;
  683 + padding-bottom: 15px;
  684 +}
  685 +
  686 +.task_boxes .task_box .organization-rating-comment-body .aditional-informations .comments-user-institution span span{
  687 + font-weight: 900;
  688 +}
  689 +
  690 +.task_boxes .task_box .organization-rating-comment-body .aditional-informations .comments-people-benefited span{
  691 + font-weight: 100;
  692 +}
  693 +
  694 +.task_boxes .task_box .organization-rating-comment-body .aditional-informations .comments-saved-value span{
  695 + font-weight: 100;
  696 +}
  697 +
  698 +.task_boxes .task_box .organization-rating-comment-body .task-comment span{
  699 + font-weight: 600;
  700 + color: rgb(140, 140, 140);
  701 + font-size: 11px;
  702 +}
  703 +
  704 +.task_boxes .task_box .organization-rating-comment-body .task-comment{
  705 + margin-bottom: 15px;
  706 +}
  707 +
  708 +.task_boxes .task_box .organization-rating-comment-body .task-comment span p{
  709 + font-weight: 100;
  710 + font-size: 12px;
  711 + color: black;
  712 + line-height: 16px;
  713 +}
  714 +
  715 +.task_boxes .task_box .organization-rating-comment-body .task-comment{
  716 + line-height: 25px;
  717 +}
  718 +
  719 +.task_boxes .task_box .organization-rating-comment-body .rating-notice{
  720 + display: block;
  721 + color: #F11467;
  722 + padding: 5px 5px;
  723 + background: #ccc;
  724 +}
  725 +
  726 +.task_boxes .task_box .organization-rating-comment-body .task-star-container{
  727 + margin-bottom: 30px;
  728 + margin-top: 10px;
  729 +}
  730 +
  731 +.action-tasks-index .task_box{
  732 + padding: 10px;
  733 +}
  734 +
  735 +/*** end of organization-rating review page (tasks of software) ***/
src/noosfero-spb/software_communities/controllers/software_communities_plugin_myprofile_controller.rb
@@ -144,7 +144,7 @@ class SoftwareCommunitiesPluginMyprofileController &lt; MyProfileController @@ -144,7 +144,7 @@ class SoftwareCommunitiesPluginMyprofileController &lt; MyProfileController
144 144
145 add_admin_to_community 145 add_admin_to_community
146 146
147 - if !environment.admins.include?(current_user.person) 147 + if !user.is_admin?
148 session[:notice] = _('Your new software request will be evaluated by an'\ 148 session[:notice] = _('Your new software request will be evaluated by an'\
149 'administrator. You will be notified.') 149 'administrator. You will be notified.')
150 redirect_to user.admin_url 150 redirect_to user.admin_url
src/noosfero-spb/software_communities/db/migrate/20151116134125_add_statistics_to_software_info.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +class AddStatisticsToSoftwareInfo < ActiveRecord::Migration
  2 + def up
  3 + add_column :software_infos, :benefited_people, :integer, :default => 0
  4 + add_column :software_infos, :saved_resources, :decimal, :default => 0
  5 + end
  6 +
  7 + def down
  8 + remove_column :software_infos, :benefited_people
  9 + remove_column :software_infos, :saved_resources
  10 + end
  11 +end
src/noosfero-spb/software_communities/db/migrate/20151116140329_move_software_statistics_from_block_to_software_info.rb 0 → 100644
@@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
  1 +class MoveSoftwareStatisticsFromBlockToSoftwareInfo < ActiveRecord::Migration
  2 + def up
  3 + benefited_people = 0
  4 + saved_resources = 0
  5 +
  6 + select_all("SELECT * FROM tasks WHERE status=3 AND type='CreateOrganizationRatingComment'").each do |task|
  7 + settings = YAML.load(task['data'])
  8 + organization_rating = select_one("SELECT * FROM organization_ratings WHERE id=#{settings[:organization_rating_id]}")
  9 +
  10 + benefited_people += organization_rating["people_benefited"].to_i
  11 + saved_resources += organization_rating["saved_value"].to_f
  12 + execute("UPDATE software_infos SET benefited_people=#{benefited_people}, saved_resources=#{saved_resources} WHERE software_infos.community_id=#{organization_rating["organization_id"]}")
  13 + end
  14 + end
  15 +
  16 + def down
  17 + execute("UPDATE software_infos SET benefited_people=0, saved_resources=0")
  18 + end
  19 +end
src/noosfero-spb/software_communities/features/software_block.feature
@@ -25,6 +25,7 @@ Feature: edit adherent fields @@ -25,6 +25,7 @@ Feature: edit adherent fields
25 25
26 Scenario: Change software block to generic software block 26 Scenario: Change software block to generic software block
27 Given I am logged in as mpog_admin 27 Given I am logged in as mpog_admin
  28 + And I go to /myprofile/mpog_admin
28 And I follow "Control panel" 29 And I follow "Control panel"
29 And I follow "Edit sideboxes" 30 And I follow "Edit sideboxes"
30 When I follow "Add a block" 31 When I follow "Add a block"
@@ -45,4 +46,4 @@ Feature: edit adherent fields @@ -45,4 +46,4 @@ Feature: edit adherent fields
45 And I follow "Edit" within ".softwares-block" 46 And I follow "Edit" within ".softwares-block"
46 And I select "Public" from "block_software_type" 47 And I select "Public" from "block_software_type"
47 And I press "Save" 48 And I press "Save"
48 - Then I should see "public software"  
49 \ No newline at end of file 49 \ No newline at end of file
  50 + Then I should see "public software"
src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb
@@ -64,6 +64,53 @@ Given /^I type in &quot;([^&quot;]*)&quot; in autocomplete list &quot;([^&quot;]*)&quot; and I choose &quot;([^&quot;]*) @@ -64,6 +64,53 @@ Given /^I type in &quot;([^&quot;]*)&quot; in autocomplete list &quot;([^&quot;]*)&quot; and I choose &quot;([^&quot;]*)
64 sleep 1 64 sleep 1
65 end 65 end
66 66
  67 +Given /^Institutions has initial default values on database$/ do
  68 + GovernmentalPower.create(:name => "Executivo")
  69 + GovernmentalPower.create(:name => "Legislativo")
  70 + GovernmentalPower.create(:name => "Judiciario")
  71 +
  72 + GovernmentalSphere.create(:name => "Federal")
  73 +
  74 + JuridicalNature.create(:name => "Autarquia")
  75 + JuridicalNature.create(:name => "Administracao Direta")
  76 + JuridicalNature.create(:name => "Empresa Publica")
  77 + JuridicalNature.create(:name => "Fundacao")
  78 + JuridicalNature.create(:name => "Orgao Autonomo")
  79 + JuridicalNature.create(:name => "Sociedade")
  80 + JuridicalNature.create(:name => "Sociedade Civil")
  81 + JuridicalNature.create(:name => "Sociedade de Economia Mista")
  82 +
  83 + national_region = NationalRegion.new
  84 + national_region.name = "Distrito Federal"
  85 + national_region.national_region_code = '35'
  86 + national_region.national_region_type_id = NationalRegionType::STATE
  87 + national_region.save
  88 +end
  89 +
  90 +Given /^the following organization ratings$/ do |table|
  91 + table.hashes.each do |item|
  92 + person = User.where(login: item[:user_login]).first.person
  93 + organization = Organization.where(name: item[:organization_name]).first
  94 +
  95 + rating = OrganizationRating.new
  96 + rating.value = item[:value]
  97 + rating.organization_id = organization.id
  98 + rating.person_id = person.id
  99 + rating.saved_value = item[:saved_value]
  100 + rating.institution_id = Institution.where(name: item[:institution_name]).first.id
  101 + rating.save
  102 +
  103 + comment_task = CreateOrganizationRatingComment.create!(
  104 + :body => "empty comment",
  105 + :requestor => person,
  106 + :organization_rating_id => rating.id,
  107 + :target => organization)
  108 +
  109 + comment_task.status = item[:task_status]
  110 + comment_task.save
  111 + end
  112 +end
  113 +
67 Given /^the following public institutions?$/ do |table| 114 Given /^the following public institutions?$/ do |table|
68 # table is a Cucumber::Ast::Table 115 # table is a Cucumber::Ast::Table
69 table.hashes.each do |item| 116 table.hashes.each do |item|
@@ -247,3 +294,7 @@ end @@ -247,3 +294,7 @@ end
247 Then /^there should be (\d+) divs? with class "([^"]*)"$/ do |count, klass| 294 Then /^there should be (\d+) divs? with class "([^"]*)"$/ do |count, klass|
248 should have_selector("div.#{klass}", :count => count) 295 should have_selector("div.#{klass}", :count => count)
249 end 296 end
  297 +
  298 +Given /^I should see "([^"]*)" in the page/ do |message|
  299 + assert_match message, page.body
  300 +end
src/noosfero-spb/software_communities/lib/ext/application_helper.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +require_dependency "application_helper"
  2 +
  3 +ApplicationHelper.class_eval do
  4 +
  5 + def number_to_human(value)
  6 + number_with_delimiter(value, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter)
  7 + end
  8 +end
src/noosfero-spb/software_communities/lib/ext/community.rb
@@ -18,7 +18,7 @@ class Community @@ -18,7 +18,7 @@ class Community
18 community = Community.new(attributes) 18 community = Community.new(attributes)
19 19
20 if community.environment.enabled?('admin_must_approve_new_communities') && 20 if community.environment.enabled?('admin_must_approve_new_communities') &&
21 - !community.environment.admins.include?(requestor) 21 + !community.is_admin?(requestor)
22 22
23 cc = CreateCommunity.create(attributes.merge(:requestor => requestor)) 23 cc = CreateCommunity.create(attributes.merge(:requestor => requestor))
24 else 24 else
src/noosfero-spb/software_communities/lib/ext/create_organization_rating_comment.rb 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +require_dependency "create_organization_rating_comment"
  2 +
  3 +CreateOrganizationRatingComment.class_eval do
  4 + after_save :update_software_statistic
  5 +
  6 + def update_software_statistic
  7 + if(self.status == Task::Status::FINISHED)
  8 + rating = OrganizationRating.find_by_id(self.organization_rating_id)
  9 + software = SoftwareInfo.find_by_community_id(self.target_id)
  10 + if software.present? and rating.present?
  11 + software.saved_resources += rating.saved_value if rating.saved_value
  12 + software.benefited_people += rating.people_benefited if rating.people_benefited
  13 + software.save
  14 + end
  15 + end
  16 + end
  17 +end
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
@@ -100,14 +100,38 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -100,14 +100,38 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
100 Proc::new do "<h1 class='title'>#{title}</h1>" end 100 Proc::new do "<h1 class='title'>#{title}</h1>" end
101 end 101 end
102 102
103 - def organization_ratings_plugin_extra_fields_show_data user_rating 103 + def organization_ratings_plugin_container_extra_fields user_rating
104 Proc::new { 104 Proc::new {
105 if logged_in? 105 if logged_in?
106 - is_admin = environment.admins.include?(current_user.person)  
107 - is_admin ||= user_rating.organization.admins.include?(current_user.person) 106 + is_admin = user.is_admin? || user_rating.organization.is_admin?(user)
108 107
109 if is_admin and profile.software? 108 if is_admin and profile.software?
110 - render :file => 'organization_ratings_extra_fields_show_data', 109 +
  110 + render :file => 'organization_ratings_container_extra_fields_show_statistics',
  111 + :locals => {:user_rating => user_rating}
  112 + end
  113 + end
  114 + }
  115 + end
  116 +
  117 + def organization_ratings_plugin_rating_created rating, params
  118 + if params[:organization_rating].present? && (params[:organization_rating][:people_benefited].present? ||
  119 + params[:organization_rating][:saved_value].present?)
  120 + CreateOrganizationRatingComment.create!(
  121 + :requestor => rating.person,
  122 + :organization_rating_id => rating.id,
  123 + :target => rating.organization) unless params[:comments] && params[:comments][:body].present?
  124 + end
  125 + end
  126 +
  127 + def organization_ratings_plugin_task_extra_fields user_rating
  128 + Proc::new {
  129 + if logged_in?
  130 + is_admin = user.is_admin? || user_rating.organization.is_admin?(user)
  131 +
  132 + if is_admin and profile.software?
  133 +
  134 + render :file => 'organization_ratings_task_extra_fields_show_statistics',
111 :locals => {:user_rating => user_rating} 135 :locals => {:user_rating => user_rating}
112 end 136 end
113 end 137 end
src/noosfero-spb/software_communities/lib/software_info.rb
@@ -166,7 +166,7 @@ class SoftwareInfo &lt; ActiveRecord::Base @@ -166,7 +166,7 @@ class SoftwareInfo &lt; ActiveRecord::Base
166 another_license_link = attributes.delete(:another_license_link) 166 another_license_link = attributes.delete(:another_license_link)
167 167
168 software_info = SoftwareInfo.new(attributes) 168 software_info = SoftwareInfo.new(attributes)
169 - unless environment.admins.include? requestor 169 + if !requestor.is_admin?
170 CreateSoftware.create!( 170 CreateSoftware.create!(
171 attributes.merge( 171 attributes.merge(
172 :requestor => requestor, 172 :requestor => requestor,
src/noosfero-spb/software_communities/lib/statistic_block.rb
@@ -20,13 +20,15 @@ class StatisticBlock &lt; Block @@ -20,13 +20,15 @@ class StatisticBlock &lt; Block
20 end 20 end
21 21
22 block = self 22 block = self
  23 + statistics = get_software_statistics
23 24
24 lambda do |object| 25 lambda do |object|
25 render( 26 render(
26 :file => 'blocks/software_statistics', 27 :file => 'blocks/software_statistics',
27 :locals => { 28 :locals => {
28 :block => block, 29 :block => block,
29 - :total_downloads => downloads.sum 30 + :total_downloads => downloads.sum,
  31 + :statistics => statistics
30 } 32 }
31 ) 33 )
32 end 34 end
@@ -49,4 +51,12 @@ class StatisticBlock &lt; Block @@ -49,4 +51,12 @@ class StatisticBlock &lt; Block
49 downloads.select! {|value| not value.nil? } 51 downloads.select! {|value| not value.nil? }
50 downloads.sum 52 downloads.sum
51 end 53 end
  54 +
  55 + def get_software_statistics
  56 + statistics = {}
  57 + software = SoftwareInfo.find_by_community_id(self.owner.id)
  58 + statistics[:saved_resources] = software.saved_resources
  59 + statistics[:benefited_people] = software.benefited_people
  60 + statistics
  61 + end
52 end 62 end
src/noosfero-spb/software_communities/test/functional/organization_ratings_plugin_profile_controller_test.rb 0 → 100644
@@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
  1 +require 'test_helper'
  2 +require 'organization_ratings_plugin_profile_controller'
  3 +require File.dirname(__FILE__) + '/../helpers/software_test_helper'
  4 +
  5 +# Re-raise errors caught by the controller.
  6 +class OrganizationRatingsPluginProfileController; def rescue_action(e) raise e end; end
  7 +
  8 +class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCase
  9 + include SoftwareTestHelper
  10 +
  11 + def setup
  12 + @controller = OrganizationRatingsPluginProfileController.new
  13 + @request = ActionController::TestRequest.new
  14 + @response = ActionController::TestResponse.new
  15 +
  16 + @environment = Environment.default
  17 + @environment.enabled_plugins = ['OrganizationRatingsPlugin']
  18 + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin']
  19 + @environment.save
  20 +
  21 + LicenseInfo.create(:version=>"CC-GPL-V2",
  22 + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt")
  23 +
  24 + @person = create_user('testuser').person
  25 + @software = create_software(software_fields)
  26 + @statistic_block = StatisticBlock.new
  27 + @software.community.blocks << @statistic_block
  28 + @software.community.save!
  29 +
  30 + login_as(@person.identifier)
  31 + @controller.stubs(:logged_in?).returns(true)
  32 + @controller.stubs(:current_user).returns(@person.user)
  33 + end
  34 +
  35 + test "should create a task with a valid benefited people value and no comment" do
  36 + assert_difference 'CreateOrganizationRatingComment.count' do
  37 + post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
  38 + :organization_rating_value => 3, :organization_rating => {:people_benefited => 50}
  39 + end
  40 + end
  41 +
  42 + test "should create a task with a valid saved value and no comment" do
  43 + assert_difference 'CreateOrganizationRatingComment.count' do
  44 + post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
  45 + :organization_rating_value => 3, :organization_rating => {:saved_value => 50000000}
  46 + end
  47 + end
  48 +
  49 + test "should not create a task with no saved value or benefited poeple, and no comment" do
  50 + assert_no_difference 'CreateOrganizationRatingComment.count' do
  51 + post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
  52 + :organization_rating_value => 3, :organization_rating => nil
  53 + end
  54 + end
  55 +
  56 + test "software statistics should be updated when task is accepted" do
  57 + @software.reload
  58 + assert_equal 0, @software.benefited_people
  59 + assert_equal 0.0, @software.saved_resources
  60 +
  61 + post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
  62 + :organization_rating_value => 3,
  63 + :organization_rating => {:saved_value => 500, :people_benefited => 10}
  64 +
  65 + CreateOrganizationRatingComment.last.finish
  66 + @software.reload
  67 + assert_equal 10, @software.benefited_people
  68 + assert_equal 500.0, @software.saved_resources
  69 + end
  70 +
  71 + test "software statistics should not be updated when task is cancelled" do
  72 + @software.reload
  73 + assert_equal 0, @software.benefited_people
  74 + assert_equal 0.0, @software.saved_resources
  75 +
  76 + post :new_rating, profile: @software.community.identifier, :comments => {:body => ""},
  77 + :organization_rating_value => 3,
  78 + :organization_rating => {:saved_value => 500, :people_benefited => 10}
  79 +
  80 + CreateOrganizationRatingComment.last.cancel
  81 + @software.reload
  82 + assert_equal 0, @software.benefited_people
  83 + assert_equal 0.0, @software.saved_resources
  84 + end
  85 +end
src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require File.dirname(__FILE__) + '/../helpers/software_test_helper'
  2 +require 'test_helper'
2 require( 3 require(
3 File.dirname(__FILE__) + 4 File.dirname(__FILE__) +
4 '/../../../../app/controllers/my_profile/profile_editor_controller' 5 '/../../../../app/controllers/my_profile/profile_editor_controller'
@@ -7,13 +8,18 @@ require( @@ -7,13 +8,18 @@ require(
7 class ProfileEditorController; def rescue_action(e) raise e end; end 8 class ProfileEditorController; def rescue_action(e) raise e end; end
8 9
9 class ProfileEditorControllerTest < ActionController::TestCase 10 class ProfileEditorControllerTest < ActionController::TestCase
10 - 11 + include SoftwareTestHelper
11 def setup 12 def setup
12 @controller = ProfileEditorController.new 13 @controller = ProfileEditorController.new
13 @request = ActionController::TestRequest.new 14 @request = ActionController::TestRequest.new
14 @response = ActionController::TestResponse.new 15 @response = ActionController::TestResponse.new
15 @profile = create_user('default_user').person 16 @profile = create_user('default_user').person
16 17
  18 + LicenseInfo.create(
  19 + :version=>"CC-GPL-V2",
  20 + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
  21 + )
  22 +
17 Environment.default.affiliate( 23 Environment.default.affiliate(
18 @profile, 24 @profile,
19 [Environment::Roles.admin(Environment.default.id)] + 25 [Environment::Roles.admin(Environment.default.id)] +
@@ -29,42 +35,14 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -29,42 +35,14 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
29 @environment.save 35 @environment.save
30 end 36 end
31 37
32 - should "redirect to edit_software_community on edit community of software" do  
33 - software = create_software_info("Test Software") 38 + def teardown
  39 + Community.destroy_all
  40 + SoftwareInfo.destroy_all
  41 + end
34 42
  43 + should "redirect to edit_software_community on edit community of software" do
  44 + software = create_software(software_fields)
35 post :edit, :profile => software.community.identifier 45 post :edit, :profile => software.community.identifier
36 -  
37 assert_redirected_to :controller => 'profile_editor', :action => 'edit_software_community' 46 assert_redirected_to :controller => 'profile_editor', :action => 'edit_software_community'
38 end 47 end
39 -  
40 -  
41 - protected  
42 -  
43 - def create_basic_user  
44 - user = fast_create(User)  
45 - user.person = fast_create(Person)  
46 - user.person.user = user  
47 - user.save!  
48 - user.person.save!  
49 - user  
50 - end  
51 -  
52 - def create_community name  
53 - community = fast_create(Community)  
54 - community.name = name  
55 - community.save  
56 - community  
57 - end  
58 -  
59 - def create_software_info name, finality = "something", acronym = ""  
60 - community = create_community(name)  
61 - software_info = SoftwareInfo.new  
62 - software_info.community = community  
63 - software_info.finality = finality  
64 - software_info.acronym = acronym  
65 - software_info.public_software = true  
66 - software_info.save  
67 - software_info  
68 - end  
69 -  
70 end 48 end
src/noosfero-spb/software_communities/test/functional/search_controller_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 require( 3 require(
4 File.dirname(__FILE__) + 4 File.dirname(__FILE__) +
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_controller_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin_controller' 2 require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin_controller'
3 3
4 class SoftwareCommunitiesPluginController; def rescue_action(e) raise e end; end 4 class SoftwareCommunitiesPluginController; def rescue_action(e) raise e end; end
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_myprofile_controller_test.rb
1 require 'test_helper' 1 require 'test_helper'
2 -require_relative '../helpers/software_test_helper'  
3 -require_relative(  
4 - '../../controllers/software_communities_plugin_myprofile_controller' 2 +require File.dirname(__FILE__) + '/../helpers/software_test_helper'
  3 +require(
  4 + File.dirname(__FILE__) +
  5 + '/../../controllers/software_communities_plugin_myprofile_controller'
5 ) 6 )
6 7
7 class SoftwareCommunitiesPluginMyprofileController; def rescue_action(e) raise e end; 8 class SoftwareCommunitiesPluginMyprofileController; def rescue_action(e) raise e end;
src/noosfero-spb/software_communities/test/functional/software_communities_plugin_profile_controller_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/software_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/software_test_helper'
3 require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin_profile_controller' 3 require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin_profile_controller'
4 4
src/noosfero-spb/software_communities/test/unit/categories_and_tags_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class CategoriesAndTagsBlockTest < ActiveSupport::TestCase 4 class CategoriesAndTagsBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/categories_software_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class CategoriesSoftwareBlockTest < ActiveSupport::TestCase 4 class CategoriesSoftwareBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/communities_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class CommunitiesBlockTest < ActiveSupport::TestCase 4 class CommunitiesBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/database_helper_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class DatabaseHelperTest < ActiveSupport::TestCase 3 class DatabaseHelperTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/database_validation_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class DatabaseValidationTest < ActiveSupport::TestCase 3 class DatabaseValidationTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/download_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class DownloadBlockTest < ActiveSupport::TestCase 4 class DownloadBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/download_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class DownloadTest < ActiveSupport::TestCase 4 class DownloadTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/library_helper_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class LibraryHelperTest < ActiveSupport::TestCase 3 class LibraryHelperTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/library_validation_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class LibraryValidationTest < ActiveSupport::TestCase 3 class LibraryValidationTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 OperatingSystemName.create(:name=>"Debina") 3 OperatingSystemName.create(:name=>"Debina")
4 OperatingSystemName.create(:name=>"Fedora") 4 OperatingSystemName.create(:name=>"Fedora")
src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class OperatingSystemValidationTest < ActiveSupport::TestCase 3 class OperatingSystemValidationTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/repository_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class RepositoryBlockTest < ActiveSupport::TestCase 4 class RepositoryBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/search_catalog_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class SearchCatalogBlockTest < ActiveSupport::TestCase 4 class SearchCatalogBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/search_helper_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../../lib/ext/search_helper.rb' 2 require File.dirname(__FILE__) + '/../../lib/ext/search_helper.rb'
3 3
4 class SearchHelperTest < ActiveSupport::TestCase 4 class SearchHelperTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb
1 # encoding: utf-8 1 # encoding: utf-8
2 2
3 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 3 +require 'test_helper'
4 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 4 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
5 5
6 class GovUserPluginPersonTest < ActiveSupport::TestCase 6 class GovUserPluginPersonTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/software_database_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareDatabaseTest < ActiveSupport::TestCase 3 class SoftwareDatabaseTest < ActiveSupport::TestCase
4 def setup 4 def setup
src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class SoftwareEventsBlockTest < ActiveSupport::TestCase 4 class SoftwareEventsBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/software_helper_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareHelperTest < ActiveSupport::TestCase 3 class SoftwareHelperTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/software_info_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class SoftwareInfoValidationTest < ActiveSupport::TestCase 4 class SoftwareInfoValidationTest < ActiveSupport::TestCase
@@ -41,4 +41,4 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase @@ -41,4 +41,4 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase
41 assert_equal @software_info.license_info.link, another_license_link 41 assert_equal @software_info.license_info.link, another_license_link
42 end 42 end
43 43
44 -end  
45 \ No newline at end of file 44 \ No newline at end of file
  45 +end
src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareInfoValidationTest < ActiveSupport::TestCase 3 class SoftwareInfoValidationTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareLanguageHelperTest < ActiveSupport::TestCase 3 class SoftwareLanguageHelperTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/software_language_validation.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareLanguageValidationTest < ActiveSupport::TestCase 3 class SoftwareLanguageValidationTest < ActiveSupport::TestCase
4 def setup 4 def setup
src/noosfero-spb/software_communities/test/unit/software_license_info_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareDatabaseTest < ActiveSupport::TestCase 3 class SoftwareDatabaseTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/software_registration_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 2
3 class SoftwareRegistrationTest < ActiveSupport::TestCase 3 class SoftwareRegistrationTest < ActiveSupport::TestCase
4 4
src/noosfero-spb/software_communities/test/unit/software_tab_data_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class SoftwareTabDataBlockTest < ActiveSupport::TestCase 4 class SoftwareTabDataBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/test/unit/softwares_block_test.rb
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 +require 'test_helper'
2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' 2 require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
3 3
4 class SoftwaresBlockTest < ActiveSupport::TestCase 4 class SoftwaresBlockTest < ActiveSupport::TestCase
src/noosfero-spb/software_communities/views/blocks/software_statistics.html.erb
1 <div class="software-metrics-block"> 1 <div class="software-metrics-block">
2 <ul class="metrics-list"> 2 <ul class="metrics-list">
3 <li> 3 <li>
4 - <span class="arrow-globe-icon"></span>  
5 - <span id="visit-count">  
6 - <%= pluralize(profile.hits, 'visita', 'visitas') %>  
7 - </span> 4 + <span class="arrow-globe-icon"></span>
  5 + <span id="visit-count">
  6 + <%= pluralize(profile.hits, 'visita', 'visitas') %>
  7 + </span>
8 </li> 8 </li>
9 <li> 9 <li>
10 - <span class="downloads-icon"></span>  
11 - <span id="downloads-count">  
12 - <%= pluralize(total_downloads, 'download', 'downloads') %>  
13 - </span> 10 + <span class="downloads-icon"></span>
  11 + <span id="downloads-count">
  12 + <%= pluralize(total_downloads, 'download', 'downloads') %>
  13 + </span>
14 </li> 14 </li>
15 <li> 15 <li>
16 - <span class="face-icon"></span>  
17 - <span id="benefited-people">  
18 - <%= block.benefited_people.to_s + _(' benefited people*') %>  
19 - </span> 16 + <span class="face-icon"></span>
  17 + <span id="benefited-people">
  18 + <%= number_to_human(statistics[:benefited_people]) + _(' benefited people*') %>
  19 + </span>
20 </li> 20 </li>
21 <li> 21 <li>
22 - <span class="pig-safe-icon"></span>  
23 - <span id="saved-resources">  
24 - <strong class="saved-money">  
25 - <%= number_to_currency(block.saved_resources, unit: 'R$ ',  
26 - separator: ',', delimiter: '.') %>  
27 - </strong>  
28 - <%= _(' saved resources*') %>  
29 - </span> 22 + <span class="pig-safe-icon"></span>
  23 + <span id="saved-resources">
  24 + <strong class="saved-money">
  25 + <%= float_to_currency(statistics[:saved_resources]) %>
  26 + </strong>
  27 + <%= _(' saved resources*') %>
  28 + </span>
30 </li> 29 </li>
31 </ul> 30 </ul>
32 31
33 <div class="admin-estimation"> 32 <div class="admin-estimation">
34 - * <%= _("Data estimated by the software administrator.") %> 33 + * <%= _("Data estimated by the software administrator.") %>
35 </div> 34 </div>
36 </div> 35 </div>
src/noosfero-spb/software_communities/views/box_organizer/_statistic_block.html.erb
1 <div id='edit-softwares-block'> 1 <div id='edit-softwares-block'>
2 - <% suggestion_benefited_people = @block.owner.organization_ratings.collect{ |r| r.people_benefited.to_f }.inject(:+) || 0.0 %>  
3 - <% suggestion_saved_resources = @block.owner.organization_ratings.collect{ |r| r.saved_value.to_f }.inject(:+) || 0.0 %> 2 + <% benefited_people = @block.owner.software_info.benefited_people + 5 %>
  3 + <% saved_resources = @block.owner.software_info.saved_resources + 5 %>
4 4
5 - <%= labelled_form_field _('Benefited People'), text_field(:block, :benefited_people) %>  
6 - <p> <%= _("Portal suggested value: ") %> <span> <%= "%d" % (suggestion_benefited_people) %> <span> </p>  
7 - <%= labelled_form_field _('Saved Resources'), text_field(:block, :saved_resources) %>  
8 - <p> <%= _("Portal suggested value: ") %> <span> <%= "R$%.2f" % (suggestion_saved_resources) %> <span> </p>  
9 -</div> 5 + <p> <%= _("Statistics to be displayed ") %>
10 6
  7 + <p> <%= _("People Benefited: ") %> <span> <%= number_to_human(benefited_people) %> </span> </p>
  8 + <p> <%= _("Saved Resources: ") %> <span> <%= float_to_currency(saved_resources) %> </span> </p>
  9 +</div>
src/noosfero-spb/software_communities/views/organization_ratings_container_extra_fields_show_statistics.html.erb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +<div class="aditional-informations">
  2 + <div class="comments-people-benefited">
  3 + <span><%=_("Benefited People")%>:</span> <%= number_with_delimiter(user_rating.people_benefited, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter) unless user_rating.nil? %>
  4 + </div>
  5 +
  6 + <div class="comments-saved-value">
  7 + <span><%=_("Saved Resources")%>:</span> <%= float_to_currency(user_rating.saved_value) unless user_rating.nil? %>
  8 + </div>
  9 +</div>
  10 +
src/noosfero-spb/software_communities/views/organization_ratings_extra_fields_show_data.html.erb
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<div class="aditional-informations">  
2 - <div class="comments-people-benefited">  
3 - <span><%=_("Benefited People")%>:</span> <%= number_with_delimiter(user_rating.people_benefited, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter) unless user_rating.nil? %>  
4 - </div>  
5 -  
6 - <div class="comments-saved-value">  
7 - <span><%=_("Saved Resources")%>:</span> <%= float_to_currency(user_rating.saved_value) unless user_rating.nil? %>  
8 - </div>  
9 -</div>  
10 -  
src/noosfero-spb/software_communities/views/organization_ratings_task_extra_fields_show_statistics.html.erb 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +<div class="aditional-informations">
  2 + <div class="comments-people-benefited">
  3 + <span><%=_("Benefited People")%> :</span> <%= user_rating.people_benefited unless user_rating.nil? %>
  4 + </div>
  5 +
  6 + <div class="comments-saved-value">
  7 + <span><%=_("Saved Resources")%> :</span> <%= user_rating.saved_value unless user_rating.nil? %>
  8 + </div>
  9 +</div>
  10 +
src/noosfero-spb/software_communities/views/profile_editor/edit_software_community.html.erb
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 13
14 <%= labelled_form_for :profile_data, :html => { :id => 'profile-data', :multipart => true } do |f| %> 14 <%= labelled_form_for :profile_data, :html => { :id => 'profile-data', :multipart => true } do |f| %>
15 15
16 - <% if environment.admins.include?(user) %> 16 + <% if user.is_admin? %>
17 <div id="profile-is-template"> 17 <div id="profile-is-template">
18 <%= labelled_check_box(_('This profile is a template'), 'profile_data[is_template]', true, @profile.is_template) %> 18 <%= labelled_check_box(_('This profile is a template'), 'profile_data[is_template]', true, @profile.is_template) %>
19 </div> 19 </div>
@@ -78,7 +78,7 @@ @@ -78,7 +78,7 @@
78 <% if user && user.has_permission?('destroy_profile', profile) && !@first_edit %> 78 <% if user && user.has_permission?('destroy_profile', profile) && !@first_edit %>
79 <% button_bar(:id => 'delete-profile') do %> 79 <% button_bar(:id => 'delete-profile') do %>
80 <%= button(:remove, _('Delete software and community'), {:action => :destroy_profile}) %> 80 <%= button(:remove, _('Delete software and community'), {:action => :destroy_profile}) %>
81 - <% if environment.admins.include?(current_person) %> 81 + <% if user.is_admin? %>
82 <% if profile.visible? %> 82 <% if profile.visible? %>
83 <%= button(:remove, _('Deactivate software and community'), {:action => :deactivate_profile, :id=>profile.id}, :id=>'deactivate_profile_button', :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %> 83 <%= button(:remove, _('Deactivate software and community'), {:action => :deactivate_profile, :id=>profile.id}, :id=>'deactivate_profile_button', :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %>
84 <% else %> 84 <% else %>