Commit 907b6b10aa13028d10ac44b77f6bf8e9db4a86f4
1 parent
0c221480
Exists in
master
and in
3 other branches
Fix CommunityRating institution field bug and his tests
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Simiao Carvalho <simiaosimis@gmail.com>
Showing
3 changed files
with
45 additions
and
43 deletions
Show diff stats
lib/ext/community_rating.rb
1 | 1 | require_dependency "community_rating" |
2 | 2 | |
3 | 3 | CommunityRating.class_eval do |
4 | - attr_accessible :institution_id | |
5 | 4 | |
6 | 5 | belongs_to :institution |
7 | 6 | |
7 | + attr_accessible :institution, :institution_id | |
8 | + | |
8 | 9 | validate :verify_institution |
9 | 10 | |
10 | 11 | private |
11 | 12 | |
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 | |
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 | 17 | end |
18 | + end | |
18 | 19 | end | ... | ... |
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,38 @@ |
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 | + | ... | ... |