File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -655,6 +655,11 @@ def <=> other
655
655
end
656
656
include Comparable
657
657
658
+ # Hash serialization helper for use back into other libraries (Like Selenium)
659
+ def to_h
660
+ PERSISTENT_PROPERTIES . each_with_object ( { } ) { |property , hash | hash [ property . to_sym ] = instance_variable_get ( "@#{ property } " ) }
661
+ end
662
+
658
663
# YAML serialization helper for Syck.
659
664
def to_yaml_properties
660
665
PERSISTENT_PROPERTIES . map { |name | "@#{ name } " }
Original file line number Diff line number Diff line change @@ -1168,4 +1168,45 @@ def test_s_path_match?
1168
1168
assert_equal true , HTTP ::Cookie . path_match? ( '/admin' , '/admin/' )
1169
1169
assert_equal true , HTTP ::Cookie . path_match? ( '/admin' , '/admin/index' )
1170
1170
end
1171
+
1172
+ def test_to_h
1173
+ now = Time . now
1174
+
1175
+ cookie = HTTP ::Cookie . new ( cookie_values . merge ( { max_age : 3600 , created_at : now , accessed_at : now } ) )
1176
+ expected_hash =
1177
+ {
1178
+ accessed_at : now ,
1179
+ created_at : now ,
1180
+ domain : 'rubyforge.org' ,
1181
+ expires : nil ,
1182
+ for_domain : true ,
1183
+ httponly : cookie . httponly? ,
1184
+ max_age : 3600 ,
1185
+ name : 'Foo' ,
1186
+ path : '/' ,
1187
+ secure : cookie . secure? ,
1188
+ value : 'Bar' ,
1189
+ }
1190
+
1191
+ assert_equal expected_hash , cookie . to_h
1192
+
1193
+ # exercise expires/max_age interaction
1194
+ cookie = HTTP ::Cookie . new ( cookie_values . merge ( { expires : now , created_at : now , accessed_at : now } ) )
1195
+ expected_hash =
1196
+ {
1197
+ accessed_at : now ,
1198
+ created_at : now ,
1199
+ domain : 'rubyforge.org' ,
1200
+ expires : now ,
1201
+ for_domain : true ,
1202
+ httponly : cookie . httponly? ,
1203
+ max_age : nil ,
1204
+ name : 'Foo' ,
1205
+ path : '/' ,
1206
+ secure : cookie . secure? ,
1207
+ value : 'Bar' ,
1208
+ }
1209
+
1210
+ assert_equal expected_hash , cookie . to_h
1211
+ end
1171
1212
end
You can’t perform that action at this time.
0 commit comments