falcor 0.0.1 → 0.0.2
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.
- checksums.yaml +5 -13
- data/.gitignore +3 -0
- data/README.md +45 -8
- data/Rakefile +6 -1
- data/falcor.gemspec +13 -12
- data/lib/falcor/define_dsl.rb +5 -1
- data/lib/falcor/fabricator.rb +1 -1
- data/lib/falcor/factory.rb +3 -3
- data/lib/falcor/version.rb +1 -1
- data/spec/fabricator_spec.rb +14 -0
- data/spec/factory_spec.rb +48 -0
- data/spec/spec_helper.rb +1 -0
- metadata +32 -12
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MmU5ZWUzMTYxM2Y1MzgxMDI2ZDc1NjM4NzJmMWEzY2RkYjc5MjY5MQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c555733f4c7649530fcb7e375c404ee2f8e03fa
|
4
|
+
data.tar.gz: a338aa2d1cce1bf75832f356762abdeab7a9d7bc
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NzZiZjQxOGJhYWZlMWNjYTdmNjI4OGEzYmRmNDcxOTQ3OTIzNWFkMTMwODZj
|
11
|
-
YTBjYTkzOGU4MjdhOWJiMWFhNWI4Mzk4NjllMGZkOTUyYjgwNDM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTRhNTMwMjYyZDdmYTcxNjZlNDIxNDgwNzg2NTY3Yzk3NjdkNDAyZGQwMjU5
|
14
|
-
ZmNlMGUzN2YyMzQzNTk1YTQ5NGQ3Njk3MDJiYWZhN2JmYTg4Yzc1ZmM2MmZi
|
15
|
-
MmRiNmJjMjg2YWNiNjRjZWI3NDM5YzU3ODMwYzljNTgyODg5MDc=
|
6
|
+
metadata.gz: 651195049a51fbb1461457f585e51fdb86a2748feea4a92582f2642c3e7587189f855a038611e1c22564539996c2917b5c415b47b5394e743cb1870e259d0150
|
7
|
+
data.tar.gz: 4ca3b1990de719dd0fcb95d0ff0e5872d373bb709f441e54aea7d44611e76f480d76482451421cafc0386ca6e8235f44b61568883a29b71dfeda725b11f11849
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,9 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
|
29
|
+
### Defining factories & creating instances
|
30
|
+
|
31
|
+
Here's how you'd define some factories, create an instance of the new `user` factory, and then turn it into a hash to use as JSON:
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
Falcor::Fabricator.define :blog_post do
|
@@ -44,23 +46,58 @@ end
|
|
44
46
|
user = Factory :user
|
45
47
|
|
46
48
|
user.to_json
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
|
50
|
+
=> {"email"=>"user@example.com",
|
51
|
+
"full_name"=>"Matt Gauger",
|
52
|
+
"blog_posts"=>
|
53
|
+
[{"title"=>"My post", "body"=>"Lots of text"},
|
54
|
+
{"title"=>"My post", "body"=>"Lots of text"}]}
|
52
55
|
```
|
53
56
|
|
57
|
+
### Overriding defaults
|
58
|
+
|
54
59
|
You can also override defaults:
|
55
60
|
|
56
61
|
```ruby
|
57
62
|
post = Factory :blog_post, title: "My really cool post"
|
58
63
|
|
59
64
|
post.title
|
60
|
-
|
65
|
+
=> "My really cool blog post"
|
66
|
+
```
|
67
|
+
|
68
|
+
### Optional fields
|
69
|
+
|
70
|
+
For optional fields on factories (those that don't have a default value and shouldn't show up in JSON unless set), use `allow`:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Falcor::Fabricator.define :contact do
|
74
|
+
allow :full_name
|
75
|
+
allow :phone_number
|
76
|
+
allow :address
|
77
|
+
end
|
78
|
+
|
79
|
+
contact = Factory :contact, full_name: "Robert Pitts"
|
80
|
+
|
81
|
+
contact.to_json
|
82
|
+
=> {"full_name"=>"Robert Pitts"} # Other attributes don't appear in JSON
|
61
83
|
```
|
62
84
|
|
63
|
-
|
85
|
+
### Associations
|
86
|
+
|
87
|
+
The most basic form of association assumes that the name of the attribute matches the Factory of the assocation:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Falcor::Fabricator.define :metadata do
|
91
|
+
field :api_version, "2.1"
|
92
|
+
field :stub_data, false
|
93
|
+
end
|
94
|
+
|
95
|
+
Falcor::Fabricator.define :report do
|
96
|
+
field :name, "Simple Report"
|
97
|
+
field :answer, 42
|
98
|
+
association :metadata
|
99
|
+
end
|
100
|
+
```
|
64
101
|
|
65
102
|
## Contributing
|
66
103
|
|
data/Rakefile
CHANGED
data/falcor.gemspec
CHANGED
@@ -4,24 +4,25 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'falcor/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'falcor'
|
8
8
|
spec.version = Falcor::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Matt Gauger']
|
10
|
+
spec.email = ['matt.gauger@gmail.com']
|
11
|
+
spec.description = 'Quickly build example data'
|
12
|
+
spec.summary = 'Quickly build example data'
|
13
|
+
spec.homepage = 'https://github.com/mathias/falcor'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'activesupport', '~> 4.0.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'pry-debugger'
|
27
|
+
spec.add_development_dependency 'rspec'
|
27
28
|
end
|
data/lib/falcor/define_dsl.rb
CHANGED
@@ -33,9 +33,13 @@ module Falcor
|
|
33
33
|
self.send(:define_method, "#{attr}=", default_assignment_blk)
|
34
34
|
end
|
35
35
|
|
36
|
-
def association(attr, model)
|
36
|
+
def association(attr, model=nil)
|
37
37
|
self.associations = (self.associations || []).push(attr)
|
38
38
|
|
39
|
+
unless model
|
40
|
+
model = Factory attr
|
41
|
+
end
|
42
|
+
|
39
43
|
default_blk = Proc.new { return self.instance_variable_get("@#{attr}".to_sym) || model }
|
40
44
|
self.send(:define_method, attr, default_blk)
|
41
45
|
|
data/lib/falcor/fabricator.rb
CHANGED
data/lib/falcor/factory.rb
CHANGED
@@ -39,16 +39,16 @@ module Falcor
|
|
39
39
|
fields.each do |field|
|
40
40
|
value = self.send(field)
|
41
41
|
unless value.nil?
|
42
|
-
json[field] = self.send(field)
|
42
|
+
json[field.to_s] = self.send(field)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
associations.each do |field|
|
47
|
-
json[field] = self.send(field).send(:to_json)
|
47
|
+
json[field.to_js] = self.send(field).send(:to_json)
|
48
48
|
end
|
49
49
|
|
50
50
|
lists.each do |field|
|
51
|
-
json[field] = self.send(field).map { |m| m.to_json }
|
51
|
+
json[field.to_s] = self.send(field).map { |m| m.to_json }
|
52
52
|
end
|
53
53
|
|
54
54
|
json
|
data/lib/falcor/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Falcor::Fabricator do
|
4
|
+
describe '.define' do
|
5
|
+
it 'can define basic factories' do
|
6
|
+
Falcor::Fabricator.define :xyzzy do
|
7
|
+
field :foo, "bar"
|
8
|
+
field :baz, "quux"
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(Falcor::Fabricator.factories).to have_key(:xyzzy)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Factory' do
|
4
|
+
context 'basic factory functionality' do
|
5
|
+
before do
|
6
|
+
Falcor::Fabricator.define :blog_post do
|
7
|
+
field :title, "My post"
|
8
|
+
field :body, "Lots of text"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can create a basic factory with default attributes' do
|
13
|
+
post = Factory :blog_post
|
14
|
+
expect(post.title).to eq "My post"
|
15
|
+
expect(post.body).to eq "Lots of text"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'generates the expected hash for JSON' do
|
19
|
+
post = Factory :blog_post
|
20
|
+
expect(post.to_json).to eq({ "title" => "My post", "body" => "Lots of text" })
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'allows attributes to be overridden' do
|
24
|
+
post = Factory :blog_post, title: "My super sweet post"
|
25
|
+
expect(post.title).to eq "My super sweet post"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'factory associations' do
|
30
|
+
before do
|
31
|
+
Falcor::Fabricator.define :author do
|
32
|
+
field :username, "matt@example.com"
|
33
|
+
field :password, "password"
|
34
|
+
end
|
35
|
+
|
36
|
+
Falcor::Fabricator.define :blog_post do
|
37
|
+
field :title, "My post"
|
38
|
+
field :body, "Lots of text"
|
39
|
+
association :author
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'can create associations that default to the factory named by the attribute' do
|
44
|
+
post = Factory :blog_post
|
45
|
+
expect(post.author.username).to eq "matt@example.com"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'falcor'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: falcor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Gauger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -42,42 +42,56 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry-debugger
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
description: Quickly build example data
|
@@ -99,6 +113,9 @@ files:
|
|
99
113
|
- lib/falcor/fabricator.rb
|
100
114
|
- lib/falcor/factory.rb
|
101
115
|
- lib/falcor/version.rb
|
116
|
+
- spec/fabricator_spec.rb
|
117
|
+
- spec/factory_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
102
119
|
homepage: https://github.com/mathias/falcor
|
103
120
|
licenses:
|
104
121
|
- MIT
|
@@ -109,18 +126,21 @@ require_paths:
|
|
109
126
|
- lib
|
110
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
128
|
requirements:
|
112
|
-
- -
|
129
|
+
- - '>='
|
113
130
|
- !ruby/object:Gem::Version
|
114
131
|
version: '0'
|
115
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
133
|
requirements:
|
117
|
-
- -
|
134
|
+
- - '>='
|
118
135
|
- !ruby/object:Gem::Version
|
119
136
|
version: '0'
|
120
137
|
requirements: []
|
121
138
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.0.6
|
123
140
|
signing_key:
|
124
141
|
specification_version: 4
|
125
142
|
summary: Quickly build example data
|
126
|
-
test_files:
|
143
|
+
test_files:
|
144
|
+
- spec/fabricator_spec.rb
|
145
|
+
- spec/factory_spec.rb
|
146
|
+
- spec/spec_helper.rb
|