strong_presenter 0.1.0 → 0.2.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.md +14 -6
- data/README.md +107 -30
- data/lib/strong_presenter/associable.rb +47 -7
- data/lib/strong_presenter/collection_presenter.rb +16 -0
- data/lib/strong_presenter/permissible.rb +9 -32
- data/lib/strong_presenter/permissions.rb +78 -75
- data/lib/strong_presenter/presenter.rb +2 -3
- data/lib/strong_presenter/presenter_helper_constructor.rb +1 -1
- data/lib/strong_presenter/version.rb +1 -1
- data/spec/dummy/app/controllers/posts_controller.rb +1 -1
- data/spec/dummy/app/mailers/post_mailer.rb +1 -1
- data/spec/strong_presenter/associable_spec.rb +197 -18
- data/spec/strong_presenter/collection_presenter_spec.rb +38 -6
- data/spec/strong_presenter/controller_additions_spec.rb +115 -0
- data/spec/strong_presenter/helper_proxy_spec.rb +53 -0
- data/spec/strong_presenter/permissible_spec.rb +6 -6
- data/spec/strong_presenter/permissions_spec.rb +81 -67
- data/spec/strong_presenter/presenter_spec.rb +83 -1
- data/spec/strong_presenter/view_context/build_strategy_spec.rb +116 -0
- data/spec/strong_presenter/view_context_spec.rb +154 -0
- data/spec/strong_presenter/view_helpers_spec.rb +8 -0
- data/spec/support/shared_examples/view_helpers.rb +39 -0
- data/strong_presenter.gemspec +2 -2
- metadata +74 -100
- checksums.yaml +0 -7
@@ -17,18 +17,50 @@ module StrongPresenter
|
|
17
17
|
expect(products_presenter[0].class).to be ProductPresenter
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
it "has to_s method" do
|
22
|
+
collection = CollectionPresenter.new([Model.new, Model.new])
|
23
|
+
expect(collection.to_s).to include "inferred"
|
24
|
+
end
|
25
|
+
|
20
26
|
describe "Permissible" do
|
21
|
-
|
22
|
-
collection = [Model.new, Model.new]
|
23
|
-
collection_presenter = CollectionPresenter.new(collection, :with => Presenter)
|
27
|
+
before(:each) do
|
28
|
+
@collection = [Model.new, Model.new]
|
29
|
+
@collection_presenter = CollectionPresenter.new(@collection, :with => Presenter)
|
30
|
+
end
|
24
31
|
|
25
|
-
|
32
|
+
it "collection permits on items" do
|
33
|
+
expect(@collection_presenter[0].select_permitted :z).to be_empty
|
26
34
|
|
27
|
-
collection_presenter.permit :a, :b, :c
|
28
|
-
permitted = collection_presenter[0].
|
35
|
+
@collection_presenter.permit! :a, :b, :c
|
36
|
+
permitted = @collection_presenter[0].select_permitted :a, :c, :z
|
29
37
|
expect(permitted).to include(:a, :c)
|
30
38
|
expect(permitted).to_not include(:b, :z)
|
31
39
|
end
|
40
|
+
|
41
|
+
it "permits items" do
|
42
|
+
@collection_presenter[0].permit! :a
|
43
|
+
expect(@collection_presenter[0].select_permitted :a).to eq [:a]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "does not leak item permit to siblings" do
|
47
|
+
@collection_presenter[0].permit! :a
|
48
|
+
expect(@collection_presenter[1].select_permitted :a).to be_empty
|
49
|
+
end
|
50
|
+
|
51
|
+
it "resets item permit on reload" do
|
52
|
+
@collection_presenter[0].permit! :a
|
53
|
+
@collection_presenter.reload!
|
54
|
+
expect(@collection_presenter[0].select_permitted :a).to be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
it "propagates to items" do
|
58
|
+
@collection_presenter[0].permit! :a
|
59
|
+
expect(@collection_presenter[0].select_permitted :a, :b).to eq [:a]
|
60
|
+
@collection_presenter.permit! :b
|
61
|
+
expect(@collection_presenter[0].select_permitted :a, :b).to eq [:a, :b]
|
62
|
+
expect(@collection_presenter[1].select_permitted :a, :b).to eq [:b]
|
63
|
+
end
|
32
64
|
end
|
33
65
|
end
|
34
66
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module StrongPresenter
|
4
|
+
describe ControllerAdditions do
|
5
|
+
before(:each) do
|
6
|
+
stub_const "MyController", Class.new {
|
7
|
+
attr_writer :action_name
|
8
|
+
def action_name
|
9
|
+
@action_name || ""
|
10
|
+
end
|
11
|
+
}
|
12
|
+
allow(MyController).to receive(:helper_method)
|
13
|
+
allow(MyController).to receive(:before_filter)
|
14
|
+
StrongPresenter.setup_action_controller(MyController)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#presents' do
|
18
|
+
it 'sets up arbitrary helper method for presenter' do
|
19
|
+
expect(MyController).to receive(:helper_method).with(:arbitrary).once
|
20
|
+
MyController.presents :arbitrary
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets up multiple helper methods' do
|
24
|
+
expect(MyController).to receive(:helper_method).with(:arbitrary).once
|
25
|
+
expect(MyController).to receive(:helper_method).with(:arb).once
|
26
|
+
MyController.presents :arbitrary, :arb
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets up helper method with only' do
|
30
|
+
MyController.presents :arbitrary, :only => :show
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'sets up helper method with except' do
|
34
|
+
MyController.presents :arbitrary, :except => :show
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'sets up helper method with presenter option' do
|
38
|
+
MyController.presents :arbitrary, :with => ProductPresenter
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with product helper' do
|
43
|
+
before(:each) do
|
44
|
+
@controller = MyController.new
|
45
|
+
@controller.send :instance_variable_set, :@product, Product.new
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with plain presents' do
|
49
|
+
before(:each) do
|
50
|
+
MyController.presents :product
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'presents product' do
|
54
|
+
expect(@controller.product.class).to be ProductPresenter
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'memoizes presenter' do
|
58
|
+
presenter = @controller.product
|
59
|
+
expect(@controller.product).to be presenter
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with only' do
|
64
|
+
before(:each) do
|
65
|
+
MyController.presents :product, :only => :show
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'presents on action' do
|
69
|
+
@controller.action_name = "show"
|
70
|
+
expect(@controller.product.class).to be ProductPresenter
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not present on action' do
|
74
|
+
expect{@controller.product}.to raise_error NoMethodError
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with shadowed method, multiple presents with' do
|
79
|
+
before(:each) do
|
80
|
+
stub_const('Presenter1', Class.new(StrongPresenter::Presenter))
|
81
|
+
stub_const('Presenter2', Class.new(StrongPresenter::Presenter))
|
82
|
+
MyController.send(:define_method, :product) {|number| "Product ##{number}"}
|
83
|
+
MyController.presents :product, :with => Presenter1, :only => :unused
|
84
|
+
MyController.presents :product, :except => :index
|
85
|
+
MyController.presents :product, :with => Presenter1, :only => :show
|
86
|
+
MyController.presents :product, :with => Presenter2, :only => :edit
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'presents show on show' do
|
90
|
+
@controller.action_name = "show"
|
91
|
+
expect(@controller.product.class).to be Presenter1
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'presents show on edit' do
|
95
|
+
@controller.action_name = "edit"
|
96
|
+
expect(@controller.product.class).to be Presenter2
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'presents default on other' do
|
100
|
+
expect(@controller.product.class).to be ProductPresenter
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'presents default on shadowed unused presents' do
|
104
|
+
@controller.action_name = "unused"
|
105
|
+
expect(@controller.product.class).to be ProductPresenter
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'falls back to original method without match' do
|
109
|
+
@controller.action_name = "index"
|
110
|
+
expect(@controller.product(5)).to eq "Product #5"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module StrongPresenter
|
4
|
+
describe HelperProxy do
|
5
|
+
describe "#initialize" do
|
6
|
+
it "sets the view context" do
|
7
|
+
view_context = double
|
8
|
+
helper_proxy = HelperProxy.new(view_context)
|
9
|
+
|
10
|
+
expect(helper_proxy.send(:view_context)).to be view_context
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#method_missing" do
|
15
|
+
protect_class HelperProxy
|
16
|
+
|
17
|
+
it "proxies methods to the view context" do
|
18
|
+
view_context = double
|
19
|
+
helper_proxy = HelperProxy.new(view_context)
|
20
|
+
|
21
|
+
view_context.stub(:foo).and_return{|arg| arg}
|
22
|
+
expect(helper_proxy.foo(:passed)).to be :passed
|
23
|
+
end
|
24
|
+
|
25
|
+
it "passes blocks" do
|
26
|
+
view_context = double
|
27
|
+
helper_proxy = HelperProxy.new(view_context)
|
28
|
+
|
29
|
+
view_context.stub(:foo).and_return{|&block| block.call}
|
30
|
+
expect(helper_proxy.foo{:yielded}).to be :yielded
|
31
|
+
end
|
32
|
+
|
33
|
+
it "defines the method for better performance" do
|
34
|
+
helper_proxy = HelperProxy.new(double(foo: "bar"))
|
35
|
+
|
36
|
+
expect(HelperProxy.instance_methods).not_to include :foo
|
37
|
+
helper_proxy.foo
|
38
|
+
expect(HelperProxy.instance_methods).to include :foo
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "proxying methods which are overriding" do
|
43
|
+
it "proxies :capture" do
|
44
|
+
view_context = double
|
45
|
+
helper_proxy = HelperProxy.new(view_context)
|
46
|
+
|
47
|
+
view_context.stub(:capture).and_return{|*args, &block| [*args, block.call] }
|
48
|
+
expect(helper_proxy.capture(:first_arg, :second_arg){:yielded}).to \
|
49
|
+
be_eql [:first_arg, :second_arg, :yielded]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -2,22 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module StrongPresenter
|
4
4
|
describe Permissible do
|
5
|
-
it "
|
5
|
+
it "selects permitted attributes" do
|
6
6
|
object = Model.new
|
7
7
|
presenter = Presenter.new(object)
|
8
8
|
|
9
|
-
presenter.permit :a, :b, :c
|
10
|
-
permitted = presenter.
|
9
|
+
presenter.permit! :a, :b, :c
|
10
|
+
permitted = presenter.select_permitted :a, :c, :z
|
11
11
|
expect(permitted).to include(:a, :c)
|
12
12
|
expect(permitted).to_not include(:b, :z)
|
13
13
|
end
|
14
14
|
|
15
|
-
it "permits all if
|
15
|
+
it "permits all if permit_all!" do
|
16
16
|
object = Model.new
|
17
17
|
presenter = Presenter.new(object)
|
18
18
|
|
19
|
-
presenter.
|
20
|
-
permitted = presenter.
|
19
|
+
presenter.permit_all!
|
20
|
+
permitted = presenter.select_permitted :a, :b, :c
|
21
21
|
expect(permitted).to include(:a, :b, :c)
|
22
22
|
end
|
23
23
|
end
|
@@ -16,131 +16,148 @@ module StrongPresenter
|
|
16
16
|
|
17
17
|
describe "#permit" do
|
18
18
|
it 'permits an attribute' do
|
19
|
-
expect(Permissions.new.permit(
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'permits with prefix' do
|
23
|
-
expect(Permissions.new.permit(:prefix, :attr).permitted?(:prefix, :attr)).to be true
|
19
|
+
expect(Permissions.new.permit(:attr).permitted?(:attr)).to be true
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'permits with arrays of symbols' do
|
27
|
-
expect(Permissions.new.permit([:
|
23
|
+
expect(Permissions.new.permit([:attr, :array]).permitted?([:attr, :array])).to be true
|
28
24
|
end
|
29
25
|
|
30
26
|
it 'permits multiple at once' do
|
31
|
-
permissions = Permissions.new.permit([:
|
32
|
-
expect(permissions.permitted?(
|
33
|
-
expect(permissions.permitted?([:
|
27
|
+
permissions = Permissions.new.permit([:another, :array], [:attr, :array], :attr2, :attr3)
|
28
|
+
expect(permissions.permitted?(:attr2)).to be true
|
29
|
+
expect(permissions.permitted?([:attr, :array])).to be true
|
34
30
|
end
|
35
31
|
|
36
32
|
it 'does not mutate arguments' do
|
37
|
-
prefix = [:pre, :fix]
|
38
33
|
attrpaths = [[:attr, :path], :s]
|
39
|
-
Permissions.new.permit(
|
34
|
+
Permissions.new.permit(attrpathsarg = attrpaths.dup)
|
40
35
|
|
41
|
-
expect(prefixarg).to eq prefix
|
42
36
|
expect(attrpathsarg).to eq attrpaths
|
43
37
|
end
|
38
|
+
|
39
|
+
it 'permits specific path after wildcard' do
|
40
|
+
permissions = Permissions.new.permit([:prefix, :*])
|
41
|
+
expect(permissions.permitted?([:prefix, "specific".taint])).to be false
|
42
|
+
permissions.permit([:prefix, :specific])
|
43
|
+
expect(permissions.permitted?([:prefix, "specific".taint])).to be true
|
44
|
+
end
|
44
45
|
end
|
45
46
|
|
46
47
|
describe "#permitted?" do
|
47
48
|
context 'with some attributes permitted' do
|
48
49
|
before(:all) do
|
49
|
-
@permissions = Permissions.new.permit([:
|
50
|
+
@permissions = Permissions.new.permit([:another, :array], [:attr, :array], :attr2, :attr3, [:a, :wildcard, :*], [:wild, :**])
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'permits single wildcard' do
|
54
|
+
expect(@permissions.permitted?([:a, :wildcard, :irrelevant])).to be true
|
50
55
|
end
|
51
56
|
|
52
|
-
it 'permits
|
53
|
-
expect(@permissions.permitted?([:
|
57
|
+
it 'permits full wildcard' do
|
58
|
+
expect(@permissions.permitted?([:wild, :wildcard, :irrelevant])).to be true
|
59
|
+
expect(@permissions.permitted?([:wild, :irrelevant])).to be true
|
54
60
|
end
|
55
61
|
|
56
62
|
it 'does not permit un-prefixed path' do
|
57
|
-
|
58
|
-
expect(
|
63
|
+
permissions = Permissions.new(@permissions, :attr)
|
64
|
+
expect(permissions.permitted?(:attr2)).to be false
|
65
|
+
expect(permissions.permitted?([:wild, :irrelevant])).to be false
|
59
66
|
end
|
60
67
|
|
61
|
-
it 'permits
|
62
|
-
|
63
|
-
expect(
|
64
|
-
expect(@permissions.permitted?([:prefix], [:array, :attr2, :irrelevant])).to be true
|
65
|
-
expect(@permissions.permitted?([], [:prefix, :array, :attr2, :irrelevant])).to be true
|
68
|
+
it 'permits with prefix' do
|
69
|
+
permissions = Permissions.new(@permissions, :attr)
|
70
|
+
expect(permissions.permitted?(:array)).to be true
|
66
71
|
end
|
67
72
|
|
68
73
|
it 'does not permit other attributes' do
|
69
|
-
expect(@permissions.permitted?([:
|
74
|
+
expect(@permissions.permitted?([:attr4, :irrelevant])).to be false
|
70
75
|
end
|
71
76
|
|
72
77
|
it 'does not permit shortened paths' do
|
73
|
-
expect(@permissions.permitted?(
|
78
|
+
expect(@permissions.permitted?(:attr)).to be false
|
74
79
|
end
|
75
80
|
|
76
81
|
it 'does not mutate arguments' do
|
77
|
-
prefix = [:pre, :fix]
|
78
82
|
attrpaths = [[:attr, :path], :s, [:array, :attr2]]
|
79
83
|
|
80
|
-
@permissions.permitted?(
|
81
|
-
expect(prefixarg).to eq prefix
|
84
|
+
@permissions.permitted?(attrpathsarg = attrpaths.dup)
|
82
85
|
expect(attrpathsarg).to eq attrpaths
|
83
86
|
|
84
87
|
prefix = [:prefix]
|
85
|
-
@permissions.permitted?(
|
86
|
-
expect(prefixarg).to eq prefix
|
88
|
+
@permissions.permitted?(attrpathsarg = attrpaths.dup)
|
87
89
|
expect(attrpathsarg).to eq attrpaths
|
88
90
|
end
|
91
|
+
|
92
|
+
it 'is indifferent to strings' do
|
93
|
+
expect(@permissions.permitted?(["attr","array"])).to be true
|
94
|
+
expect(@permissions.permitted?("a/wildcard/irrelevant".split("/"))).to be true
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'does not permit single wildcard if tainted' do
|
98
|
+
expect(@permissions.permitted?([:a, :wildcard, "irrelevant".taint])).to be false
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'does not permit full wildcard if tainted' do
|
102
|
+
expect(@permissions.permitted?(["wild".taint, :wildcard, :irrelevant])).to be false
|
103
|
+
expect(@permissions.permitted?(["wild", "irrelevant"].taint)).to be false
|
104
|
+
expect(@permissions.permitted?("a/wildcard/irrelevant".taint.split("/"))).to be false
|
105
|
+
end
|
89
106
|
end
|
90
107
|
|
91
108
|
context 'with permit all' do
|
92
|
-
it '
|
109
|
+
it 'all methods are true' do
|
93
110
|
permissions = Permissions.new.permit_all!
|
94
111
|
expect(permissions.permitted?(:a)).to be true
|
95
|
-
expect(permissions.permitted?(
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
expect(permissions.permitted?([:
|
101
|
-
expect(permissions.permitted?([],[:a,:b])).to be true
|
112
|
+
expect(permissions.permitted?(:b)).to be true
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'association methods are false' do
|
116
|
+
permissions = Permissions.new.permit_all!
|
117
|
+
expect(permissions.permitted?([:a,:a])).to be false
|
102
118
|
end
|
103
119
|
end
|
104
120
|
end
|
105
121
|
describe "#select_permitted" do
|
106
122
|
context 'with some attributes permitted' do
|
107
123
|
before(:all) do
|
108
|
-
@permissions = Permissions.new.permit([:
|
109
|
-
@permissions.permit([], [:attr, :
|
124
|
+
@permissions = Permissions.new.permit([:another, :array], [:attr, :array, :*], :attr2, :attr3)
|
125
|
+
@permissions.permit([], [:attr, :arrays], :attr2, :attr3)
|
110
126
|
end
|
111
127
|
|
112
128
|
it 'can select something which is permitted' do
|
113
|
-
expect(@permissions.select_permitted(
|
114
|
-
expect(@permissions.select_permitted([:
|
115
|
-
expect(@permissions.select_permitted([:
|
129
|
+
expect(@permissions.select_permitted(:attr2)).to eq [:attr2]
|
130
|
+
expect(@permissions.select_permitted([:attr, :array, :irrelevant])).to eq [[:attr, :array, :irrelevant]]
|
131
|
+
expect(@permissions.select_permitted([:another, :array])).to eq [[:another, :array]]
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'does not select wildcard path without wildcard' do
|
135
|
+
expect(@permissions.select_permitted([:attr, :array])).to be_empty
|
116
136
|
end
|
117
137
|
|
118
138
|
it 'can select multiple permitted attributes' do
|
119
|
-
attribute_paths = [:attr2, :attr3, [:
|
120
|
-
permitted = @permissions.select_permitted(
|
139
|
+
attribute_paths = [[:attr2], :attr3, [:another, :array], [:attr, :array, :method]]
|
140
|
+
permitted = @permissions.select_permitted(*attribute_paths)
|
121
141
|
attribute_paths.each do |attribute_path|
|
122
|
-
expect(permitted).to include
|
142
|
+
expect(permitted).to include attribute_path
|
123
143
|
end
|
124
144
|
end
|
125
145
|
|
126
146
|
it 'selects only permitted attributes in the original order' do
|
127
|
-
permitted_paths = [:attr2, :attr3, [:
|
128
|
-
unpermitted_paths = [:attr4, :attr5, [:attrk, :irrelevant], [:attr, :ar]]
|
147
|
+
permitted_paths = [:attr2, :attr3, [:attr, :arrays], [:attr, :array, :meth], [:attr3]]
|
148
|
+
unpermitted_paths = [:attr4, :attr5, [:attrk, :irrelevant], [:attr, :ar], [:attr, :arrays, :more]]
|
129
149
|
attribute_paths = (unpermitted_paths + permitted_paths).shuffle
|
130
|
-
expect(@permissions.select_permitted(
|
150
|
+
expect(@permissions.select_permitted(*attribute_paths)).to eq((attribute_paths & permitted_paths))
|
131
151
|
end
|
132
152
|
|
133
153
|
it 'does not mutate arguments' do
|
134
|
-
prefix = [:pre, :fix]
|
135
154
|
attrpaths = [[:attr, :path], :s, [:array, :attr2]]
|
136
155
|
|
137
|
-
@permissions.select_permitted(
|
138
|
-
expect(prefixarg).to eq prefix
|
156
|
+
@permissions.select_permitted(attrpathsarg = attrpaths.dup)
|
139
157
|
expect(attrpathsarg).to eq attrpaths
|
140
158
|
|
141
|
-
|
142
|
-
@permissions.select_permitted(
|
143
|
-
expect(prefixarg).to eq prefix
|
159
|
+
attrpaths = [[:attr, :array, :meth], :s, [:array, :attr2]]
|
160
|
+
@permissions.select_permitted(attrpathsarg = attrpaths.dup)
|
144
161
|
expect(attrpathsarg).to eq attrpaths
|
145
162
|
end
|
146
163
|
end
|
@@ -148,37 +165,34 @@ module StrongPresenter
|
|
148
165
|
context 'with permit all' do
|
149
166
|
it 'everything is selected' do
|
150
167
|
permissions = Permissions.new.permit_all!
|
151
|
-
attribute_paths = [:attr2, :attr3,
|
168
|
+
attribute_paths = [:attr2, :attr3, :attr2, :attr, :array]
|
152
169
|
permitted = permissions.select_permitted([:prefix, :array], *attribute_paths)
|
153
|
-
expect(permitted).to eq(attribute_paths
|
170
|
+
expect(permitted).to eq(attribute_paths)
|
154
171
|
end
|
155
172
|
end
|
156
173
|
end
|
157
174
|
describe "#reject_permitted" do
|
158
175
|
context 'with some attributes permitted' do
|
159
176
|
before(:all) do
|
160
|
-
@permissions = Permissions.new.permit([:
|
161
|
-
@permissions.permit([], [:attr, :
|
177
|
+
@permissions = Permissions.new.permit([:another, :array], [:attr, :array, :*], :attr2, :attr3)
|
178
|
+
@permissions.permit([], [:attr, :arrays], :attr2, :attr3)
|
162
179
|
end
|
163
180
|
|
164
181
|
it 'selects only unpermitted attributes in the original order' do
|
165
|
-
permitted_paths = [:attr2, :attr3, [:
|
166
|
-
unpermitted_paths = [:attr4, :attr5, [:attrk, :irrelevant], [:attr, :ar]]
|
182
|
+
permitted_paths = [:attr2, :attr3, [:attr, :arrays], [:attr, :array, :meth], [:attr3]]
|
183
|
+
unpermitted_paths = [:attr4, :attr5, [:attrk, :irrelevant], [:attr, :ar], [:attr, :arrays, :more]]
|
167
184
|
attribute_paths = (unpermitted_paths + permitted_paths).shuffle
|
168
|
-
expect(@permissions.reject_permitted(
|
185
|
+
expect(@permissions.reject_permitted(*attribute_paths)).to eq((attribute_paths & unpermitted_paths))
|
169
186
|
end
|
170
187
|
|
171
188
|
it 'does not mutate arguments' do
|
172
|
-
prefix = [:pre, :fix]
|
173
189
|
attrpaths = [[:attr, :path], :s, [:array, :attr2]]
|
174
190
|
|
175
|
-
@permissions.reject_permitted(
|
176
|
-
expect(prefixarg).to eq prefix
|
191
|
+
@permissions.reject_permitted(attrpathsarg = attrpaths.dup)
|
177
192
|
expect(attrpathsarg).to eq attrpaths
|
178
193
|
|
179
|
-
|
180
|
-
@permissions.reject_permitted(
|
181
|
-
expect(prefixarg).to eq prefix
|
194
|
+
attrpaths = [[:attr, :array, :meth], :s, [:array, :attr2]]
|
195
|
+
@permissions.reject_permitted(attrpathsarg = attrpaths.dup)
|
182
196
|
expect(attrpathsarg).to eq attrpaths
|
183
197
|
end
|
184
198
|
end
|