File tree Expand file tree Collapse file tree 2 files changed +9
-15
lines changed Expand file tree Collapse file tree 2 files changed +9
-15
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "active_support/callbacks"
4
+ require "active_support/core_ext/object/with"
4
5
require "active_support/core_ext/enumerable"
5
6
require "active_support/core_ext/module/delegation"
6
7
@@ -207,12 +208,8 @@ def initialize
207
208
# end
208
209
# end
209
210
# end
210
- def set ( set_attributes )
211
- old_attributes = compute_attributes ( set_attributes . keys )
212
- assign_attributes ( set_attributes )
213
- yield
214
- ensure
215
- assign_attributes ( old_attributes )
211
+ def set ( attributes , &block )
212
+ with ( **attributes , &block )
216
213
end
217
214
218
215
# Reset all attributes. Should be called before and after actions, when used as a per-request singleton.
@@ -221,14 +218,5 @@ def reset
221
218
self . attributes = { }
222
219
end
223
220
end
224
-
225
- private
226
- def assign_attributes ( new_attributes )
227
- new_attributes . each { |key , value | public_send ( "#{ key } =" , value ) }
228
- end
229
-
230
- def compute_attributes ( keys )
231
- keys . index_with { |key | public_send ( key ) }
232
- end
233
221
end
234
222
end
Original file line number Diff line number Diff line change @@ -144,6 +144,12 @@ def after_teardown
144
144
145
145
assert_equal "world/1" , Current . world
146
146
assert_equal "account/1" , Current . account
147
+
148
+ hash = { world : "world/2" , account : "account/2" }
149
+ Current . set ( hash ) do
150
+ assert_equal "world/2" , Current . world
151
+ assert_equal "account/2" , Current . account
152
+ end
147
153
end
148
154
149
155
test "using keyword arguments" do
You can’t perform that action at this time.
0 commit comments