Commit d5199c086a4d83365ed40e86279605b6e810b6c9
1 parent
8651abee
Exists in
temp_ratings
Make possible to rate as zero and tests
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
3 changed files
with
26 additions
and
39 deletions
Show diff stats
plugins/communities_ratings/public/rate.js
... | ... | @@ -92,18 +92,20 @@ |
92 | 92 | |
93 | 93 | .on("click", function() { // On mouse click, set the selected star rate |
94 | 94 | var rate_mouseover = parseInt(this.getAttribute(DATA.DATA_RATE_ATTRIBUTE)); |
95 | - DATA.selected_rate = rate_mouseover; | |
96 | - }); | |
97 | - } | |
98 | 95 | |
96 | + // If the new rate is different from actual, update it | |
97 | + if (rate_mouseover !== DATA.selected_rate) { | |
98 | + DATA.selected_rate = rate_mouseover; | |
99 | + } else { // or else, uncheck it | |
100 | + DATA.selected_rate = DATA.NOT_SELECTED_VALUE; | |
101 | + } | |
99 | 102 | |
100 | - /* | |
101 | - * Display a message to the user if there is no star selected when he/she | |
102 | - * clicks on the rate button | |
103 | - */ | |
104 | - function not_selected_rate_action(notice_element) { | |
105 | - var notice = $("#empty-star-notice").val(); | |
106 | - notice_element.html(notice); | |
103 | + var star_notice = $(".star-notice"); | |
104 | + star_notice.removeClass("star-hide"); | |
105 | + | |
106 | + // Call selected_rate_action to send the rate data. | |
107 | + selected_rate_action(star_notice); | |
108 | + }); | |
107 | 109 | } |
108 | 110 | |
109 | 111 | |
... | ... | @@ -127,27 +129,6 @@ |
127 | 129 | |
128 | 130 | |
129 | 131 | /* |
130 | - * Set the rate button actions. It verify if the user selected a rate. | |
131 | - * If true: | |
132 | - * Call selected_rate_action to send the rate data. | |
133 | - * If false: | |
134 | - * Call not_selected_rate_action to display a error message to the user | |
135 | - */ | |
136 | - function set_rate_button_action() { | |
137 | - $("#star-rate-action").on("click", function() { | |
138 | - var star_notice = $(".star-notice"); | |
139 | - star_notice.removeClass("star-hide"); | |
140 | - | |
141 | - if (DATA.selected_rate !== DATA.NOT_SELECTED_VALUE) { | |
142 | - selected_rate_action(star_notice); | |
143 | - } else { | |
144 | - not_selected_rate_action(star_notice); | |
145 | - } | |
146 | - }); | |
147 | - } | |
148 | - | |
149 | - | |
150 | - /* | |
151 | 132 | * When the page DOM is ready, set all the stars events |
152 | 133 | */ |
153 | 134 | $(document).ready(function() { | ... | ... |
plugins/communities_ratings/test/functional/communities_ratings_plugin_profile_controller_test.rb
... | ... | @@ -25,10 +25,20 @@ class CommunitiesRatingsPluginProfileControllerTest < ActionController::TestCase |
25 | 25 | |
26 | 26 | |
27 | 27 | test "should logged person rate a community" do |
28 | - #xhr :post , :rate, :profile => @community, :value => 4 | |
29 | - #xhr :post , url_for(:action=>:rate), :profile => @community, :value => 4 | |
28 | + xhr :post , :rate, :profile => @community.identifier, :value => 4 | |
30 | 29 | |
31 | - assert_equal true, true | |
30 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
31 | + | |
32 | + assert_equal true, json_response['success'] | |
33 | + end | |
34 | + | |
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) | |
39 | + | |
40 | + assert_equal false, json_response['success'] | |
41 | + assert_equal 'Value must be between 0 and 5', json_response['errors'].first | |
32 | 42 | end |
33 | 43 | |
34 | 44 | test "should add new comment to community" do | ... | ... |
plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb
1 | 1 | <input type="hidden" id="community-profile" value="<%= @profile.identifier %>"> |
2 | -<input type="hidden" id="empty-star-notice" value="<%= _("At least one star must be selected") %>"> | |
3 | 2 | <input type="hidden" id="selected-star-rate" value="<%= @actual_rate_value %>"> |
4 | 3 | |
5 | 4 | <div class="star-notice star-hide"></div> |
... | ... | @@ -19,9 +18,6 @@ |
19 | 18 | <% end %> |
20 | 19 | </div> |
21 | 20 | |
22 | - <div class="star-action"> | |
23 | - <button id="star-rate-action"><%= _("Rate") %></button> | |
24 | - </div> | |
25 | 21 | </div> |
26 | 22 | <div> |
27 | 23 | <%= form_for :comments do |c| %> |
... | ... | @@ -31,7 +27,7 @@ |
31 | 27 | </div> |
32 | 28 | |
33 | 29 | <%= @plugins.dispatch(:communities_ratings_plugin_comments_extra_fields).collect { |content| instance_exec(&content) }.join("") %> |
34 | - <%= c.submit %> | |
30 | + <%= c.submit _("Send") %> | |
35 | 31 | <% end %> |
36 | 32 | </div> |
37 | 33 | </div> | ... | ... |