Commit 20bfa5ce980eb8aaa7479cdf8f7d47cc1321e596

Authored by Arthur Neves
1 parent 97b59153
Exists in master and in 1 other branch production

Update remaning models/controller/tests for rails 4

app/controllers/application_controller.rb
@@ -15,9 +15,8 @@ class ApplicationController < ActionController::Base @@ -15,9 +15,8 @@ class ApplicationController < ActionController::Base
15 rescue_from ActionController::RedirectBackError, :with => :redirect_to_root 15 rescue_from ActionController::RedirectBackError, :with => :redirect_to_root
16 16
17 class StrongParametersWithEagerAttributesStrategy < DecentExposure::StrongParametersStrategy 17 class StrongParametersWithEagerAttributesStrategy < DecentExposure::StrongParametersStrategy
18 - def attributes  
19 - super  
20 - @attributes ||= params[inflector.param_key] || {} 18 + def assign_attributes?
  19 + singular? && !get? && !delete? && (params[options[:param_key] || inflector.param_key]).present?
21 end 20 end
22 end 21 end
23 22
app/controllers/apps_controller.rb
@@ -15,7 +15,8 @@ class AppsController &lt; ApplicationController @@ -15,7 +15,8 @@ class AppsController &lt; ApplicationController
15 app_scope.all.sort.to_a 15 app_scope.all.sort.to_a
16 } 16 }
17 17
18 - expose(:app, :ancestor => :app_scope) 18 + expose(:app, ancestor: :app_scope, attributes: :app_params)
  19 +
19 expose(:app_decorate) do 20 expose(:app_decorate) do
20 AppDecorator.new(app) 21 AppDecorator.new(app)
21 end 22 end
@@ -23,6 +24,7 @@ class AppsController &lt; ApplicationController @@ -23,6 +24,7 @@ class AppsController &lt; ApplicationController
23 expose(:all_errs) { 24 expose(:all_errs) {
24 !!params[:all_errs] 25 !!params[:all_errs]
25 } 26 }
  27 +
26 expose(:problems) { 28 expose(:problems) {
27 if request.format == :atom 29 if request.format == :atom
28 app.problems.unresolved.ordered 30 app.problems.unresolved.ordered
@@ -140,4 +142,9 @@ class AppsController &lt; ApplicationController @@ -140,4 +142,9 @@ class AppsController &lt; ApplicationController
140 end 142 end
141 end 143 end
142 end 144 end
  145 +
  146 + private
  147 + def app_params
  148 + params.require(:app).permit!
  149 + end
143 end 150 end
app/controllers/comments_controller.rb
@@ -3,7 +3,7 @@ class CommentsController &lt; ApplicationController @@ -3,7 +3,7 @@ class CommentsController &lt; ApplicationController
3 before_filter :find_problem 3 before_filter :find_problem
4 4
5 def create 5 def create
6 - @comment = Comment.new(params[:comment].merge(:user_id => current_user.id)) 6 + @comment = Comment.new(comment_params.merge(:user_id => current_user.id))
7 if @comment.valid? 7 if @comment.valid?
8 @problem.comments << @comment 8 @problem.comments << @comment
9 @problem.save 9 @problem.save
@@ -36,5 +36,8 @@ class CommentsController &lt; ApplicationController @@ -36,5 +36,8 @@ class CommentsController &lt; ApplicationController
36 def find_problem 36 def find_problem
37 @problem = @app.problems.find(params[:problem_id]) 37 @problem = @app.problems.find(params[:problem_id])
38 end 38 end
39 -end  
40 39
  40 + def comment_params
  41 + params.require(:comment).permit!
  42 + end
  43 +end
app/controllers/problems_controller.rb
@@ -153,4 +153,3 @@ class ProblemsController &lt; ApplicationController @@ -153,4 +153,3 @@ class ProblemsController &lt; ApplicationController
153 end 153 end
154 end 154 end
155 end 155 end
156 -  
app/interactors/problem_updater_cache.rb
@@ -22,7 +22,7 @@ class ProblemUpdaterCache @@ -22,7 +22,7 @@ class ProblemUpdaterCache
22 22
23 def update_notices_count 23 def update_notices_count
24 if @notice 24 if @notice
25 - problem.inc(:notices_count, 1) 25 + problem.inc(notices_count: 1)
26 else 26 else
27 problem.update_attribute( 27 problem.update_attribute(
28 :notices_count, problem.notices.count 28 :notices_count, problem.notices.count
app/models/app.rb
@@ -172,7 +172,7 @@ class App @@ -172,7 +172,7 @@ class App
172 end 172 end
173 173
174 def regenerate_api_key! 174 def regenerate_api_key!
175 - set(:api_key, SecureRandom.hex) 175 + update_attribute(:api_key, SecureRandom.hex)
176 end 176 end
177 177
178 ## 178 ##
app/models/comment.rb
@@ -30,11 +30,11 @@ class Comment @@ -30,11 +30,11 @@ class Comment
30 30
31 protected 31 protected
32 def increase_counter_cache 32 def increase_counter_cache
33 - err.inc(:comments_count, 1) 33 + err.inc(comments_count: 1)
34 end 34 end
35 35
36 def decrease_counter_cache 36 def decrease_counter_cache
37 - err.inc(:comments_count, -1) if err 37 + err.inc(comments_count: -1) if err
38 end 38 end
39 39
40 end 40 end
app/models/notice.rb
@@ -139,7 +139,7 @@ class Notice @@ -139,7 +139,7 @@ class Notice
139 protected 139 protected
140 140
141 def decrease_counter_cache 141 def decrease_counter_cache
142 - problem.inc(:notices_count, -1) if err 142 + problem.inc(notices_count: -1) if err
143 end 143 end
144 144
145 def remove_cached_attributes_from_problem 145 def remove_cached_attributes_from_problem
@@ -195,4 +195,3 @@ class Notice @@ -195,4 +195,3 @@ class Notice
195 end 195 end
196 196
197 end 197 end
198 -  
spec/controllers/apps_controller_spec.rb
@@ -400,7 +400,5 @@ describe AppsController do @@ -400,7 +400,5 @@ describe AppsController do
400 end.to change { app.api_key } 400 end.to change { app.api_key }
401 end 401 end
402 end 402 end
403 -  
404 end 403 end
405 -  
406 end 404 end
spec/controllers/problems_controller_spec.rb
@@ -250,7 +250,7 @@ describe ProblemsController do @@ -250,7 +250,7 @@ describe ProblemsController do
250 end 250 end
251 251
252 it "should redirect back to problems page" do 252 it "should redirect back to problems page" do
253 - request.env["Referer"] = problems_path 253 + request.env["HTTP_REFERER"] = problems_path
254 put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id 254 put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id
255 expect(response).to redirect_to(problems_path) 255 expect(response).to redirect_to(problems_path)
256 end 256 end
@@ -446,4 +446,3 @@ describe ProblemsController do @@ -446,4 +446,3 @@ describe ProblemsController do
446 end 446 end
447 447
448 end 448 end
449 -