data_magic 0.17 → 0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/README.md +3 -1
- data/lib/data_magic.rb +6 -2
- data/lib/data_magic/version.rb +1 -1
- data/spec/lib/data_magic_spec.rb +20 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a04c1cb00c09395692bea5fc105c5ae9ee5eb390
|
4
|
+
data.tar.gz: e6b7181c7c446e504ff85e57f9b6b4496e16309a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b35cd92595c0b2258cccd45cf5825ec668bea1c49d3bc01628f1f77a2b8be9ea8d60c8b24ccc063cd845f654f25f575efa8785621b6a5795bb4b9f7bf70ed4e7
|
7
|
+
data.tar.gz: 1b333b8c0d3230f392ca046e8c3019aef74bf85c9be1aea6ee027097241915dfaaa830943e955bc579cbae6e77492d271f0e341b9dc9337732c7b1551e534d45
|
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== Version 0.18 / 2014-3-2
|
2
|
+
* Enhancements
|
3
|
+
* Can now set the file to be used by setting a DATA_MAGIC_FILE environment file
|
4
|
+
* Fixes
|
5
|
+
* Only forcing available locales if it is available
|
6
|
+
|
1
7
|
=== Version 0.17 / 2014-1-22
|
2
8
|
* Fixes
|
3
9
|
* Eliminated the deprecation message from I18n
|
data/README.md
CHANGED
@@ -23,7 +23,9 @@ DataMagic.load 'filename.yml'
|
|
23
23
|
|
24
24
|
If you do not specify a filename the gem will attempt to use a file named _default.yml_. If you are using this for testing you will more than likely want to call load before each test to load the proper data for the specific test, or use the namespaced keys method, detailed below.
|
25
25
|
|
26
|
-
|
26
|
+
Another option is to set an environment variable DATA_MAGIC_FILE. When this is set it will be used instead of the _default.yml_ file.
|
27
|
+
|
28
|
+
The final thing to do is use the data. The gem has a `data_for` method that will return the data for a specific key. The most common way to use this is to include the _DataMagic_ module in a [page-object](https://github.com/cheezy/page-object) and then populate a page with the data. Here's an example:
|
27
29
|
|
28
30
|
````ruby
|
29
31
|
class MyPage
|
data/lib/data_magic.rb
CHANGED
@@ -10,7 +10,7 @@ module DataMagic
|
|
10
10
|
|
11
11
|
attr_reader :parent
|
12
12
|
|
13
|
-
I18n.enforce_available_locales = false
|
13
|
+
I18n.enforce_available_locales = false if I18n.respond_to? :enforce_available_locales
|
14
14
|
|
15
15
|
def self.included(cls)
|
16
16
|
@parent = cls
|
@@ -25,7 +25,7 @@ module DataMagic
|
|
25
25
|
DataMagic.load("#{filename}.yml")
|
26
26
|
else
|
27
27
|
record = key.to_s
|
28
|
-
DataMagic.load(
|
28
|
+
DataMagic.load(the_file) unless DataMagic.yml
|
29
29
|
end
|
30
30
|
data = DataMagic.yml[record]
|
31
31
|
raise ArgumentError, "Undefined key #{key}" unless data
|
@@ -34,6 +34,10 @@ module DataMagic
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
def the_file
|
38
|
+
ENV['DATA_MAGIC_FILE'] ? ENV['DATA_MAGIC_FILE'] : 'default.yml'
|
39
|
+
end
|
40
|
+
|
37
41
|
def prep_data(data)
|
38
42
|
data.each do |key, value|
|
39
43
|
unless value.nil?
|
data/lib/data_magic/version.rb
CHANGED
data/spec/lib/data_magic_spec.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class UserPage
|
4
|
+
include DataMagic
|
5
|
+
end
|
6
|
+
|
3
7
|
describe DataMagic do
|
4
8
|
context "when configuring the yml directory" do
|
5
9
|
before(:each) do
|
@@ -22,14 +26,27 @@ describe DataMagic do
|
|
22
26
|
YAML.should_receive(:load_file).with("test/fname").and_return({})
|
23
27
|
DataMagic.load("fname")
|
24
28
|
end
|
29
|
+
|
30
|
+
it "should default to reading a file named default.yml" do
|
31
|
+
DataMagic.yml_directory = 'config/data'
|
32
|
+
DataMagic.yml = nil
|
33
|
+
data = UserPage.new.data_for :dm
|
34
|
+
expect(data.keys).to include('value1')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should use the value of DATA_MAGIC_FILE if it exists" do
|
38
|
+
DataMagic.yml_directory = 'config/data'
|
39
|
+
DataMagic.yml = nil
|
40
|
+
ENV['DATA_MAGIC_FILE'] = 'user.yml'
|
41
|
+
data = UserPage.new.data_for "valid"
|
42
|
+
expect(data.keys.sort).to eq(['job','name'])
|
43
|
+
ENV['DATA_MAGIC_FILE'] = nil
|
44
|
+
end
|
25
45
|
end
|
26
46
|
|
27
47
|
context "namespaced keys" do
|
28
48
|
it "loads correct file and retrieves data" do
|
29
49
|
DataMagic.yml_directory = 'config/data'
|
30
|
-
class UserPage
|
31
|
-
include DataMagic
|
32
|
-
end
|
33
50
|
data = UserPage.new.data_for "user/valid"
|
34
51
|
expect(data.keys.sort).to eq(['job','name'])
|
35
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.18'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|