Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed May 5, 2017
1 parent 5049add commit 49614af
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 266 deletions.
35 changes: 0 additions & 35 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,18 @@ language: ruby
sudo: false
cache: bundler
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2.6
- 2.3.3
- 2.4.0
- ruby-head

gemfile:
- gemfiles/Gemfile-rails-4.0-stable
- gemfiles/Gemfile-rails-4.1-stable
- gemfiles/Gemfile-rails-4.2-stable
- gemfiles/Gemfile-rails-5.0-stable
- gemfiles/Gemfile-rails-5.1-stable
- gemfiles/Gemfile-rails-4.0
- gemfiles/Gemfile-rails-4.1
- gemfiles/Gemfile-rails-4.2
- gemfiles/Gemfile-rails-5.0
- gemfiles/Gemfile-rails-5.1

matrix:
exclude:
- rvm: 1.9.3
gemfile: gemfiles/Gemfile-rails-5.0
- rvm: 1.9.3
gemfile: gemfiles/Gemfile-rails-5.0-stable
- rvm: 1.9.3
gemfile: gemfiles/Gemfile-rails-5.1
- rvm: 1.9.3
gemfile: gemfiles/Gemfile-rails-5.1-stable
- rvm: 2.0
gemfile: gemfiles/Gemfile-rails-5.0
- rvm: 2.0
gemfile: gemfiles/Gemfile-rails-5.0-stable
- rvm: 2.0
gemfile: gemfiles/Gemfile-rails-5.1
- rvm: 2.0
gemfile: gemfiles/Gemfile-rails-5.1-stable
- rvm: 2.1
gemfile: gemfiles/Gemfile-rails-5.0
- rvm: 2.1
gemfile: gemfiles/Gemfile-rails-5.0-stable
- rvm: 2.1
gemfile: gemfiles/Gemfile-rails-5.1
- rvm: 2.1
gemfile: gemfiles/Gemfile-rails-5.1-stable

allow_failures:
- rvm: ruby-head

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 1.2.5
## 1.3.0

* Add Rails 5.1 support
* Dont require activerecord in non-activerecord environments
* Drop support for Rails 4, it now only support Rails 5

## 1.2.4

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source 'https://rubygems.org'

gem 'rails', '>=4.0'
gem 'rails', '~>5.0'

gemspec
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

