smash_the_state 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 591b5f213e895130ff25cf2bc2638275d6f89a054abbe01c0fb55ff5c6f3cc84
4
- data.tar.gz: 249752c9f3aa7a7efea1adf1dcc4af85bfe135235bf0d07b6961fb3a5eca2a80
3
+ metadata.gz: 9a4407b73af1d296ca49dc0e0d112e3fd4a497d37e66cc97026bcf75835e8d48
4
+ data.tar.gz: 19c36a89864c088ff0ff068768049dc68c798b57b3b074dd4cd4721f46386abb
5
5
  SHA512:
6
- metadata.gz: c74f691d3f1d7d9e6fe008e67d97b7da9cf24cef2d444a57744c1a4ee41f559358d39d6e1e74f5222f93c5d41c1eb9a53f3a61f9635a0cd522798fc77e0d2395
7
- data.tar.gz: fbf4c5c27f114281a9db33f2d76d64a50f8f42594f1e2a5a84dfce2414893e1728dae5702e0ea8a65ccd4a3c82790ace05cba760e4634f08ab157e8b115c2e91
6
+ metadata.gz: 3054575953e6e59b15a454609698b8346a6a2fab75ee578c94029b895e03568ed0af214db70cd283c7db0eb97954a41d752d8ed4b18898282940a01534969b49
7
+ data.tar.gz: b08cde0d76694574172be59467ffe790013aaa462664182345fb494d84976837102db57c60ba74e0753cda7c1b7925fa85adef77fae15e2eefecf5bb0903b41e
@@ -93,13 +93,20 @@ module SmashTheState
93
93
  step.error_handler = block
94
94
  end
95
95
 
96
- # rubocop:disable Lint/ShadowedException
97
96
  def middleware_class(state, original_state = nil)
98
- middleware_class_block.call(state, original_state).constantize
99
- rescue NameError, NoMethodError
100
- nil
97
+ klass = middleware_class_block.call(state, original_state)
98
+
99
+ case klass
100
+ when Module, Class
101
+ klass
102
+ else
103
+ begin
104
+ klass.constantize if klass.respond_to?(:constantize)
105
+ rescue NameError
106
+ nil
107
+ end
108
+ end
101
109
  end
102
- # rubocop:enable Lint/ShadowedException
103
110
 
104
111
  def add_middleware_step(step_name, options = {})
105
112
  step = Operation::Step.new step_name, options do |state, original_state|
@@ -127,7 +134,9 @@ module SmashTheState
127
134
  def make_original_state(state)
128
135
  return dynamic_schema_step.implementation.call(state, state, run_options) if dynamic_schema?
129
136
 
130
- state.dup
137
+ state.
138
+ dup.
139
+ freeze # don't allow any modifications to the original state
131
140
  end
132
141
 
133
142
  def run_steps(steps_to_run, state)
@@ -1,3 +1,3 @@
1
1
  module SmashTheState
2
- VERSION = "1.4.3".freeze
2
+ VERSION = "1.4.4".freeze
3
3
  end
@@ -204,28 +204,40 @@ describe SmashTheState::Operation::Sequence do
204
204
  end
205
205
 
206
206
  context "with a middleware_class_block" do
207
- it "runs the middleware_class_block, passes in the state, constantizes" do
208
- expect(instance.middleware_class("String")).to eq(String)
207
+ context "that returns a string" do
208
+ it "runs the middleware_class_block, passes in the state, constantizes" do
209
+ expect(instance.middleware_class("String")).to eq(String)
210
+ end
209
211
  end
210
- end
211
212
 
212
- context "with a NameError" do
213
- it "returns nil" do
214
- expect(instance.middleware_class("Whazzat")).to eq(nil)
215
- end
216
- end
213
+ context "that returns a constant" do
214
+ before do
215
+ instance.middleware_class_block = proc do |state|
216
+ state
217
+ end
218
+ end
217
219
 
218
- context "with a NoMethodError" do
219
- let!(:state) { double }
220
+ context "that is a class" do
221
+ let!(:klass) { Class.new }
220
222
 
221
- before do
222
- allow(state).to receive(:to_s) do
223
- raise NoMethodError
223
+ it "runs the middleware_class_block, passes in the state" do
224
+ expect(instance.middleware_class(klass)).to eq(klass)
225
+ end
226
+ end
227
+
228
+ context "that returns a module" do
229
+ let!(:modyule) { Module.new }
230
+
231
+ it "runs the middleware_class_block, passes in the state" do
232
+ expect(instance.middleware_class(modyule)).to eq(modyule)
233
+ end
224
234
  end
225
235
  end
236
+ end
226
237
 
238
+ context "with a NameError" do
227
239
  it "returns nil" do
228
- expect(instance.middleware_class(state)).to eq(nil)
240
+ expect(instance.middleware_class("Whazzat")).to eq(nil)
229
241
  end
230
242
  end
231
243
  end
@@ -254,10 +266,11 @@ describe SmashTheState::Operation::Sequence do
254
266
  instance.add_middleware_step :extra_step
255
267
  end
256
268
 
257
- it "block receives both the state and original state" do
269
+ it "block receives both the state and frozen original state" do
258
270
  instance.middleware_class_block = proc do |state, original_state|
259
271
  expect(state).to eq(baz: "bing")
260
272
  expect(original_state).to eq(foo: "bar")
273
+ expect(original_state.frozen?).to eq(true)
261
274
  end
262
275
 
263
276
  instance.call(foo: "bar")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smash_the_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Connor
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-21 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_attributes
@@ -68,7 +68,7 @@ homepage: https://github.com/ibm-cloud/smash-the-state
68
68
  licenses:
69
69
  - Apache-2.0
70
70
  metadata: {}
71
- post_install_message:
71
+ post_install_message:
72
72
  rdoc_options: []
73
73
  require_paths:
74
74
  - lib
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubygems_version: 3.1.4
87
- signing_key:
87
+ signing_key:
88
88
  specification_version: 4
89
89
  summary: A useful utility for transforming state that provides step sequencing, middleware,
90
90
  and validation.