diff --git a/plugins/communities_ratings/lib/community_rating.rb b/plugins/communities_ratings/lib/community_rating.rb index c1b9f8c..0b82629 100644 --- a/plugins/communities_ratings/lib/community_rating.rb +++ b/plugins/communities_ratings/lib/community_rating.rb @@ -6,7 +6,7 @@ class CommunityRating < ActiveRecord::Base validates :value, :presence => true, :inclusion => { - in: 0..5, message: _("must be between 0 and 5") + in: 1..5, message: _("must be between 1 and 5") } validates :community_id, :person_id, diff --git a/plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb b/plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb index adfa7a5..ed868f4 100644 --- a/plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb +++ b/plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb @@ -23,33 +23,21 @@ class CommunitiesRatingsPluginProfileControllerTest < ActionController::TestCase @controller.stubs(:current_user).returns(@person.user) end - - test "should logged person rate a community" do - xhr :post , :rate, :profile => @community.identifier, :value => 4 - - json_response = ActiveSupport::JSON.decode(@response.body) - - assert_equal true, json_response['success'] + test "should add new comment to community" do + post :new_rating, profile: @community.identifier, :comments => {:body => "This is a test"}, :community_rating_value => 4 + assert_equal "#{@community.name} successfully rated!", session[:notice] end - test "should logged person not rate a community with invalid value" do - xhr :post , :rate, :profile => @community.identifier, :value => 7 - - json_response = ActiveSupport::JSON.decode(@response.body) + test "Create community_rating without comment body" do + post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :community_rating_value => 2 - assert_equal false, json_response['success'] - assert_equal 'Value must be between 0 and 5', json_response['errors'].first + assert_equal "#{@community.name} successfully rated!", session[:notice] end - test "should add new comment to community" do - post :new_rating, profile: @community.identifier, :comments => {:body => "This is a test"} - assert_response :success - end - - test "not create comment without comment body" do - post :new_rating, profile: @community.identifier, :comments => {:body => ""} + test "Do not create community_rating without a rate value" do + post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :community_rating_value => nil - assert_response 302 + assert_equal "Sorry, there were problems rating this profile.", session[:notice] end - end + diff --git a/plugins/communities_ratings/test/unit/community_rating_test.rb b/plugins/communities_ratings/test/unit/community_rating_test.rb index b730537..efebd78 100644 --- a/plugins/communities_ratings/test/unit/community_rating_test.rb +++ b/plugins/communities_ratings/test/unit/community_rating_test.rb @@ -1,14 +1,23 @@ require 'test_helper' class CommunityRatingTest < ActiveSupport::TestCase - test "The value must be between 0 and 5" do + test "The value must be between 1 and 5" do cr1 = CommunityRating.new :value => -1 cr2 = CommunityRating.new :value => 6 assert_equal false, cr1.valid? assert_equal false, cr2.valid? - assert_equal true, cr1.errors[:value].include?("must be between 0 and 5") - assert_equal true, cr2.errors[:value].include?("must be between 0 and 5") + assert_equal true, cr1.errors[:value].include?("must be between 1 and 5") + assert_equal true, cr2.errors[:value].include?("must be between 1 and 5") + + cr1.value = 1 + cr1.valid? + + cr2.value = 5 + cr2.valid? + + assert_equal false, cr1.errors[:value].include?("must be between 1 and 5") + assert_equal false, cr2.errors[:value].include?("must be between 1 and 5") end end -- libgit2 0.21.2