adequate_exposure 0.0.3 → 0.0.4
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 +4 -4
- data/lib/adequate_exposure/exposure.rb +5 -0
- data/lib/adequate_exposure/flow.rb +2 -1
- data/lib/adequate_exposure/version.rb +1 -1
- data/spec/controller_spec.rb +20 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08518a93835d972d60b024e436f478f894b811c4
|
4
|
+
data.tar.gz: 7d0c3042b2d662a44e1d22ec6415fc46c1957078
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3925a14260bd04bf95bba1e8785595ccb2771526b056f42bcc63e88978ab218520bc911462a61b124cef4df0c8103f08e1a2314c63e5623007552387d5786f8a
|
7
|
+
data.tar.gz: 027d750fbafb02bcee26be876daa877e04c033d5656a035c8df117f0289b8ffa5cc3f4becb93563e952f8b1a40ed95c5ac57efd797136eaebaa204af7389ccdd
|
@@ -17,6 +17,7 @@ module AdequateExposure
|
|
17
17
|
assert_singleton_option :from
|
18
18
|
assert_incompatible_options_pair :parent, :model
|
19
19
|
assert_incompatible_options_pair :parent, :scope
|
20
|
+
assert_incompatible_options_pair :find_by, :find
|
20
21
|
|
21
22
|
normalize_options
|
22
23
|
end
|
@@ -70,6 +71,10 @@ module AdequateExposure
|
|
70
71
|
if from = options.delete(:from)
|
71
72
|
merge_lambda_option :fetch, ->{ send(from).send(exposure_name) }
|
72
73
|
end
|
74
|
+
|
75
|
+
if find_by = options.delete(:find_by)
|
76
|
+
merge_lambda_option :find, ->(id, scope){ scope.find_by!(find_by => id) }
|
77
|
+
end
|
73
78
|
end
|
74
79
|
|
75
80
|
def normalize_non_proc_option(name)
|
@@ -23,7 +23,8 @@ module AdequateExposure
|
|
23
23
|
|
24
24
|
def default_fetch
|
25
25
|
computed_scope = scope(model)
|
26
|
-
id ?
|
26
|
+
instance = id ? find(id, computed_scope) : build(computed_scope)
|
27
|
+
decorate(instance)
|
27
28
|
end
|
28
29
|
|
29
30
|
def default_id
|
data/spec/controller_spec.rb
CHANGED
@@ -104,7 +104,6 @@ describe AdequateExposure::Controller do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
context "default behaviour" do
|
107
|
-
|
108
107
|
context "build" do
|
109
108
|
let(:thing){ double("Thing") }
|
110
109
|
|
@@ -138,6 +137,12 @@ describe AdequateExposure::Controller do
|
|
138
137
|
expect(Thing).to receive(:new).with(foo: :bar).and_return(thing)
|
139
138
|
expect(controller).to receive(:custom_params_method_name).and_return(foo: :bar)
|
140
139
|
end
|
140
|
+
|
141
|
+
it "can use custom build params" do
|
142
|
+
expose :thing, build_params: ->{ foobar }
|
143
|
+
expect(controller).to receive(:foobar).and_return(42)
|
144
|
+
expect(Thing).to receive(:new).with(42).and_return(thing)
|
145
|
+
end
|
141
146
|
end
|
142
147
|
end
|
143
148
|
|
@@ -163,6 +168,20 @@ describe AdequateExposure::Controller do
|
|
163
168
|
end
|
164
169
|
end
|
165
170
|
|
171
|
+
context "find_by" do
|
172
|
+
it "throws and error when using with :find" do
|
173
|
+
action = ->{ expose :thing, find: :foo, find_by: :bar }
|
174
|
+
expect(&action).to raise_error(ArgumentError, "Using :find_by option with :find doesn't make sense")
|
175
|
+
end
|
176
|
+
|
177
|
+
it "allows to specify what attribute to use for find" do
|
178
|
+
expect(Thing).to receive(:find_by!).with(foo: 10).and_return(42)
|
179
|
+
expose :thing, find_by: :foo
|
180
|
+
controller.params.merge! id: 10
|
181
|
+
expect(controller.thing).to eq(42)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
166
185
|
context "parent option" do
|
167
186
|
context "with scope/model options" do
|
168
187
|
it "throws an error when used with scope option" do
|