sprig-reap 0.0.3 → 0.0.4
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.
- data/README.md +2 -2
- data/lib/sprig/reap.rb +9 -2
- data/lib/sprig/reap/association.rb +45 -0
- data/lib/sprig/reap/configuration.rb +10 -4
- data/lib/sprig/reap/model.rb +7 -3
- data/lib/sprig/reap/railtie.rb +7 -0
- data/lib/sprig/reap/record.rb +20 -16
- data/lib/sprig/reap/seed_file.rb +2 -0
- data/lib/sprig/reap/version.rb +1 -1
- data/lib/tasks/reap.rake +0 -1
- data/spec/db/activerecord.db +0 -0
- data/spec/fixtures/models/post.rb +3 -0
- data/spec/fixtures/models/vote.rb +5 -0
- data/spec/fixtures/yaml/polymorphic_vote_record.yml +3 -0
- data/spec/lib/sprig/reap/association_spec.rb +86 -0
- data/spec/lib/sprig/reap/configuration_spec.rb +23 -1
- data/spec/lib/sprig/reap/model_spec.rb +42 -2
- data/spec/lib/sprig/reap/record_spec.rb +12 -8
- data/spec/lib/sprig/reap/seed_file_spec.rb +20 -0
- data/spec/lib/sprig/reap_spec.rb +16 -2
- data/spec/spec_helper.rb +6 -1
- data/spec/support/rails_stubs.rb +6 -0
- metadata +33 -11
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -23,7 +23,7 @@ rake db:seed:reap
|
|
23
23
|
```
|
24
24
|
Or from the Rails console:
|
25
25
|
```
|
26
|
-
Sprig
|
26
|
+
Sprig.reap
|
27
27
|
```
|
28
28
|
|
29
29
|
By default, Sprig::Reap will create seed files (currently in `.yaml` only) for every model in your Rails
|
@@ -44,7 +44,7 @@ or any ignored attributes you don't want to show up in any of the seed files.
|
|
44
44
|
rake db:seed:reap TARGET_ENV=integration MODELS=User,Post IGNORED_ATTRS=created_at,updated_at
|
45
45
|
|
46
46
|
# Rails Console
|
47
|
-
Sprig
|
47
|
+
Sprig.reap(target_env: 'integration', models: [User, Post], ignored_attrs: [:created_at,
|
48
48
|
:updated_at])
|
49
49
|
```
|
50
50
|
|
data/lib/sprig/reap.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require "sprig/reap/version"
|
2
|
+
require "sprig/reap/railtie"
|
2
3
|
|
3
4
|
module Sprig::Reap
|
4
5
|
autoload :Sprig, 'sprig'
|
5
6
|
autoload :TsortableHash, 'sprig/reap/tsortable_hash'
|
6
|
-
autoload :Railtie, 'sprig/reap/railtie'
|
7
7
|
autoload :Configuration, 'sprig/reap/configuration'
|
8
8
|
autoload :Model, 'sprig/reap/model'
|
9
|
+
autoload :Association, 'sprig/reap/association'
|
9
10
|
autoload :Record, 'sprig/reap/record'
|
10
11
|
autoload :SeedFile, 'sprig/reap/seed_file'
|
11
12
|
|
12
13
|
class << self
|
13
|
-
def reap(
|
14
|
+
def reap(input = {})
|
15
|
+
options = input.to_hash
|
16
|
+
|
14
17
|
configure do |config|
|
15
18
|
config.target_env = options[:target_env] || options['TARGET_ENV']
|
16
19
|
config.classes = options[:models] || options['MODELS']
|
@@ -20,6 +23,10 @@ module Sprig::Reap
|
|
20
23
|
Model.all.each { |model| SeedFile.new(model).write }
|
21
24
|
end
|
22
25
|
|
26
|
+
def clear_config
|
27
|
+
@@configuration = nil
|
28
|
+
end
|
29
|
+
|
23
30
|
private
|
24
31
|
|
25
32
|
cattr_reader :configuration
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Sprig::Reap
|
2
|
+
class Association
|
3
|
+
attr_reader :association
|
4
|
+
|
5
|
+
def initialize(association)
|
6
|
+
@association = association
|
7
|
+
end
|
8
|
+
|
9
|
+
def klass
|
10
|
+
name.to_s.classify.constantize
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
association.options[:class_name] || association.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def polymorphic?
|
18
|
+
!!association.options[:polymorphic]
|
19
|
+
end
|
20
|
+
|
21
|
+
def polymorphic_dependencies
|
22
|
+
return [] unless polymorphic?
|
23
|
+
@polymorphic_dependencies ||= ActiveRecord::Base.subclasses.select { |model| polymorphic_match? model }
|
24
|
+
end
|
25
|
+
|
26
|
+
def polymorphic_match?(model)
|
27
|
+
model.reflect_on_all_associations(:has_many).any? do |has_many_association|
|
28
|
+
has_many_association.options[:as] == association.name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def dependencies
|
33
|
+
polymorphic? ? polymorphic_dependencies : Array(klass)
|
34
|
+
end
|
35
|
+
|
36
|
+
def foreign_key
|
37
|
+
association.options[:foreign_key] || name.to_s + '_id'
|
38
|
+
end
|
39
|
+
|
40
|
+
def polymorphic_type
|
41
|
+
name.to_s + '_type'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Sprig::Reap
|
2
2
|
class Configuration
|
3
|
-
VALID_CLASSES = ActiveRecord::Base.subclasses
|
4
3
|
|
5
4
|
def target_env
|
6
5
|
@target_env ||= Rails.env
|
@@ -13,7 +12,7 @@ module Sprig::Reap
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def classes
|
16
|
-
@classes ||=
|
15
|
+
@classes ||= valid_classes
|
17
16
|
end
|
18
17
|
|
19
18
|
def classes=(given_classes)
|
@@ -32,9 +31,16 @@ module Sprig::Reap
|
|
32
31
|
|
33
32
|
private
|
34
33
|
|
34
|
+
def valid_classes
|
35
|
+
@valid_classes ||= begin
|
36
|
+
Rails.application.eager_load!
|
37
|
+
ActiveRecord::Base.subclasses
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
35
41
|
def parse_valid_env_from(input)
|
36
42
|
return if input.nil?
|
37
|
-
target_environment = input.strip.downcase
|
43
|
+
target_environment = input.to_s.strip.downcase
|
38
44
|
create_seeds_folder(target_environment)
|
39
45
|
yield target_environment
|
40
46
|
end
|
@@ -60,7 +66,7 @@ module Sprig::Reap
|
|
60
66
|
|
61
67
|
def validate_classes(classes)
|
62
68
|
classes.each do |klass|
|
63
|
-
unless
|
69
|
+
unless valid_classes.include? klass
|
64
70
|
raise ArgumentError, "Cannot create a seed file for #{klass} because it is not a subclass of ActiveRecord::Base."
|
65
71
|
end
|
66
72
|
end
|
data/lib/sprig/reap/model.rb
CHANGED
@@ -3,7 +3,7 @@ module Sprig::Reap
|
|
3
3
|
def self.all
|
4
4
|
@@all ||= begin
|
5
5
|
models = Sprig::Reap.classes.map { |klass| new(klass) }
|
6
|
-
|
6
|
+
|
7
7
|
tsorted_classes(models).map do |klass|
|
8
8
|
models.find { |model| model.klass == klass }
|
9
9
|
end
|
@@ -26,8 +26,12 @@ module Sprig::Reap
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def dependencies
|
29
|
-
@dependencies ||=
|
30
|
-
|
29
|
+
@dependencies ||= associations.flat_map(&:dependencies)
|
30
|
+
end
|
31
|
+
|
32
|
+
def associations
|
33
|
+
@associations ||= klass.reflect_on_all_associations(:belongs_to).map do |association|
|
34
|
+
Association.new(association)
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
data/lib/sprig/reap/record.rb
CHANGED
@@ -3,19 +3,21 @@ module Sprig::Reap
|
|
3
3
|
attr_reader :record, :model
|
4
4
|
attr_writer :sprig_id
|
5
5
|
|
6
|
+
delegate :id, to: :record
|
7
|
+
|
6
8
|
def initialize(record, model)
|
7
9
|
@record = record
|
8
10
|
@model = model
|
9
11
|
end
|
10
12
|
|
11
13
|
def attributes
|
12
|
-
@attributes ||=
|
13
|
-
attrs[0] = 'sprig_id'
|
14
|
-
end
|
14
|
+
@attributes ||= model.attributes.delete_if { |a| a == "id" }
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_hash
|
18
|
-
attributes.reduce(
|
18
|
+
attributes.reduce({"sprig_id" => sprig_id}) do |hash, attr|
|
19
|
+
hash.merge(attr => get_value_for(attr))
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def sprig_id
|
@@ -24,12 +26,8 @@ module Sprig::Reap
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
if attr.nil?
|
31
|
-
super
|
32
|
-
elsif dependency_finder.match(attr)
|
29
|
+
def get_value_for(attr)
|
30
|
+
if dependency?(attr)
|
33
31
|
klass = klass_for(attr)
|
34
32
|
id = record.send(attr)
|
35
33
|
sprig_id = Model.find(klass, id).sprig_id
|
@@ -40,16 +38,22 @@ module Sprig::Reap
|
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
|
-
def
|
44
|
-
model.
|
41
|
+
def dependency?(attr)
|
42
|
+
attr.in? model.associations.map(&:foreign_key)
|
45
43
|
end
|
46
44
|
|
47
|
-
def
|
48
|
-
|
45
|
+
def klass_for(foreign_key)
|
46
|
+
association = association_for(foreign_key)
|
47
|
+
|
48
|
+
if association.polymorphic?
|
49
|
+
record.send(association.polymorphic_type).constantize
|
50
|
+
else
|
51
|
+
association.klass
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
|
-
def
|
52
|
-
|
55
|
+
def association_for(foreign_key)
|
56
|
+
model.associations.detect { |a| a.foreign_key == foreign_key }
|
53
57
|
end
|
54
58
|
|
55
59
|
def sprig_record(klass, sprig_id)
|
data/lib/sprig/reap/seed_file.rb
CHANGED
data/lib/sprig/reap/version.rb
CHANGED
data/lib/tasks/reap.rake
CHANGED
data/spec/db/activerecord.db
CHANGED
Binary file
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sprig::Reap::Association do
|
4
|
+
let!(:user) { User.create(:first_name => 'Bo', :last_name => 'Janglez') }
|
5
|
+
let!(:post) { Post.create(:poster => user) }
|
6
|
+
let!(:comment) { Comment.create(:post => post) }
|
7
|
+
let!(:vote) { Vote.create(:votable => post) }
|
8
|
+
|
9
|
+
let(:standard_association) { Comment.reflect_on_all_associations(:belongs_to).first }
|
10
|
+
let(:class_named_association) { Post.reflect_on_all_associations(:belongs_to).first }
|
11
|
+
let(:polymorphic_association) { Vote.reflect_on_all_associations(:belongs_to).first }
|
12
|
+
|
13
|
+
describe "#polymorphic?" do
|
14
|
+
context "when given a non-polymorphic dependency" do
|
15
|
+
subject { described_class.new(standard_association) }
|
16
|
+
|
17
|
+
its(:polymorphic?) { should == false }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when given a polymorphic dependency" do
|
21
|
+
subject { described_class.new(polymorphic_association) }
|
22
|
+
|
23
|
+
its(:polymorphic?) { should == true }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#klass" do
|
28
|
+
context "given a standard association" do
|
29
|
+
subject { described_class.new(standard_association) }
|
30
|
+
|
31
|
+
its(:klass) { should == Post }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "given a named association" do
|
35
|
+
subject { described_class.new(class_named_association) }
|
36
|
+
|
37
|
+
its(:klass) { should == User }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#polymorphic_dependencies" do
|
42
|
+
context "when the association is not polymorphic" do
|
43
|
+
subject { described_class.new(standard_association) }
|
44
|
+
|
45
|
+
its(:polymorphic_dependencies) { should == [] }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when the association is polymorphic" do
|
49
|
+
subject { described_class.new(polymorphic_association) }
|
50
|
+
|
51
|
+
its(:polymorphic_dependencies) { should == [Post] }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#polymorphic_match?" do
|
56
|
+
context "when the given model does not have a matching polymorphic association" do
|
57
|
+
subject { described_class.new(polymorphic_association) }
|
58
|
+
|
59
|
+
it "returns false" do
|
60
|
+
subject.polymorphic_match?(User).should == false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when the given model has a matching polymorphic association" do
|
65
|
+
subject { described_class.new(polymorphic_association) }
|
66
|
+
|
67
|
+
it "returns true" do
|
68
|
+
subject.polymorphic_match?(Post).should == true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#dependencies" do
|
74
|
+
context "when the association is polymorphic" do
|
75
|
+
subject { described_class.new(standard_association) }
|
76
|
+
|
77
|
+
its(:dependencies) { should == [Post] }
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when the association is not polymorphic" do
|
81
|
+
subject { described_class.new(polymorphic_association) }
|
82
|
+
|
83
|
+
its(:dependencies) { should == [Post] }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -22,7 +22,7 @@ describe Sprig::Reap::Configuration do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context "given a non-nil value" do
|
25
|
+
context "given a non-nil string value" do
|
26
26
|
let(:input) { ' ShaBOOSH' }
|
27
27
|
|
28
28
|
it "formats the given value and then sets the target environment" do
|
@@ -43,6 +43,28 @@ describe Sprig::Reap::Configuration do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
context "given a non-nil symbol value" do
|
48
|
+
let(:input) { :shaboosh }
|
49
|
+
|
50
|
+
it "formats the given value and then sets the target environment" do
|
51
|
+
subject.target_env = input
|
52
|
+
|
53
|
+
subject.target_env.should == 'shaboosh'
|
54
|
+
end
|
55
|
+
|
56
|
+
context "and the corresponding seeds folder does not yet exist" do
|
57
|
+
after do
|
58
|
+
FileUtils.remove_dir('./spec/fixtures/db/seeds/shaboosh')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "creates the seeds folder" do
|
62
|
+
subject.target_env = input
|
63
|
+
|
64
|
+
File.directory?('./spec/fixtures/db/seeds/shaboosh').should == true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
46
68
|
end
|
47
69
|
|
48
70
|
describe "#classes" do
|
@@ -4,14 +4,15 @@ describe Sprig::Reap::Model do
|
|
4
4
|
describe ".all" do
|
5
5
|
let(:all_models) do
|
6
6
|
[
|
7
|
+
described_class.new(User),
|
7
8
|
described_class.new(Post),
|
8
9
|
described_class.new(Comment),
|
9
|
-
described_class.new(
|
10
|
+
described_class.new(Vote)
|
10
11
|
]
|
11
12
|
end
|
12
13
|
|
13
14
|
before do
|
14
|
-
Sprig::Reap.stub(:classes).and_return([Comment, Post, User])
|
15
|
+
Sprig::Reap.stub(:classes).and_return([Comment, Post, User, Vote])
|
15
16
|
end
|
16
17
|
|
17
18
|
it "returns an dependency-sorted array of Sprig::Reap::Models" do
|
@@ -64,6 +65,34 @@ describe Sprig::Reap::Model do
|
|
64
65
|
subject { described_class.new(Comment) }
|
65
66
|
|
66
67
|
its(:dependencies) { should == [Post] }
|
68
|
+
|
69
|
+
context "when the model is polymorphic" do
|
70
|
+
subject { described_class.new(Vote) }
|
71
|
+
|
72
|
+
its(:dependencies) { should == [Post] }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the model has a dependency with an explicit :class_name" do
|
76
|
+
subject { described_class.new(Post) }
|
77
|
+
|
78
|
+
its(:dependencies) { should == [User] }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#associations" do
|
83
|
+
let(:association) { double('Association') }
|
84
|
+
|
85
|
+
subject { described_class.new(Post) }
|
86
|
+
|
87
|
+
before do
|
88
|
+
Post.stub(:reflect_on_all_associations).with(:belongs_to).and_return([association])
|
89
|
+
end
|
90
|
+
|
91
|
+
it "creates an Association object for each belongs to association the model has" do
|
92
|
+
Sprig::Reap::Association.should_receive(:new).with(association)
|
93
|
+
|
94
|
+
subject.associations
|
95
|
+
end
|
67
96
|
end
|
68
97
|
|
69
98
|
describe "#find" do
|
@@ -96,6 +125,7 @@ describe Sprig::Reap::Model do
|
|
96
125
|
before do
|
97
126
|
subject.existing_sprig_ids = [1, 5, 'l_2', 'l_10', 'such_sprigs', 10.9]
|
98
127
|
end
|
128
|
+
|
99
129
|
it "returns an integer-type sprig_id that is not taken" do
|
100
130
|
subject.generate_sprig_id.should == 6
|
101
131
|
end
|
@@ -128,6 +158,16 @@ describe Sprig::Reap::Model do
|
|
128
158
|
subject.to_yaml.should == yaml_from_file('records_without_namespace.yml')
|
129
159
|
end
|
130
160
|
end
|
161
|
+
|
162
|
+
context "for a polymorphic model" do
|
163
|
+
it "returns the correct yaml" do
|
164
|
+
Vote.create(:votable => post1)
|
165
|
+
|
166
|
+
subject = described_class.new(Vote)
|
167
|
+
|
168
|
+
subject.to_yaml.should == yaml_from_file('polymorphic_vote_record.yml')
|
169
|
+
end
|
170
|
+
end
|
131
171
|
end
|
132
172
|
|
133
173
|
def yaml_from_file(basename)
|
@@ -6,12 +6,19 @@ describe Sprig::Reap::Record do
|
|
6
6
|
let(:record) { double('ActiveRecord::Base Instance') }
|
7
7
|
let(:model) { double('Sprig::Reap::Model') }
|
8
8
|
let(:reap_record) { double('Sprig::Reap::Record for class Very', :sprig_id => 5) }
|
9
|
+
let(:association) do
|
10
|
+
double('Sprig::Reap::Association',
|
11
|
+
:foreign_key => "very_id",
|
12
|
+
:klass => Very,
|
13
|
+
:polymorphic? => false
|
14
|
+
)
|
15
|
+
end
|
9
16
|
let(:sprig_record) { "<%= sprig_record(Very, 5).id %>" }
|
10
17
|
|
11
18
|
subject { described_class.new(record, model) }
|
12
19
|
|
13
20
|
before do
|
14
|
-
attrs = {
|
21
|
+
attrs = {
|
15
22
|
'id' => 0,
|
16
23
|
'such' => 1,
|
17
24
|
'wow' => 2,
|
@@ -24,21 +31,18 @@ describe Sprig::Reap::Record do
|
|
24
31
|
|
25
32
|
model.stub(:attributes).and_return(attrs.keys)
|
26
33
|
model.stub(:existing_sprig_ids).and_return([])
|
34
|
+
model.stub(:associations).and_return([association])
|
27
35
|
|
28
36
|
Sprig::Reap::Model.stub(:find).and_return(reap_record)
|
29
37
|
end
|
30
38
|
|
31
|
-
its(:id)
|
32
|
-
its(:such) { should == 1 }
|
33
|
-
its(:wow) { should == 2 }
|
34
|
-
its(:very_id) { should == sprig_record }
|
39
|
+
its(:id) { should == 0 }
|
35
40
|
|
36
41
|
describe "#attributes" do
|
37
|
-
it "returns an array of attributes from the given model
|
42
|
+
it "returns an array of attributes from the given model sans id" do
|
38
43
|
subject.attributes.should == %w(
|
39
|
-
sprig_id
|
40
44
|
such
|
41
|
-
wow
|
45
|
+
wow
|
42
46
|
very_id
|
43
47
|
)
|
44
48
|
end
|
@@ -86,6 +86,26 @@ describe Sprig::Reap::SeedFile do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
context "when the seed file exists but is empty inside" do
|
90
|
+
before do
|
91
|
+
File.open(subject.path, 'w') { |file| file.write('') }
|
92
|
+
end
|
93
|
+
|
94
|
+
it "grabs the yaml for the given model without a namespace" do
|
95
|
+
model.should_receive(:to_yaml).with(:namespace => nil)
|
96
|
+
|
97
|
+
subject.write
|
98
|
+
end
|
99
|
+
|
100
|
+
it "populates the file" do
|
101
|
+
starting_size = File.size(subject.path)
|
102
|
+
|
103
|
+
subject.write
|
104
|
+
|
105
|
+
File.size?(subject.path).should > starting_size
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
89
109
|
context "when the seed file does not yet exist" do
|
90
110
|
it "does not pass any existing sprig ids to the given model" do
|
91
111
|
model.should_not_receive(:existing_sprig_ids=)
|
data/spec/lib/sprig/reap_spec.rb
CHANGED
@@ -14,8 +14,14 @@ describe Sprig::Reap do
|
|
14
14
|
setup_seed_folder('./spec/fixtures/db/seeds/dreamland', &example)
|
15
15
|
end
|
16
16
|
|
17
|
+
after do
|
18
|
+
subject.clear_config
|
19
|
+
end
|
20
|
+
|
17
21
|
it "generates a seed file for each class" do
|
18
|
-
|
22
|
+
count = Sprig::Reap.classes.count
|
23
|
+
|
24
|
+
seed_file.should_receive(:write).exactly(count).times
|
19
25
|
|
20
26
|
subject.reap
|
21
27
|
end
|
@@ -30,7 +36,7 @@ describe Sprig::Reap do
|
|
30
36
|
|
31
37
|
context "in 'TARGET_ENV'" do
|
32
38
|
it "sets the environment" do
|
33
|
-
subject.reap('
|
39
|
+
subject.reap('TARGET_ENV' => ' Dreamland')
|
34
40
|
subject.target_env.should == 'dreamland'
|
35
41
|
end
|
36
42
|
end
|
@@ -68,4 +74,12 @@ describe Sprig::Reap do
|
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
77
|
+
|
78
|
+
describe ".clear_config" do
|
79
|
+
it "sets the configuration to nil" do
|
80
|
+
subject.clear_config
|
81
|
+
|
82
|
+
subject.class_variable_get(:@@configuration).should == nil
|
83
|
+
end
|
84
|
+
end
|
71
85
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -26,6 +26,8 @@ RSpec.configure do |config|
|
|
26
26
|
|
27
27
|
config.before(:each) do
|
28
28
|
DatabaseCleaner.start
|
29
|
+
|
30
|
+
stub_rails_application
|
29
31
|
end
|
30
32
|
|
31
33
|
config.after(:each) do
|
@@ -40,7 +42,10 @@ User.connection.execute "DROP TABLE IF EXISTS users;"
|
|
40
42
|
User.connection.execute "CREATE TABLE users (id INTEGER PRIMARY KEY , first_name VARCHAR(255), last_name VARCHAR(255), type VARCHAR(255));"
|
41
43
|
|
42
44
|
Post.connection.execute "DROP TABLE IF EXISTS posts;"
|
43
|
-
Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY , title VARCHAR(255), content VARCHAR(255), published BOOLEAN ,
|
45
|
+
Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY , title VARCHAR(255), content VARCHAR(255), published BOOLEAN , poster_id INTEGER);"
|
44
46
|
|
45
47
|
Comment.connection.execute "DROP TABLE IF EXISTS comments;"
|
46
48
|
Comment.connection.execute "CREATE TABLE comments (id INTEGER PRIMARY KEY , post_id INTEGER, body VARCHAR(255));"
|
49
|
+
|
50
|
+
Vote.connection.execute "DROP TABLE IF EXISTS votes;"
|
51
|
+
Vote.connection.execute "CREATE TABLE votes (id INTEGER PRIMARY KEY, votable_id INTEGER, votable_type VARCHAR(255));"
|
data/spec/support/rails_stubs.rb
CHANGED
@@ -8,4 +8,10 @@ module RailsStubs
|
|
8
8
|
def stub_rails_env(env='development')
|
9
9
|
Rails.stub(:env).and_return(env)
|
10
10
|
end
|
11
|
+
|
12
|
+
def stub_rails_application
|
13
|
+
application_double = double("application", :eager_load! => true)
|
14
|
+
|
15
|
+
Rails.stub(:application).and_return(application_double)
|
16
|
+
end
|
11
17
|
end
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprig-reap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Ryan Stenberg
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: sqlite3
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: database_cleaner
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,29 +78,33 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: pry
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
|
-
- - '>='
|
83
|
+
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
75
85
|
version: '0'
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
|
-
- - '>='
|
91
|
+
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
82
93
|
version: '0'
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: generator_spec
|
85
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
86
98
|
requirements:
|
87
|
-
- - '>='
|
99
|
+
- - ! '>='
|
88
100
|
- !ruby/object:Gem::Version
|
89
101
|
version: '0'
|
90
102
|
type: :development
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
93
106
|
requirements:
|
94
|
-
- - '>='
|
107
|
+
- - ! '>='
|
95
108
|
- !ruby/object:Gem::Version
|
96
109
|
version: '0'
|
97
110
|
description: Sprig-Reap is a gem that allows you to output your application's data
|
@@ -102,8 +115,10 @@ executables: []
|
|
102
115
|
extensions: []
|
103
116
|
extra_rdoc_files: []
|
104
117
|
files:
|
118
|
+
- lib/sprig/reap/association.rb
|
105
119
|
- lib/sprig/reap/configuration.rb
|
106
120
|
- lib/sprig/reap/model.rb
|
121
|
+
- lib/sprig/reap/railtie.rb
|
107
122
|
- lib/sprig/reap/record.rb
|
108
123
|
- lib/sprig/reap/seed_file.rb
|
109
124
|
- lib/sprig/reap/tsortable_hash.rb
|
@@ -118,11 +133,14 @@ files:
|
|
118
133
|
- spec/fixtures/models/comment.rb
|
119
134
|
- spec/fixtures/models/post.rb
|
120
135
|
- spec/fixtures/models/user.rb
|
136
|
+
- spec/fixtures/models/vote.rb
|
121
137
|
- spec/fixtures/yaml/comment_seeds.yml
|
138
|
+
- spec/fixtures/yaml/polymorphic_vote_record.yml
|
122
139
|
- spec/fixtures/yaml/post_seeds.yml
|
123
140
|
- spec/fixtures/yaml/records_with_namespace.yml
|
124
141
|
- spec/fixtures/yaml/records_without_namespace.yml
|
125
142
|
- spec/fixtures/yaml/user_seeds.yml
|
143
|
+
- spec/lib/sprig/reap/association_spec.rb
|
126
144
|
- spec/lib/sprig/reap/configuration_spec.rb
|
127
145
|
- spec/lib/sprig/reap/model_spec.rb
|
128
146
|
- spec/lib/sprig/reap/record_spec.rb
|
@@ -135,37 +153,41 @@ files:
|
|
135
153
|
homepage: http://www.github.com/vigetlabs/sprig-reap
|
136
154
|
licenses:
|
137
155
|
- MIT
|
138
|
-
metadata: {}
|
139
156
|
post_install_message:
|
140
157
|
rdoc_options: []
|
141
158
|
require_paths:
|
142
159
|
- lib
|
143
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
144
162
|
requirements:
|
145
|
-
- - '>='
|
163
|
+
- - ! '>='
|
146
164
|
- !ruby/object:Gem::Version
|
147
165
|
version: '0'
|
148
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
149
168
|
requirements:
|
150
|
-
- - '>='
|
169
|
+
- - ! '>='
|
151
170
|
- !ruby/object:Gem::Version
|
152
171
|
version: '0'
|
153
172
|
requirements: []
|
154
173
|
rubyforge_project:
|
155
|
-
rubygems_version:
|
174
|
+
rubygems_version: 1.8.23
|
156
175
|
signing_key:
|
157
|
-
specification_version:
|
176
|
+
specification_version: 3
|
158
177
|
summary: Automatic seed file generation for Rails apps using Sprig.
|
159
178
|
test_files:
|
160
179
|
- spec/db/activerecord.db
|
161
180
|
- spec/fixtures/models/comment.rb
|
162
181
|
- spec/fixtures/models/post.rb
|
163
182
|
- spec/fixtures/models/user.rb
|
183
|
+
- spec/fixtures/models/vote.rb
|
164
184
|
- spec/fixtures/yaml/comment_seeds.yml
|
185
|
+
- spec/fixtures/yaml/polymorphic_vote_record.yml
|
165
186
|
- spec/fixtures/yaml/post_seeds.yml
|
166
187
|
- spec/fixtures/yaml/records_with_namespace.yml
|
167
188
|
- spec/fixtures/yaml/records_without_namespace.yml
|
168
189
|
- spec/fixtures/yaml/user_seeds.yml
|
190
|
+
- spec/lib/sprig/reap/association_spec.rb
|
169
191
|
- spec/lib/sprig/reap/configuration_spec.rb
|
170
192
|
- spec/lib/sprig/reap/model_spec.rb
|
171
193
|
- spec/lib/sprig/reap/record_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: f72d013c5b2bbf87257269498744996d79443026
|
4
|
-
data.tar.gz: 57f5ec7ef4b336f5fada9d80e44e3968d6060495
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 11beed039a533edd3ad4d9a39ea237fd1c2f1a9e55c281950dc7e0d57c21c68b7d5466dd30e3435371346f7c5e5c480dff1508442cb14c209f87a478d8b03279
|
7
|
-
data.tar.gz: 73d1507a59b8c44690fc676f6e9e1ba6c15711ca8ba33b2ab697dfe8eb29252fc8daff5f042c0a3f7ec9a6ab355060858047f5ae4e2651c60a6d148d766fa229
|