Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rails 3.0+ Compatibility #13

Closed
wants to merge 1 commit into from

5 participants

@joslynesser

I went ahead and isolated the issues that were causing failures using strong_parameters with rails 3.0 stable. I'm not entirely sold on my proposed solution, but figured I'd get the conversation started on the best way to achieve 3.0+ compatibility :)

@dhh
Owner

We just got another solution merged for the dup. Can you update and see if that fixes the problem? Otherwise I'm glad to see this become 3.0 compatible.

@joslynesser

I tested with the recently merged dup solution (#12), but the test was still failing in rails 3-0 stable due to 3.0's HashWithIndifferentAccess#dup not using self.class.new: https://github.com/rails/rails/blob/3-0-stable/activesupport/lib/active_support/hash_with_indifferent_access.rb#L99-101

I went ahead and merged the recent dup solution with the 3.0 fix and updated the commit. Tests are now fully passing in 3.0 and 3.2. Let me know if that works!

@brentvatne

A new test failure has also arisen from the use of module_namespacing (introduced in Rails 3.1) in the controller scaffold template:

Finished tests in 0.263376s, 98.7182 tests/s, 212.6238 assertions/s.

  1) Error:
test_controller_content(StrongParametersControllerGeneratorTest):
NoMethodError: undefined method `module_namespacing' for #<Rails::Generators::StrongParametersControllerGenerator:0x007fcbb4dde190>
    (erb):1:in `template'

26 tests, 56 assertions, 0 failures, 1 errors, 0 skips

The current fixes in this pull request would make strong_parameters compatible with Rails 3.1, but fixing this failure for 3.0 would be hacky.

@dhh
Owner
dhh commented

I'd be happy with 3.1 compatibility, then. Can we update this PR to get that done?

@orend

This PR doesn't work with the current code base - rails 3.0 or 3.1. I've opened a new pull request for adding rails 3.1 compatibility here: #46.

@rafaelfranca

Closing this in favor of #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2012
  1. @joslynesser

    Rails 3.0+ Compatibility

    joslynesser authored
This page is out of date. Refresh to see the latest.
View
5 lib/action_controller/parameters.rb
@@ -29,7 +29,7 @@ def permit!
def require(key)
self[key].presence || raise(ActionController::ParameterMissing.new(key))
end
-
+
alias :required :require
def permit(*filters)
@@ -75,7 +75,8 @@ def slice(*keys)
end
def dup
- super.tap do |duplicate|
+ self.class.new(self).tap do |duplicate|
+ duplicate.default = default
duplicate.instance_variable_set :@permitted, @permitted
end
end
View
3  lib/active_model/forbidden_attributes_protection.rb
@@ -3,7 +3,8 @@ class ForbiddenAttributes < StandardError
end
module ForbiddenAttributesProtection
- def sanitize_for_mass_assignment(new_attributes, options = {})
+ def sanitize_for_mass_assignment(*args)
+ new_attributes = args.first
if !new_attributes.respond_to?(:permitted?) || (new_attributes.respond_to?(:permitted?) && new_attributes.permitted?)
super
else
View
4 strong_parameters.gemspec
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
- s.add_dependency "actionpack", ">= 3.2.0"
- s.add_dependency "activemodel", ">= 3.2.0"
+ s.add_dependency "actionpack", ">= 3"
+ s.add_dependency "activemodel", ">= 3"
s.add_development_dependency "rake"
end
Something went wrong with that request. Please try again.