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