initial-test-data 0.5.0 → 0.6.0.beta
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1bf27ea213a7bc0c569b4aafee43d63322da79c
|
4
|
+
data.tar.gz: 58c059b207f0b088f3eeebe7988f75604d17a5e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0746355dd9578d1e0397fb8fde9cf464b0ba88ceda4c983f58adedde632756891838b806cf3e80135ad0accf7cf3733ad0062ea1dda9befb0d50116d6f1edcd2
|
7
|
+
data.tar.gz: 76478cb5e62ab7664bcbbf8f048f72b62d594bf3b95103036609abe82d9391e25d8361aa263671ce22be35055d948e19c013c1b426ba23890418a1aaf1d6bcb6
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ in the _test_ environment
|
|
14
14
|
it is rather cumbersome to construct a real (often complicated) data structure
|
15
15
|
from YAML files.
|
16
16
|
|
17
|
-
The `initial-test-data` provides a
|
17
|
+
The `initial-test-data` provides a way to create a test fixture using Active Record, Factory Girl, etc.
|
18
18
|
|
19
19
|
It also offers utility methods called `store` and `fetch`
|
20
20
|
to register and access the initialized data.
|
@@ -158,9 +158,9 @@ end
|
|
158
158
|
|
159
159
|
You should use relative paths from the `Rails.root`.
|
160
160
|
|
161
|
-
#### `
|
161
|
+
#### `quiet`
|
162
162
|
|
163
|
-
Specify `true` to this option in order to suppress the
|
163
|
+
Specify `true` to this option in order to suppress the info messages from the
|
164
164
|
`initial-test-data`.
|
165
165
|
|
166
166
|
### Utility methods: `store` and `fetch`
|
@@ -187,7 +187,7 @@ Then, you can get this record with `fetch` method in the test scripts:
|
|
187
187
|
|
188
188
|
```ruby
|
189
189
|
customer = fetch(:customer, :john)
|
190
|
-
|
190
|
+
shop_owner = fetch(:shop_owner, :mike)
|
191
191
|
```
|
192
192
|
|
193
193
|
The fetch method treats `:john` and `"john"` as the same key.
|
data/lib/initial-test-data.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module FactoryGirl
|
4
|
+
class Sequence
|
5
|
+
def initialize_with_patch(name, *args, &proc)
|
6
|
+
options = args.extract_options!
|
7
|
+
enumerator = args.first || InitialTestData::SequenceEnumerator.new(name)
|
8
|
+
initialize_without_patch(name, enumerator, options, &proc)
|
9
|
+
end
|
10
|
+
alias_method_chain :initialize, :patch
|
11
|
+
end
|
12
|
+
end
|
@@ -29,6 +29,7 @@ module InitialTestData
|
|
29
29
|
end
|
30
30
|
|
31
31
|
if needs_reinitialization
|
32
|
+
SequenceEnumerator.reset
|
32
33
|
RECORD_IDS.clear
|
33
34
|
initialize_data
|
34
35
|
|
@@ -40,6 +41,7 @@ module InitialTestData
|
|
40
41
|
File.open(record_ids_path, 'w') do |f|
|
41
42
|
f.write RECORD_IDS.to_hash.to_yaml
|
42
43
|
end
|
44
|
+
SequenceEnumerator.save
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module InitialTestData
|
2
|
+
class SequenceEnumerator
|
3
|
+
def initialize(name)
|
4
|
+
@name = name
|
5
|
+
@index = self.class.register(name, self)
|
6
|
+
@value = self.class.initial_value_for(name, @index)
|
7
|
+
end
|
8
|
+
|
9
|
+
def peek
|
10
|
+
@value
|
11
|
+
end
|
12
|
+
|
13
|
+
def next
|
14
|
+
@value = @value.next
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
@value = 1
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def enumerators
|
23
|
+
@enumerators ||= {}
|
24
|
+
@enumerators
|
25
|
+
end
|
26
|
+
|
27
|
+
def register(name, enumerator)
|
28
|
+
enumerators[name.to_s] ||= []
|
29
|
+
enumerators[name.to_s] << enumerator
|
30
|
+
enumerators[name.to_s].size - 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def initial_value_for(name, index)
|
34
|
+
cached_values_for(name)[index] || 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset
|
38
|
+
enumerators.each_value do |enums|
|
39
|
+
enums.each do |enum|
|
40
|
+
enum.reset
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def save
|
46
|
+
hash = {}
|
47
|
+
enumerators.each do |name, enums|
|
48
|
+
hash[name] = enums.map(&:peek)
|
49
|
+
end
|
50
|
+
File.open(data_path, 'w') do |f|
|
51
|
+
f.write hash.to_yaml
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def cached_values_for(name)
|
57
|
+
if @cached_values
|
58
|
+
return @cached_values[name.to_s] || []
|
59
|
+
end
|
60
|
+
@cached_values = {}
|
61
|
+
if File.exists?(data_path)
|
62
|
+
begin
|
63
|
+
@cached_values.merge! YAML.load_file(data_path)
|
64
|
+
rescue SyntaxError
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@cached_values[name.to_s] || []
|
68
|
+
end
|
69
|
+
|
70
|
+
def data_path
|
71
|
+
Rails.root.join('tmp', 'initial_data_enumerators.yml')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: initial-test-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsutomu KURODA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -98,6 +98,20 @@ dependencies:
|
|
98
98
|
- - "~>"
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '1.3'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: factory_girl
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '4.5'
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '4.5'
|
101
115
|
description: initial-test-data provides a way to create a test fixture using Active
|
102
116
|
Record, Factory Girl, etc.
|
103
117
|
email: t-kuroda@oiax.jp
|
@@ -109,7 +123,9 @@ files:
|
|
109
123
|
- MIT-LICENSE
|
110
124
|
- README.md
|
111
125
|
- lib/initial-test-data.rb
|
126
|
+
- lib/initial-test-data/factory_girl_patches.rb
|
112
127
|
- lib/initial-test-data/initial_test_data.rb
|
128
|
+
- lib/initial-test-data/sequence_enumerator.rb
|
113
129
|
- lib/initial-test-data/utilities.rb
|
114
130
|
homepage: https://github.com/oiax/initial-test-data
|
115
131
|
licenses:
|
@@ -126,9 +142,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
142
|
version: '2.0'
|
127
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
144
|
requirements:
|
129
|
-
- - "
|
145
|
+
- - ">"
|
130
146
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
147
|
+
version: 1.3.1
|
132
148
|
requirements: []
|
133
149
|
rubyforge_project:
|
134
150
|
rubygems_version: 2.5.1
|