Module: Familia::Validation::FamiliaTestHelpers
- Includes:
- TestHelpers
- Defined in:
- lib/familia/validation/test_helpers.rb
Overview
Extended test helpers specifically for Familia data types
Instance Method Summary collapse
-
#assert_familia_destroy(obj, &block) ⇒ Object
-
#assert_familia_load(obj_class, identifier, &block) ⇒ Object
-
#assert_familia_save(obj, expected_fields = nil, &block) ⇒ Object
Assert Familia object operations.
-
#assert_list_operation(obj, list_name, operation, *args, &block) ⇒ Object
Assert data type operations.
-
#assert_set_operation(obj, set_name, operation, *args, &block) ⇒ Object
-
#assert_sorted_set_operation(obj, zset_name, operation, *args, &block) ⇒ Object
Methods included from TestHelpers
#any_number, #any_string, #any_value, #assert_atomic_operation, #assert_command_count, #assert_commands_executed, #assert_efficient_commands, #assert_no_redis_commands, #assert_no_transaction_used, #assert_performance_within, #assert_redis_commands, #assert_transaction_used, #capture_redis_commands, #debug_print_commands, #debug_print_performance, #expect_data_type_operation, #expect_horreum_load, #expect_horreum_save, #match_command, #match_pattern, #setup_validation_test, #teardown_validation_test, #with_validation_test
Instance Method Details
#assert_familia_destroy(obj, &block) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/familia/validation/test_helpers.rb', line 390 def assert_familia_destroy(obj, &block) class_name = obj.class.name.split('::').last.downcase identifier = obj.identifier assert_redis_commands do |expect| expect.del("#{class_name}:#{identifier}:object") block.call if block obj.destroy! end end |
#assert_familia_load(obj_class, identifier, &block) ⇒ Object
379 380 381 382 383 384 385 386 387 388 |
# File 'lib/familia/validation/test_helpers.rb', line 379 def assert_familia_load(obj_class, identifier, &block) class_name = obj_class.name.split('::').last.downcase assert_redis_commands do |expect| expect.hgetall("#{class_name}:#{identifier}:object") block.call if block obj_class.new(id: identifier).refresh! end end |
#assert_familia_save(obj, expected_fields = nil, &block) ⇒ Object
Assert Familia object operations
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/familia/validation/test_helpers.rb', line 361 def assert_familia_save(obj, expected_fields = nil, &block) class_name = obj.class.name.split('::').last.downcase identifier = obj.identifier assert_redis_commands do |expect| if expected_fields expected_fields.each do |field, value| expect.hset("#{class_name}:#{identifier}:object", field.to_s, value.to_s) end else expect.match_pattern(/^HSET #{class_name}:#{identifier}:object/) end block.call if block obj.save end end |
#assert_list_operation(obj, list_name, operation, *args, &block) ⇒ Object
Assert data type operations
403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/familia/validation/test_helpers.rb', line 403 def assert_list_operation(obj, list_name, operation, *args, &block) class_name = obj.class.name.split('::').last.downcase identifier = obj.identifier dbkey = "#{class_name}:#{identifier}:#{list_name}" assert_redis_commands do |expect| expect.command(operation.to_s.upcase, dbkey, *args) block.call if block obj.send(list_name).send(operation, *args) end end |
#assert_set_operation(obj, set_name, operation, *args, &block) ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/familia/validation/test_helpers.rb', line 416 def assert_set_operation(obj, set_name, operation, *args, &block) class_name = obj.class.name.split('::').last.downcase identifier = obj.identifier dbkey = "#{class_name}:#{identifier}:#{set_name}" assert_redis_commands do |expect| expect.command(operation.to_s.upcase, dbkey, *args) block.call if block obj.send(set_name).send(operation, *args) end end |
#assert_sorted_set_operation(obj, zset_name, operation, *args, &block) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/familia/validation/test_helpers.rb', line 429 def assert_sorted_set_operation(obj, zset_name, operation, *args, &block) class_name = obj.class.name.split('::').last.downcase identifier = obj.identifier dbkey = "#{class_name}:#{identifier}:#{zset_name}" assert_redis_commands do |expect| expect.command(operation.to_s.upcase, dbkey, *args) block.call if block obj.send(zset_name).send(operation, *args) end end |