sequel-seed 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/lib/sequel/extensions/seed.rb +24 -22
- data/spec/extensions/seed_spec.rb +165 -163
- data/spec/extensions/seed_with_pg_array_spec.rb +185 -182
- data/spec/spec_helper.rb +9 -7
- metadata +8 -8
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
describe Sequel::Seeder do
|
4
|
-
let!(:environment) {"#{Faker::Lorem.word}_#{Faker::Lorem.word}"}
|
5
|
-
let!(:random_word) {Faker::Lorem.word}
|
6
|
+
let!(:environment) { "#{Faker::Lorem.word}_#{Faker::Lorem.word}" }
|
7
|
+
let!(:random_word) { Faker::Lorem.word }
|
6
8
|
|
7
9
|
before do
|
8
10
|
Sequel.extension :seed
|
@@ -13,14 +15,15 @@ describe Sequel::Seeder do
|
|
13
15
|
|
14
16
|
before(:all) do
|
15
17
|
dsn = begin
|
16
|
-
if RUBY_PLATFORM ==
|
17
|
-
|
18
|
+
if RUBY_PLATFORM == "java"
|
19
|
+
"jdbc:postgresql://localhost/sequel_seed_test"
|
18
20
|
else
|
19
|
-
|
21
|
+
"postgres://localhost/sequel_seed_test"
|
20
22
|
end
|
21
23
|
end
|
22
24
|
@db = Sequel.connect(dsn)
|
23
25
|
@db.extension(:pg_array)
|
26
|
+
@db.drop_table?(:array_spec_models)
|
24
27
|
@db.create_table(:array_spec_models) do
|
25
28
|
primary_key :id, :serial
|
26
29
|
column :selectors, "text[]"
|
@@ -40,391 +43,391 @@ describe Sequel::Seeder do
|
|
40
43
|
Sequel::Seed.setup environment
|
41
44
|
|
42
45
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
43
|
-
expect{Sequel::Seeder.apply(@db,
|
46
|
+
expect { Sequel::Seeder.apply(@db, "/") }.to raise_error("seeder not available for files; please check the configured seed directory \"/\". Also ensure seed files are in YYYYMMDD_seed_file.rb format.")
|
44
47
|
expect(ArraySpecModel.dataset.all.length).to be 0
|
45
48
|
end
|
46
49
|
|
47
50
|
describe "Seeds defined using Ruby code (.rb extension)" do
|
48
|
-
describe
|
49
|
-
context
|
50
|
-
it
|
51
|
+
describe "environment references should be indistinguishable between Symbol and String" do
|
52
|
+
context "when the environment is defined using a String" do
|
53
|
+
it "should apply the Seed accordingly" do
|
51
54
|
Sequel::Seed.setup environment
|
52
55
|
|
53
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
56
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
54
57
|
f.puts "Sequel.seed(:#{environment}) do"
|
55
|
-
f.puts
|
56
|
-
f.puts
|
57
|
-
f.puts
|
58
|
-
f.puts
|
59
|
-
f.puts
|
60
|
-
f.puts
|
58
|
+
f.puts " def run"
|
59
|
+
f.puts " ArraySpecModel.create \\"
|
60
|
+
f.puts " :sentence => \"environment defined by String\","
|
61
|
+
f.puts " :selectors => [\".body\", \".header\", \".string\"]"
|
62
|
+
f.puts " end"
|
63
|
+
f.puts "end"
|
61
64
|
end
|
62
65
|
|
63
66
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
64
67
|
expect(Sequel::Seeder.seeder_class(seed_test_dir)).to be Sequel::TimestampSeeder
|
65
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
68
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
66
69
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
67
70
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
68
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
69
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
71
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "environment defined by String"
|
72
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".string")
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
73
|
-
context
|
74
|
-
it
|
76
|
+
context "when the Seed is defined using a String" do
|
77
|
+
it "should apply the Seed accordingly" do
|
75
78
|
Sequel::Seed.setup environment.to_sym
|
76
79
|
|
77
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
80
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
78
81
|
f.puts "Sequel.seed(\"#{environment}\") do"
|
79
|
-
f.puts
|
80
|
-
f.puts
|
81
|
-
f.puts
|
82
|
-
f.puts
|
83
|
-
f.puts
|
84
|
-
f.puts
|
82
|
+
f.puts " def run"
|
83
|
+
f.puts " ArraySpecModel.create \\"
|
84
|
+
f.puts " :sentence => \"Seed defined by String\","
|
85
|
+
f.puts " :selectors => [\".body\", \".header\", \".environment\"]"
|
86
|
+
f.puts " end"
|
87
|
+
f.puts "end"
|
85
88
|
end
|
86
89
|
|
87
90
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
88
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
91
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
89
92
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
90
93
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
91
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
92
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
94
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "Seed defined by String"
|
95
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".environment")
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
96
|
-
context
|
97
|
-
it
|
99
|
+
context "when both Seed and environment are defined using a String" do
|
100
|
+
it "should apply the Seed accordingly" do
|
98
101
|
Sequel::Seed.setup environment
|
99
102
|
|
100
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
103
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
101
104
|
f.puts "Sequel.seed(\"#{environment}\") do"
|
102
|
-
f.puts
|
103
|
-
f.puts
|
104
|
-
f.puts
|
105
|
-
f.puts
|
106
|
-
f.puts
|
107
|
-
f.puts
|
105
|
+
f.puts " def run"
|
106
|
+
f.puts " ArraySpecModel.create \\"
|
107
|
+
f.puts " :sentence => \"Seed and environment defined by String\","
|
108
|
+
f.puts " :selectors => [\".body\", \".header\", \".string\", \".environment\"]"
|
109
|
+
f.puts " end"
|
110
|
+
f.puts "end"
|
108
111
|
end
|
109
112
|
|
110
113
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
111
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
114
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
112
115
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
113
116
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
114
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
115
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
117
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "Seed and environment defined by String"
|
118
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".string", ".environment")
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
119
|
-
context
|
120
|
-
it
|
122
|
+
context "when both Seed and environment are defined using a Symbol" do
|
123
|
+
it "should apply the Seed accordingly" do
|
121
124
|
Sequel::Seed.setup environment.to_sym
|
122
125
|
|
123
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
126
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
124
127
|
f.puts "Sequel.seed(:#{environment}) do"
|
125
|
-
f.puts
|
126
|
-
f.puts
|
127
|
-
f.puts
|
128
|
-
f.puts
|
129
|
-
f.puts
|
130
|
-
f.puts
|
128
|
+
f.puts " def run"
|
129
|
+
f.puts " ArraySpecModel.create \\"
|
130
|
+
f.puts " :sentence => \"Seed and environment defined by Symbol\","
|
131
|
+
f.puts " :selectors => [\".body\", \".header\", \".string\", \".environment\", \".symbol\"]"
|
132
|
+
f.puts " end"
|
133
|
+
f.puts "end"
|
131
134
|
end
|
132
135
|
|
133
136
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
134
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
137
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
135
138
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
136
139
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
137
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
138
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
140
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "Seed and environment defined by Symbol"
|
141
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".string", ".environment", ".symbol")
|
139
142
|
end
|
140
143
|
end
|
141
144
|
|
142
|
-
context
|
143
|
-
it
|
145
|
+
context "when the environment is defined using a String and we have a wildcard Seed" do
|
146
|
+
it "should apply the Seed accordingly" do
|
144
147
|
Sequel::Seed.setup environment
|
145
148
|
|
146
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
147
|
-
f.puts
|
148
|
-
f.puts
|
149
|
-
f.puts
|
150
|
-
f.puts
|
151
|
-
f.puts
|
152
|
-
f.puts
|
153
|
-
f.puts
|
149
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
150
|
+
f.puts "Sequel.seed do"
|
151
|
+
f.puts " def run"
|
152
|
+
f.puts " ArraySpecModel.create \\"
|
153
|
+
f.puts " :sentence => \"Wildcard Seed and environment defined by String\","
|
154
|
+
f.puts " :selectors => [\".body\", \".header\", \".string\", \".wildcard\"]"
|
155
|
+
f.puts " end"
|
156
|
+
f.puts "end"
|
154
157
|
end
|
155
158
|
|
156
159
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
157
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
160
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
158
161
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
159
162
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
160
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
161
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
163
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "Wildcard Seed and environment defined by String"
|
164
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".string", ".wildcard")
|
162
165
|
end
|
163
166
|
end
|
164
167
|
end
|
165
168
|
|
166
|
-
context
|
167
|
-
it
|
169
|
+
context "when there\"s a Seed created" do
|
170
|
+
it "should change the database accordingly only once" do
|
168
171
|
Sequel::Seed.setup environment
|
169
172
|
|
170
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
171
|
-
f.puts
|
172
|
-
f.puts
|
173
|
-
f.puts
|
174
|
-
f.puts
|
175
|
-
f.puts
|
176
|
-
f.puts
|
177
|
-
f.puts
|
173
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
174
|
+
f.puts "Sequel.seed do"
|
175
|
+
f.puts " def run"
|
176
|
+
f.puts " ArraySpecModel.create \\"
|
177
|
+
f.puts " :sentence => \"should have changed (from Ruby file)\","
|
178
|
+
f.puts " :selectors => [\".body\", \".header\", \".string\", \".ruby\"]"
|
179
|
+
f.puts " end"
|
180
|
+
f.puts "end"
|
178
181
|
end
|
179
182
|
|
180
183
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
181
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
184
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
182
185
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
183
186
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
184
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
185
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
187
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from Ruby file)"
|
188
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".string", ".ruby")
|
186
189
|
# Once again
|
187
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
190
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
188
191
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
189
192
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
190
|
-
expect(ArraySpecModel.dataset.first.sentence).to eq
|
191
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
193
|
+
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from Ruby file)"
|
194
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".string", ".ruby")
|
192
195
|
end
|
193
196
|
end
|
194
197
|
|
195
|
-
context
|
196
|
-
it
|
198
|
+
context "when the specified Seed is not applicable to the given environment" do
|
199
|
+
it "should not make any change to the database" do
|
197
200
|
Sequel::Seed.setup environment
|
198
201
|
|
199
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.rb",
|
202
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.rb", "w+") do |f|
|
200
203
|
f.puts "Sequel.seed(:another_#{Faker::Lorem.word}_word) do"
|
201
|
-
f.puts
|
202
|
-
f.puts
|
203
|
-
f.puts
|
204
|
-
f.puts
|
205
|
-
f.puts
|
206
|
-
f.puts
|
204
|
+
f.puts " def run"
|
205
|
+
f.puts " ArraySpecModel.create \\"
|
206
|
+
f.puts " :sentence => \"should not have changed (from Ruby file)\","
|
207
|
+
f.puts " :selectors => [\".body\", \".header\", \".unchanged\", \".ruby\"]"
|
208
|
+
f.puts " end"
|
209
|
+
f.puts "end"
|
207
210
|
end
|
208
211
|
|
209
212
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
210
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
213
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
211
214
|
expect(ArraySpecModel.dataset.all.length).to be 0
|
212
215
|
end
|
213
216
|
end
|
214
217
|
end
|
215
218
|
|
216
|
-
describe
|
217
|
-
it
|
219
|
+
describe "Seeds defined using YAML code (.{yaml,yml} extension)" do
|
220
|
+
it "should apply a basic YAML Seed if it was specified for the given environment" do
|
218
221
|
Sequel::Seed.setup environment
|
219
222
|
|
220
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.yml",
|
223
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.yml", "w+") do |f|
|
221
224
|
f.puts "environment: :#{environment}"
|
222
|
-
f.puts
|
223
|
-
f.puts " sentence:
|
225
|
+
f.puts "array_spec_model:"
|
226
|
+
f.puts " sentence: \"should have changed (from YAML file) #{random_word}\""
|
224
227
|
f.puts " selectors:"
|
225
|
-
f.puts " -
|
226
|
-
f.puts " -
|
227
|
-
f.puts " -
|
228
|
-
f.puts
|
228
|
+
f.puts " - \".body\""
|
229
|
+
f.puts " - \".header\""
|
230
|
+
f.puts " - \".yaml\""
|
231
|
+
f.puts ""
|
229
232
|
end
|
230
233
|
|
231
234
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
232
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
235
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
233
236
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
234
237
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
235
238
|
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from YAML file) #{random_word}"
|
236
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
239
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".yaml")
|
237
240
|
end
|
238
241
|
|
239
|
-
it
|
242
|
+
it "should apply a YAML Seed if it was specified for the given environment" do
|
240
243
|
Sequel::Seed.setup environment
|
241
244
|
|
242
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.yml",
|
245
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.yml", "w+") do |f|
|
243
246
|
f.puts "environment: :#{environment}"
|
244
|
-
f.puts
|
245
|
-
f.puts
|
246
|
-
f.puts
|
247
|
-
f.puts
|
248
|
-
f.puts " sentence:
|
247
|
+
f.puts "model:"
|
248
|
+
f.puts " class: \"ArraySpecModel\""
|
249
|
+
f.puts " entries:"
|
250
|
+
f.puts " -"
|
251
|
+
f.puts " sentence: \"should have changed (from YAML file) #{random_word}\""
|
249
252
|
f.puts " selectors:"
|
250
253
|
f.puts " - .body"
|
251
254
|
f.puts " - .header"
|
252
255
|
f.puts " - .yaml"
|
253
|
-
f.puts
|
256
|
+
f.puts ""
|
254
257
|
end
|
255
258
|
|
256
259
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
257
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
260
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
258
261
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
259
262
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
260
263
|
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from YAML file) #{random_word}"
|
261
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
264
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".yaml")
|
262
265
|
end
|
263
266
|
|
264
|
-
it
|
267
|
+
it "should apply a YAML file with multiple Seeds descriptors if they were specified for the given environment" do
|
265
268
|
Sequel::Seed.setup environment
|
266
269
|
|
267
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.yml",
|
268
|
-
f.puts
|
270
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.yml", "w+") do |f|
|
271
|
+
f.puts "-"
|
269
272
|
f.puts " environment: :#{environment}"
|
270
|
-
f.puts
|
271
|
-
f.puts
|
272
|
-
f.puts
|
273
|
-
f.puts
|
274
|
-
f.puts " sentence:
|
273
|
+
f.puts " model:"
|
274
|
+
f.puts " class: \"ArraySpecModel\""
|
275
|
+
f.puts " entries:"
|
276
|
+
f.puts " -"
|
277
|
+
f.puts " sentence: \"should have changed (from YAML file) #{random_word}\""
|
275
278
|
f.puts " selectors:"
|
276
279
|
f.puts " - .body"
|
277
280
|
f.puts " - .header"
|
278
281
|
f.puts " - .yaml"
|
279
282
|
f.puts " - .environment"
|
280
|
-
f.puts
|
283
|
+
f.puts "-"
|
281
284
|
f.puts " environment: :another_#{environment}"
|
282
|
-
f.puts
|
283
|
-
f.puts " sentence:
|
285
|
+
f.puts " array_spec_model:"
|
286
|
+
f.puts " sentence: \"should not have changed (from YAML file) #{random_word}\""
|
284
287
|
f.puts " selectors:"
|
285
288
|
f.puts " - .body"
|
286
289
|
f.puts " - .header"
|
287
290
|
f.puts " - .yaml"
|
288
291
|
f.puts " - .another_environment"
|
289
|
-
f.puts
|
292
|
+
f.puts ""
|
290
293
|
end
|
291
294
|
|
292
295
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
293
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
296
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
294
297
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
295
298
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
296
299
|
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from YAML file) #{random_word}"
|
297
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
300
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".yaml", ".environment")
|
298
301
|
end
|
299
302
|
|
300
|
-
it
|
303
|
+
it "should not apply a basic Seed if it was not specified for the given environment" do
|
301
304
|
Sequel::Seed.setup environment
|
302
305
|
|
303
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.yml",
|
306
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.yml", "w+") do |f|
|
304
307
|
f.puts "environment: :another_environment_#{Faker::Lorem.word}"
|
305
|
-
f.puts
|
306
|
-
f.puts
|
308
|
+
f.puts "array_spec_model:"
|
309
|
+
f.puts " sentence: \"should not have changed (from YAML file)\""
|
307
310
|
f.puts " selectors:"
|
308
311
|
f.puts " - .body"
|
309
312
|
f.puts " - .header"
|
310
313
|
f.puts " - .yaml"
|
311
|
-
f.puts
|
314
|
+
f.puts ""
|
312
315
|
end
|
313
316
|
|
314
317
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
315
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
318
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
316
319
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
317
320
|
expect(ArraySpecModel.dataset.all.length).to be 0
|
318
321
|
end
|
319
322
|
end
|
320
323
|
|
321
|
-
describe
|
322
|
-
it
|
324
|
+
describe "Seeds defined using JSON code (.json extension)" do
|
325
|
+
it "should apply a basic JSON Seed if it was specified for the given environment" do
|
323
326
|
Sequel::Seed.setup environment
|
324
327
|
|
325
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.json",
|
326
|
-
f.puts
|
328
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.json", "w+") do |f|
|
329
|
+
f.puts "{"
|
327
330
|
f.puts " \"environment\": \"#{environment}\","
|
328
331
|
f.puts " \"array_spec_model\": {"
|
329
332
|
f.puts " \"sentence\": \"should have changed (from JSON file) #{random_word}\","
|
330
333
|
f.puts " \"selectors\": [\".body\", \".header\", \".json\"]"
|
331
|
-
f.puts
|
332
|
-
f.puts
|
333
|
-
f.puts
|
334
|
+
f.puts " }"
|
335
|
+
f.puts "}"
|
336
|
+
f.puts ""
|
334
337
|
end
|
335
338
|
|
336
339
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
337
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
340
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
338
341
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
339
342
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
340
343
|
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from JSON file) #{random_word}"
|
341
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
344
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".json")
|
342
345
|
end
|
343
346
|
|
344
|
-
it
|
347
|
+
it "should apply a JSON Seed if it was specified for the given environment" do
|
345
348
|
Sequel::Seed.setup environment
|
346
349
|
|
347
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.json",
|
348
|
-
f.puts
|
350
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.json", "w+") do |f|
|
351
|
+
f.puts "{"
|
349
352
|
f.puts " \"environment\": \"#{environment}\","
|
350
353
|
f.puts " \"model\": {"
|
351
354
|
f.puts " \"class\": \"ArraySpecModel\","
|
352
355
|
f.puts " \"entries\": ["
|
353
|
-
f.puts
|
356
|
+
f.puts " {"
|
354
357
|
f.puts " \"sentence\": \"should have changed (from JSON file) #{random_word}\","
|
355
358
|
f.puts " \"selectors\": [\".body\", \".header\", \".json\"]"
|
356
|
-
f.puts
|
357
|
-
f.puts
|
358
|
-
f.puts
|
359
|
-
f.puts
|
360
|
-
f.puts
|
359
|
+
f.puts " }"
|
360
|
+
f.puts " ]"
|
361
|
+
f.puts " }"
|
362
|
+
f.puts "}"
|
363
|
+
f.puts ""
|
361
364
|
end
|
362
365
|
|
363
366
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
364
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
367
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
365
368
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
366
369
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
367
370
|
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from JSON file) #{random_word}"
|
368
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
371
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".json")
|
369
372
|
end
|
370
373
|
|
371
|
-
it
|
374
|
+
it "should apply a JSON file with multiple Seeds descriptors if they were specified for the given environment" do
|
372
375
|
Sequel::Seed.setup environment
|
373
376
|
|
374
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.json",
|
375
|
-
f.puts
|
376
|
-
f.puts
|
377
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.json", "w+") do |f|
|
378
|
+
f.puts "["
|
379
|
+
f.puts " {"
|
377
380
|
f.puts " \"environment\": \"#{environment}\","
|
378
381
|
f.puts " \"model\": {"
|
379
382
|
f.puts " \"class\": \"ArraySpecModel\","
|
380
383
|
f.puts " \"entries\": ["
|
381
|
-
f.puts
|
384
|
+
f.puts " {"
|
382
385
|
f.puts " \"sentence\": \"should have changed (from JSON file) #{random_word}\","
|
383
386
|
f.puts " \"selectors\": [\".body\", \".header\", \".json\", \".environment\"]"
|
384
|
-
f.puts
|
385
|
-
f.puts
|
386
|
-
f.puts
|
387
|
-
f.puts
|
388
|
-
f.puts
|
387
|
+
f.puts " }"
|
388
|
+
f.puts " ]"
|
389
|
+
f.puts " }"
|
390
|
+
f.puts " },"
|
391
|
+
f.puts " {"
|
389
392
|
f.puts " \"environment\": \"another_#{environment}\","
|
390
393
|
f.puts " \"model\": {"
|
391
394
|
f.puts " \"class\": \"ArraySpecModel\","
|
392
395
|
f.puts " \"entries\": ["
|
393
|
-
f.puts
|
396
|
+
f.puts " {"
|
394
397
|
f.puts " \"sentence\": \"should have changed (from JSON file) #{random_word}\","
|
395
398
|
f.puts " \"selectors\": [\".body\", \".header\", \".json\", \".another_environment\"]"
|
396
|
-
f.puts
|
397
|
-
f.puts
|
398
|
-
f.puts
|
399
|
-
f.puts
|
400
|
-
f.puts
|
401
|
-
f.puts
|
399
|
+
f.puts " }"
|
400
|
+
f.puts " ]"
|
401
|
+
f.puts " }"
|
402
|
+
f.puts " }"
|
403
|
+
f.puts "]"
|
404
|
+
f.puts ""
|
402
405
|
end
|
403
406
|
|
404
407
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
405
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
408
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
406
409
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
407
410
|
expect(ArraySpecModel.dataset.all.length).to be 1
|
408
411
|
expect(ArraySpecModel.dataset.first.sentence).to eq "should have changed (from JSON file) #{random_word}"
|
409
|
-
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(
|
412
|
+
expect(ArraySpecModel.dataset.first.selectors).to contain_exactly(".body", ".header", ".json", ".environment")
|
410
413
|
end
|
411
414
|
|
412
|
-
it
|
415
|
+
it "should not apply a basic Seed if it was not specified for the given environment" do
|
413
416
|
Sequel::Seed.setup environment
|
414
417
|
|
415
|
-
File.open("#{seed_test_dir}/#{seed_file_name}.json",
|
416
|
-
f.puts
|
418
|
+
File.open("#{seed_test_dir}/#{seed_file_name}.json", "w+") do |f|
|
419
|
+
f.puts "{"
|
417
420
|
f.puts " \"environment\": \"another_#{environment}\","
|
418
421
|
f.puts " \"array_spec_model\": {"
|
419
422
|
f.puts " \"sentence\": \"should not changed (from JSON file) #{random_word}\","
|
420
423
|
f.puts " \"selectors\": [\".body\", \".header\", \".json\"]"
|
421
|
-
f.puts
|
422
|
-
f.puts
|
423
|
-
f.puts
|
424
|
+
f.puts " }"
|
425
|
+
f.puts "}"
|
426
|
+
f.puts ""
|
424
427
|
end
|
425
428
|
|
426
429
|
expect(Sequel::Seed::Base.descendants.length).to be 0
|
427
|
-
expect{Sequel::Seeder.apply(@db, seed_test_dir)}.not_to raise_error
|
430
|
+
expect { Sequel::Seeder.apply(@db, seed_test_dir) }.not_to raise_error
|
428
431
|
expect(Sequel::Seed::Base.descendants.length).to be 1
|
429
432
|
expect(ArraySpecModel.dataset.all.length).to be 0
|
430
433
|
end
|