Commit 14b34706cdf9618601b3fad420c33d4f3822f0c8

Authored by Marcos Pereira
2 parents a9ba6bfa 07f7b850

Merge branch 'fix_rating_creation_error_message' into 'master'

Adds models error message to session notice

Adds models error messages instead of a fixed message for every error.

See merge request !947
app/helpers/application_helper.rb
... ... @@ -1130,7 +1130,7 @@ module ApplicationHelper
1130 1130 content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do
1131 1131 content_tag(:h2, _('Errors while saving')) +
1132 1132 content_tag(:ul) do
1133   - safe_join(errors.map { |err| content_tag(:li, err) })
  1133 + safe_join(errors.map { |err| content_tag(:li, err.html_safe) })
1134 1134 end
1135 1135 end
1136 1136 end
... ...
plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
... ... @@ -37,20 +37,17 @@ class OrganizationRatingsPluginProfileController < ProfileController
37 37 end
38 38  
39 39 def create_new_rate
40   - rating = OrganizationRating.new(params[:organization_rating])
41   - rating.person = current_user.person
42   - rating.organization = profile
43   - rating.value = params[:organization_rating_value] if params[:organization_rating_value]
  40 + @rating = OrganizationRating.new(params[:organization_rating])
  41 + @rating.person = current_user.person
  42 + @rating.organization = profile
  43 + @rating.value = params[:organization_rating_value] if params[:organization_rating_value]
44 44  
45   - if rating.save
46   - @plugins.dispatch(:organization_ratings_plugin_rating_created, rating, params)
47   - create_rating_comment(rating)
  45 + if @rating.save
  46 + @plugins.dispatch(:organization_ratings_plugin_rating_created, @rating, params)
  47 + create_rating_comment(@rating)
48 48 session[:notice] = _("%s successfully rated!") % profile.name
49   - else
50   - session[:notice] = _("Sorry, there were problems rating this profile.")
  49 + redirect_to profile.url
51 50 end
52   -
53   - redirect_to profile.url
54 51 end
55 52  
56 53 def create_rating_comment(rating)
... ...
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
... ... @@ -46,7 +46,7 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
46 46 test "do not create community_rating without a rate value" do
47 47 post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil
48 48  
49   - assert_equal "Sorry, there were problems rating this profile.", session[:notice]
  49 + assert_tag :tag => 'div', :attributes => {:class => /errorExplanation/}, :content => /Value can't be blank/
50 50 end
51 51  
52 52 test "do not create two ratings on Community when vote once config is true" do
... ...
plugins/organization_ratings/views/organization_ratings_plugin_profile/new_rating.html.erb
  1 +<%= error_messages_for 'rating' %>
  2 +
1 3 <% config = env_organization_ratings_config %>
2 4 <% if logged_in? %>
3 5 <%= render :partial => "new_rating_fields" %>
... ... @@ -15,4 +17,4 @@
15 17  
16 18 <div id='pagination-profiles'>
17 19 <%= pagination_links @users_ratings, :param_name => 'npage' %>
18   -</div>
19 20 \ No newline at end of file
  21 +</div>
... ...