[Git][noosfero/noosfero][master] 4 commits: Adds models error message to session notice

Marcos Ronaldo Pereira Junior gitlab at mg.gitlab.com
Mon May 30 16:41:49 BRT 2016


Marcos Ronaldo Pereira Junior pushed to branch master at Noosfero / noosfero


Commits:
da0b1b3f by Marcos Ronaldo at 2016-05-30T12:08:56-03:00
Adds models error message to session notice

Signed-off-by: Thiago Ribeiro <thiagitosouza at gmail.com>

- - - - -
7dbd8a28 by Joenio Costa at 2016-05-30T16:01:55-03:00
using error_messages_for() to display errors

- - - - -
07f7b850 by Marcos Ronaldo at 2016-05-30T16:25:35-03:00
html_safe for error message and test fix

- - - - -
14b34706 by Marcos Ronaldo Pereira Junior at 2016-05-30T19:41:35+00:00
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
- - - - -


4 changed files:

- app/helpers/application_helper.rb
- plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
- plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
- plugins/organization_ratings/views/organization_ratings_plugin_profile/new_rating.html.erb


Changes:

=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1130,7 +1130,7 @@ module ApplicationHelper
     content_tag(:div, :class => 'errorExplanation', :id => 'errorExplanation') do
       content_tag(:h2, _('Errors while saving')) +
       content_tag(:ul) do
-        safe_join(errors.map { |err| content_tag(:li, err) })
+        safe_join(errors.map { |err| content_tag(:li, err.html_safe) })
       end
     end
   end


=====================================
plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
=====================================
--- a/plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
+++ b/plugins/organization_ratings/controllers/organization_ratings_plugin_profile_controller.rb
@@ -37,20 +37,17 @@ class OrganizationRatingsPluginProfileController < ProfileController
   end
 
   def create_new_rate
-    rating = OrganizationRating.new(params[:organization_rating])
-    rating.person = current_user.person
-    rating.organization = profile
-    rating.value = params[:organization_rating_value] if params[:organization_rating_value]
+    @rating = OrganizationRating.new(params[:organization_rating])
+    @rating.person = current_user.person
+    @rating.organization = profile
+    @rating.value = params[:organization_rating_value] if params[:organization_rating_value]
 
-    if rating.save
-      @plugins.dispatch(:organization_ratings_plugin_rating_created, rating, params)
-      create_rating_comment(rating)
+    if @rating.save
+      @plugins.dispatch(:organization_ratings_plugin_rating_created, @rating, params)
+      create_rating_comment(@rating)
       session[:notice] = _("%s successfully rated!") % profile.name
-    else
-      session[:notice] = _("Sorry, there were problems rating this profile.")
+      redirect_to profile.url
     end
-
-    redirect_to profile.url
   end
 
   def create_rating_comment(rating)


=====================================
plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
=====================================
--- a/plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
+++ b/plugins/organization_ratings/test/functional/organization_ratings_plugin_profile_controller_test.rb
@@ -46,7 +46,7 @@ class OrganizationRatingsPluginProfileControllerTest < ActionController::TestCas
   test "do not create community_rating without a rate value" do
     post :new_rating, profile: @community.identifier, :comments => {:body => ""}, :organization_rating_value => nil
 
-    assert_equal "Sorry, there were problems rating this profile.", session[:notice]
+    assert_tag :tag => 'div', :attributes => {:class => /errorExplanation/}, :content => /Value can't be blank/
   end
 
   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
=====================================
--- a/plugins/organization_ratings/views/organization_ratings_plugin_profile/new_rating.html.erb
+++ b/plugins/organization_ratings/views/organization_ratings_plugin_profile/new_rating.html.erb
@@ -1,3 +1,5 @@
+<%= error_messages_for 'rating' %>
+
 <% config = env_organization_ratings_config %>
 <% if logged_in? %>
   <%= render :partial => "new_rating_fields" %>
@@ -15,4 +17,4 @@
 
 <div id='pagination-profiles'>
   <%= pagination_links @users_ratings, :param_name => 'npage' %>
-</div>
\ No newline at end of file
+</div>



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/a9ba6bfaa291967adb5cde021e27d8a9f84cdbb3...14b34706cdf9618601b3fad420c33d4f3822f0c8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160530/08e14a1f/attachment-0001.html>


More information about the Noosfero-dev mailing list