fixture_dependencies 1.2.3 → 1.2.4
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.
- data/LICENSE +1 -1
- data/README +11 -2
- data/lib/fixture_dependencies.rb +14 -1
- metadata +4 -4
data/LICENSE
CHANGED
data/README
CHANGED
|
@@ -18,8 +18,7 @@ the following features:
|
|
|
18
18
|
|
|
19
19
|
== Installation
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
--source http://gemcutter.org
|
|
21
|
+
gem install fixture_dependencies
|
|
23
22
|
|
|
24
23
|
== Source
|
|
25
24
|
|
|
@@ -92,6 +91,16 @@ nx7010, and a vendors fixture with the name lxg_computers.
|
|
|
92
91
|
|
|
93
92
|
Fixture files still use the table_name of the model.
|
|
94
93
|
|
|
94
|
+
== ERB Fixtures
|
|
95
|
+
|
|
96
|
+
Fixtures can also use ERB to preprocess the fixture file, useful if you need
|
|
97
|
+
to do any programming inside the fixture file, such as looping to create
|
|
98
|
+
multiple records. For the ERB support to be invoked, your fixture file
|
|
99
|
+
should be named #{table_name}.yml.erb instead of #{table_name}.yml. You can
|
|
100
|
+
mix ERB fixture files and regular fixture files, but you can not have an
|
|
101
|
+
ERB fixture file and a regular fixture file for the same table (the regular
|
|
102
|
+
fixture file will be used in that case).
|
|
103
|
+
|
|
95
104
|
== Changes to the fixtures Class Method:
|
|
96
105
|
|
|
97
106
|
fixture_dependencies can still use the fixtures class method in your test:
|
data/lib/fixture_dependencies.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require('sequel/extensions/inflector') unless [:singularize, :camelize, :underscore, :constantize].all?{|meth| "".respond_to?(meth)}
|
|
2
|
+
require 'erb'
|
|
2
3
|
|
|
3
4
|
class FixtureDependencies
|
|
4
5
|
@fixtures = {}
|
|
@@ -82,7 +83,19 @@ class << FixtureDependencies
|
|
|
82
83
|
# hash (does not add them to the database, see add).
|
|
83
84
|
def load_yaml(model_name)
|
|
84
85
|
raise(ArgumentError, "No fixture_path set. Use FixtureDependencies.fixture_path = ...") unless fixture_path
|
|
85
|
-
|
|
86
|
+
|
|
87
|
+
filename = model_name.camelize.constantize.table_name
|
|
88
|
+
yaml_path = File.join(fixture_path, "#{filename}.yml")
|
|
89
|
+
|
|
90
|
+
if File.exist?(yaml_path)
|
|
91
|
+
yaml = YAML.load(File.read(yaml_path))
|
|
92
|
+
elsif File.exist?("#{yaml_path}.erb")
|
|
93
|
+
yaml = YAML.load(ERB.new(File.read("#{yaml_path}.erb")).result)
|
|
94
|
+
else
|
|
95
|
+
raise(ArgumentError, "No valid fixture found at #{yaml_path}[.erb]")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
yaml.each do |name, attributes|
|
|
86
99
|
symbol_attrs = {}
|
|
87
100
|
attributes.each{|k,v| symbol_attrs[k.to_sym] = v}
|
|
88
101
|
add(model_name.to_sym, name, symbol_attrs)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fixture_dependencies
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 1.2.
|
|
9
|
+
- 4
|
|
10
|
+
version: 1.2.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Jeremy Evans
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-10-15 00:00:00 -07:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies: []
|
|
21
21
|
|