testingrecord 0.5 → 0.7
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/testing_record/dsl/builder/filters.rb +17 -3
- data/lib/testing_record/dsl/builder/helpers.rb +10 -7
- data/lib/testing_record/dsl/builder/settings.rb +1 -25
- data/lib/testing_record/model.rb +53 -9
- data/lib/testing_record/version.rb +1 -1
- data/lib/testing_record.rb +18 -0
- metadata +16 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 163d454cbedadbfb903dcfd141aafe10554fb9aa6b8ef2ff8c5c44abe6d1a7b3
|
|
4
|
+
data.tar.gz: bb4fcd7db84017b1032cbf1a362cdddc9fae583b7b71146c6b4019ed7b372288
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1cb9024a7d5dd9cda0f15841e955ae45e4caa508d90c13433be6e70fc12aa75b7ec54cd9f9e1bb04b050e4f7e23408558106a18e67cd64403a20da57184e4057
|
|
7
|
+
data.tar.gz: 0d479648df51da1455edfa5b2b5c4a749cefc6f68e572fd3e9384a8d21b7e097a5a5e3d4a5ae2a049b8338815b07c4a389defbbdb9e0b710bdfbd3fe64c30fa7
|
|
@@ -21,6 +21,21 @@ module TestingRecord
|
|
|
21
21
|
find_by({ email_address: })&.first&.tap { |entity| entity.class.current = entity }
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
# Checks to see whether an entity exists with the provided id
|
|
25
|
+
#
|
|
26
|
+
# @return [Boolean]
|
|
27
|
+
def with_id?(id)
|
|
28
|
+
!with_id(id).nil?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Finds an entity with the provided id
|
|
32
|
+
# If one is found, set it as the current entity
|
|
33
|
+
#
|
|
34
|
+
# @return [TestingRecord::Model, nil]
|
|
35
|
+
def with_id(id)
|
|
36
|
+
find_by({ id: })&.first&.tap { |entity| entity.class.current = entity }
|
|
37
|
+
end
|
|
38
|
+
|
|
24
39
|
private
|
|
25
40
|
|
|
26
41
|
# Finds all entities that match specified attribute values
|
|
@@ -29,9 +44,8 @@ module TestingRecord
|
|
|
29
44
|
def find_by(attributes)
|
|
30
45
|
pool = all
|
|
31
46
|
attributes.each do |key, value|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# AutomationLogger.debug("Filtering User list by #{key}: #{value}")
|
|
47
|
+
TestingRecord.logger.debug("Current user pool size: #{pool.length}")
|
|
48
|
+
TestingRecord.logger.debug("Filtering User list by #{key}: #{value}")
|
|
35
49
|
pool = pool.select { |entity| entity.attributes[key] == value }
|
|
36
50
|
end
|
|
37
51
|
pool
|
|
@@ -6,17 +6,20 @@ module TestingRecord
|
|
|
6
6
|
# [TestingRecord::DSL::Builder::Helpers]
|
|
7
7
|
# Ways in which we can build in extra helper methods from building requests
|
|
8
8
|
module Helpers
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def add_helpers
|
|
13
|
-
attributes.each do |attribute|
|
|
14
|
-
add_presence_helper(attribute)
|
|
15
|
-
end
|
|
9
|
+
# DSL signature to add all helpers - Should be procedurally called in the class definition
|
|
10
|
+
def include_helpers
|
|
11
|
+
@include_helpers = true
|
|
16
12
|
end
|
|
17
13
|
|
|
18
14
|
private
|
|
19
15
|
|
|
16
|
+
# Top level wrapper method that will incrementally add each helper (Currently only one)
|
|
17
|
+
def add_helpers(attributes)
|
|
18
|
+
attributes.each_key do |attribute|
|
|
19
|
+
add_presence_helper(attribute)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
20
23
|
# Add the boolean helper which will perform a check to determine whether...
|
|
21
24
|
# For singular / default categorisations, this checks if one has been set over the default empty value
|
|
22
25
|
# For plural attributes whether the array has any values
|
|
@@ -10,18 +10,7 @@ module TestingRecord
|
|
|
10
10
|
module Settings
|
|
11
11
|
include DSL::Validation::Input
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
# @return [Array<Symbol>]
|
|
16
|
-
def attribute(name)
|
|
17
|
-
attr_reader name
|
|
18
|
-
|
|
19
|
-
attributes << name
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def attributes
|
|
23
|
-
@attributes ||= []
|
|
24
|
-
end
|
|
13
|
+
attr_reader :__primary_key
|
|
25
14
|
|
|
26
15
|
# Create a cache of the entities, named according to the classname
|
|
27
16
|
#
|
|
@@ -40,19 +29,6 @@ module TestingRecord
|
|
|
40
29
|
# @return [Symbol]
|
|
41
30
|
def primary_key(option)
|
|
42
31
|
instance_variable_set(:@__primary_key, option.to_sym)
|
|
43
|
-
define_singleton_method(:__primary_key) { instance_variable_get(:@__primary_key) }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
def add_to_cache(entity)
|
|
49
|
-
self.current = entity
|
|
50
|
-
all << entity
|
|
51
|
-
# TODO: Add log message (Requires adding logger)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def update_cache(entity)
|
|
55
|
-
# TODO: This needs implementing properly
|
|
56
32
|
end
|
|
57
33
|
end
|
|
58
34
|
end
|
data/lib/testing_record/model.rb
CHANGED
|
@@ -17,17 +17,39 @@ module TestingRecord
|
|
|
17
17
|
attr_accessor :current
|
|
18
18
|
|
|
19
19
|
# Creates an instance of the model
|
|
20
|
-
# -> Adding it to the cache if caching is enabled
|
|
21
20
|
# -> Creating iVar values for each attribute that was provided
|
|
21
|
+
# -> Adding it to the cache if caching is enabled
|
|
22
22
|
#
|
|
23
23
|
# @return [TestingRecord::Model]
|
|
24
|
-
def create(attributes
|
|
24
|
+
def create(attributes)
|
|
25
25
|
new(attributes).tap do |entity|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
configure_data(entity, attributes)
|
|
27
|
+
add_helpers(attributes) if entity.class.instance_variable_get(:@include_helpers)
|
|
28
|
+
cache_entity(entity)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Deletes the instance of the model from the cache (Does nothing if caching is disabled)
|
|
33
|
+
#
|
|
34
|
+
# @return [TestingRecord::Model]
|
|
35
|
+
def delete(entity)
|
|
36
|
+
all.delete(entity) if respond_to?(:all)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def cache_entity(entity)
|
|
42
|
+
return unless respond_to?(:all)
|
|
43
|
+
|
|
44
|
+
self.current = entity
|
|
45
|
+
all << entity
|
|
46
|
+
TestingRecord.logger.debug("Entity: #{entity} added to cache")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def configure_data(entity, attributes)
|
|
50
|
+
attributes.each do |attribute_key, attribute_value|
|
|
51
|
+
entity.instance_variable_set("@#{attribute_key}", attribute_value)
|
|
52
|
+
entity.class.attr_reader attribute_key
|
|
31
53
|
end
|
|
32
54
|
end
|
|
33
55
|
end
|
|
@@ -36,21 +58,43 @@ module TestingRecord
|
|
|
36
58
|
@attributes = attributes
|
|
37
59
|
end
|
|
38
60
|
|
|
61
|
+
# View the entity in question in a readable format. Displays all iVars and their values (Primary Key first if set)
|
|
62
|
+
#
|
|
63
|
+
# @return [String]
|
|
39
64
|
def inspect
|
|
65
|
+
reorder_attributes_for_inspect!
|
|
40
66
|
"#<#{self.class.name} #{attributes.map { |k, v| "@#{k}=#{v.inspect}" }.join(', ')}>"
|
|
41
67
|
end
|
|
42
68
|
|
|
69
|
+
# Functionally equivalent to `inspect`
|
|
70
|
+
#
|
|
71
|
+
# @return [String]
|
|
43
72
|
def to_s
|
|
44
73
|
inspect
|
|
45
74
|
end
|
|
46
75
|
|
|
76
|
+
# Updates an entity (instance), of a model
|
|
77
|
+
# -> Updating iVar values for each attribute that was provided
|
|
78
|
+
# -> It will **not** create new reader methods for new variables added
|
|
79
|
+
#
|
|
80
|
+
# @return [TestingRecord::Model]
|
|
47
81
|
def update(attrs)
|
|
48
82
|
attrs.each do |key, value|
|
|
49
|
-
# TODO: Once logger is implemented this needs modifying to output a log message
|
|
50
|
-
# AutomationLogger.debug("Updating '#{key}' on current User to be '#{value}'")
|
|
51
83
|
attributes[key] = value
|
|
52
84
|
instance_variable_set("@#{key}", value)
|
|
85
|
+
TestingRecord.logger.info("Updated '#{key}' on current #{self.class} entity to be '#{value}'")
|
|
53
86
|
end
|
|
87
|
+
self
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def reorder_attributes_for_inspect!
|
|
93
|
+
return unless self.class.__primary_key
|
|
94
|
+
return if attributes.keys.first == self.class.__primary_key
|
|
95
|
+
|
|
96
|
+
pk_value = attributes.delete(self.class.__primary_key)
|
|
97
|
+
@attributes = { self.class.__primary_key => pk_value }.merge(attributes)
|
|
54
98
|
end
|
|
55
99
|
end
|
|
56
100
|
end
|
data/lib/testing_record.rb
CHANGED
|
@@ -32,5 +32,23 @@ module TestingRecord
|
|
|
32
32
|
def log_path=(logdev)
|
|
33
33
|
logger.reopen(logdev)
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
# To enable full logging (This uses the Ruby API, so can accept any of a
|
|
37
|
+
# Symbol / String / Integer as an input
|
|
38
|
+
# TestingRecord.log_level = :DEBUG
|
|
39
|
+
# TestingRecord.log_level = 'DEBUG'
|
|
40
|
+
# TestingRecord.log_level = 0
|
|
41
|
+
#
|
|
42
|
+
# To disable all logging
|
|
43
|
+
# TestingRecord.log_level = :UNKNOWN
|
|
44
|
+
def log_level=(value)
|
|
45
|
+
logger.level = value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# To query what level is being logged
|
|
49
|
+
# TestingRecord.log_level # => :DEBUG # By default
|
|
50
|
+
def log_level
|
|
51
|
+
%i[DEBUG INFO WARN ERROR FATAL UNKNOWN][logger.level]
|
|
52
|
+
end
|
|
35
53
|
end
|
|
36
54
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: testingrecord
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.7'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luke Hill
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-03-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: automation_helpers
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5'
|
|
20
|
+
- - "<"
|
|
18
21
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
22
|
+
version: '7'
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '5'
|
|
30
|
+
- - "<"
|
|
25
31
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
32
|
+
version: '7'
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: logger
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,14 +64,14 @@ dependencies:
|
|
|
58
64
|
requirements:
|
|
59
65
|
- - "~>"
|
|
60
66
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 1.
|
|
67
|
+
version: 1.85.0
|
|
62
68
|
type: :development
|
|
63
69
|
prerelease: false
|
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
71
|
requirements:
|
|
66
72
|
- - "~>"
|
|
67
73
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 1.
|
|
74
|
+
version: 1.85.0
|
|
69
75
|
- !ruby/object:Gem::Dependency
|
|
70
76
|
name: rubocop-performance
|
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,14 +92,14 @@ dependencies:
|
|
|
86
92
|
requirements:
|
|
87
93
|
- - "~>"
|
|
88
94
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 3.
|
|
95
|
+
version: 3.9.0
|
|
90
96
|
type: :development
|
|
91
97
|
prerelease: false
|
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
99
|
requirements:
|
|
94
100
|
- - "~>"
|
|
95
101
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 3.
|
|
102
|
+
version: 3.9.0
|
|
97
103
|
description: |-
|
|
98
104
|
Use metaprogrammed cache-models to store data you create on-the-fly. Access and retrieve references to data \
|
|
99
105
|
created from any place inside your tests.
|