diff --git a/plugins/communities_ratings/public/rate.js b/plugins/communities_ratings/public/rate.js index 671d296..4077c5f 100644 --- a/plugins/communities_ratings/public/rate.js +++ b/plugins/communities_ratings/public/rate.js @@ -92,18 +92,20 @@ .on("click", function() { // On mouse click, set the selected star rate var rate_mouseover = parseInt(this.getAttribute(DATA.DATA_RATE_ATTRIBUTE)); - DATA.selected_rate = rate_mouseover; - }); - } + // If the new rate is different from actual, update it + if (rate_mouseover !== DATA.selected_rate) { + DATA.selected_rate = rate_mouseover; + } else { // or else, uncheck it + DATA.selected_rate = DATA.NOT_SELECTED_VALUE; + } - /* - * Display a message to the user if there is no star selected when he/she - * clicks on the rate button - */ - function not_selected_rate_action(notice_element) { - var notice = $("#empty-star-notice").val(); - notice_element.html(notice); + var star_notice = $(".star-notice"); + star_notice.removeClass("star-hide"); + + // Call selected_rate_action to send the rate data. + selected_rate_action(star_notice); + }); } @@ -127,27 +129,6 @@ /* - * Set the rate button actions. It verify if the user selected a rate. - * If true: - * Call selected_rate_action to send the rate data. - * If false: - * Call not_selected_rate_action to display a error message to the user - */ - function set_rate_button_action() { - $("#star-rate-action").on("click", function() { - var star_notice = $(".star-notice"); - star_notice.removeClass("star-hide"); - - if (DATA.selected_rate !== DATA.NOT_SELECTED_VALUE) { - selected_rate_action(star_notice); - } else { - not_selected_rate_action(star_notice); - } - }); - } - - - /* * When the page DOM is ready, set all the stars events */ $(document).ready(function() { 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 03d1dff..adfa7a5 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 @@ -25,10 +25,20 @@ class CommunitiesRatingsPluginProfileControllerTest < ActionController::TestCase test "should logged person rate a community" do - #xhr :post , :rate, :profile => @community, :value => 4 - #xhr :post , url_for(:action=>:rate), :profile => @community, :value => 4 + xhr :post , :rate, :profile => @community.identifier, :value => 4 - assert_equal true, true + json_response = ActiveSupport::JSON.decode(@response.body) + + assert_equal true, json_response['success'] + 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) + + assert_equal false, json_response['success'] + assert_equal 'Value must be between 0 and 5', json_response['errors'].first end test "should add new comment to community" do diff --git a/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb b/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb index 30a9d0c..6547be2 100644 --- a/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb +++ b/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb @@ -1,5 +1,4 @@ -">
@@ -19,9 +18,6 @@ <% end %> -