From b49f159e24d310aa5457cb0ccecbe9b638fe6886 Mon Sep 17 00:00:00 2001 From: AvnerCohen Date: Tue, 9 Oct 2012 22:56:26 +0200 Subject: moving to new hash syntax, for discussion before I take the time on full folders --- actionpack/lib/action_controller/base.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 6b8d9384d4..9b3bf99fc3 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -43,7 +43,7 @@ module ActionController # # def server_ip # location = request.env["SERVER_ADDR"] - # render :text => "This server hosted at #{location}" + # render text: "This server hosted at #{location}" # end # # == Parameters @@ -113,9 +113,9 @@ module ActionController # def search # @results = Search.find(params[:query]) # case @results.count - # when 0 then render :action => "no_results" - # when 1 then render :action => "show" - # when 2..10 then render :action => "show_many" + # when 0 then render action: "no_results" + # when 1 then render action: "show" + # when 2..10 then render action: "show_many" # end # end # @@ -131,7 +131,7 @@ module ActionController # @entry = Entry.new(params[:entry]) # if @entry.save # # The entry was saved correctly, redirect to show - # redirect_to :action => 'show', :id => @entry.id + # redirect_to action: 'show', id: @entry.id # else # # things didn't go so well, do something else # end @@ -148,15 +148,15 @@ module ActionController # An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError: # # def do_something - # redirect_to :action => "elsewhere" - # render :action => "overthere" # raises DoubleRenderError + # redirect_to action: "elsewhere" + # render action: "overthere" # raises DoubleRenderError # end # # If you need to redirect on the condition of something, then be sure to add "and return" to halt execution. # # def do_something - # redirect_to(:action => "elsewhere") and return if monkeys.nil? - # render :action => "overthere" # won't be called if monkeys is nil + # redirect_to(action: "elsewhere") and return if monkeys.nil? + # render action: "overthere" # won't be called if monkeys is nil # end # class Base < Metal -- cgit v1.2.3 From ed9567401dfc7b476bf9ccac82826fc63283f708 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 8 Oct 2012 22:22:47 +0200 Subject: recognizes when a partial was rendered twice. Closes #3675 --- actionpack/lib/action_controller/test_case.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index ace5a2c822..6aa43edf47 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -123,11 +123,17 @@ module ActionController if expected_partial = options[:partial] if expected_locals = options[:locals] - if defined?(@locals) - actual_locals = @locals[expected_partial.to_s.sub(/^_/,'')] - expected_locals.each_pair do |k,v| - assert_equal(v, actual_locals[k]) + if defined?(@_locals) + actual_locals_collection = @_locals[expected_partial.to_s.sub(/^_/,'')] + result = actual_locals_collection.any? do |actual_locals| + expected_locals.each_pair.all? do |k,v| + v == actual_locals[k] + end end + msg = 'expecting %s to be rendered with %s but was with %s' % [expected_partial, + expected_locals, + actual_locals_collection] + assert(result, msg) else warn "the :locals option to #assert_template is only supported in a ActionView::TestCase" end -- cgit v1.2.3 From d6524d78687b39c72e0814e61b80e3e6b6d9997e Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 9 Oct 2012 21:14:11 +0200 Subject: refactor `ActionView::TestCase` internals to track rendered locals this refactoring extracts the semi complex data structure of rendered locals per view into into a separate class --- actionpack/lib/action_controller/test_case.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 6aa43edf47..d911d47a1d 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -123,17 +123,12 @@ module ActionController if expected_partial = options[:partial] if expected_locals = options[:locals] - if defined?(@_locals) - actual_locals_collection = @_locals[expected_partial.to_s.sub(/^_/,'')] - result = actual_locals_collection.any? do |actual_locals| - expected_locals.each_pair.all? do |k,v| - v == actual_locals[k] - end - end + if defined?(@_rendered_views) + view = expected_partial.to_s.sub(/^_/,'') msg = 'expecting %s to be rendered with %s but was with %s' % [expected_partial, expected_locals, - actual_locals_collection] - assert(result, msg) + @_rendered_views.locals_for(view)] + assert(@_rendered_views.view_rendered?(view, options[:locals]), msg) else warn "the :locals option to #assert_template is only supported in a ActionView::TestCase" end -- cgit v1.2.3 From bdd105d8b91c5d0881ab78e36a65a79fdca4a7fb Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 12 Oct 2012 00:50:20 -0200 Subject: When executing permit with just a key that points to a hash, DO NOT allow all the hash params.require(:person).permit(:projects_attributes) was returning => {"projects_attributes"=>{"0"=>{"name"=>"Project 1"}}} When should return => {} You should be doing ... params.require(:person).permit(projects_attributes: :name) to get just the projects attributes you want to allow --- actionpack/lib/action_controller/metal/strong_parameters.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 398454d39f..a6250f5d03 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -177,7 +177,10 @@ module ActionController filters.each do |filter| case filter when Symbol, String then - params[filter] = self[filter] if has_key?(filter) + if has_key?(filter) + value = self[filter] + params[filter] = value unless Hash === value + end keys.grep(/\A#{Regexp.escape(filter)}\(\di\)\z/) { |key| params[key] = self[key] } when Hash then self.slice(*filter.keys).each do |key, values| -- cgit v1.2.3 From 299fee5919ec41290421684436a50105c4ddc485 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 11 Oct 2012 22:41:01 -0500 Subject: update AC::Parameters#permit documentation [ci skip] bdd105d changes the behaviour of AC::Parameters#permit. --- .../action_controller/metal/strong_parameters.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index a6250f5d03..c42b3dddc9 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -171,6 +171,28 @@ module ActionController # permitted[:person][:age] # => nil # permitted[:person][:pets][0][:name] # => "Purplish" # permitted[:person][:pets][0][:category] # => nil + # + # Note that if you use +permit+ in a key that points to a hash, + # it won't allow all the hash. You also need to specify which + # attributes inside the hash should be whitelisted. + # + # params = ActionController::Parameters.new({ + # person: { + # contact: { + # email: 'none@test.com' + # phone: '555-1234' + # } + # } + # }) + # + # params.require(:person).permit(:contact) + # # => {} + # + # params.require(:person).permit(contact: :phone) + # # => {"contact"=>{"phone"=>"555-1234"}} + # + # params.require(:person).permit(contact: [ :email, :phone ]) + # # => {"contact"=>{"email"=>"none@test.com", "phone"=>"555-1234"}} def permit(*filters) params = self.class.new -- cgit v1.2.3 From 11f01bee6574fe2580b408fc067fd564fd846af3 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 12 Oct 2012 18:53:15 +0530 Subject: warning removed: shadowing outer local variable - value --- actionpack/lib/action_controller/metal/strong_parameters.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index c42b3dddc9..6f46954266 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -200,8 +200,8 @@ module ActionController case filter when Symbol, String then if has_key?(filter) - value = self[filter] - params[filter] = value unless Hash === value + _value = self[filter] + params[filter] = _value unless Hash === _value end keys.grep(/\A#{Regexp.escape(filter)}\(\di\)\z/) { |key| params[key] = self[key] } when Hash then -- cgit v1.2.3 From 3db69909b9d4549128984c4c76f8a51eca3d79e6 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Oct 2012 09:47:16 -0500 Subject: :fire: Rails asset id support --- actionpack/lib/action_controller/railtie.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index ee0f053bad..3e44155f73 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -34,7 +34,6 @@ module ActionController options.stylesheets_dir ||= paths["public/stylesheets"].first # Ensure readers methods get compiled - options.asset_path ||= app.config.asset_path options.asset_host ||= app.config.asset_host options.relative_url_root ||= app.config.relative_url_root -- cgit v1.2.3 From 0c3ca0f013904d40bf11ac9da95ed0ef3d9ddc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 18 Oct 2012 00:31:46 -0300 Subject: Permit string and float values in the multiparameter attributes --- actionpack/lib/action_controller/metal/strong_parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 6f46954266..e33201b273 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -203,7 +203,7 @@ module ActionController _value = self[filter] params[filter] = _value unless Hash === _value end - keys.grep(/\A#{Regexp.escape(filter)}\(\di\)\z/) { |key| params[key] = self[key] } + keys.grep(/\A#{Regexp.escape(filter)}\(\d+[if]?\)\z/) { |key| params[key] = self[key] } when Hash then self.slice(*filter.keys).each do |key, values| return unless values -- cgit v1.2.3 From 7cc5bf51b4c16e89340b8c45ca0297e387226aaf Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sat, 30 Jun 2012 17:09:12 +0200 Subject: There is already a Set of non-hidden action_names lying around. --- actionpack/lib/action_controller/metal/hide_actions.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb index 420b22cf56..2aa6b7adaf 100644 --- a/actionpack/lib/action_controller/metal/hide_actions.rb +++ b/actionpack/lib/action_controller/metal/hide_actions.rb @@ -26,20 +26,14 @@ module ActionController self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze end - def inherited(klass) - klass.class_eval { @visible_actions = {} } - super - end - def visible_action?(action_name) - return @visible_actions[action_name] if @visible_actions.key?(action_name) - @visible_actions[action_name] = !hidden_actions.include?(action_name) + action_methods.include?(action_name) end # Overrides AbstractController::Base#action_methods to remove any methods # that are listed as hidden methods. def action_methods - @action_methods ||= Set.new(super.reject { |name| hidden_actions.include?(name) }) + @action_methods ||= Set.new(super.reject { |name| hidden_actions.include?(name) }).freeze end end end -- cgit v1.2.3 From ae057d622fccf7cc5dcd2609a7fe3f1e0589808f Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Sun, 21 Oct 2012 11:49:51 -0500 Subject: fix StrongParameters example [ci skip] --- actionpack/lib/action_controller/metal/strong_parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 7d5781b23a..73f2e94cd1 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -361,7 +361,7 @@ module ActionController # # It's mandatory to specify the nested attributes that should be whitelisted. # # If you use `permit` with just the key that points to the nested attributes hash, # # it will return an empty hash. - # params.require(:person).permit(:name, :age, pets_attributes: { :name, :category }) + # params.require(:person).permit(:name, :age, pets_attributes: [ :name, :category ]) # end # end # -- cgit v1.2.3