mongoid-fixture_set 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/lib/mongoid/fixture_set.rb +4 -0
- data/lib/mongoid/fixture_set/test_helper.rb +17 -4
- data/lib/mongoid/fixture_set/version.rb +1 -1
- data/test/load_once_fixtures/tests.yml +2 -0
- data/test/models/test.rb +6 -0
- data/test/mongoid/load_once_test.rb +35 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deee45d8bd6cce4b9e484a8adde2467f0d258a28
|
4
|
+
data.tar.gz: d0e05c7fa2ce09d4685998e213ab8de144c8a20e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95d1a77135689a9bbb3c8e142e43d0e2fd3df43b4f2c15d9b325ab94b8ccff6aacd72039ea867d090cafcd0de29fc2dffa0078a33738581a629120adb369f193
|
7
|
+
data.tar.gz: 8cd816d775042c2bda59152ad2fa5cbe475c907e118a3db5fa8510a526cbb5b8c49776640c61309e27582162977321cd027b4282aff5765e72a43a91f9a53749
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Geoffroy Planquart
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/mongoid/fixture_set.rb
CHANGED
@@ -18,8 +18,10 @@ module Mongoid
|
|
18
18
|
included do
|
19
19
|
class_attribute :fixture_path, :instance_writer => false
|
20
20
|
class_attribute :fixture_set_names
|
21
|
+
class_attribute :load_fixtures_once
|
21
22
|
|
22
23
|
self.fixture_set_names = []
|
24
|
+
self.load_fixtures_once = false
|
23
25
|
end
|
24
26
|
|
25
27
|
module ClassMethods
|
@@ -63,13 +65,21 @@ module Mongoid
|
|
63
65
|
|
64
66
|
def setup_fixtures
|
65
67
|
@fixture_cache = {}
|
68
|
+
@@fixtures_loaded ||= false
|
66
69
|
|
67
|
-
Mongoid::FixtureSet.
|
68
|
-
|
70
|
+
if @@fixtures_loaded && self.class.load_fixtures_once && !Mongoid::FixtureSet.cache_empty?
|
71
|
+
self.class.fixtures(:all)
|
72
|
+
self.loaded_fixtures = Mongoid::FixtureSet.cached_fixtures
|
73
|
+
else
|
74
|
+
Mongoid::FixtureSet.reset_cache
|
75
|
+
self.loaded_fixtures = load_fixtures
|
76
|
+
@@fixtures_loaded = true
|
77
|
+
@loaded_fixtures
|
78
|
+
end
|
69
79
|
end
|
70
80
|
|
71
81
|
def teardown_fixtures
|
72
|
-
Mongoid::FixtureSet.reset_cache
|
82
|
+
Mongoid::FixtureSet.reset_cache unless self.class.load_fixtures_once
|
73
83
|
end
|
74
84
|
|
75
85
|
private
|
@@ -80,7 +90,10 @@ module Mongoid
|
|
80
90
|
fixture_set_names = self.class.fixture_set_names
|
81
91
|
end
|
82
92
|
fixtures = Mongoid::FixtureSet.create_fixtures(fixture_path, fixture_set_names)
|
83
|
-
|
93
|
+
end
|
94
|
+
|
95
|
+
def loaded_fixtures=(fixtures)
|
96
|
+
@loaded_fixtures = Hash[fixtures.map { |f| [f.name, f] }]
|
84
97
|
end
|
85
98
|
end
|
86
99
|
end
|
data/test/models/test.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LoadOnceTest < BaseTest
|
4
|
+
include Mongoid::FixtureSet::TestHelper
|
5
|
+
self.fixture_path = 'test/load_once_fixtures'
|
6
|
+
self.load_fixtures_once = true
|
7
|
+
|
8
|
+
class_attribute :count
|
9
|
+
self.count = 0
|
10
|
+
|
11
|
+
module FixtureLoadCount
|
12
|
+
def count
|
13
|
+
LoadOnceTest.count += 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
Mongoid::FixtureSet.context_class.send :include, FixtureLoadCount
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
end
|
20
|
+
|
21
|
+
def count_equal_1
|
22
|
+
assert_equal 1, self.class.count
|
23
|
+
begin
|
24
|
+
tests(:test1)
|
25
|
+
assert true
|
26
|
+
rescue => e
|
27
|
+
assert false, "#{e}\n#{e.backtrace.join("\n")}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
5.times do |i|
|
32
|
+
alias_method "test_load_once_#{i}", :count_equal_1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-fixture_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoffroy Planquart
|
@@ -59,21 +59,24 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- lib/mongoid/fixture_set/version.rb
|
63
62
|
- lib/mongoid/fixture_set/errors.rb
|
64
63
|
- lib/mongoid/fixture_set/file.rb
|
65
64
|
- lib/mongoid/fixture_set/class_cache.rb
|
66
|
-
- lib/mongoid/fixture_set/test_helper.rb
|
67
65
|
- lib/mongoid/fixture_set/fixture.rb
|
66
|
+
- lib/mongoid/fixture_set/version.rb
|
67
|
+
- lib/mongoid/fixture_set/test_helper.rb
|
68
68
|
- lib/mongoid/fixture_set.rb
|
69
69
|
- lib/mongoid-fixture_set.rb
|
70
|
+
- MIT-LICENSE
|
70
71
|
- Rakefile
|
71
72
|
- test/mongoid/fixtures_test.rb
|
72
73
|
- test/mongoid/fixture_set_test.rb
|
74
|
+
- test/mongoid/load_once_test.rb
|
73
75
|
- test/models/group.rb
|
74
76
|
- test/models/organisation.rb
|
75
77
|
- test/models/school.rb
|
76
78
|
- test/models/user.rb
|
79
|
+
- test/models/test.rb
|
77
80
|
- test/mongoid.yml
|
78
81
|
- test/fixtures/users.yml
|
79
82
|
- test/fixtures/groups.yml
|
@@ -82,6 +85,7 @@ files:
|
|
82
85
|
- test/fixtures/users/family.yml
|
83
86
|
- test/fixtures/not_models.yml
|
84
87
|
- test/test_helper.rb
|
88
|
+
- test/load_once_fixtures/tests.yml
|
85
89
|
homepage: https://github.com/Aethelflaed/mongoid-fixture_set
|
86
90
|
licenses:
|
87
91
|
- MIT
|
@@ -109,10 +113,12 @@ summary: Fixtures for Mongoid
|
|
109
113
|
test_files:
|
110
114
|
- test/mongoid/fixtures_test.rb
|
111
115
|
- test/mongoid/fixture_set_test.rb
|
116
|
+
- test/mongoid/load_once_test.rb
|
112
117
|
- test/models/group.rb
|
113
118
|
- test/models/organisation.rb
|
114
119
|
- test/models/school.rb
|
115
120
|
- test/models/user.rb
|
121
|
+
- test/models/test.rb
|
116
122
|
- test/mongoid.yml
|
117
123
|
- test/fixtures/users.yml
|
118
124
|
- test/fixtures/groups.yml
|
@@ -121,4 +127,5 @@ test_files:
|
|
121
127
|
- test/fixtures/users/family.yml
|
122
128
|
- test/fixtures/not_models.yml
|
123
129
|
- test/test_helper.rb
|
130
|
+
- test/load_once_fixtures/tests.yml
|
124
131
|
has_rdoc:
|