Commit 1dc57e650ba171dc9a1866876230ed28661e1272
1 parent
907b6b10
Exists in
master
and in
3 other branches
Refactoring Plugin to fit new Ratings Structure
Showing
12 changed files
with
98 additions
and
102 deletions
Show diff stats
db/migrate/20150714123613_add_institution_to_comments.rb
db/migrate/20150714123613_add_institution_to_organization_rating.rb
0 → 100644
db/migrate/20150814192230_add_institution_id_to_create_community_rating.rb
lib/ext/community_rating.rb
@@ -1,19 +0,0 @@ | @@ -1,19 +0,0 @@ | ||
1 | -require_dependency "community_rating" | ||
2 | - | ||
3 | -CommunityRating.class_eval do | ||
4 | - | ||
5 | - belongs_to :institution | ||
6 | - | ||
7 | - attr_accessible :institution, :institution_id | ||
8 | - | ||
9 | - validate :verify_institution | ||
10 | - | ||
11 | - private | ||
12 | - | ||
13 | - def verify_institution | ||
14 | - if self.institution != nil | ||
15 | - institution = Institution.find_by_id self.institution.id | ||
16 | - self.errors.add :institution, _("not found") unless institution | ||
17 | - end | ||
18 | - end | ||
19 | -end |
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +require_dependency "organization_rating" | ||
2 | + | ||
3 | +OrganizationRating.class_eval do | ||
4 | + | ||
5 | + belongs_to :institution | ||
6 | + | ||
7 | + attr_accessible :institution, :institution_id | ||
8 | + | ||
9 | + validate :verify_institution | ||
10 | + | ||
11 | + private | ||
12 | + | ||
13 | + def verify_institution | ||
14 | + if self.institution != nil | ||
15 | + institution = Institution.find_by_id self.institution.id | ||
16 | + self.errors.add :institution, _("not found") unless institution | ||
17 | + end | ||
18 | + end | ||
19 | + | ||
20 | +end |
lib/gov_user_plugin.rb
@@ -231,18 +231,18 @@ class GovUserPlugin < Noosfero::Plugin | @@ -231,18 +231,18 @@ class GovUserPlugin < Noosfero::Plugin | ||
231 | end | 231 | end |
232 | end | 232 | end |
233 | 233 | ||
234 | - def communities_ratings_plugin_comments_extra_fields | ||
235 | - Proc::new do render :file => 'comments_extra_field' end | 234 | + def organization_ratings_plugin_comments_extra_fields |
235 | + Proc::new do render :file => 'ratings_extra_field' end | ||
236 | end | 236 | end |
237 | 237 | ||
238 | - def communities_ratings_plugin_extra_fields_show_data user_rating | 238 | + def organization_ratings_plugin_extra_fields_show_data user_rating |
239 | if logged_in? | 239 | if logged_in? |
240 | is_admin = environment.admins.include?(current_user.person) | 240 | is_admin = environment.admins.include?(current_user.person) |
241 | - is_admin ||= user_rating.community.admins.include?(current_user.person) | 241 | + is_admin ||= user_rating.organization.admins.include?(current_user.person) |
242 | 242 | ||
243 | if is_admin and context.profile.software? | 243 | if is_admin and context.profile.software? |
244 | Proc::new { | 244 | Proc::new { |
245 | - render :file => 'communities_ratings_extra_fields_show_institution', | 245 | + render :file => 'organization_ratings_extra_fields_show_institution', |
246 | :locals => {:user_rating => user_rating} | 246 | :locals => {:user_rating => user_rating} |
247 | } | 247 | } |
248 | end | 248 | end |
test/unit/community_rating_test.rb
@@ -1,38 +0,0 @@ | @@ -1,38 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | - | ||
4 | -class CommunityRatingTest < ActiveSupport::TestCase | ||
5 | - include PluginTestHelper | ||
6 | - | ||
7 | - should "validate institution if there an institution_id" do | ||
8 | - community = fast_create(Community) | ||
9 | - private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | ||
10 | - | ||
11 | - community_rating = CommunityRating.new(:value => 3, :community => community, :institution => private_institution) | ||
12 | - community_rating.valid? | ||
13 | - | ||
14 | - assert_equal true, community_rating.errors[:institution].include?("not found") | ||
15 | - | ||
16 | - private_institution.save | ||
17 | - | ||
18 | - community_rating.institution = private_institution | ||
19 | - community_rating.valid? | ||
20 | - | ||
21 | - assert_equal false, community_rating.errors[:institution].include?("not found") | ||
22 | - end | ||
23 | - | ||
24 | - private | ||
25 | - | ||
26 | - def build_private_institution name, corporate_name, cnpj, country="AR" | ||
27 | - community = Community.new :name => name | ||
28 | - community.country = country | ||
29 | - | ||
30 | - institution = PrivateInstitution.new :name=> name | ||
31 | - institution.corporate_name = corporate_name | ||
32 | - institution.cnpj = cnpj | ||
33 | - institution.community = community | ||
34 | - | ||
35 | - institution | ||
36 | - end | ||
37 | -end | ||
38 | - |
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' | ||
2 | +require File.expand_path(File.dirname(__FILE__)) + '/../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class OrganizationRatingTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + | ||
7 | + def setup | ||
8 | + @environment = Environment.default | ||
9 | + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] | ||
10 | + @environment.save | ||
11 | + end | ||
12 | + | ||
13 | + should "validate institution if there is an institution_id" do | ||
14 | + person = fast_create(Person) | ||
15 | + community = fast_create(Community) | ||
16 | + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | ||
17 | + | ||
18 | + community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) | ||
19 | + assert_equal false, community_rating.valid? | ||
20 | + | ||
21 | + assert_equal true, community_rating.errors[:institution].include?("not found") | ||
22 | + | ||
23 | + private_institution.save | ||
24 | + community_rating.institution = private_institution | ||
25 | + | ||
26 | + assert_equal true, community_rating.valid? | ||
27 | + assert_equal false, community_rating.errors[:institution].include?("not found") | ||
28 | + end | ||
29 | + | ||
30 | + private | ||
31 | + | ||
32 | + def build_private_institution name, corporate_name, cnpj, country="AR" | ||
33 | + community = Community.new :name => name | ||
34 | + community.country = country | ||
35 | + | ||
36 | + institution = PrivateInstitution.new :name=> name | ||
37 | + institution.corporate_name = corporate_name | ||
38 | + institution.cnpj = cnpj | ||
39 | + institution.community = community | ||
40 | + | ||
41 | + institution | ||
42 | + end | ||
43 | +end | ||
44 | + |
views/comments_extra_field.html.erb
@@ -1,10 +0,0 @@ | @@ -1,10 +0,0 @@ | ||
1 | -<div id="input_institution_comments"> | ||
2 | - <%= label_tag "input_institution", _("Organization name or Enterprise name")%> | ||
3 | - <span class="star-tooltip" title="Órgão ou Empresa que você representa e utiliza o software"></span> | ||
4 | - <input type="text" id="input_institution"> | ||
5 | - | ||
6 | - <%= content_tag(:div, _("No institution found"), | ||
7 | - :id=>"institution_empty_ajax_message", | ||
8 | - :class=>"errorExplanation hide-field") %> | ||
9 | - <%= hidden_field_tag "community_rating[institution_id]", "", id: "institution_selected" %> | ||
10 | -</div> |
views/communities_ratings_extra_fields_show_institution.html.erb
views/organization_ratings_extra_fields_show_institution.html.erb
0 → 100644
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<div id="input_institution_comments"> | ||
2 | + <%= label_tag "input_institution", _("Organization name or Enterprise name")%> | ||
3 | + <span class="star-tooltip" title="Órgão ou Empresa que você representa e utiliza o software"></span> | ||
4 | + <input type="text" id="input_institution"> | ||
5 | + | ||
6 | + <%= content_tag(:div, _("No institution found"), | ||
7 | + :id=>"institution_empty_ajax_message", | ||
8 | + :class=>"errorExplanation hide-field") %> | ||
9 | + <%= hidden_field_tag "organization_rating[institution_id]", "", id: "institution_selected" %> | ||
10 | +</div> |