param_protected 1.3.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
+ 2.0.0
2
+ -----
3
+ * Upgrade to Rails 3.
4
+
1
5
  1.3.1
2
- - Bugfix: hashes nested in regexp params could get through unfiltered
6
+ -----
7
+ * Bugfix: hashes nested in regexp params could get through unfiltered
3
8
 
4
9
  09/12/2009
5
10
  ----------
@@ -19,4 +24,4 @@
19
24
 
20
25
  07/16/2008
21
26
  ----------
22
- * rewrote the entire plugin (it should actually work now)
27
+ * rewrote the entire plugin (it should actually work now)
data/README.rdoc CHANGED
@@ -3,11 +3,11 @@ This plugin provides two class methods on <tt>ActiveController::Base</tt> that f
3
3
 
4
4
  === Installation
5
5
 
6
- Put in your <tt>environment.rb</tt> file...
7
-
8
- config.gem "param_protected"
6
+ gem install param_protected
9
7
 
10
- Alternatively, just install the gem from the command line and <tt>require "param_protected"</tt> somewhere in your project.
8
+ Note: the latest version works with Rails 3.0.x. If you want Rails 2.3.x compatibility, install the latest 1.x.x version of <tt>param_protected</tt>. See the rails23 branch {here}[http://github.com/cjbottaro/param_protected/tree/rails23] for the most up to date 1.x.x version (look at the tags).
9
+
10
+ Thanks to {jonleighton}[http://github.com/jonleighton] for the Rails 3 port.
11
11
 
12
12
  === Usage
13
13
  class YourController < ActiveController::Base
@@ -71,8 +71,9 @@ Credit: Mortiz Heidkamp
71
71
  === How does it work?
72
72
  It does an <tt>alias_method_chain</tt> on <tt>ActionController::Base#params</tt> that filters (and caches) the params. You can get the unfiltered, pristine params by calling <tt>ActionController::Base#params_without_protection</tt>.
73
73
 
74
- === Author
74
+ === Original Author
75
75
  Christopher J. Bottaro - {cjbottaro}[http://github.com/cjbottaro]
76
76
 
77
77
  === Contributors
78
- Moritz Heidkamp - {DerGuteMoritz}[http://github.com/DerGuteMoritz]
78
+ Moritz Heidkamp - {DerGuteMoritz}[http://github.com/DerGuteMoritz]
79
+ Jon Leighton - {jonleighton}[http://github.com/jonleighton]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 2.0.0
@@ -1,6 +1,5 @@
1
- require "param_protected/meta_class"
2
1
  require "param_protected/constants"
3
2
  require "param_protected/protector"
4
3
  require "param_protected/controller_modifications"
5
4
 
6
- ActionController::Base.extend(ParamProtected::ControllerModifications)
5
+ ActionController::Base.extend(ParamProtected::ControllerModifications)
@@ -4,7 +4,7 @@ module ParamProtected
4
4
  def self.extended(action_controller)
5
5
  action_controller.class_eval do
6
6
  extend ClassMethods
7
- metaclass.alias_method_chain :inherited, :protector
7
+ singleton_class.alias_method_chain :inherited, :protector
8
8
  include InstanceMethods
9
9
  alias_method_chain :params, :protection
10
10
  end
@@ -54,4 +54,4 @@ module ParamProtected
54
54
  end
55
55
 
56
56
  end
57
- end
57
+ end
@@ -4,7 +4,7 @@ module ParamProtected
4
4
  def self.instance(controller)
5
5
  unless controller.respond_to?(:pp_protector)
6
6
  controller.class_eval{ @pp_protector = Protector.new }
7
- controller.meta_eval { attr_reader :pp_protector }
7
+ controller.singleton_class.class_eval { attr_reader :pp_protector }
8
8
  end
9
9
  controller.pp_protector
10
10
  end
@@ -24,7 +24,7 @@ module ParamProtected
24
24
  end
25
25
 
26
26
  def protect(controller, controller_params, action_name)
27
- returning(deep_copy(controller_params)) do |params|
27
+ deep_copy(controller_params).tap do |params|
28
28
  protections_for_action(controller, action_name).each do |exclusivity, protected_params|
29
29
  filter_params(protected_params, params, exclusivity) unless protected_params.empty?
30
30
  end
@@ -130,7 +130,7 @@ module ParamProtected
130
130
 
131
131
  # When #dup just isn't enough... :P
132
132
  def deep_copy(object)
133
- returning(try_to_clone(object)) do |new_object|
133
+ try_to_clone(object).tap do |new_object|
134
134
  case new_object
135
135
  when Hash
136
136
  new_object.each{ |k, v| new_object[k] = deep_copy(v) }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{param_protected}
8
- s.version = "1.3.1"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christopher J. Bottaro"]
12
- s.date = %q{2010-10-03}
12
+ s.date = %q{2010-10-18}
13
13
  s.description = %q{Provides two class methods on ActiveController::Base that filter the params hash for that controller's actions. You can think of them as the controller analog of attr_protected and attr_accessible.}
14
14
  s.email = %q{cjbottaro@alumni.cs.utexas.edu}
15
15
  s.extra_rdoc_files = [
@@ -23,16 +23,15 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "init.rb",
26
- "install.rb",
27
26
  "lib/param_protected.rb",
28
27
  "lib/param_protected/constants.rb",
29
28
  "lib/param_protected/controller_modifications.rb",
30
- "lib/param_protected/meta_class.rb",
31
29
  "lib/param_protected/protector.rb",
32
30
  "param_protected.gemspec",
33
- "tasks/param_protected_tasks.rake",
34
31
  "test/accessible_except_test.rb",
35
32
  "test/accessible_only_test.rb",
33
+ "test/app_root/.gitignore",
34
+ "test/app_root/Gemfile",
36
35
  "test/app_root/app/controllers/accessible_except_controller.rb",
37
36
  "test/app_root/app/controllers/accessible_only_controller.rb",
38
37
  "test/app_root/app/controllers/application_controller.rb",
@@ -41,24 +40,20 @@ Gem::Specification.new do |s|
41
40
  "test/app_root/app/controllers/merge_controller.rb",
42
41
  "test/app_root/app/controllers/protected_controller.rb",
43
42
  "test/app_root/app/controllers/users_controller.rb",
43
+ "test/app_root/config.ru",
44
+ "test/app_root/config/application.rb",
44
45
  "test/app_root/config/boot.rb",
45
- "test/app_root/config/database.yml",
46
46
  "test/app_root/config/environment.rb",
47
- "test/app_root/config/environments/in_memory.rb",
48
- "test/app_root/config/environments/mysql.rb",
49
- "test/app_root/config/environments/postgresql.rb",
50
- "test/app_root/config/environments/sqlite.rb",
51
- "test/app_root/config/environments/sqlite3.rb",
52
47
  "test/app_root/config/routes.rb",
53
48
  "test/app_root/lib/console_with_fixtures.rb",
49
+ "test/app_root/script/rails",
54
50
  "test/conditions_controller_test.rb",
55
51
  "test/inherited_users_controller_test.rb",
56
52
  "test/merge_controller_test.rb",
57
53
  "test/protected_controller_test.rb",
58
54
  "test/protector_test.rb",
59
55
  "test/test_helper.rb",
60
- "test/users_controller_test.rb",
61
- "uninstall.rb"
56
+ "test/users_controller_test.rb"
62
57
  ]
63
58
  s.homepage = %q{http://github.com/cjbottaro/param_protected}
64
59
  s.rdoc_options = ["--charset=UTF-8"]
@@ -76,13 +71,9 @@ Gem::Specification.new do |s|
76
71
  "test/app_root/app/controllers/merge_controller.rb",
77
72
  "test/app_root/app/controllers/protected_controller.rb",
78
73
  "test/app_root/app/controllers/users_controller.rb",
74
+ "test/app_root/config/application.rb",
79
75
  "test/app_root/config/boot.rb",
80
76
  "test/app_root/config/environment.rb",
81
- "test/app_root/config/environments/in_memory.rb",
82
- "test/app_root/config/environments/mysql.rb",
83
- "test/app_root/config/environments/postgresql.rb",
84
- "test/app_root/config/environments/sqlite.rb",
85
- "test/app_root/config/environments/sqlite3.rb",
86
77
  "test/app_root/config/routes.rb",
87
78
  "test/app_root/lib/console_with_fixtures.rb",
88
79
  "test/conditions_controller_test.rb",
@@ -0,0 +1,2 @@
1
+ log/
2
+ Gemfile.lock
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '~> 3.0'
4
+ gem 'param_protected', :path => File.dirname(__FILE__) + '/../..'
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run TestApp::Application
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+ require "action_controller/railtie"
3
+
4
+ # If you have a Gemfile, require the gems listed there, including any gems
5
+ # you've limited to :test, :development, or :production.
6
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
7
+
8
+ module TestApp
9
+ class Application < Rails::Application
10
+ config.cache_classes = false
11
+ config.whiny_nils = true
12
+ config.secret_token = 'd229e4d22437432705ab3985d4d246'
13
+ config.session_store :cookie_store, :key => 'rails_session'
14
+ config.active_support.deprecation = :stderr
15
+ end
16
+ end
@@ -1,115 +1,13 @@
1
- # Allow customization of the rails framework path
2
- RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
3
-
4
- # Don't change this file!
5
- # Configure your app in config/environment.rb and config/environments/*.rb
6
-
7
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
8
-
9
- module Rails
10
- class << self
11
- def boot!
12
- unless booted?
13
- preinitialize
14
- pick_boot.run
15
- end
16
- end
17
-
18
- def booted?
19
- defined? Rails::Initializer
20
- end
21
-
22
- def pick_boot
23
- (vendor_rails? ? VendorBoot : GemBoot).new
24
- end
25
-
26
- def vendor_rails?
27
- File.exist?(RAILS_FRAMEWORK_ROOT)
28
- end
29
-
30
- def preinitialize
31
- load(preinitializer_path) if File.exist?(preinitializer_path)
32
- end
33
-
34
- def preinitializer_path
35
- "#{RAILS_ROOT}/config/preinitializer.rb"
36
- end
37
- end
38
-
39
- class Boot
40
- def run
41
- load_initializer
42
- Rails::Initializer.run(:set_load_path)
43
- end
44
- end
45
-
46
- class VendorBoot < Boot
47
- def load_initializer
48
- require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
- Rails::Initializer.run(:install_gem_spec_stubs)
50
- Rails::GemDependency.add_frozen_gem_path
51
- end
52
- end
53
-
54
- class GemBoot < Boot
55
- def load_initializer
56
- self.class.load_rubygems
57
- load_rails_gem
58
- require 'initializer'
59
- end
60
-
61
- def load_rails_gem
62
- if version = self.class.gem_version
63
- gem 'rails', version
64
- else
65
- gem 'rails'
66
- end
67
- rescue Gem::LoadError => load_error
68
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
69
- exit 1
70
- end
71
-
72
- class << self
73
- def rubygems_version
74
- Gem::RubyGemsVersion rescue nil
75
- end
76
-
77
- def gem_version
78
- if defined? RAILS_GEM_VERSION
79
- RAILS_GEM_VERSION
80
- elsif ENV.include?('RAILS_GEM_VERSION')
81
- ENV['RAILS_GEM_VERSION']
82
- else
83
- parse_gem_version(read_environment_rb)
84
- end
85
- end
86
-
87
- def load_rubygems
88
- require 'rubygems'
89
- min_version = '1.3.1'
90
- unless rubygems_version >= min_version
91
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
92
- exit 1
93
- end
94
-
95
- rescue LoadError
96
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
97
- exit 1
98
- end
99
-
100
- def parse_gem_version(text)
101
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
102
- end
103
-
104
- private
105
- def read_environment_rb
106
- environment_rb = "#{RAILS_ROOT}/config/environment.rb"
107
- environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
108
- File.read(environment_rb)
109
- end
110
- end
111
- end
112
- end
113
-
114
- # All that for this:
115
- Rails.boot!
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -1,14 +1,5 @@
1
- require File.join(File.dirname(__FILE__), 'boot')
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
2
3
 
3
- Rails::Initializer.run do |config|
4
- config.cache_classes = false
5
- config.whiny_nils = true
6
- config.action_controller.session = {:key => 'rails_session', :secret => 'd229e4d22437432705ab3985d4d246'}
7
- config.plugin_locators.unshift(
8
- Class.new(Rails::Plugin::Locator) do
9
- def plugins
10
- [Rails::Plugin.new(File.expand_path('.'))]
11
- end
12
- end
13
- ) unless defined?(PluginTestHelper::PluginLocator)
14
- end
4
+ # Initialize the rails application
5
+ TestApp::Application.initialize!
@@ -1,4 +1,3 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- map.connect ':controller/:action/:id'
3
- map.connect ':controller/:action/:id.:format'
1
+ TestApp::Application.routes.draw do
2
+ match ':controller(/:action(/:id(.:format)))'
4
3
  end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
data/test/test_helper.rb CHANGED
@@ -1,25 +1,9 @@
1
- # Set the default environment to sqlite3's in_memory database
2
- ENV['RAILS_ENV'] ||= 'in_memory'
1
+ ENV['RAILS_ENV'] ||= 'test'
3
2
 
4
3
  # Load the Rails environment and testing framework
5
4
  require "#{File.dirname(__FILE__)}/app_root/config/environment"
6
- require 'test_help'
7
- require "param_protected"
8
-
9
- # Undo changes to RAILS_ENV
10
- silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
11
-
12
- # Run the migrations
13
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
14
-
15
- # Set default fixture loading properties
16
- ActiveSupport::TestCase.class_eval do
17
- self.use_transactional_fixtures = true
18
- self.use_instantiated_fixtures = false
19
- self.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
20
-
21
- fixtures :all
22
- end
5
+ require 'rails/test_help'
6
+ require 'param_protected'
23
7
 
24
8
  class ActionController::TestCase
25
9
  PARAMS = {
@@ -48,4 +32,4 @@ class ActionController::TestCase
48
32
  instance_eval(&block)
49
33
  end
50
34
  end
51
- end
35
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: param_protected
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
- - 1
8
- - 3
9
- - 1
10
- version: 1.3.1
6
+ - 2
7
+ - 0
8
+ - 0
9
+ version: 2.0.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Christopher J. Bottaro
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-03 00:00:00 -05:00
17
+ date: 2010-10-18 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -35,16 +34,15 @@ files:
35
34
  - Rakefile
36
35
  - VERSION
37
36
  - init.rb
38
- - install.rb
39
37
  - lib/param_protected.rb
40
38
  - lib/param_protected/constants.rb
41
39
  - lib/param_protected/controller_modifications.rb
42
- - lib/param_protected/meta_class.rb
43
40
  - lib/param_protected/protector.rb
44
41
  - param_protected.gemspec
45
- - tasks/param_protected_tasks.rake
46
42
  - test/accessible_except_test.rb
47
43
  - test/accessible_only_test.rb
44
+ - test/app_root/.gitignore
45
+ - test/app_root/Gemfile
48
46
  - test/app_root/app/controllers/accessible_except_controller.rb
49
47
  - test/app_root/app/controllers/accessible_only_controller.rb
50
48
  - test/app_root/app/controllers/application_controller.rb
@@ -53,16 +51,13 @@ files:
53
51
  - test/app_root/app/controllers/merge_controller.rb
54
52
  - test/app_root/app/controllers/protected_controller.rb
55
53
  - test/app_root/app/controllers/users_controller.rb
54
+ - test/app_root/config.ru
55
+ - test/app_root/config/application.rb
56
56
  - test/app_root/config/boot.rb
57
- - test/app_root/config/database.yml
58
57
  - test/app_root/config/environment.rb
59
- - test/app_root/config/environments/in_memory.rb
60
- - test/app_root/config/environments/mysql.rb
61
- - test/app_root/config/environments/postgresql.rb
62
- - test/app_root/config/environments/sqlite.rb
63
- - test/app_root/config/environments/sqlite3.rb
64
58
  - test/app_root/config/routes.rb
65
59
  - test/app_root/lib/console_with_fixtures.rb
60
+ - test/app_root/script/rails
66
61
  - test/conditions_controller_test.rb
67
62
  - test/inherited_users_controller_test.rb
68
63
  - test/merge_controller_test.rb
@@ -70,7 +65,6 @@ files:
70
65
  - test/protector_test.rb
71
66
  - test/test_helper.rb
72
67
  - test/users_controller_test.rb
73
- - uninstall.rb
74
68
  has_rdoc: true
75
69
  homepage: http://github.com/cjbottaro/param_protected
76
70
  licenses: []
@@ -85,7 +79,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - ">="
87
81
  - !ruby/object:Gem::Version
88
- hash: 3
89
82
  segments:
90
83
  - 0
91
84
  version: "0"
@@ -94,7 +87,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
87
  requirements:
95
88
  - - ">="
96
89
  - !ruby/object:Gem::Version
97
- hash: 3
98
90
  segments:
99
91
  - 0
100
92
  version: "0"
@@ -116,13 +108,9 @@ test_files:
116
108
  - test/app_root/app/controllers/merge_controller.rb
117
109
  - test/app_root/app/controllers/protected_controller.rb
118
110
  - test/app_root/app/controllers/users_controller.rb
111
+ - test/app_root/config/application.rb
119
112
  - test/app_root/config/boot.rb
120
113
  - test/app_root/config/environment.rb
121
- - test/app_root/config/environments/in_memory.rb
122
- - test/app_root/config/environments/mysql.rb
123
- - test/app_root/config/environments/postgresql.rb
124
- - test/app_root/config/environments/sqlite.rb
125
- - test/app_root/config/environments/sqlite3.rb
126
114
  - test/app_root/config/routes.rb
127
115
  - test/app_root/lib/console_with_fixtures.rb
128
116
  - test/conditions_controller_test.rb
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1,13 +0,0 @@
1
- class Object
2
- unless method_defined?(:meta_class)
3
- def meta_class
4
- (class << self; self; end)
5
- end
6
- end
7
-
8
- unless method_defined?(:meta_eval)
9
- def meta_eval(&block)
10
- meta_class.instance_eval(&block)
11
- end
12
- end
13
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :param_protected do
3
- # # Task goes here
4
- # end
@@ -1,31 +0,0 @@
1
- in_memory:
2
- adapter: sqlite3
3
- database: ":memory:"
4
- verbosity: quiet
5
- pool: 5
6
- timeout: 5000
7
- sqlite:
8
- adapter: sqlite
9
- dbfile: plugin_test.sqlite.db
10
- pool: 5
11
- timeout: 5000
12
- sqlite3:
13
- adapter: sqlite3
14
- dbfile: plugin_test.sqlite3.db
15
- pool: 5
16
- timeout: 5000
17
- postgresql:
18
- adapter: postgresql
19
- username: postgres
20
- password: postgres
21
- database: plugin_test
22
- pool: 5
23
- timeout: 5000
24
- mysql:
25
- adapter: mysql
26
- host: localhost
27
- username: root
28
- password:
29
- database: plugin_test
30
- pool: 5
31
- timeout: 5000
File without changes
File without changes
File without changes
File without changes
File without changes
data/uninstall.rb DELETED
@@ -1 +0,0 @@
1
- # Uninstall hook code here