sprig 0.1.4 → 0.1.5
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 +4 -4
- data/README.md +1 -1
- data/lib/sprig/dependency.rb +0 -3
- data/lib/sprig/directive.rb +1 -1
- data/lib/sprig/helpers.rb +0 -4
- data/lib/sprig/seed/factory.rb +0 -4
- data/lib/sprig/version.rb +1 -1
- data/spec/db/activerecord.db +0 -0
- data/spec/fixtures/models/post.rb +5 -0
- data/spec/fixtures/seeds/staging/posts.yml +0 -2
- data/spec/fixtures/seeds/test/comments.yml +0 -2
- data/spec/fixtures/seeds/test/files/cat.png +0 -0
- data/spec/fixtures/seeds/test/invalid_users.yml +0 -2
- data/spec/fixtures/seeds/test/legacy_posts.yml +0 -2
- data/spec/fixtures/seeds/test/posts.md +5 -0
- data/spec/fixtures/seeds/test/posts.yml +0 -2
- data/spec/fixtures/seeds/test/posts_delete_existing_by.yml +7 -0
- data/spec/fixtures/seeds/test/posts_find_existing_by_missing.yml +7 -0
- data/spec/fixtures/seeds/test/posts_find_existing_by_multiple.yml +0 -1
- data/spec/fixtures/seeds/test/posts_find_existing_by_single.yml +0 -1
- data/spec/fixtures/seeds/test/posts_missing_dependency.yml +0 -2
- data/spec/fixtures/seeds/test/posts_missing_record.yml +0 -2
- data/spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml +4 -0
- data/spec/fixtures/seeds/test/posts_with_files.yml +5 -0
- data/spec/lib/sprig/parser/base_spec.rb +11 -0
- data/spec/lib/sprig/source_spec.rb +24 -0
- data/spec/spec_helper.rb +11 -1
- data/spec/sprig_spec.rb +168 -0
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c09e094cca99e32c1042adb111565a9f79f321f2
|
4
|
+
data.tar.gz: 056a2e3a6ac418608dbbbd99dd905f36b8d0b39b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 694d572f95471fde7c7141d97c5e4cd86826791a61e6cd833fd5c54094cb63273ca7d157756c248de35e5b2b5fb35891a4b6bc9064749867a72cdb6c98115879
|
7
|
+
data.tar.gz: 3c3bd1e7530e21baec6cf9b616d271a05aa4ce1fbd2263d5404229121d391778f745113cb4293d8da6bcf2c3a67429b8ba44f9b303329d4d386008fb42bf4154
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
[](https://codeclimate.com/github/vigetlabs/sprig) [](https://travis-ci.org/vigetlabs/sprig) [](http://badge.fury.io/rb/sprig)
|
3
|
+
[](https://codeclimate.com/github/vigetlabs/sprig) [](https://coveralls.io/r/vigetlabs/sprig) [](https://travis-ci.org/vigetlabs/sprig) [](http://badge.fury.io/rb/sprig)
|
4
4
|
|
5
5
|
Seed Rails application by convention, not configuration.
|
6
6
|
|
data/lib/sprig/dependency.rb
CHANGED
data/lib/sprig/directive.rb
CHANGED
data/lib/sprig/helpers.rb
CHANGED
data/lib/sprig/seed/factory.rb
CHANGED
data/lib/sprig/version.rb
CHANGED
data/spec/db/activerecord.db
CHANGED
Binary file
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sprig::NullRecord do
|
4
|
+
let(:error_msg) { 'Something bad happened.' }
|
5
|
+
subject { described_class.new(error_msg) }
|
6
|
+
|
7
|
+
describe "#new" do
|
8
|
+
it "logs an error upon initialization" do
|
9
|
+
log_should_receive(:error, with: "#{error_msg} (Substituted with NullRecord)")
|
10
|
+
|
11
|
+
subject
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#method_missing" do
|
16
|
+
it "returns nil for undefined method calls" do
|
17
|
+
subject.enhance_your_calm.should == nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_behaves_like "a logging entity" do
|
22
|
+
subject! { described_class.new(error_msg) }
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
ENV["RAILS_ENV"] ||= 'test'
|
2
2
|
|
3
|
+
require 'simplecov'
|
4
|
+
require 'coveralls'
|
5
|
+
|
6
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
7
|
+
SimpleCov.start "rails"
|
8
|
+
|
3
9
|
require "rails"
|
4
10
|
require "active_record"
|
5
11
|
require "database_cleaner"
|
@@ -47,7 +53,7 @@ User.connection.execute "DROP TABLE IF EXISTS users;"
|
|
47
53
|
User.connection.execute "CREATE TABLE users (id INTEGER PRIMARY KEY , first_name VARCHAR(255), last_name VARCHAR(255), type VARCHAR(255));"
|
48
54
|
|
49
55
|
Post.connection.execute "DROP TABLE IF EXISTS posts;"
|
50
|
-
Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY , title VARCHAR(255), content VARCHAR(255), published BOOLEAN , user_id INTEGER);"
|
56
|
+
Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY AUTOINCREMENT, title VARCHAR(255), content VARCHAR(255), photo VARCHAR(255), published BOOLEAN , user_id INTEGER);"
|
51
57
|
|
52
58
|
Comment.connection.execute "DROP TABLE IF EXISTS comments;"
|
53
59
|
Comment.connection.execute "CREATE TABLE comments (id INTEGER PRIMARY KEY , post_id INTEGER, body VARCHAR(255));"
|
@@ -68,12 +74,16 @@ end
|
|
68
74
|
def load_seeds(*files)
|
69
75
|
env = Rails.env
|
70
76
|
|
77
|
+
`cp -R ./spec/fixtures/seeds/#{env}/files ./spec/fixtures/db/seeds/#{env}`
|
78
|
+
|
71
79
|
files.each do |file|
|
72
80
|
`cp ./spec/fixtures/seeds/#{env}/#{file} ./spec/fixtures/db/seeds/#{env}`
|
73
81
|
end
|
74
82
|
|
75
83
|
yield
|
76
84
|
|
85
|
+
`rm -R ./spec/fixtures/db/seeds/#{env}/files`
|
86
|
+
|
77
87
|
files.each do |file|
|
78
88
|
`rm ./spec/fixtures/db/seeds/#{env}/#{file}`
|
79
89
|
end
|
data/spec/sprig_spec.rb
CHANGED
@@ -60,6 +60,24 @@ describe "Seeding an application" do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
context "with an invalid custom parser" do
|
64
|
+
around do |example|
|
65
|
+
load_seeds('posts.yml', &example)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "fails with an argument error" do
|
69
|
+
expect {
|
70
|
+
sprig [
|
71
|
+
{
|
72
|
+
:class => Post,
|
73
|
+
:source => open('spec/fixtures/seeds/test/posts.yml'),
|
74
|
+
:parser => Object # Not a valid parser
|
75
|
+
}
|
76
|
+
]
|
77
|
+
}.to raise_error(ArgumentError, 'Parsers must define #parse.')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
63
81
|
context "with a custom source" do
|
64
82
|
around do |example|
|
65
83
|
load_seeds('legacy_posts.yml', &example)
|
@@ -78,6 +96,31 @@ describe "Seeding an application" do
|
|
78
96
|
end
|
79
97
|
end
|
80
98
|
|
99
|
+
context "with a custom source that cannot be parsed by native parsers" do
|
100
|
+
around do |example|
|
101
|
+
load_seeds('posts.md', &example)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "fails with an unparsable file error" do
|
105
|
+
expect {
|
106
|
+
sprig [
|
107
|
+
{
|
108
|
+
:class => Post,
|
109
|
+
:source => open('spec/fixtures/seeds/test/posts.md')
|
110
|
+
}
|
111
|
+
]
|
112
|
+
}.to raise_error(Sprig::Source::ParserDeterminer::UnparsableFileError)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with an invalid custom source" do
|
117
|
+
it "fails with an argument error" do
|
118
|
+
expect {
|
119
|
+
sprig [ { :class => Post, :source => 42 } ]
|
120
|
+
}.to raise_error(ArgumentError, 'Data sources must act like an IO.')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
81
124
|
context "with multiple file relationships" do
|
82
125
|
around do |example|
|
83
126
|
load_seeds('posts.yml', 'comments.yml', &example)
|
@@ -92,6 +135,14 @@ describe "Seeding an application" do
|
|
92
135
|
end
|
93
136
|
end
|
94
137
|
|
138
|
+
context "with missing seed files" do
|
139
|
+
it "raises a missing file error" do
|
140
|
+
expect {
|
141
|
+
sprig [Post]
|
142
|
+
}.to raise_error(Sprig::Source::SourceDeterminer::FileNotFoundError)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
95
146
|
context "with a relationship to an undefined record" do
|
96
147
|
around do |example|
|
97
148
|
load_seeds('posts.yml', 'posts_missing_dependency.yml', &example)
|
@@ -166,8 +217,125 @@ describe "Seeding an application" do
|
|
166
217
|
end
|
167
218
|
end
|
168
219
|
|
220
|
+
context "with files defined as attributes" do
|
221
|
+
around do |example|
|
222
|
+
load_seeds('posts_with_files.yml', &example)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "seeds the db" do
|
226
|
+
sprig [
|
227
|
+
{
|
228
|
+
:class => Post,
|
229
|
+
:source => open('spec/fixtures/seeds/test/posts_with_files.yml')
|
230
|
+
}
|
231
|
+
]
|
232
|
+
|
233
|
+
Post.count.should == 1
|
234
|
+
Post.pluck(:photo).should =~ ['cat.png']
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "with cyclic dependencies" do
|
239
|
+
around do |example|
|
240
|
+
load_seeds('comments.yml', 'posts_with_cyclic_dependencies.yml', &example)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "raises an cyclic dependency error" do
|
244
|
+
expect {
|
245
|
+
sprig [
|
246
|
+
{
|
247
|
+
:class => Post,
|
248
|
+
:source => open('spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml')
|
249
|
+
},
|
250
|
+
Comment
|
251
|
+
]
|
252
|
+
}.to raise_error(Sprig::DependencySorter::CircularDependencyError)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context "with a malformed directive" do
|
257
|
+
let(:expected_error_message) { 'Sprig::Directive must be instantiated with an ActiveRecord subclass or a Hash with :class defined' }
|
258
|
+
|
259
|
+
context "including a class that is not a subclass of AR" do
|
260
|
+
it "raises an argument error" do
|
261
|
+
expect {
|
262
|
+
sprig [
|
263
|
+
Object
|
264
|
+
]
|
265
|
+
}.to raise_error(ArgumentError, expected_error_message)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context "including a non-class, non-hash" do
|
270
|
+
it "raises an argument error" do
|
271
|
+
expect {
|
272
|
+
sprig [
|
273
|
+
42
|
274
|
+
]
|
275
|
+
}.to raise_error(ArgumentError, expected_error_message)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
|
169
281
|
context "with custom seed options" do
|
282
|
+
context "using delete_existing_by" do
|
283
|
+
around do |example|
|
284
|
+
load_seeds('posts_delete_existing_by.yml', &example)
|
285
|
+
end
|
286
|
+
|
287
|
+
context "with an existing record" do
|
288
|
+
let!(:existing_match) do
|
289
|
+
Post.create(
|
290
|
+
:title => "Such Title",
|
291
|
+
:content => "Old Content")
|
292
|
+
end
|
293
|
+
|
294
|
+
let!(:existing_nonmatch) do
|
295
|
+
Post.create(
|
296
|
+
:title => "Wow Title",
|
297
|
+
:content => "Much Content")
|
298
|
+
end
|
299
|
+
|
300
|
+
it "replaces only the matching existing record" do
|
301
|
+
sprig [
|
302
|
+
{
|
303
|
+
:class => Post,
|
304
|
+
:source => open("spec/fixtures/seeds/test/posts_delete_existing_by.yml")
|
305
|
+
}
|
306
|
+
]
|
307
|
+
|
308
|
+
Post.count.should == 2
|
309
|
+
|
310
|
+
expect {
|
311
|
+
existing_match.reload
|
312
|
+
}.to raise_error(ActiveRecord::RecordNotFound)
|
313
|
+
|
314
|
+
expect {
|
315
|
+
existing_nonmatch.reload
|
316
|
+
}.to_not raise_error
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
170
321
|
context "using find_existing_by" do
|
322
|
+
context "with a missing attribute" do
|
323
|
+
around do |example|
|
324
|
+
load_seeds('posts_find_existing_by_missing.yml', &example)
|
325
|
+
end
|
326
|
+
|
327
|
+
it "raises a missing attribute error" do
|
328
|
+
expect {
|
329
|
+
sprig [
|
330
|
+
{
|
331
|
+
:class => Post,
|
332
|
+
:source => open("spec/fixtures/seeds/test/posts_find_existing_by_missing.yml")
|
333
|
+
}
|
334
|
+
]
|
335
|
+
}.to raise_error(Sprig::Seed::AttributeCollection::AttributeNotFoundError, "Attribute 'unicorn' is not present.")
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
171
339
|
context "with a single attribute" do
|
172
340
|
around do |example|
|
173
341
|
load_seeds('posts.yml', 'posts_find_existing_by_single.yml', &example)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lawson Kurtz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -123,6 +123,34 @@ dependencies:
|
|
123
123
|
- - '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: simplecov
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: coveralls
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
126
154
|
description: Sprig is a library for managing interconnected, environment-specific
|
127
155
|
seed data.
|
128
156
|
email:
|
@@ -176,23 +204,31 @@ files:
|
|
176
204
|
- spec/fixtures/models/user.rb
|
177
205
|
- spec/fixtures/seeds/staging/posts.yml
|
178
206
|
- spec/fixtures/seeds/test/comments.yml
|
207
|
+
- spec/fixtures/seeds/test/files/cat.png
|
179
208
|
- spec/fixtures/seeds/test/invalid_users.yml
|
180
209
|
- spec/fixtures/seeds/test/legacy_posts.yml
|
181
210
|
- spec/fixtures/seeds/test/posts.csv
|
182
211
|
- spec/fixtures/seeds/test/posts.json
|
212
|
+
- spec/fixtures/seeds/test/posts.md
|
183
213
|
- spec/fixtures/seeds/test/posts.yml
|
214
|
+
- spec/fixtures/seeds/test/posts_delete_existing_by.yml
|
215
|
+
- spec/fixtures/seeds/test/posts_find_existing_by_missing.yml
|
184
216
|
- spec/fixtures/seeds/test/posts_find_existing_by_multiple.yml
|
185
217
|
- spec/fixtures/seeds/test/posts_find_existing_by_single.yml
|
186
218
|
- spec/fixtures/seeds/test/posts_missing_dependency.yml
|
187
219
|
- spec/fixtures/seeds/test/posts_missing_record.yml
|
220
|
+
- spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml
|
221
|
+
- spec/fixtures/seeds/test/posts_with_files.yml
|
188
222
|
- spec/lib/generators/sprig/install_generator_spec.rb
|
189
223
|
- spec/lib/sprig/configuration_spec.rb
|
190
224
|
- spec/lib/sprig/directive_list_spec.rb
|
191
225
|
- spec/lib/sprig/directive_spec.rb
|
192
226
|
- spec/lib/sprig/null_record_spec.rb
|
227
|
+
- spec/lib/sprig/parser/base_spec.rb
|
193
228
|
- spec/lib/sprig/process_notifier_spec.rb
|
194
229
|
- spec/lib/sprig/seed/entry_spec.rb
|
195
230
|
- spec/lib/sprig/seed/record_spec.rb
|
231
|
+
- spec/lib/sprig/source_spec.rb
|
196
232
|
- spec/lib/sprig_spec.rb
|
197
233
|
- spec/spec_helper.rb
|
198
234
|
- spec/sprig_spec.rb
|
@@ -235,23 +271,31 @@ test_files:
|
|
235
271
|
- spec/fixtures/models/user.rb
|
236
272
|
- spec/fixtures/seeds/staging/posts.yml
|
237
273
|
- spec/fixtures/seeds/test/comments.yml
|
274
|
+
- spec/fixtures/seeds/test/files/cat.png
|
238
275
|
- spec/fixtures/seeds/test/invalid_users.yml
|
239
276
|
- spec/fixtures/seeds/test/legacy_posts.yml
|
240
277
|
- spec/fixtures/seeds/test/posts.csv
|
241
278
|
- spec/fixtures/seeds/test/posts.json
|
279
|
+
- spec/fixtures/seeds/test/posts.md
|
242
280
|
- spec/fixtures/seeds/test/posts.yml
|
281
|
+
- spec/fixtures/seeds/test/posts_delete_existing_by.yml
|
282
|
+
- spec/fixtures/seeds/test/posts_find_existing_by_missing.yml
|
243
283
|
- spec/fixtures/seeds/test/posts_find_existing_by_multiple.yml
|
244
284
|
- spec/fixtures/seeds/test/posts_find_existing_by_single.yml
|
245
285
|
- spec/fixtures/seeds/test/posts_missing_dependency.yml
|
246
286
|
- spec/fixtures/seeds/test/posts_missing_record.yml
|
287
|
+
- spec/fixtures/seeds/test/posts_with_cyclic_dependencies.yml
|
288
|
+
- spec/fixtures/seeds/test/posts_with_files.yml
|
247
289
|
- spec/lib/generators/sprig/install_generator_spec.rb
|
248
290
|
- spec/lib/sprig/configuration_spec.rb
|
249
291
|
- spec/lib/sprig/directive_list_spec.rb
|
250
292
|
- spec/lib/sprig/directive_spec.rb
|
251
293
|
- spec/lib/sprig/null_record_spec.rb
|
294
|
+
- spec/lib/sprig/parser/base_spec.rb
|
252
295
|
- spec/lib/sprig/process_notifier_spec.rb
|
253
296
|
- spec/lib/sprig/seed/entry_spec.rb
|
254
297
|
- spec/lib/sprig/seed/record_spec.rb
|
298
|
+
- spec/lib/sprig/source_spec.rb
|
255
299
|
- spec/lib/sprig_spec.rb
|
256
300
|
- spec/spec_helper.rb
|
257
301
|
- spec/sprig_spec.rb
|