fixture_dependencies 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +1 -1
  2. data/README +11 -2
  3. data/lib/fixture_dependencies.rb +14 -1
  4. metadata +4 -4
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007-2008 Jeremy Evans
1
+ Copyright (c) 2007-2010 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README CHANGED
@@ -18,8 +18,7 @@ the following features:
18
18
 
19
19
  == Installation
20
20
 
21
- sudo gem install jeremyevans-fixture_dependencies \
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:
@@ -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
- YAML.load(File.read(File.join(fixture_path, "#{model_name.camelize.constantize.table_name}.yml"))).each do |name, attributes|
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
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-06-29 00:00:00 -07:00
18
+ date: 2010-10-15 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21