fixtory 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/fixtory.gemspec +1 -0
- data/lib/fixtory.rb +4 -0
- data/lib/fixtory/dsl/builder.rb +4 -1
- data/lib/fixtory/dsl/table.rb +13 -1
- data/lib/fixtory/methods.rb +14 -3
- data/lib/fixtory/version.rb +1 -1
- data/test/fixtories/test_4.rb +22 -0
- data/test/fixtory_test.rb +27 -0
- data/test/test_helper.rb +8 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b71cfd1393a5e6b1415c655a955e42e1ce24f48
|
4
|
+
data.tar.gz: 91a35aa8e79c1a79a33d5e6656573756f35b7267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b321ad0314b4ec7b64d84cd36f5564d146cb5e5443fb0c02c73ff947ee9d10cc80383b2fd574a9380bf6ac266d7f4f494c61f03cd98675b817efc86af52e9466
|
7
|
+
data.tar.gz: c105e333e3039ff54f01b393523d715100fcdb370abf4a91eada8589ccd98cd68a1dcb40f9a2c78f89193bd977cc19b84c8f7a03834711d73b4c1e00f039eb25
|
data/README.md
CHANGED
data/fixtory.gemspec
CHANGED
data/lib/fixtory.rb
CHANGED
data/lib/fixtory/dsl/builder.rb
CHANGED
@@ -2,6 +2,7 @@ require 'fixtory/dsl/table'
|
|
2
2
|
|
3
3
|
class Fixtory::DSL::Builder < BasicObject
|
4
4
|
attr_accessor :_tables
|
5
|
+
attr_accessor :_inserted
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@_tables = []
|
@@ -25,10 +26,12 @@ class Fixtory::DSL::Builder < BasicObject
|
|
25
26
|
def _insert
|
26
27
|
_tables.each do |table|
|
27
28
|
table._rows.each do |row|
|
28
|
-
_connection.insert_fixture(row.instance_eval('@attributes'), table.
|
29
|
+
_connection.insert_fixture(row.instance_eval('@attributes'), table._table_name)
|
29
30
|
row.instance_eval("@inserted = true")
|
30
31
|
end
|
31
32
|
end
|
33
|
+
|
34
|
+
self._inserted = true
|
32
35
|
end
|
33
36
|
|
34
37
|
def method_missing(method, *args, &block)
|
data/lib/fixtory/dsl/table.rb
CHANGED
@@ -2,6 +2,7 @@ require 'fixtory/dsl/row'
|
|
2
2
|
|
3
3
|
class Fixtory::DSL::Table
|
4
4
|
attr_accessor :_name
|
5
|
+
attr_accessor :_table_name
|
5
6
|
attr_accessor :_builder
|
6
7
|
attr_accessor :_rows
|
7
8
|
attr_accessor :_model_class
|
@@ -9,6 +10,7 @@ class Fixtory::DSL::Table
|
|
9
10
|
|
10
11
|
def initialize(name, builder, &block)
|
11
12
|
@_name = name.to_s
|
13
|
+
@_table_name = _model_class.table_name
|
12
14
|
@_builder = builder
|
13
15
|
@_rows = []
|
14
16
|
@_block = block
|
@@ -19,7 +21,11 @@ class Fixtory::DSL::Table
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def _row(name, &block)
|
22
|
-
|
24
|
+
row = ::Fixtory::DSL::Row.new(name, self, &block)
|
25
|
+
if _sti_table?
|
26
|
+
row.instance_eval('@attributes')['type'] = _name.singularize.camelize
|
27
|
+
end
|
28
|
+
_rows << row
|
23
29
|
end
|
24
30
|
|
25
31
|
def method_missing(method, *args, &block)
|
@@ -48,4 +54,10 @@ class Fixtory::DSL::Table
|
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def _sti_table?
|
61
|
+
_name != _table_name
|
62
|
+
end
|
51
63
|
end
|
data/lib/fixtory/methods.rb
CHANGED
@@ -2,8 +2,19 @@ require 'fixtory/dsl'
|
|
2
2
|
|
3
3
|
module Fixtory::Methods
|
4
4
|
def fixtory(group_name)
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
group_name = group_name.to_s
|
6
|
+
|
7
|
+
if Fixtory.identity_map.key?(group_name)
|
8
|
+
builder = Fixtory.identity_map[group_name]
|
9
|
+
unless builder._inserted
|
10
|
+
builder._insert
|
11
|
+
end
|
12
|
+
builder
|
13
|
+
else
|
14
|
+
builder = Fixtory::DSL.build_from(Fixtory.path_for(group_name))
|
15
|
+
Fixtory.identity_map[group_name] = builder
|
16
|
+
builder._insert
|
17
|
+
builder
|
18
|
+
end
|
8
19
|
end
|
9
20
|
end
|
data/lib/fixtory/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
owners do
|
2
|
+
brian do
|
3
|
+
name 'Brian'
|
4
|
+
age 35
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
beagles do
|
9
|
+
snoopy do
|
10
|
+
name 'Snoopy'
|
11
|
+
age 1.5
|
12
|
+
owner owners.brian
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
great_danes do
|
17
|
+
marmaduke do
|
18
|
+
name 'Marmaduke'
|
19
|
+
age 12
|
20
|
+
owner owners.brian
|
21
|
+
end
|
22
|
+
end
|
data/test/fixtory_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe 'Fixtories' do
|
4
|
+
after do
|
5
|
+
Fixtory.instance_variable_set(:@identity_map, {})
|
6
|
+
end
|
7
|
+
|
4
8
|
it 'allows access to specific rows from builder' do
|
5
9
|
path = File.expand_path('test/fixtories/test_1.rb')
|
6
10
|
builder = Fixtory::DSL.build_from(path)
|
@@ -53,4 +57,27 @@ describe 'Fixtories' do
|
|
53
57
|
|
54
58
|
refute_equal Owner.count, count
|
55
59
|
end
|
60
|
+
|
61
|
+
it 'supports STI' do
|
62
|
+
test_group = fixtory(:test_4)
|
63
|
+
snoopy = test_group.beagles.snoopy
|
64
|
+
marmaduke = test_group.great_danes.marmaduke
|
65
|
+
|
66
|
+
assert_equal snoopy.type, 'Beagle'
|
67
|
+
assert_equal marmaduke.type, 'GreatDane'
|
68
|
+
[snoopy, marmaduke].each do |dog|
|
69
|
+
assert_includes test_group.owners.brian.dogs, dog
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'caches data for future use rather than reading from disk twice' do
|
74
|
+
build_from = Fixtory::DSL.method(:build_from)
|
75
|
+
|
76
|
+
stub Fixtory::DSL, :build_from, build_from, Fixtory.path_for(:test_1) do
|
77
|
+
fixtory(:test_1)
|
78
|
+
fixtory(:test_1)
|
79
|
+
end
|
80
|
+
|
81
|
+
refute_called Fixtory::DSL, :build_from, 2
|
82
|
+
end
|
56
83
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,6 +4,7 @@ require 'fixtory/methods'
|
|
4
4
|
require 'byebug'
|
5
5
|
require 'active_record'
|
6
6
|
require 'database_cleaner'
|
7
|
+
require 'minitest/moar'
|
7
8
|
|
8
9
|
DatabaseCleaner.strategy = :truncation
|
9
10
|
|
@@ -25,7 +26,7 @@ ActiveRecord::Base.establish_connection(
|
|
25
26
|
)
|
26
27
|
|
27
28
|
ActiveRecord::Base.connection.execute(%{CREATE TABLE owners (id INTEGER PRIMARY KEY, name TEXT, age DOUBLE);})
|
28
|
-
ActiveRecord::Base.connection.execute(%{CREATE TABLE dogs (id INTEGER PRIMARY KEY, name TEXT, age DOUBLE, owner_id INTEGER);})
|
29
|
+
ActiveRecord::Base.connection.execute(%{CREATE TABLE dogs (id INTEGER PRIMARY KEY, name TEXT, age DOUBLE, owner_id INTEGER, type TEXT);})
|
29
30
|
ActiveRecord::Base.connection.execute(%{CREATE TABLE books (isbn INTEGER PRIMARY KEY, name TEXT, owner_id INTEGER);})
|
30
31
|
|
31
32
|
class Owner < ActiveRecord::Base
|
@@ -39,3 +40,9 @@ end
|
|
39
40
|
|
40
41
|
class Book < ActiveRecord::Base
|
41
42
|
end
|
43
|
+
|
44
|
+
class Beagle < Dog
|
45
|
+
end
|
46
|
+
|
47
|
+
class GreatDane < Dog
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixtory
|
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
|
- Brian Cardarella
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-moar
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.4
|
83
97
|
description: Fixtures and Factories living together, mass hysterica
|
84
98
|
email:
|
85
99
|
- bcardarella@gmail.com
|
@@ -104,6 +118,7 @@ files:
|
|
104
118
|
- test/fixtories/test_1.rb
|
105
119
|
- test/fixtories/test_2.rb
|
106
120
|
- test/fixtories/test_3.rb
|
121
|
+
- test/fixtories/test_4.rb
|
107
122
|
- test/fixtory_test.rb
|
108
123
|
- test/test_helper.rb
|
109
124
|
homepage: https://github.com/dockyard/fixtory
|
@@ -134,5 +149,6 @@ test_files:
|
|
134
149
|
- test/fixtories/test_1.rb
|
135
150
|
- test/fixtories/test_2.rb
|
136
151
|
- test/fixtories/test_3.rb
|
152
|
+
- test/fixtories/test_4.rb
|
137
153
|
- test/fixtory_test.rb
|
138
154
|
- test/test_helper.rb
|