[![Build Status](https://api.travis-ci.org/westonganger/protected_attributes_continued.svg?branch=master)](https://travis-ci.org/westonganger/protected_attributes_continued)

This is the community continued version of `protected_attributes`. This library is maintained and supports Rails 5+

I have created this gem and changed the name because the Rails team refuses to support the `protected_attributes` gem for Rails 5+. For people who would like to continue using this feature in their Rails 5+ apps lets continue here. This is in use successfully on number of my Rails 5 production apps.
This is the community continued version of `protected_attributes`. It works with Rails 5 only and I recommend you only use it to support legacy portions of your application that you do not want to upgrade. Note that this feature was dropped by the Rails team and switched to strong_parameters because of security issues, just so you understand your risks. This is in use successfully in some of my Rails 5 apps in which security like this is a non-issue. For people who would like to continue using this feature in their Rails 5 apps lets continue the work here.

Protect attributes from mass-assignment in Active Record models.

Expand Down
17 changes: 0 additions & 17 deletions gemfiles/Gemfile-rails-4.0

This file was deleted.

17 changes: 0 additions & 17 deletions gemfiles/Gemfile-rails-4.0-stable

This file was deleted.

17 changes: 0 additions & 17 deletions gemfiles/Gemfile-rails-4.1

This file was deleted.

17 changes: 0 additions & 17 deletions gemfiles/Gemfile-rails-4.1-stable

This file was deleted.

17 changes: 0 additions & 17 deletions gemfiles/Gemfile-rails-4.2

This file was deleted.

17 changes: 0 additions & 17 deletions gemfiles/Gemfile-rails-4.2-stable

This file was deleted.

4 changes: 0 additions & 4 deletions lib/active_record/mass_assignment_security.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
require "active_record"

def active_record_40?
ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0
end

require "active_record/mass_assignment_security/associations"
require "active_record/mass_assignment_security/attribute_assignment"
require "active_record/mass_assignment_security/core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ def accepts_nested_attributes_for(*attr_names)

attr_names.each do |association_name|
if reflection = reflect_on_association(association_name)
if active_record_40?
reflection.options[:autosave] = true
else
reflection.autosave = true
end
reflection.autosave = true
add_autosave_association_callbacks(reflection)

nested_attributes_options = self.nested_attributes_options.dup
Expand All @@ -28,7 +24,7 @@ def accepts_nested_attributes_for(*attr_names)

type = (reflection.collection? ? :collection : :one_to_one)

generated_methods_module = active_record_40? ? generated_feature_methods : generated_association_methods
generated_methods_module = generated_association_methods

# def pirate_attributes=(attributes)
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes, mass_assignment_options)
Expand Down
6 changes: 3 additions & 3 deletions lib/active_record/mass_assignment_security/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def first_or_initialize(attributes = nil, options = {}, &block)
end

def find_or_initialize_by(attributes, options = {}, &block)
find_by((attributes.to_unsafe_h if attributes.respond_to?(:to_unsafe_h))) || new(attributes, options, &block)
find_by(attributes.respond_to?(:to_unsafe_h) ? attributes.to_unsafe_h : attributes) || new(attributes, options, &block)
end

def find_or_create_by(attributes, options = {}, &block)
find_by((attributes.to_unsafe_h if attributes.respond_to?(:to_unsafe_h))) || create(attributes, options, &block)
find_by(attributes.respond_to?(:to_unsafe_h) ? attributes.to_unsafe_h : attributes) || create(attributes, options, &block)
end

def find_or_create_by!(attributes, options = {}, &block)
find_by((attributes.to_unsafe_h if attributes.respond_to?(:to_unsafe_h))) || create!(attributes, options, &block)
find_by(attributes.respond_to?(:to_unsafe_h) ? attributes.to_unsafe_h : attributes) || create!(attributes, options, &block)
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/protected_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@

module ProtectedAttributes
end

if defined?(ActiveRecord)
require 'active_record/core_patch'
end
2 changes: 1 addition & 1 deletion lib/protected_attributes/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ProtectedAttributes
VERSION = "1.2.5"
VERSION = "1.3.0"
end
8 changes: 4 additions & 4 deletions protected_attributes_continued.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Gem::Specification.new do |gem|
gem.files = Dir["LICENSE.txt", "README.md", "lib/**/*"]
gem.require_paths = ["lib"]

gem.add_dependency "activemodel", ">= 4.0.1", "<6.0"
gem.add_dependency "activemodel", "~>5.0"

gem.add_development_dependency "activerecord", ">= 4.0.1", "<6.0"
gem.add_development_dependency "actionpack", ">= 4.0.1", "<6.0"
gem.add_development_dependency "railties", ">= 4.0.1", "<6.0"
gem.add_development_dependency "activerecord", "~>5.0"
gem.add_development_dependency "actionpack", "~>5.0"
gem.add_development_dependency "railties", "~>5.0"
gem.add_development_dependency "sqlite3"
gem.add_development_dependency "mocha"
end
11 changes: 1 addition & 10 deletions test/abstract_unit.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
require 'action_dispatch'
require 'action_controller'
require 'active_support/dependencies'

def active_support_4_0?
ActiveSupport::VERSION::MAJOR == 4 && ActiveSupport::VERSION::MINOR == 0
end

if active_support_4_0?
require 'active_support/core_ext/class/attribute_accessors'
else
require 'active_support/core_ext/module/attribute_accessors'
end
require 'active_support/core_ext/module/attribute_accessors'

module SetupOnce
extend ActiveSupport::Concern
Expand Down
18 changes: 3 additions & 15 deletions test/accessible_params_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def test_derived_wrapped_keys_from_matching_model

with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
if Rails::VERSION::MAJOR > 4
post :parse, params: { 'username' => 'sikachu', 'title' => 'Developer' }
else
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
end
post :parse, params: { 'username' => 'sikachu', 'title' => 'Developer' }
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu' }})
end
end
Expand All @@ -62,11 +58,7 @@ def test_derived_wrapped_keys_from_specified_model
UsersController.wrap_parameters Person

@request.env['CONTENT_TYPE'] = 'application/json'
if Rails::VERSION::MAJOR > 4
post :parse, params: { 'username' => 'sikachu', 'title' => 'Developer' }
else
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
end
post :parse, params: { 'username' => 'sikachu', 'title' => 'Developer' }
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'person' => { 'username' => 'sikachu' }})
end
end
Expand All @@ -77,11 +69,7 @@ def test_accessible_wrapped_keys_from_matching_model

with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
if Rails::VERSION::MAJOR > 4
post :parse, params: { 'username' => 'sikachu', 'title' => 'Developer' }
else
post :parse, { 'username' => 'sikachu', 'title' => 'Developer' }
end
post :parse, params: { 'username' => 'sikachu', 'title' => 'Developer' }
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu' }})
end
end
Expand Down
Loading

0 comments on commit 49614af

Please sign in to comment.