Commit 78f4af08f465972f5827d0e2dcc66cbde32f8645

Authored by Fabio Teixeira
1 parent f6f88118
Exists in temp_ratings

Update unit and functional tests

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
plugins/communities_ratings/lib/community_rating.rb
@@ -6,7 +6,7 @@ class CommunityRating &lt; ActiveRecord::Base @@ -6,7 +6,7 @@ class CommunityRating &lt; ActiveRecord::Base
6 6
7 validates :value, 7 validates :value,
8 :presence => true, :inclusion => { 8 :presence => true, :inclusion => {
9 - in: 0..5, message: _("must be between 0 and 5") 9 + in: 1..5, message: _("must be between 1 and 5")
10 } 10 }
11 11
12 validates :community_id, :person_id, 12 validates :community_id, :person_id,
plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb
@@ -23,33 +23,21 @@ class CommunitiesRatingsPluginProfileControllerTest &lt; ActionController::TestCase @@ -23,33 +23,21 @@ class CommunitiesRatingsPluginProfileControllerTest &lt; ActionController::TestCase
23 @controller.stubs(:current_user).returns(@person.user) 23 @controller.stubs(:current_user).returns(@person.user)
24 end 24 end
25 25
26 -  
27 - test "should logged person rate a community" do  
28 - xhr :post , :rate, :profile => @community.identifier, :value => 4  
29 -  
30 - json_response = ActiveSupport::JSON.decode(@response.body)  
31 -  
32 - assert_equal true, json_response['success'] 26 + test "should add new comment to community" do
  27 + post :new_rating, profile: @community.identifier, :comments => {:body => "This is a test"}, :community_rating_value => 4
  28 + assert_equal "#{@community.name} successfully rated!", session[:notice]
33 end 29 end
34 30
35 - test "should logged person not rate a community with invalid value" do  
36 - xhr :post , :rate, :profile => @community.identifier, :value => 7  
37 -  
38 - json_response = ActiveSupport::JSON.decode(@response.body) 31 + test "Create community_rating without comment body" do
  32 + post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :community_rating_value => 2
39 33
40 - assert_equal false, json_response['success']  
41 - assert_equal 'Value must be between 0 and 5', json_response['errors'].first 34 + assert_equal "#{@community.name} successfully rated!", session[:notice]
42 end 35 end
43 36
44 - test "should add new comment to community" do  
45 - post :new_rating, profile: @community.identifier, :comments => {:body => "This is a test"}  
46 - assert_response :success  
47 - end  
48 -  
49 - test "not create comment without comment body" do  
50 - post :new_rating, profile: @community.identifier, :comments => {:body => ""} 37 + test "Do not create community_rating without a rate value" do
  38 + post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :community_rating_value => nil
51 39
52 - assert_response 302 40 + assert_equal "Sorry, there were problems rating this profile.", session[:notice]
53 end 41 end
54 -  
55 end 42 end
  43 +
plugins/communities_ratings/test/unit/community_rating_test.rb
1 require 'test_helper' 1 require 'test_helper'
2 2
3 class CommunityRatingTest < ActiveSupport::TestCase 3 class CommunityRatingTest < ActiveSupport::TestCase
4 - test "The value must be between 0 and 5" do 4 + test "The value must be between 1 and 5" do
5 cr1 = CommunityRating.new :value => -1 5 cr1 = CommunityRating.new :value => -1
6 cr2 = CommunityRating.new :value => 6 6 cr2 = CommunityRating.new :value => 6
7 7
8 assert_equal false, cr1.valid? 8 assert_equal false, cr1.valid?
9 assert_equal false, cr2.valid? 9 assert_equal false, cr2.valid?
10 10
11 - assert_equal true, cr1.errors[:value].include?("must be between 0 and 5")  
12 - assert_equal true, cr2.errors[:value].include?("must be between 0 and 5") 11 + assert_equal true, cr1.errors[:value].include?("must be between 1 and 5")
  12 + assert_equal true, cr2.errors[:value].include?("must be between 1 and 5")
  13 +
  14 + cr1.value = 1
  15 + cr1.valid?
  16 +
  17 + cr2.value = 5
  18 + cr2.valid?
  19 +
  20 + assert_equal false, cr1.errors[:value].include?("must be between 1 and 5")
  21 + assert_equal false, cr2.errors[:value].include?("must be between 1 and 5")
13 end 22 end
14 end 23 end