Merge Request #7
← To merge requests
From
r4
into
master
Commits (7)
-
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
-
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
-
Ratings refactor See merge request !6
-
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Simiao Carvalho <simiaosimis@gmail.com>
-
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Simiao Carvalho <simiaosimis@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
17 changed files
Show diff stats
db/migrate/20150910135510_add_siorg_code_to_institution.rb
0 → 100644
db/migrate/20150910203559_add_institution_to_organization_rating.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +class AddInstitutionToOrganizationRating < ActiveRecord::Migration | |
2 | + def up | |
3 | + change_table :organization_ratings do |t| | |
4 | + t.belongs_to :institution | |
5 | + end | |
6 | + end | |
7 | + | |
8 | + def down | |
9 | + remove_column :organization_ratings, :institution_id | |
10 | + end | |
11 | +end | |
0 | 12 | \ No newline at end of file | ... | ... |
... | ... | @@ -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 | 231 | end |
232 | 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 | 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 | 239 | if logged_in? |
240 | 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 | 243 | if is_admin and context.profile.software? |
244 | 244 | Proc::new { |
245 | - render :file => 'communities_ratings_extra_fields_show_institution', | |
245 | + render :file => 'organization_ratings_extra_fields_show_institution', | |
246 | 246 | :locals => {:user_rating => user_rating} |
247 | 247 | } |
248 | 248 | end | ... | ... |
lib/institution.rb
... | ... | @@ -20,10 +20,9 @@ class Institution < ActiveRecord::Base |
20 | 20 | :sub_juridical_nature, :normalization_level, |
21 | 21 | :version, :cnpj, :type, :governmental_power, |
22 | 22 | :governmental_sphere, :sisp, :juridical_nature, |
23 | - :corporate_name | |
23 | + :corporate_name, :siorg_code, :community | |
24 | 24 | |
25 | 25 | validates :name, :presence=>true, :uniqueness=>true |
26 | - validates :cnpj, :uniqueness=>true | |
27 | 26 | |
28 | 27 | before_save :verify_institution_type |
29 | 28 | ... | ... |
lib/private_institution.rb
lib/public_institution.rb
... | ... | @@ -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 | + | ... | ... |
test/unit/private_institution_test.rb
... | ... | @@ -25,21 +25,6 @@ class PrivateInstitutionTest < ActiveSupport::TestCase |
25 | 25 | assert @institution.save |
26 | 26 | end |
27 | 27 | |
28 | - should "not save with a repeated cnpj" do | |
29 | - msg = "Cnpj has already been taken" | |
30 | - assert @institution.save | |
31 | - sec_institution = create_private_institution( | |
32 | - "Another Private Institution", | |
33 | - "API", | |
34 | - "BR", | |
35 | - "DF", | |
36 | - "Gama", | |
37 | - "00.000.000/0001-00" | |
38 | - ) | |
39 | - | |
40 | - assert sec_institution.errors.full_messages.include? msg | |
41 | - end | |
42 | - | |
43 | 28 | should "save without fantasy name" do |
44 | 29 | @institution.acronym = nil |
45 | 30 | @institution.community.save | ... | ... |
views/organization_ratings_extra_fields_show_institution.html.erb
0 → 100644
... | ... | @@ -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> | ... | ... |
-
mentioned in commit b19bc1e35d3d97feaecf79c8c10f728abdb52e96