Commit a8d9c52e1be268125d0e50855ba253b54265da4b
1 parent
48109ee8
Exists in
master
and in
1 other branch
use I18n instead of pluralize text helper
Showing
3 changed files
with
17 additions
and
6 deletions
Show diff stats
app/controllers/problems_controller.rb
| 1 | class ProblemsController < ApplicationController | 1 | class ProblemsController < ApplicationController |
| 2 | - include ActionView::Helpers::TextHelper | ||
| 3 | - | ||
| 4 | before_filter :find_app, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] | 2 | before_filter :find_app, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] |
| 5 | before_filter :find_problem, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] | 3 | before_filter :find_problem, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] |
| 6 | before_filter :find_selected_problems, :only => [:destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] | 4 | before_filter :find_selected_problems, :only => [:destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] |
| @@ -87,13 +85,13 @@ class ProblemsController < ApplicationController | @@ -87,13 +85,13 @@ class ProblemsController < ApplicationController | ||
| 87 | 85 | ||
| 88 | def resolve_several | 86 | def resolve_several |
| 89 | @selected_problems.each(&:resolve!) | 87 | @selected_problems.each(&:resolve!) |
| 90 | - flash[:success] = "Great news everyone! #{pluralize(@selected_problems.count, 'err has', 'errs have')} been resolved." | 88 | + flash[:success] = "Great news everyone! #{I18n.t(:n_errs_have, :count => @selected_problems.count)} been resolved." |
| 91 | redirect_to :back | 89 | redirect_to :back |
| 92 | end | 90 | end |
| 93 | 91 | ||
| 94 | def unresolve_several | 92 | def unresolve_several |
| 95 | @selected_problems.each(&:unresolve!) | 93 | @selected_problems.each(&:unresolve!) |
| 96 | - flash[:success] = "#{pluralize(@selected_problems.count, 'err has', 'errs have')} been unresolved." | 94 | + flash[:success] = "#{I18n.t(:n_errs_have, :count => @selected_problems.count)} been unresolved." |
| 97 | redirect_to :back | 95 | redirect_to :back |
| 98 | end | 96 | end |
| 99 | 97 | ||
| @@ -109,13 +107,13 @@ class ProblemsController < ApplicationController | @@ -109,13 +107,13 @@ class ProblemsController < ApplicationController | ||
| 109 | 107 | ||
| 110 | def unmerge_several | 108 | def unmerge_several |
| 111 | all = @selected_problems.map(&:unmerge!).flatten | 109 | all = @selected_problems.map(&:unmerge!).flatten |
| 112 | - flash[:success] = "#{pluralize(all.length, 'err has', 'errs have')} been unmerged." | 110 | + flash[:success] = "#{I18n.t(:n_errs_have, :count => all.length)} been unmerged." |
| 113 | redirect_to :back | 111 | redirect_to :back |
| 114 | end | 112 | end |
| 115 | 113 | ||
| 116 | def destroy_several | 114 | def destroy_several |
| 117 | nb_problem_destroy = ProblemDestroy.execute(@selected_problems) | 115 | nb_problem_destroy = ProblemDestroy.execute(@selected_problems) |
| 118 | - flash[:notice] = "#{pluralize(nb_problem_destroy, 'err has', 'errs have')} been deleted." | 116 | + flash[:notice] = "#{I18n.t(:n_errs_have, :count => nb_problem_destroy)} been deleted." |
| 119 | redirect_to :back | 117 | redirect_to :back |
| 120 | end | 118 | end |
| 121 | 119 |
config/locales/en.yml
| @@ -11,3 +11,6 @@ en: | @@ -11,3 +11,6 @@ en: | ||
| 11 | success: "Good news everyone! '%{app_name}' was successfully updated." | 11 | success: "Good news everyone! '%{app_name}' was successfully updated." |
| 12 | destroy: | 12 | destroy: |
| 13 | success: "'%{app_name}' was successfully destroyed." | 13 | success: "'%{app_name}' was successfully destroyed." |
| 14 | + n_errs_have: | ||
| 15 | + one: "%{count} err has" | ||
| 16 | + other: "%{count} errs have" |
spec/controllers/problems_controller_spec.rb
| @@ -419,6 +419,16 @@ describe ProblemsController do | @@ -419,6 +419,16 @@ describe ProblemsController do | ||
| 419 | post :resolve_several, :problems => [@problem2.id.to_s] | 419 | post :resolve_several, :problems => [@problem2.id.to_s] |
| 420 | @problem2.reload.resolved?.should == true | 420 | @problem2.reload.resolved?.should == true |
| 421 | end | 421 | end |
| 422 | + | ||
| 423 | + it "should display a message about 1 err" do | ||
| 424 | + post :resolve_several, :problems => [@problem2.id.to_s] | ||
| 425 | + flash[:success].should match(/1 err has been resolved/) | ||
| 426 | + end | ||
| 427 | + | ||
| 428 | + it "should display a message about 2 errs" do | ||
| 429 | + post :resolve_several, :problems => [@problem1.id.to_s, @problem2.id.to_s] | ||
| 430 | + flash[:success].should match(/2 errs have been resolved/) | ||
| 431 | + end | ||
| 422 | end | 432 | end |
| 423 | 433 | ||
| 424 | context "POST /problems/unresolve_several" do | 434 | context "POST /problems/unresolve_several" do |