rails_conditional_params 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0147ea4dea489f5b3a34ca1dba8b955a1058d2ff
4
- data.tar.gz: 06d56463e9de9be6b50ed8ac72dec291a01a4d0d
3
+ metadata.gz: cceaa82567b2886771f063721752211d3742b645
4
+ data.tar.gz: e3d518c542b164db67efed96a65673a5afca73a4
5
5
  SHA512:
6
- metadata.gz: 242e25d5664b5002f3e1af4569be93e43851f6c1a9472a39bce4794d1aa5e47d2ac7b43beeef162a72761fcd87d447eaf3a588334100da05bad62fc7f9450195
7
- data.tar.gz: 2478d1b6affaf4e801fbe77fea341b745597fd4e5ed8ef48d5d5cbd55e7cee23e587ac2b6794ee7d5fad66648f1567eeede61ce4931681b373d90c806221d8fd
6
+ metadata.gz: d376c355f226bdf3f6010f5c926193aa02485bf2258c0c9fb285c85343d31e32be3bc5d75aafc6754504aad33452687ca6aa5c9167bb69ab6b8fa8183247cf4a
7
+ data.tar.gz: ab6dae2701787461acf7cedc6b5236feaf176fade0cb0545d2a6b07bbe5d5a0bb772243d1efbfc9b89d351c54a0b4cfeb3e7070430b24ac8741f2f707070e8aa
@@ -1,10 +1,15 @@
1
1
  require 'action_controller'
2
2
 
3
3
  require "rails_conditional_params/version"
4
- require "rails_conditional_params/patch"
4
+ require "rails_conditional_params/alias_patch"
5
+ require "rails_conditional_params/prepend_patch"
5
6
 
6
7
  module RailsConditionalParams
7
- ActionController::Parameters.include Patch
8
+ if ActionController::Parameters.respond_to? :prepend
9
+ ActionController::Parameters.prepend PrependPatch
10
+ else
11
+ ActionController::Parameters.include AliasPatch
12
+ end
8
13
 
9
14
  def RailsConditionalParams.restructure_filters!(filters)
10
15
  filters.each do |filter|
@@ -1,5 +1,5 @@
1
1
  module RailsConditionalParams
2
- module Patch
2
+ module AliasPatch
3
3
  # Adds support for conditional params:
4
4
  #
5
5
  # params.permit(yes: true, no: false)
@@ -15,7 +15,7 @@ module RailsConditionalParams
15
15
  permit_without_conditional_params(*filters)
16
16
  end
17
17
 
18
- def Patch.included(other)
18
+ def AliasPatch.included(other)
19
19
  other.alias_method_chain :permit, :conditional_params
20
20
  end
21
21
  end
@@ -0,0 +1,18 @@
1
+ module RailsConditionalParams
2
+ module PrependPatch
3
+ # Adds support for conditional params:
4
+ #
5
+ # params.permit(yes: true, no: false)
6
+ # # => { "yes" => "..." }
7
+ #
8
+ # This is useful for parameters that should be permitted in some cases,
9
+ # but not others:
10
+ #
11
+ # params.permit(:title, :body, published: admin?)
12
+ # # Result only includes published if admin? is true.
13
+ def permit(*filters)
14
+ RailsConditionalParams.restructure_filters! filters
15
+ super(*filters)
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsConditionalParams
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/spec/params_spec.rb CHANGED
@@ -17,4 +17,15 @@ describe ActionController::Parameters do
17
17
  it "should exclude conditionals when conditionals are false" do
18
18
  expect(@params.permit(:allowed, maybe: false).to_h).to eq("allowed" => "allowed")
19
19
  end
20
+
21
+ it "should not carry over allowed-ness between separate calls" do
22
+ def filtered(maybe: false)
23
+ @params.permit(:allowed, maybe: maybe).to_h
24
+ end
25
+
26
+ expect(filtered(maybe: false).to_h).to eq("allowed" => "allowed")
27
+ expect(filtered(maybe: true).to_h).to eq("allowed" => "allowed", "maybe" => "maybe")
28
+ expect(filtered(maybe: false).to_h).to eq("allowed" => "allowed")
29
+ expect(filtered(maybe: true).to_h).to eq("allowed" => "allowed", "maybe" => "maybe")
30
+ end
20
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_conditional_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Royal-Gordon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2017-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -93,7 +93,8 @@ files:
93
93
  - README.md
94
94
  - Rakefile
95
95
  - lib/rails_conditional_params.rb
96
- - lib/rails_conditional_params/patch.rb
96
+ - lib/rails_conditional_params/alias_patch.rb
97
+ - lib/rails_conditional_params/prepend_patch.rb
97
98
  - lib/rails_conditional_params/version.rb
98
99
  - rails_conditional_params.gemspec
99
100
  - spec/params_spec.rb