Commit b19bc1e35d3d97feaecf79c8c10f728abdb52e96
Exists in
master
and in
79 other branches
Merge branch 'r4' into 'master'
R4 See merge request !7
Showing
17 changed files
with
108 additions
and
120 deletions
Show diff stats
db/migrate/20150714123613_add_institution_to_comments.rb
db/migrate/20150814192230_add_institution_id_to_create_community_rating_comment.rb
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 | ... | ... |
lib/ext/comment.rb
... | ... | @@ -1,18 +0,0 @@ |
1 | -require_dependency "comment" | |
2 | - | |
3 | -Comment.class_eval do | |
4 | - attr_accessible :institution_id | |
5 | - | |
6 | - belongs_to :institution | |
7 | - | |
8 | - validate :verify_institution | |
9 | - | |
10 | - private | |
11 | - | |
12 | - def verify_institution | |
13 | - if self.institution_id != nil | |
14 | - institution = Institution.find_by_id self.institution_id | |
15 | - self.errors.add :institution, _("not found") unless institution | |
16 | - end | |
17 | - end | |
18 | -end |
... | ... | @@ -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
test/unit/comment_test.rb
... | ... | @@ -1,37 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | |
3 | - | |
4 | -class CommentTest < ActiveSupport::TestCase | |
5 | - include PluginTestHelper | |
6 | - | |
7 | - should "validate institution if there an institution_id" do | |
8 | - private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | |
9 | - | |
10 | - assert_equal true, private_institution.save | |
11 | - | |
12 | - comment = Comment.new :institution_id => 123456, :body => "simple body" | |
13 | - comment.valid? | |
14 | - | |
15 | - assert_equal true, comment.errors[:institution].include?("not found") | |
16 | - | |
17 | - comment.institution = private_institution | |
18 | - comment.valid? | |
19 | - | |
20 | - assert_equal false, comment.errors[:institution].include?("not found") | |
21 | - end | |
22 | - | |
23 | - private | |
24 | - | |
25 | - def build_private_institution name, corporate_name, cnpj, country="AR" | |
26 | - community = Community.new :name => name | |
27 | - community.country = country | |
28 | - | |
29 | - institution = PrivateInstitution.new :name=> name | |
30 | - institution.corporate_name = corporate_name | |
31 | - institution.cnpj = cnpj | |
32 | - institution.community = community | |
33 | - | |
34 | - institution | |
35 | - end | |
36 | -end | |
37 | - |
... | ... | @@ -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/comments_extra_field.html.erb
... | ... | @@ -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 "comments[institution_id]", "", id: "institution_selected" %> | |
10 | -</div> |
views/communities_ratings_extra_fields_show_institution.html.erb
... | ... | @@ -1,8 +0,0 @@ |
1 | -<% if user_rating.comment and user_rating.comment.institution %> | |
2 | -<div class="aditional-informations"> | |
3 | - <div class="comments-user-institution"> | |
4 | - <span>Institution :<span> <%= user_rating.comment.institution.name unless user_rating.comment.nil? %> | |
5 | - </div> | |
6 | -</div> | |
7 | -<% end %> | |
8 | - |
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> | ... | ... |