sprig-reap 0.0.5 → 0.0.6
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/lib/sprig/reap/association.rb +4 -7
- data/lib/sprig/reap/file_attribute.rb +82 -0
- data/lib/sprig/reap/record.rb +10 -2
- data/lib/sprig/reap/version.rb +1 -1
- data/lib/sprig/reap.rb +1 -0
- data/spec/db/activerecord.db +0 -0
- data/spec/fixtures/images/avatar.png +0 -0
- data/spec/fixtures/models/post.rb +8 -0
- data/spec/fixtures/models/user.rb +4 -0
- data/spec/fixtures/uploaders/avatar_uploader.rb +3 -0
- data/spec/lib/sprig/reap/association_spec.rb +42 -2
- data/spec/lib/sprig/reap/file_attribute_spec.rb +201 -0
- data/spec/lib/sprig/reap/record_spec.rb +84 -36
- data/spec/spec_helper.rb +4 -2
- data/spec/support/matchers/be_same_file_as.rb +21 -0
- metadata +27 -2
@@ -2,12 +2,14 @@ module Sprig::Reap
|
|
2
2
|
class Association
|
3
3
|
attr_reader :association
|
4
4
|
|
5
|
+
delegate :foreign_key, :to => :association
|
6
|
+
|
5
7
|
def initialize(association)
|
6
8
|
@association = association
|
7
9
|
end
|
8
10
|
|
9
11
|
def klass
|
10
|
-
|
12
|
+
polymorphic? ? nil : association.klass
|
11
13
|
end
|
12
14
|
|
13
15
|
def name
|
@@ -33,13 +35,8 @@ module Sprig::Reap
|
|
33
35
|
polymorphic? ? polymorphic_dependencies : Array(klass)
|
34
36
|
end
|
35
37
|
|
36
|
-
def foreign_key
|
37
|
-
association.options[:foreign_key] || name.to_s + '_id'
|
38
|
-
end
|
39
|
-
|
40
38
|
def polymorphic_type
|
41
|
-
|
39
|
+
polymorphic? ? association.foreign_type : nil
|
42
40
|
end
|
43
|
-
|
44
41
|
end
|
45
42
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Sprig::Reap
|
2
|
+
class FileAttribute
|
3
|
+
attr_reader :input
|
4
|
+
|
5
|
+
def initialize(input)
|
6
|
+
@input = input
|
7
|
+
end
|
8
|
+
|
9
|
+
def file
|
10
|
+
local_file if file?
|
11
|
+
end
|
12
|
+
|
13
|
+
def file?
|
14
|
+
input.is_a? CarrierWave::Uploader::Base
|
15
|
+
end
|
16
|
+
|
17
|
+
def existing_location
|
18
|
+
begin
|
19
|
+
input.url if input.url.present? && open(input.url).is_a?(Tempfile)
|
20
|
+
rescue
|
21
|
+
input.path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def filename
|
26
|
+
File.basename(existing_location)
|
27
|
+
end
|
28
|
+
|
29
|
+
def target_folder
|
30
|
+
@target_folder ||= begin
|
31
|
+
path = Rails.root.join('db', 'seeds', Sprig::Reap.target_env, 'files')
|
32
|
+
FileUtils.mkdir_p(path)
|
33
|
+
path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def target_location
|
38
|
+
target_folder.join(filename)
|
39
|
+
end
|
40
|
+
|
41
|
+
def local_file
|
42
|
+
@local_file ||= LocalFile.new(existing_location, target_location)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
class LocalFile < Struct.new(:uri, :target_location)
|
48
|
+
delegate :path, :size, :to => :file
|
49
|
+
|
50
|
+
def file
|
51
|
+
@file ||= File.open(unique_location, 'w', :encoding => encoding).tap do |file|
|
52
|
+
io.rewind
|
53
|
+
file.write(io.read)
|
54
|
+
io.close
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def io
|
59
|
+
@io ||= open uri
|
60
|
+
end
|
61
|
+
|
62
|
+
def sprig_location
|
63
|
+
"<%= sprig_file('#{File.basename(file.path)}') %>"
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def unique_location
|
69
|
+
File.exist?(target_location) ? target_location.to_s.gsub(basename, basename + SecureRandom::uuid.to_s) : target_location
|
70
|
+
end
|
71
|
+
|
72
|
+
def encoding
|
73
|
+
io.rewind
|
74
|
+
io.read.encoding
|
75
|
+
end
|
76
|
+
|
77
|
+
def basename
|
78
|
+
@basename ||= File.basename(target_location).gsub(File.extname(target_location), '')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/sprig/reap/record.rb
CHANGED
@@ -30,11 +30,11 @@ module Sprig::Reap
|
|
30
30
|
if dependency?(attr)
|
31
31
|
klass = klass_for(attr)
|
32
32
|
id = record.send(attr)
|
33
|
-
sprig_id = Model.find(klass, id).sprig_id
|
33
|
+
sprig_id = Model.find(klass, id).try(:sprig_id)
|
34
34
|
|
35
35
|
sprig_record(klass, sprig_id)
|
36
36
|
else
|
37
|
-
|
37
|
+
read_attribute attr
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -57,7 +57,15 @@ module Sprig::Reap
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def sprig_record(klass, sprig_id)
|
60
|
+
return if sprig_id.nil?
|
61
|
+
|
60
62
|
"<%= sprig_record(#{klass}, #{sprig_id}).id %>"
|
61
63
|
end
|
64
|
+
|
65
|
+
def read_attribute(attr)
|
66
|
+
file_attr = FileAttribute.new(record.send(attr))
|
67
|
+
|
68
|
+
file_attr.file.try(:sprig_location) || record.read_attribute(attr)
|
69
|
+
end
|
62
70
|
end
|
63
71
|
end
|
data/lib/sprig/reap/version.rb
CHANGED
data/lib/sprig/reap.rb
CHANGED
data/spec/db/activerecord.db
CHANGED
Binary file
|
Binary file
|
@@ -36,6 +36,12 @@ describe Sprig::Reap::Association do
|
|
36
36
|
|
37
37
|
its(:klass) { should == User }
|
38
38
|
end
|
39
|
+
|
40
|
+
context "given a polymorphic association" do
|
41
|
+
subject { described_class.new(polymorphic_association) }
|
42
|
+
|
43
|
+
its(:klass) { should == nil }
|
44
|
+
end
|
39
45
|
end
|
40
46
|
|
41
47
|
describe "#polymorphic_dependencies" do
|
@@ -72,15 +78,49 @@ describe Sprig::Reap::Association do
|
|
72
78
|
|
73
79
|
describe "#dependencies" do
|
74
80
|
context "when the association is polymorphic" do
|
75
|
-
subject { described_class.new(
|
81
|
+
subject { described_class.new(polymorphic_association) }
|
76
82
|
|
77
83
|
its(:dependencies) { should == [Post] }
|
78
84
|
end
|
79
85
|
|
80
86
|
context "when the association is not polymorphic" do
|
81
|
-
subject { described_class.new(
|
87
|
+
subject { described_class.new(standard_association) }
|
82
88
|
|
83
89
|
its(:dependencies) { should == [Post] }
|
84
90
|
end
|
85
91
|
end
|
92
|
+
|
93
|
+
describe "#foreign_key" do
|
94
|
+
context "given a standard association" do
|
95
|
+
subject { described_class.new(standard_association) }
|
96
|
+
|
97
|
+
its(:foreign_key) { should == 'post_id' }
|
98
|
+
end
|
99
|
+
|
100
|
+
context "given a named association" do
|
101
|
+
subject { described_class.new(class_named_association) }
|
102
|
+
|
103
|
+
its(:foreign_key) { should == 'poster_id' }
|
104
|
+
end
|
105
|
+
|
106
|
+
context "given a polymorphic association" do
|
107
|
+
subject { described_class.new(polymorphic_association) }
|
108
|
+
|
109
|
+
its(:foreign_key) { should == 'votable_id' }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#polymorphic_type" do
|
114
|
+
context "when the association is polymorphic" do
|
115
|
+
subject { described_class.new(polymorphic_association) }
|
116
|
+
|
117
|
+
its(:polymorphic_type) { should == 'votable_type' }
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when the association is not polymorphic" do
|
121
|
+
subject { described_class.new(standard_association) }
|
122
|
+
|
123
|
+
its(:polymorphic_type) { should == nil }
|
124
|
+
end
|
125
|
+
end
|
86
126
|
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sprig::Reap::FileAttribute do
|
4
|
+
let!(:user) do
|
5
|
+
User.create(:first_name => 'Bo',
|
6
|
+
:last_name => 'Janglez',
|
7
|
+
:avatar => File.open('spec/fixtures/images/avatar.png'))
|
8
|
+
end
|
9
|
+
|
10
|
+
let!(:carrierwave) { described_class.new(user.avatar) }
|
11
|
+
let!(:not_a_file) { described_class.new(user.first_name) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
stub_rails_root
|
15
|
+
Sprig::Reap.stub(:target_env).and_return('dreamland')
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
FileUtils.remove_dir('./uploads') # Generated by CarrierWave
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#file" do
|
23
|
+
around do |example|
|
24
|
+
setup_seed_folder('./spec/fixtures/db/seeds/dreamland/files', &example)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when the given input is a carrierwave uploader" do
|
28
|
+
subject { carrierwave }
|
29
|
+
|
30
|
+
its(:file) { should be_an_instance_of(Sprig::Reap::FileAttribute::LocalFile) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the given input is not a recognized file object" do
|
34
|
+
subject { not_a_file }
|
35
|
+
|
36
|
+
its(:file) { should == nil }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#file?" do
|
41
|
+
context "when the given input is a carrierwave uploader" do
|
42
|
+
subject { carrierwave }
|
43
|
+
|
44
|
+
its(:file?) { should == true }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the given input is not a recognized file object" do
|
48
|
+
subject { not_a_file }
|
49
|
+
|
50
|
+
its(:file?) { should == false }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#existing_location" do
|
55
|
+
subject { carrierwave }
|
56
|
+
|
57
|
+
context "for a locally-stored file" do
|
58
|
+
its(:existing_location) { should == subject.input.path }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "for a remotely-stored file" do
|
62
|
+
context "with an incomplete url (CarrierWave storage set to :file for dev/test)" do
|
63
|
+
before { subject.input.stub(:url).and_return('/carrierwave/storage/file') }
|
64
|
+
|
65
|
+
it "falls back to the local path in the case of " do
|
66
|
+
subject.existing_location.should == subject.input.path
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with a valid url" do
|
71
|
+
before { mock_remote subject }
|
72
|
+
|
73
|
+
its(:existing_location) { should == sprig_logo_url }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#filename" do
|
79
|
+
subject { carrierwave }
|
80
|
+
|
81
|
+
context "for a locally-stored file" do
|
82
|
+
its(:filename) { should == 'avatar.png' }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "for a remotely-stored file" do
|
86
|
+
before { mock_remote subject }
|
87
|
+
|
88
|
+
its(:filename) { should == File.basename(sprig_logo_url) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#target_location" do
|
93
|
+
subject { carrierwave }
|
94
|
+
|
95
|
+
context "when the files folder does not exist" do
|
96
|
+
let(:files_folder) { './spec/fixtures/db/seeds/dreamland/files' }
|
97
|
+
let(:delete_folder) { FileUtils.remove_dir(files_folder) if Dir.exists?(files_folder) }
|
98
|
+
|
99
|
+
before { delete_folder }
|
100
|
+
after { delete_folder }
|
101
|
+
|
102
|
+
it "creates the folder and returns the path" do
|
103
|
+
Dir.exists?(files_folder).should == false
|
104
|
+
|
105
|
+
subject.target_location.to_s.should == files_folder + '/' + subject.filename
|
106
|
+
|
107
|
+
Dir.exists?(files_folder).should == true
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when the files folder exists" do
|
112
|
+
around do |example|
|
113
|
+
setup_seed_folder('./spec/fixtures/db/seeds/dreamland/files', &example)
|
114
|
+
end
|
115
|
+
|
116
|
+
its(:target_location) { should == Rails.root.join('db', 'seeds', 'dreamland', 'files', subject.filename) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#local_file" do
|
121
|
+
around do |example|
|
122
|
+
setup_seed_folder('./spec/fixtures/db/seeds/dreamland/files', &example)
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when the existing location is a url" do
|
126
|
+
subject { carrierwave }
|
127
|
+
|
128
|
+
let(:local_file) { subject.local_file }
|
129
|
+
|
130
|
+
before do
|
131
|
+
mock_remote subject
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns a LocalFile" do
|
135
|
+
local_file.should be_an_instance_of(Sprig::Reap::FileAttribute::LocalFile)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "creates a file at the target location" do
|
139
|
+
local_file.path.should == subject.target_location.to_s
|
140
|
+
end
|
141
|
+
|
142
|
+
it "creates a file with the same contents as the file from the existing location" do
|
143
|
+
File.open(local_file.path, 'r') do |local_file|
|
144
|
+
open(subject.existing_location) do |existing_file|
|
145
|
+
local_file.should be_same_file_as(existing_file)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "and a file already exists at the target location" do
|
151
|
+
before do
|
152
|
+
File.stub(:exist?).with(subject.target_location).and_return(true)
|
153
|
+
end
|
154
|
+
|
155
|
+
it "assigns a unique filename" do
|
156
|
+
local_file.path.should_not == subject.target_location.to_s
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when the existing location is a path" do
|
162
|
+
subject { carrierwave }
|
163
|
+
|
164
|
+
let(:local_file) { subject.local_file }
|
165
|
+
|
166
|
+
it "returns a LocalFile" do
|
167
|
+
local_file.should be_an_instance_of(Sprig::Reap::FileAttribute::LocalFile)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "creates a file at the target location" do
|
171
|
+
local_file.path.should == subject.target_location.to_s
|
172
|
+
end
|
173
|
+
|
174
|
+
it "creates a file with the same contents as the file from the existing location" do
|
175
|
+
File.open(local_file.path, 'r') do |local_file|
|
176
|
+
File.open(subject.existing_location, 'r') do |existing_file|
|
177
|
+
local_file.should be_same_file_as(existing_file)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "and a file already exists at the target location" do
|
183
|
+
before do
|
184
|
+
File.stub(:exist?).with(subject.target_location).and_return(true)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "assigns a unique filename" do
|
188
|
+
local_file.path.should_not == subject.target_location.to_s
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def mock_remote(file_attr)
|
195
|
+
file_attr.input.stub(:url).and_return(sprig_logo_url)
|
196
|
+
end
|
197
|
+
|
198
|
+
def sprig_logo_url
|
199
|
+
'https://camo.githubusercontent.com/ac48b093dc90330d2b9f3bb59671d384fe092166/687474703a2f2f692e696d6775722e636f6d2f5843753369564f2e706e67'
|
200
|
+
end
|
201
|
+
end
|
@@ -3,68 +3,116 @@ require 'spec_helper'
|
|
3
3
|
class Very; end
|
4
4
|
|
5
5
|
describe Sprig::Reap::Record do
|
6
|
-
let(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
double('Sprig::Reap::Association',
|
11
|
-
:foreign_key => "very_id",
|
12
|
-
:klass => Very,
|
13
|
-
:polymorphic? => false
|
14
|
-
)
|
6
|
+
let!(:user) do
|
7
|
+
User.create(:first_name => 'Bo',
|
8
|
+
:last_name => 'Janglez',
|
9
|
+
:avatar => File.open('spec/fixtures/images/avatar.png'))
|
15
10
|
end
|
16
|
-
let(:sprig_record) { "<%= sprig_record(Very, 5).id %>" }
|
17
11
|
|
18
|
-
|
12
|
+
let!(:post) do
|
13
|
+
Post.create(:poster => user,
|
14
|
+
:title => 'Such Title',
|
15
|
+
:content => 'Very Content',
|
16
|
+
:published => true)
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}
|
27
|
-
|
28
|
-
attrs.each_pair do |attr, val|
|
29
|
-
record.stub(attr).and_return(val)
|
30
|
-
end
|
19
|
+
let!(:posterless_post) do
|
20
|
+
Post.create(:poster => nil,
|
21
|
+
:title => 'Wow Title',
|
22
|
+
:content => 'Much Content',
|
23
|
+
:published => false)
|
24
|
+
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
let!(:models) { Sprig::Reap::Model.all }
|
27
|
+
let!(:model) { models.find { |model| model.klass == Post } }
|
28
|
+
|
29
|
+
before do
|
30
|
+
stub_rails_root
|
31
|
+
Sprig::Reap.stub(:target_env).and_return('dreamland')
|
32
|
+
end
|
35
33
|
|
36
|
-
|
34
|
+
after do
|
35
|
+
FileUtils.remove_dir('./uploads')
|
37
36
|
end
|
38
37
|
|
39
|
-
|
38
|
+
describe "#id" do
|
39
|
+
subject { described_class.new(post, model) }
|
40
|
+
|
41
|
+
its(:id) { should == post.id }
|
42
|
+
end
|
40
43
|
|
41
44
|
describe "#attributes" do
|
45
|
+
subject { described_class.new(post, model) }
|
46
|
+
|
42
47
|
it "returns an array of attributes from the given model sans id" do
|
43
48
|
subject.attributes.should == %w(
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
title
|
50
|
+
content
|
51
|
+
published
|
52
|
+
poster_id
|
47
53
|
)
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
51
57
|
describe "#to_hash" do
|
58
|
+
subject { described_class.new(post, model) }
|
59
|
+
|
52
60
|
it "returns its attributes and their values in a hash" do
|
53
61
|
subject.to_hash.should == {
|
54
|
-
'sprig_id'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
62
|
+
'sprig_id' => post.id,
|
63
|
+
'title' => 'Such Title',
|
64
|
+
'content' => 'Very Content',
|
65
|
+
'published' => true,
|
66
|
+
'poster_id' => "<%= sprig_record(User, #{user.id}).id %>"
|
58
67
|
}
|
59
68
|
end
|
69
|
+
|
70
|
+
context "when an association/foreign_key is nil" do
|
71
|
+
subject { described_class.new(posterless_post, model) }
|
72
|
+
|
73
|
+
it "does not list a sprig record for the nil association" do
|
74
|
+
subject.to_hash.should == {
|
75
|
+
'sprig_id' => posterless_post.id,
|
76
|
+
'title' => 'Wow Title',
|
77
|
+
'content' => 'Much Content',
|
78
|
+
'published' => false,
|
79
|
+
'poster_id' => nil
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when an attribute is wrapped in a CarrierWave uploader" do
|
85
|
+
let(:user_model) { models.find { |model| model.klass == User } }
|
86
|
+
|
87
|
+
subject { described_class.new(user, user_model) }
|
88
|
+
|
89
|
+
around do |example|
|
90
|
+
setup_seed_folder('./spec/fixtures/db/seeds/dreamland/files', &example)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "provides a path for a locally-stored version of the file" do
|
94
|
+
subject.to_hash.should == {
|
95
|
+
'sprig_id' => user.id,
|
96
|
+
'first_name' => 'Bo',
|
97
|
+
'last_name' => 'Janglez',
|
98
|
+
'type' => user.type,
|
99
|
+
'avatar' => "<%= sprig_file('avatar.png') %>"
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#local_file_for" do
|
60
106
|
end
|
61
107
|
|
62
108
|
describe "#sprig_id" do
|
63
|
-
|
109
|
+
subject { described_class.new(post, model) }
|
110
|
+
|
111
|
+
its(:sprig_id) { should == post.id }
|
64
112
|
|
65
113
|
context "when an existing seed record has a sprig_id equal to the record's id" do
|
66
114
|
before do
|
67
|
-
model.stub(:existing_sprig_ids).and_return([
|
115
|
+
model.stub(:existing_sprig_ids).and_return([post.id])
|
68
116
|
model.stub(:generate_sprig_id).and_return(25)
|
69
117
|
end
|
70
118
|
|
data/spec/spec_helper.rb
CHANGED
@@ -5,11 +5,13 @@ require "active_record"
|
|
5
5
|
require "database_cleaner"
|
6
6
|
require "pry"
|
7
7
|
require "generator_spec"
|
8
|
+
require "carrierwave"
|
9
|
+
require 'carrierwave/orm/activerecord'
|
8
10
|
|
9
11
|
require "sprig-reap"
|
10
12
|
|
11
13
|
%w(
|
12
|
-
/fixtures
|
14
|
+
/fixtures/**/*.rb
|
13
15
|
/support/**/*.rb
|
14
16
|
).each do |file_set|
|
15
17
|
Dir[File.dirname(__FILE__) + file_set].each { |file| require file }
|
@@ -39,7 +41,7 @@ end
|
|
39
41
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "spec/db/activerecord.db")
|
40
42
|
|
41
43
|
User.connection.execute "DROP TABLE IF EXISTS users;"
|
42
|
-
User.connection.execute "CREATE TABLE users (id INTEGER PRIMARY KEY , first_name VARCHAR(255), last_name VARCHAR(255), type VARCHAR(255));"
|
44
|
+
User.connection.execute "CREATE TABLE users (id INTEGER PRIMARY KEY , first_name VARCHAR(255), last_name VARCHAR(255), type VARCHAR(255), avatar VARCHAR(225));"
|
43
45
|
|
44
46
|
Post.connection.execute "DROP TABLE IF EXISTS posts;"
|
45
47
|
Post.connection.execute "CREATE TABLE posts (id INTEGER PRIMARY KEY , title VARCHAR(255), content VARCHAR(255), published BOOLEAN , poster_id INTEGER);"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec::Matchers.define(:be_same_file_as) do |exected_file|
|
2
|
+
match do |actual_file|
|
3
|
+
md5_hash(relevant_contents_of(actual_file)).should == md5_hash(relevant_contents_of(exected_file))
|
4
|
+
end
|
5
|
+
|
6
|
+
def md5_hash(string)
|
7
|
+
Digest::MD5.hexdigest(string)
|
8
|
+
end
|
9
|
+
|
10
|
+
def relevant_contents_of(file)
|
11
|
+
file.read.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '').tap do |contents|
|
12
|
+
contents.sub!(/\/Title[^\n]*/, '')
|
13
|
+
contents.sub!(/\/CreationDate[^\n]*/, '')
|
14
|
+
contents.sub!(/\/ModDate[^\n]*/, '')
|
15
|
+
contents.sub!(/\/Producer[^\n]*/, '')
|
16
|
+
contents.sub!(/\/ID[^\]]*/, '')
|
17
|
+
contents.sub!(/\/DocChecksum[^\n]*/, '')
|
18
|
+
contents.sub!(/startxref\n[\d]+/, '')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: carrierwave
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.10.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.10.0
|
110
126
|
description: Sprig-Reap is a gem that allows you to output your application's data
|
111
127
|
state to seed files.
|
112
128
|
email:
|
@@ -117,6 +133,7 @@ extra_rdoc_files: []
|
|
117
133
|
files:
|
118
134
|
- lib/sprig/reap/association.rb
|
119
135
|
- lib/sprig/reap/configuration.rb
|
136
|
+
- lib/sprig/reap/file_attribute.rb
|
120
137
|
- lib/sprig/reap/model.rb
|
121
138
|
- lib/sprig/reap/railtie.rb
|
122
139
|
- lib/sprig/reap/record.rb
|
@@ -130,10 +147,12 @@ files:
|
|
130
147
|
- Rakefile
|
131
148
|
- README.md
|
132
149
|
- spec/db/activerecord.db
|
150
|
+
- spec/fixtures/images/avatar.png
|
133
151
|
- spec/fixtures/models/comment.rb
|
134
152
|
- spec/fixtures/models/post.rb
|
135
153
|
- spec/fixtures/models/user.rb
|
136
154
|
- spec/fixtures/models/vote.rb
|
155
|
+
- spec/fixtures/uploaders/avatar_uploader.rb
|
137
156
|
- spec/fixtures/yaml/comment_seeds.yml
|
138
157
|
- spec/fixtures/yaml/polymorphic_vote_record.yml
|
139
158
|
- spec/fixtures/yaml/post_seeds.yml
|
@@ -142,6 +161,7 @@ files:
|
|
142
161
|
- spec/fixtures/yaml/user_seeds.yml
|
143
162
|
- spec/lib/sprig/reap/association_spec.rb
|
144
163
|
- spec/lib/sprig/reap/configuration_spec.rb
|
164
|
+
- spec/lib/sprig/reap/file_attribute_spec.rb
|
145
165
|
- spec/lib/sprig/reap/model_spec.rb
|
146
166
|
- spec/lib/sprig/reap/record_spec.rb
|
147
167
|
- spec/lib/sprig/reap/seed_file_spec.rb
|
@@ -149,6 +169,7 @@ files:
|
|
149
169
|
- spec/lib/sprig_spec.rb
|
150
170
|
- spec/spec_helper.rb
|
151
171
|
- spec/support/file_setup.rb
|
172
|
+
- spec/support/matchers/be_same_file_as.rb
|
152
173
|
- spec/support/rails_stubs.rb
|
153
174
|
homepage: http://www.github.com/vigetlabs/sprig-reap
|
154
175
|
licenses:
|
@@ -177,10 +198,12 @@ specification_version: 3
|
|
177
198
|
summary: Automatic seed file generation for Rails apps using Sprig.
|
178
199
|
test_files:
|
179
200
|
- spec/db/activerecord.db
|
201
|
+
- spec/fixtures/images/avatar.png
|
180
202
|
- spec/fixtures/models/comment.rb
|
181
203
|
- spec/fixtures/models/post.rb
|
182
204
|
- spec/fixtures/models/user.rb
|
183
205
|
- spec/fixtures/models/vote.rb
|
206
|
+
- spec/fixtures/uploaders/avatar_uploader.rb
|
184
207
|
- spec/fixtures/yaml/comment_seeds.yml
|
185
208
|
- spec/fixtures/yaml/polymorphic_vote_record.yml
|
186
209
|
- spec/fixtures/yaml/post_seeds.yml
|
@@ -189,6 +212,7 @@ test_files:
|
|
189
212
|
- spec/fixtures/yaml/user_seeds.yml
|
190
213
|
- spec/lib/sprig/reap/association_spec.rb
|
191
214
|
- spec/lib/sprig/reap/configuration_spec.rb
|
215
|
+
- spec/lib/sprig/reap/file_attribute_spec.rb
|
192
216
|
- spec/lib/sprig/reap/model_spec.rb
|
193
217
|
- spec/lib/sprig/reap/record_spec.rb
|
194
218
|
- spec/lib/sprig/reap/seed_file_spec.rb
|
@@ -196,4 +220,5 @@ test_files:
|
|
196
220
|
- spec/lib/sprig_spec.rb
|
197
221
|
- spec/spec_helper.rb
|
198
222
|
- spec/support/file_setup.rb
|
223
|
+
- spec/support/matchers/be_same_file_as.rb
|
199
224
|
- spec/support/rails_stubs.rb
|