Commit 2bb0faf9bfc3feed3b01c0cd850238cf481e0dbd
1 parent
1e146e55
Exists in
gov-user-refactoring-rails4
gov-user: relation between institutions and organization_ratings
TODO: adapt organization_ratings plugin to this new relation.
Showing
6 changed files
with
74 additions
and
69 deletions
Show diff stats
src/noosfero-spb/gov_user/lib/ext/organization_rating.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -require_dependency "organization_rating" | |
2 | - | |
3 | -OrganizationRating.class_eval do | |
4 | - | |
5 | - belongs_to :institution, :class_name => 'GovUserPlugin::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 = GovUserPlugin::Institution.find_by_id self.institution.id | |
16 | - self.errors.add :institution, _("not found") unless institution | |
17 | - end | |
18 | - end | |
19 | - | |
20 | -end |
src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_organization_ratings.rb
0 → 100644
... | ... | @@ -0,0 +1,27 @@ |
1 | +class GovUserPlugin::InstitutionsOrganizationRatings < Noosfero::Plugin::ActiveRecord | |
2 | + self.primary_key = :institution_id | |
3 | + | |
4 | + attr_accessible :institution, :organization_rating | |
5 | + | |
6 | + belongs_to :institution, :class_name => 'GovUserPlugin::Institution' | |
7 | + belongs_to :organization_rating, :class_name => 'OrganizationRating' | |
8 | + | |
9 | + validate :verify_institution | |
10 | + | |
11 | + def self.get_institution(rating) | |
12 | + find_by_organization_rating_id(rating.id) | |
13 | + end | |
14 | + | |
15 | + def self.get_rating(institution) | |
16 | + find_by_institution_id(rating.id) | |
17 | + end | |
18 | + | |
19 | + private | |
20 | + | |
21 | + def verify_institution | |
22 | + if self.institution != nil | |
23 | + institution = GovUserPlugin::Institution.find_by_id self.institution.id | |
24 | + self.errors.add :institution, _("not found") unless institution | |
25 | + end | |
26 | + end | |
27 | +end | ... | ... |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_organization_ratings_test.rb
0 → 100644
... | ... | @@ -0,0 +1,39 @@ |
1 | +require_relative '../../../../../test/test_helper' | |
2 | +require_relative '../../helpers/plugin_test_helper' | |
3 | + | |
4 | +class GovUserPlugin::InstitutionsOrganizationRatingsTest < ActiveSupport::TestCase | |
5 | + include PluginTestHelper | |
6 | + | |
7 | + def setup | |
8 | + @environment = Environment.default | |
9 | + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'GovUserPlugin'] | |
10 | + @environment.save! | |
11 | + end | |
12 | + | |
13 | + should "validate institution if there is an institution_id" do | |
14 | + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | |
15 | + relation = GovUserPlugin::InstitutionsOrganizationRatings.new(:institution => private_institution) | |
16 | + assert !relation.valid? | |
17 | + assert relation.errors[:institution].include?("not found") | |
18 | + | |
19 | + private_institution.save | |
20 | + relation.institution = private_institution | |
21 | + relation.valid? | |
22 | + assert !relation.errors[:institution].include?("not found") | |
23 | + end | |
24 | + | |
25 | + private | |
26 | + | |
27 | + def build_private_institution name, corporate_name, cnpj, country="AR" | |
28 | + community = Community.new :name => name | |
29 | + community.country = country | |
30 | + | |
31 | + institution = GovUserPlugin::PrivateInstitution.new :name=> name | |
32 | + institution.corporate_name = corporate_name | |
33 | + institution.cnpj = cnpj | |
34 | + institution.community = community | |
35 | + | |
36 | + institution | |
37 | + end | |
38 | +end | |
39 | + | ... | ... |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/organization_rating_test.rb
... | ... | @@ -1,44 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../../../../../test/test_helper' | |
2 | -require File.dirname(__FILE__) + '/../../helpers/plugin_test_helper' | |
3 | - | |
4 | -class GovUserPlugin::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 = GovUserPlugin::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 | - |
src/noosfero-spb/gov_user/views/organization_ratings_extra_fields_show_institution.html.erb
1 | -<% if user_rating.institution %> | |
2 | -<div class="aditional-informations"> | |
3 | - <div class="comments-user-institution"> | |
4 | - <span><%=_("Institution")%> :<span> <%= user_rating.institution.name unless user_rating.institution.nil? %> | |
1 | +<% institution = GovUserPlugin::InstitutionsOrganizationRatings.get_institution(user_rating) %> | |
2 | +<% if institution %> | |
3 | + <div class="aditional-informations"> | |
4 | + <div class="comments-user-institution"> | |
5 | + <span><%=_("Institution")%> :<span> <%= institution.name unless institution.nil? %> | |
6 | + </div> | |
5 | 7 | </div> |
6 | -</div> | |
7 | 8 | <% end %> |
8 | 9 | ... | ... |
src/noosfero-spb/gov_user/views/ratings_extra_field.html.erb
1 | +<% #FIXME Ajust this to work according to InstitutionsOrganizationRatings relation. %> | |
2 | + | |
1 | 3 | <div id="input_institution_comments"> |
2 | 4 | <%= label_tag "input_institution", _("Organization name or Enterprise name")%> |
3 | 5 | <span class="star-tooltip" title="Órgão ou Empresa que você representa e utiliza o software"></span> | ... | ... |