sprig 0.1.6 → 0.3.1
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 -5
- data/README.md +61 -10
- data/lib/generators/sprig/install_generator.rb +5 -1
- data/lib/sprig.rb +21 -0
- data/lib/sprig/configuration.rb +19 -2
- data/lib/sprig/directive.rb +3 -3
- data/lib/sprig/helpers.rb +15 -3
- data/lib/sprig/planter.rb +1 -1
- data/lib/sprig/process_notifier.rb +4 -4
- data/lib/sprig/seed/attribute.rb +27 -3
- data/lib/sprig/seed/entry.rb +8 -4
- data/lib/sprig/seed/factory.rb +1 -1
- data/lib/sprig/source.rb +10 -1
- data/lib/sprig/version.rb +8 -1
- data/spec/adapters/active_record.rb +34 -0
- data/spec/adapters/mongoid.rb +19 -0
- data/spec/adapters/mongoid.yml +12 -0
- data/spec/feature/configurations_spec.rb +5 -5
- data/spec/fixtures/models/{comment.rb → active_record/comment.rb} +0 -0
- data/spec/fixtures/models/{post.rb → active_record/post.rb} +0 -0
- data/spec/fixtures/models/{tag.rb → active_record/tag.rb} +0 -0
- data/spec/fixtures/models/{user.rb → active_record/user.rb} +0 -0
- data/spec/fixtures/models/mongoid/comment.rb +9 -0
- data/spec/fixtures/models/mongoid/post.rb +18 -0
- data/spec/fixtures/models/mongoid/tag.rb +7 -0
- data/spec/fixtures/models/mongoid/user.rb +9 -0
- data/spec/fixtures/seeds/shared/comments.yml +4 -0
- data/spec/fixtures/seeds/shared/files/cat.png +0 -0
- data/spec/fixtures/seeds/shared/invalid_users.yml +4 -0
- data/spec/fixtures/seeds/shared/legacy_posts.yml +4 -0
- data/spec/fixtures/seeds/shared/posts.csv +2 -0
- data/spec/fixtures/seeds/shared/posts.json +1 -0
- data/spec/fixtures/seeds/shared/posts.md +5 -0
- data/spec/fixtures/seeds/shared/posts.yml +4 -0
- data/spec/fixtures/seeds/shared/posts_delete_existing_by.yml +7 -0
- data/spec/fixtures/seeds/shared/posts_find_existing_by_missing.yml +7 -0
- data/spec/fixtures/seeds/shared/posts_find_existing_by_multiple.yml +8 -0
- data/spec/fixtures/seeds/shared/posts_find_existing_by_single.yml +7 -0
- data/spec/fixtures/seeds/shared/posts_missing_dependency.yml +5 -0
- data/spec/fixtures/seeds/shared/posts_missing_record.yml +5 -0
- data/spec/fixtures/seeds/shared/posts_partially_dynamic_value.yml +4 -0
- data/spec/fixtures/seeds/shared/posts_with_cyclic_dependencies.yml +4 -0
- data/spec/fixtures/seeds/shared/posts_with_files.yml +5 -0
- data/spec/fixtures/seeds/shared/posts_with_habtm.yml +7 -0
- data/spec/fixtures/seeds/shared/tags.yml +5 -0
- data/spec/fixtures/seeds/test/posts_partially_dynamic_value.yml +4 -0
- data/spec/lib/generators/sprig/install_generator_spec.rb +6 -2
- data/spec/lib/sprig/configuration_spec.rb +6 -6
- data/spec/lib/sprig/directive_list_spec.rb +4 -4
- data/spec/lib/sprig/directive_spec.rb +21 -11
- data/spec/lib/sprig/null_record_spec.rb +2 -2
- data/spec/lib/sprig/parser/base_spec.rb +1 -1
- data/spec/lib/sprig/process_notifier_spec.rb +5 -3
- data/spec/lib/sprig/seed/entry_spec.rb +3 -3
- data/spec/lib/sprig/seed/record_spec.rb +3 -3
- data/spec/lib/sprig/source_spec.rb +2 -2
- data/spec/lib/sprig_spec.rb +59 -8
- data/spec/spec_helper.rb +35 -31
- data/spec/sprig_shared_spec.rb +467 -0
- data/spec/sprig_spec.rb +105 -34
- data/spec/support/helpers/logger_mock.rb +2 -1
- metadata +167 -87
- data/lib/sprig/data.rb +0 -6
- data/spec/db/activerecord.db +0 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require "database_cleaner"
|
2
|
+
|
3
|
+
RSpec.configure do |c|
|
4
|
+
c.before(:suite) do
|
5
|
+
DatabaseCleaner[:active_record].strategy = :transaction
|
6
|
+
DatabaseCleaner[:active_record].clean_with(:truncation)
|
7
|
+
end
|
8
|
+
|
9
|
+
c.before(:each) do
|
10
|
+
DatabaseCleaner[:active_record].start
|
11
|
+
end
|
12
|
+
|
13
|
+
c.after(:each) do
|
14
|
+
DatabaseCleaner[:active_record].clean
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Database
|
19
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "spec/db/activerecord.db")
|
20
|
+
|
21
|
+
User.connection.execute "DROP TABLE IF EXISTS users;"
|
22
|
+
User.connection.execute "CREATE TABLE users (id INTEGER PRIMARY KEY , first_name VARCHAR(255), last_name VARCHAR(255), type VARCHAR(255));"
|
23
|
+
|
24
|
+
Post.connection.execute "DROP TABLE IF EXISTS posts;"
|
25
|
+
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);"
|
26
|
+
|
27
|
+
Comment.connection.execute "DROP TABLE IF EXISTS comments;"
|
28
|
+
Comment.connection.execute "CREATE TABLE comments (id INTEGER PRIMARY KEY , post_id INTEGER, body VARCHAR(255));"
|
29
|
+
|
30
|
+
Tag.connection.execute "DROP TABLE IF EXISTS tags;"
|
31
|
+
Tag.connection.execute "CREATE TABLE tags (id INTEGER PRIMARY KEY , name VARCHAR(255));"
|
32
|
+
|
33
|
+
Tag.connection.execute "DROP TABLE IF EXISTS posts_tags;"
|
34
|
+
Tag.connection.execute "CREATE TABLE posts_tags (id INTEGER PRIMARY KEY , post_id INTEGER, tag_id INTEGER);"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "database_cleaner"
|
2
|
+
|
3
|
+
RSpec.configure do |c|
|
4
|
+
c.before(:suite) do
|
5
|
+
DatabaseCleaner[:mongoid].strategy = :truncation
|
6
|
+
DatabaseCleaner[:mongoid].clean_with(:truncation)
|
7
|
+
end
|
8
|
+
|
9
|
+
c.before(:each) do
|
10
|
+
DatabaseCleaner[:mongoid].start
|
11
|
+
end
|
12
|
+
|
13
|
+
c.after(:each) do
|
14
|
+
DatabaseCleaner[:mongoid].clean
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Datastore
|
19
|
+
Mongoid.load!(File.join File.dirname(__FILE__), 'mongoid.yml')
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Configurating Sprig" do
|
3
|
+
RSpec.describe "Configurating Sprig" do
|
4
4
|
before do
|
5
5
|
stub_rails_root '~'
|
6
6
|
stub_rails_env 'development'
|
7
7
|
end
|
8
8
|
|
9
9
|
it "can set the directory" do
|
10
|
-
Sprig.configuration.directory.to_path.
|
10
|
+
expect(Sprig.configuration.directory.to_path).to eq('~/db/seeds/development')
|
11
11
|
|
12
12
|
Sprig.configure do |c|
|
13
13
|
c.directory = 'seed_files'
|
14
14
|
end
|
15
15
|
|
16
|
-
Sprig.configuration.directory.to_path.
|
16
|
+
expect(Sprig.configuration.directory.to_path).to eq('~/seed_files/development')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "can reset the configuration" do
|
@@ -21,10 +21,10 @@ describe "Configurating Sprig" do
|
|
21
21
|
c.directory = 'seed_files'
|
22
22
|
end
|
23
23
|
|
24
|
-
Sprig.configuration.directory.to_path.
|
24
|
+
expect(Sprig.configuration.directory.to_path).to eq('~/seed_files/development')
|
25
25
|
|
26
26
|
Sprig.reset_configuration
|
27
27
|
|
28
|
-
Sprig.configuration.directory.to_path.
|
28
|
+
expect(Sprig.configuration.directory.to_path).to eq('~/db/seeds/development')
|
29
29
|
end
|
30
30
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Post
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
if Mongoid::VERSION.split('.').first == "3"
|
5
|
+
field :user_id, :type => Moped::BSON::ObjectId
|
6
|
+
else
|
7
|
+
field :user_id, :type => BSON::ObjectId
|
8
|
+
end
|
9
|
+
field :title, :type => String
|
10
|
+
field :content, :type => String
|
11
|
+
field :published, :type => Boolean
|
12
|
+
|
13
|
+
has_and_belongs_to_many :tags
|
14
|
+
|
15
|
+
def photo=(file)
|
16
|
+
write_attribute(:photo, File.basename(file.path))
|
17
|
+
end
|
18
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
{"records":[{"sprig_id":1,"title":"Json title","content":"Json content"}]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'generators/sprig/install_generator'
|
3
3
|
|
4
|
-
describe Sprig::Generators::InstallGenerator do
|
4
|
+
RSpec.describe Sprig::Generators::InstallGenerator, type: :generator do
|
5
5
|
destination File.expand_path("../../tmp", __FILE__)
|
6
6
|
|
7
7
|
before do
|
@@ -14,6 +14,10 @@ describe Sprig::Generators::InstallGenerator do
|
|
14
14
|
assert_directory "db/seeds"
|
15
15
|
end
|
16
16
|
|
17
|
+
it "creates empty shared directory" do
|
18
|
+
assert_directory "db/seeds/shared"
|
19
|
+
end
|
20
|
+
|
17
21
|
it "creates empty seed environment directories" do
|
18
22
|
[
|
19
23
|
:development,
|
@@ -29,7 +33,7 @@ end
|
|
29
33
|
# Generator arguments are set on a class basis. We need to open
|
30
34
|
# a new describe block to make these examples work.
|
31
35
|
|
32
|
-
describe Sprig::Generators::InstallGenerator do
|
36
|
+
RSpec.describe Sprig::Generators::InstallGenerator, type: :generator do
|
33
37
|
context "with arguments" do
|
34
38
|
destination File.expand_path("../../tmp", __FILE__)
|
35
39
|
arguments %w(development test integration)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sprig::Configuration do
|
3
|
+
RSpec.describe Sprig::Configuration do
|
4
4
|
before do
|
5
5
|
stub_rails_root '~'
|
6
6
|
stub_rails_env 'development'
|
@@ -8,29 +8,29 @@ describe Sprig::Configuration do
|
|
8
8
|
|
9
9
|
describe "#directory" do
|
10
10
|
it "returns db/seeds/:env by default" do
|
11
|
-
subject.directory.to_path.
|
11
|
+
expect(subject.directory.to_path).to eq('~/db/seeds/development')
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns a custom directory" do
|
15
15
|
subject.directory = 'seed_files'
|
16
16
|
|
17
|
-
subject.directory.to_path.
|
17
|
+
expect(subject.directory.to_path).to eq('~/seed_files/development')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#logger" do
|
22
22
|
it "returns an stdout logger by default" do
|
23
23
|
logger = double('Logger')
|
24
|
-
Logger.
|
24
|
+
allow(Logger).to receive(:new).with($stdout).and_return(logger)
|
25
25
|
|
26
|
-
subject.logger.
|
26
|
+
expect(subject.logger).to eq(logger)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns a custom logger" do
|
30
30
|
logger = double('Logger')
|
31
31
|
subject.logger = logger
|
32
32
|
|
33
|
-
subject.logger.
|
33
|
+
expect(subject.logger).to eq(logger)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sprig::DirectiveList do
|
3
|
+
RSpec.describe Sprig::DirectiveList do
|
4
4
|
|
5
5
|
describe "#add_seeds_to_hopper" do
|
6
6
|
let(:hopper) { Array.new }
|
@@ -10,13 +10,13 @@ describe Sprig::DirectiveList do
|
|
10
10
|
subject { described_class.new(Post) }
|
11
11
|
|
12
12
|
before do
|
13
|
-
Sprig::Directive.
|
13
|
+
allow(Sprig::Directive).to receive(:new).with(Post).and_return(directive)
|
14
14
|
|
15
|
-
Sprig::Seed::Factory.
|
15
|
+
allow(Sprig::Seed::Factory).to receive(:new_from_directive).with(directive).and_return(seed_factory)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "builds seeds from directives and adds to the given array" do
|
19
|
-
seed_factory.
|
19
|
+
expect(seed_factory).to receive(:add_seeds_to_hopper).with(hopper)
|
20
20
|
|
21
21
|
subject.add_seeds_to_hopper(hopper)
|
22
22
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sprig::Directive do
|
3
|
+
RSpec.describe Sprig::Directive do
|
4
4
|
|
5
5
|
module Users
|
6
6
|
class Admin < User
|
@@ -11,19 +11,25 @@ describe Sprig::Directive do
|
|
11
11
|
context "given a class" do
|
12
12
|
subject { described_class.new(Post) }
|
13
13
|
|
14
|
-
|
14
|
+
it "returns the class" do
|
15
|
+
expect(subject.klass).to eq(Post)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
context "given a class within a module" do
|
18
20
|
subject { described_class.new(Users::Admin) }
|
19
21
|
|
20
|
-
|
22
|
+
it "returns the full class" do
|
23
|
+
expect(subject.klass).to eq(Users::Admin)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
context "given options with a class" do
|
24
28
|
subject { described_class.new(:class => Post) }
|
25
29
|
|
26
|
-
|
30
|
+
it "returns the class" do
|
31
|
+
expect(subject.klass).to eq(Post)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
context "given options without a class" do
|
@@ -34,8 +40,8 @@ describe Sprig::Directive do
|
|
34
40
|
subject.klass
|
35
41
|
}.to raise_error(
|
36
42
|
ArgumentError,
|
37
|
-
'Sprig::Directive must be instantiated with
|
38
|
-
|
43
|
+
'Sprig::Directive must be instantiated with a(n) '\
|
44
|
+
"#{Sprig.adapter_model_class} class or a Hash with :class defined"
|
39
45
|
)
|
40
46
|
end
|
41
47
|
end
|
@@ -45,13 +51,17 @@ describe Sprig::Directive do
|
|
45
51
|
context "given no options" do
|
46
52
|
subject { described_class.new(Post) }
|
47
53
|
|
48
|
-
|
54
|
+
it "returns an empty hash" do
|
55
|
+
expect(subject.options).to eq({})
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
context "given options" do
|
52
60
|
subject { described_class.new(:class => Post, :source => 'source') }
|
53
61
|
|
54
|
-
|
62
|
+
it "returns a the options" do
|
63
|
+
expect(subject.options).to eq(:source => 'source')
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
@@ -62,11 +72,11 @@ describe Sprig::Directive do
|
|
62
72
|
subject { described_class.new(:class => Post, :source => 'source') }
|
63
73
|
|
64
74
|
before do
|
65
|
-
Sprig::Source.
|
75
|
+
allow(Sprig::Source).to receive(:new).with('posts', { :source => 'source' }).and_return(datasource)
|
66
76
|
end
|
67
77
|
|
68
78
|
it "returns a sprig data source" do
|
69
|
-
subject.datasource.
|
79
|
+
expect(subject.datasource).to eq(datasource)
|
70
80
|
end
|
71
81
|
end
|
72
82
|
|
@@ -74,7 +84,7 @@ describe Sprig::Directive do
|
|
74
84
|
subject { described_class.new(Users::Admin) }
|
75
85
|
|
76
86
|
it "passes the correct path to Source" do
|
77
|
-
Sprig::Source.
|
87
|
+
expect(Sprig::Source).to receive(:new).with("users_admins", {})
|
78
88
|
|
79
89
|
subject.datasource
|
80
90
|
end
|