active-fixtures 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/active-fixtures.rb +4 -0
- data/lib/active-fixtures/context.rb +22 -0
- data/lib/active-fixtures/resource.rb +1 -15
- data/lib/active-fixtures/rspec.rb +1 -0
- data/lib/active-fixtures/state_builder.rb +10 -0
- data/lib/active-fixtures/time.rb +16 -0
- data/lib/active-fixtures/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb9b6ca8e5e19862750be9fb2a2ebc12be640bd
|
4
|
+
data.tar.gz: cbebe7c918bfb00b824a282b24ca935787c3309b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae89f016fb515ce79cf08e7bdc25bdb1f78aa3559df9cb389bddb451e1ac0330c734e5cc70b252b8e0a60ac765896be3ef0d7ffa0efcabbd6d270ec51a29806
|
7
|
+
data.tar.gz: 694ebbbd72fd4d53a3266fd836ae12ed424b961876891f4b1105172ca8b7f18e4a675b67eb51973e29eb1894d311aa5a853b7e2cb5d617d99a4f23e4d14b0bcd
|
data/README.md
CHANGED
@@ -172,6 +172,34 @@ it 'should pass' do
|
|
172
172
|
end
|
173
173
|
```
|
174
174
|
|
175
|
+
### Active time
|
176
|
+
Lets stop to use the magic time moments for time freezing and traveling.
|
177
|
+
Use the `named` time moments:
|
178
|
+
```ruby
|
179
|
+
ActiveFixtures.populate(:default) do
|
180
|
+
time(:today) { Time.new(1983, 1, 2, 3, 4) }
|
181
|
+
time(:yesterday) { af_time(:today) - 1.day }
|
182
|
+
time(:week_ago) { af_time(:today) - 7.days }
|
183
|
+
|
184
|
+
resource(:invited_admin) {
|
185
|
+
af_time(:week_ago) {
|
186
|
+
AFUser.create(login: 'new_user@lvh.me')
|
187
|
+
}
|
188
|
+
}
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
In the tests:
|
193
|
+
```ruby
|
194
|
+
describe 'Users' do
|
195
|
+
around { |example|
|
196
|
+
af_time(:today) { example.run }
|
197
|
+
}
|
198
|
+
|
199
|
+
it 'should pass' do; end
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
175
203
|
### How it works
|
176
204
|
ActiveFixtures work fairly, but effectively.
|
177
205
|
|
data/lib/active-fixtures.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'active-fixtures/version'
|
2
2
|
require 'active-fixtures/railtie'
|
3
3
|
require 'active_attr'
|
4
|
+
require 'timecop'
|
4
5
|
|
5
6
|
module ActiveFixtures
|
7
|
+
autoload :Context, 'active-fixtures/context'
|
8
|
+
|
6
9
|
autoload :Resource, 'active-fixtures/resource'
|
7
10
|
|
8
11
|
autoload :Session, 'active-fixtures/session'
|
12
|
+
autoload :Time, 'active-fixtures/time'
|
9
13
|
autoload :StateBuilder, 'active-fixtures/state_builder'
|
10
14
|
autoload :State, 'active-fixtures/state'
|
11
15
|
autoload :StateDumper, 'active-fixtures/state_dumper'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveFixtures
|
2
|
+
module Context
|
3
|
+
|
4
|
+
def self.extended(klass)
|
5
|
+
klass.instance_eval do
|
6
|
+
delegate :context, to: :class
|
7
|
+
define_method(:method_missing, &method(:method_missing))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def context
|
12
|
+
RSpec.current_example.example_group_instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
context.respond_to?(method) ?
|
17
|
+
context.public_send(method, *args, &block) :
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -1,25 +1,11 @@
|
|
1
1
|
module ActiveFixtures
|
2
2
|
class Resource
|
3
|
+
extend Context
|
3
4
|
include ActiveAttr::Model
|
4
5
|
|
5
|
-
delegate :context, to: :class
|
6
|
-
|
7
6
|
def self.[](name)
|
8
7
|
ActiveFixtures.current_state.read_entity(name, self)
|
9
8
|
end
|
10
9
|
|
11
|
-
private
|
12
|
-
|
13
|
-
def self.context
|
14
|
-
RSpec.current_example.example_group_instance
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.method_missing(method, *args, &block)
|
18
|
-
context.respond_to?(method) ?
|
19
|
-
context.public_send(method, *args, &block) :
|
20
|
-
super
|
21
|
-
end
|
22
|
-
|
23
|
-
define_method(:method_missing, &method(:method_missing))
|
24
10
|
end
|
25
11
|
end
|
@@ -2,6 +2,7 @@ Dir[Rails.root.join('spec/active_fixtures/**/*.rb')].each { |f| require f }
|
|
2
2
|
|
3
3
|
RSpec.configure do |config|
|
4
4
|
config.include ActiveFixtures::Session::Helper
|
5
|
+
config.include ActiveFixtures::Time::Helper
|
5
6
|
|
6
7
|
config.around(:each) do |example|
|
7
8
|
ActiveFixtures.prepare!(:default)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module ActiveFixtures
|
2
2
|
class StateBuilder
|
3
|
+
extend Context
|
4
|
+
|
3
5
|
attr_accessor :steps
|
4
6
|
|
5
7
|
def initialize(block)
|
@@ -26,6 +28,10 @@ module ActiveFixtures
|
|
26
28
|
steps << {type: :session, name: name, block: block}
|
27
29
|
end
|
28
30
|
|
31
|
+
def time(name, &block)
|
32
|
+
steps << {type: :time, name: name, block: block}
|
33
|
+
end
|
34
|
+
|
29
35
|
def build_resource(build_step)
|
30
36
|
build_step[:block].call
|
31
37
|
end
|
@@ -33,5 +39,9 @@ module ActiveFixtures
|
|
33
39
|
def build_session(build_step)
|
34
40
|
Session.new(build_step)
|
35
41
|
end
|
42
|
+
|
43
|
+
def build_time(build_step)
|
44
|
+
Time.new(moment: build_step[:block].call)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fixtures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Tokarenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: timecop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: active-fixtures provides the way how to populate the server state (DB,
|
42
56
|
sessions) as an application user but not as programmer.
|
43
57
|
email: private.tokarenko.sergey@gmail.com
|
@@ -48,6 +62,7 @@ files:
|
|
48
62
|
- LICENSE
|
49
63
|
- README.md
|
50
64
|
- lib/active-fixtures.rb
|
65
|
+
- lib/active-fixtures/context.rb
|
51
66
|
- lib/active-fixtures/railtie.rb
|
52
67
|
- lib/active-fixtures/resource.rb
|
53
68
|
- lib/active-fixtures/rspec.rb
|
@@ -55,6 +70,7 @@ files:
|
|
55
70
|
- lib/active-fixtures/state.rb
|
56
71
|
- lib/active-fixtures/state_builder.rb
|
57
72
|
- lib/active-fixtures/state_dumper.rb
|
73
|
+
- lib/active-fixtures/time.rb
|
58
74
|
- lib/active-fixtures/version.rb
|
59
75
|
- lib/tasks/active_fixtures.rake
|
60
76
|
homepage: https://github.com/Anadea/active-fixtures
|