testingrecord 0.4.1 → 0.6
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 +56 -0
- data/lib/testing_record/dsl/builder/settings.rb +15 -21
- data/lib/testing_record/dsl/builder.rb +1 -0
- data/lib/testing_record/logger.rb +24 -0
- data/lib/testing_record/model.rb +55 -3
- data/lib/testing_record/version.rb +1 -1
- data/lib/testing_record.rb +27 -1
- metadata +33 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 544af1645ff65521c916a5ab879ad49711e9ef0aa18e58360ebc175672fc22bc
|
|
4
|
+
data.tar.gz: 139ed45cbfdc8f24cd77a88538a46962457b7c3c78e94142e501633d8ce603a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0f8a9a6b9a1ec1d238038ee9bd3fcae8441d4488e1328fb8bf1693015ff309613a8ffdfb70c0bf12dc2189f1aaa9f5c83ea1cc7231bdf5e2dc63641cb865d94
|
|
7
|
+
data.tar.gz: cf54b5e657d77a034e631a4b1c5bb35cd21fe88f7281c26b317f0f832b26b8dedee3b5b1015fd5f453afb33a5479736c6722fba3d703fd36dbd77c98406618b9
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TestingRecord
|
|
4
|
+
module DSL
|
|
5
|
+
module Builder
|
|
6
|
+
# [TestingRecord::DSL::Builder::Filters]
|
|
7
|
+
# Ways in which we can filter our collection to find specific models
|
|
8
|
+
module Filters
|
|
9
|
+
# Checks to see whether an entity exists with the provided attributes
|
|
10
|
+
#
|
|
11
|
+
# @return [Boolean]
|
|
12
|
+
def exists?(attributes)
|
|
13
|
+
find_by(attributes).any?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Finds an entity with the provided email address
|
|
17
|
+
# If one is found, set it as the current entity
|
|
18
|
+
#
|
|
19
|
+
# @return [TestingRecord::Model, nil]
|
|
20
|
+
def with_email(email_address)
|
|
21
|
+
find_by({ email_address: })&.first&.tap { |entity| entity.class.current = entity }
|
|
22
|
+
end
|
|
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
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# Finds all entities that match specified attribute values
|
|
42
|
+
#
|
|
43
|
+
# @return [Array<TestingRecord::Model>]
|
|
44
|
+
def find_by(attributes)
|
|
45
|
+
pool = all
|
|
46
|
+
attributes.each do |key, value|
|
|
47
|
+
TestingRecord.logger.debug("Current user pool size: #{pool.length}")
|
|
48
|
+
TestingRecord.logger.debug("Filtering User list by #{key}: #{value}")
|
|
49
|
+
pool = pool.select { |entity| entity.attributes[key] == value }
|
|
50
|
+
end
|
|
51
|
+
pool
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -10,16 +10,7 @@ module TestingRecord
|
|
|
10
10
|
module Settings
|
|
11
11
|
include DSL::Validation::Input
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
# @return [Symbol]
|
|
16
|
-
def caching(option)
|
|
17
|
-
raise Error, 'Invalid caching option, must be :enabled or :disabled' unless caching_valid?(option)
|
|
18
|
-
return unless option == :enabled
|
|
19
|
-
|
|
20
|
-
instance_variable_set(ivar_name, [])
|
|
21
|
-
define_singleton_method(cache_name) { instance_variable_get(ivar_name) }
|
|
22
|
-
end
|
|
13
|
+
attr_reader :__primary_key
|
|
23
14
|
|
|
24
15
|
# Sets an attribute on the model
|
|
25
16
|
#
|
|
@@ -34,20 +25,23 @@ module TestingRecord
|
|
|
34
25
|
@attributes ||= []
|
|
35
26
|
end
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
end
|
|
28
|
+
# Create a cache of the entities, named according to the classname
|
|
29
|
+
#
|
|
30
|
+
# @return [Symbol]
|
|
31
|
+
def caching(option)
|
|
32
|
+
raise Error, 'Invalid caching option, must be :enabled or :disabled' unless caching_valid?(option)
|
|
33
|
+
return unless option == :enabled
|
|
44
34
|
|
|
45
|
-
|
|
46
|
-
:
|
|
35
|
+
instance_variable_set(:@all, [])
|
|
36
|
+
define_singleton_method(:all) { instance_variable_get(:@all) }
|
|
47
37
|
end
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
# Sets the primary key value of all entities - used for deduplication
|
|
40
|
+
# TODO: Use this for deduplication proper
|
|
41
|
+
#
|
|
42
|
+
# @return [Symbol]
|
|
43
|
+
def primary_key(option)
|
|
44
|
+
instance_variable_set(:@__primary_key, option.to_sym)
|
|
51
45
|
end
|
|
52
46
|
end
|
|
53
47
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
|
|
5
|
+
module TestingRecord
|
|
6
|
+
#
|
|
7
|
+
# @api private
|
|
8
|
+
#
|
|
9
|
+
class Logger
|
|
10
|
+
#
|
|
11
|
+
# Generate the Logger used in the gem
|
|
12
|
+
#
|
|
13
|
+
def self.create(output = $stdout)
|
|
14
|
+
logger = ::Logger.new(output)
|
|
15
|
+
logger.progname = 'Testing Record'
|
|
16
|
+
logger.level = :DEBUG
|
|
17
|
+
logger.formatter = proc do |severity, time, progname, msg|
|
|
18
|
+
"#{time.strftime('%F %T')} - #{severity} - #{progname} - #{msg}\n"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
logger
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/testing_record/model.rb
CHANGED
|
@@ -7,6 +7,7 @@ module TestingRecord
|
|
|
7
7
|
# The top level Model. Most of the behaviours specified here are fairly rudimentary ones that will then
|
|
8
8
|
# include other behaviour(s), from the included modules
|
|
9
9
|
class Model
|
|
10
|
+
extend DSL::Builder::Filters
|
|
10
11
|
extend DSL::Builder::Helpers
|
|
11
12
|
extend DSL::Builder::Settings
|
|
12
13
|
|
|
@@ -16,23 +17,74 @@ module TestingRecord
|
|
|
16
17
|
attr_accessor :current
|
|
17
18
|
|
|
18
19
|
# Creates an instance of the model
|
|
19
|
-
# -> Adding it to the cache if caching is enabled
|
|
20
20
|
# -> Creating iVar values for each attribute that was provided
|
|
21
|
+
# -> Adding it to the cache if caching is enabled
|
|
21
22
|
#
|
|
22
23
|
# @return [TestingRecord::Model]
|
|
23
24
|
def create(attributes = self.attributes)
|
|
24
25
|
new(attributes).tap do |entity|
|
|
25
26
|
attributes.each do |attribute_key, attribute_value|
|
|
26
27
|
entity.instance_variable_set("@#{attribute_key}", attribute_value)
|
|
27
|
-
attr_reader attribute_key
|
|
28
|
+
entity.class.attr_reader attribute_key
|
|
28
29
|
end
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
break entity unless respond_to?(:all)
|
|
32
|
+
|
|
33
|
+
self.current = entity
|
|
34
|
+
all << entity
|
|
35
|
+
TestingRecord.logger.debug("Entity: #{entity} added to cache")
|
|
30
36
|
end
|
|
31
37
|
end
|
|
38
|
+
|
|
39
|
+
# Deletes the instance of the model from the cache (Does nothing if caching is disabled)
|
|
40
|
+
#
|
|
41
|
+
# @return [TestingRecord::Model]
|
|
42
|
+
def delete(entity)
|
|
43
|
+
all.delete(entity) if respond_to?(:all)
|
|
44
|
+
end
|
|
32
45
|
end
|
|
33
46
|
|
|
34
47
|
def initialize(attributes = {})
|
|
35
48
|
@attributes = attributes
|
|
36
49
|
end
|
|
50
|
+
|
|
51
|
+
# View the entity in question in a readable format. Displays all iVars and their values (Primary Key first if set)
|
|
52
|
+
#
|
|
53
|
+
# @return [String]
|
|
54
|
+
def inspect
|
|
55
|
+
reorder_attributes_for_inspect!
|
|
56
|
+
"#<#{self.class.name} #{attributes.map { |k, v| "@#{k}=#{v.inspect}" }.join(', ')}>"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Functionally equivalent to `inspect`
|
|
60
|
+
#
|
|
61
|
+
# @return [String]
|
|
62
|
+
def to_s
|
|
63
|
+
inspect
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Updates an entity (instance), of a model
|
|
67
|
+
# -> Updating iVar values for each attribute that was provided
|
|
68
|
+
# -> It will **not** create new reader methods for new variables added
|
|
69
|
+
#
|
|
70
|
+
# @return [TestingRecord::Model]
|
|
71
|
+
def update(attrs)
|
|
72
|
+
attrs.each do |key, value|
|
|
73
|
+
attributes[key] = value
|
|
74
|
+
instance_variable_set("@#{key}", value)
|
|
75
|
+
TestingRecord.logger.info("Updated '#{key}' on current #{self.class} entity to be '#{value}'")
|
|
76
|
+
end
|
|
77
|
+
self
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def reorder_attributes_for_inspect!
|
|
83
|
+
return unless self.class.__primary_key
|
|
84
|
+
return if attributes.keys.first == self.class.__primary_key
|
|
85
|
+
|
|
86
|
+
pk_value = attributes.delete(self.class.__primary_key)
|
|
87
|
+
@attributes = { self.class.__primary_key => pk_value }.merge(attributes)
|
|
88
|
+
end
|
|
37
89
|
end
|
|
38
90
|
end
|
data/lib/testing_record.rb
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'testing_record/dsl'
|
|
4
|
+
require_relative 'testing_record/logger'
|
|
4
5
|
require_relative 'testing_record/model'
|
|
5
6
|
require_relative 'testing_record/version'
|
|
6
7
|
|
|
8
|
+
# {TestingRecord} namespace
|
|
7
9
|
module TestingRecord
|
|
10
|
+
# Generic TestingRecord error. Will be extended in the future
|
|
8
11
|
class Error < StandardError; end
|
|
9
|
-
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
# The Testing Record logger object - This is called automatically in several
|
|
15
|
+
# locations and will log messages according to the normal Ruby protocol
|
|
16
|
+
#
|
|
17
|
+
# This logger object can also be used to manually log messages
|
|
18
|
+
#
|
|
19
|
+
# To Manually log a message
|
|
20
|
+
# TestingRecord.logger.info('Information')
|
|
21
|
+
# TestingRecord.logger.debug('Input debug message')
|
|
22
|
+
#
|
|
23
|
+
# By default the logger will output all messages to $stdout, but can be
|
|
24
|
+
# altered to log to a file or another IO location by calling `.log_path=`
|
|
25
|
+
def logger
|
|
26
|
+
@logger ||= Logger.create
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# This writer method allows you to configure where you want the testingrecord logs to be sent to (Default is $stdout)
|
|
30
|
+
#
|
|
31
|
+
# Example: TestingRecord.log_path = 'testingrecord.log' would save all log messages to `./testingrecord.log`
|
|
32
|
+
def log_path=(logdev)
|
|
33
|
+
logger.reopen(logdev)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
10
36
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: testingrecord
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: '0.6'
|
|
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-02-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: automation_helpers
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '7'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '5'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '7'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: logger
|
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
|
16
36
|
requirements:
|
|
17
37
|
- - "~>"
|
|
18
38
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
39
|
+
version: '1.7'
|
|
20
40
|
type: :runtime
|
|
21
41
|
prerelease: false
|
|
22
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
43
|
requirements:
|
|
24
44
|
- - "~>"
|
|
25
45
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
46
|
+
version: '1.7'
|
|
27
47
|
- !ruby/object:Gem::Dependency
|
|
28
48
|
name: rspec
|
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -44,14 +64,14 @@ dependencies:
|
|
|
44
64
|
requirements:
|
|
45
65
|
- - "~>"
|
|
46
66
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 1.
|
|
67
|
+
version: 1.84.0
|
|
48
68
|
type: :development
|
|
49
69
|
prerelease: false
|
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
71
|
requirements:
|
|
52
72
|
- - "~>"
|
|
53
73
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 1.
|
|
74
|
+
version: 1.84.0
|
|
55
75
|
- !ruby/object:Gem::Dependency
|
|
56
76
|
name: rubocop-performance
|
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,16 +92,17 @@ dependencies:
|
|
|
72
92
|
requirements:
|
|
73
93
|
- - "~>"
|
|
74
94
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 3.
|
|
95
|
+
version: 3.9.0
|
|
76
96
|
type: :development
|
|
77
97
|
prerelease: false
|
|
78
98
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
99
|
requirements:
|
|
80
100
|
- - "~>"
|
|
81
101
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 3.
|
|
83
|
-
description:
|
|
84
|
-
|
|
102
|
+
version: 3.9.0
|
|
103
|
+
description: |-
|
|
104
|
+
Use metaprogrammed cache-models to store data you create on-the-fly. Access and retrieve references to data \
|
|
105
|
+
created from any place inside your tests.
|
|
85
106
|
email:
|
|
86
107
|
- lukehill_uk@hotmail.com
|
|
87
108
|
executables: []
|
|
@@ -93,10 +114,12 @@ files:
|
|
|
93
114
|
- lib/testing_record.rb
|
|
94
115
|
- lib/testing_record/dsl.rb
|
|
95
116
|
- lib/testing_record/dsl/builder.rb
|
|
117
|
+
- lib/testing_record/dsl/builder/filters.rb
|
|
96
118
|
- lib/testing_record/dsl/builder/helpers.rb
|
|
97
119
|
- lib/testing_record/dsl/builder/settings.rb
|
|
98
120
|
- lib/testing_record/dsl/validation.rb
|
|
99
121
|
- lib/testing_record/dsl/validation/input.rb
|
|
122
|
+
- lib/testing_record/logger.rb
|
|
100
123
|
- lib/testing_record/model.rb
|
|
101
124
|
- lib/testing_record/version.rb
|
|
102
125
|
homepage: https://github.com/site-prism/testingrecord
|