Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeckman committed Aug 1, 2014
2 parents bace2f5 + d808138 commit 2669ba9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
75 changes: 65 additions & 10 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

context 'destroy' do

before {
before(:all) {
@p = Project.create(name: 'a little bit of everything')
$project_id = @p.id
$user_id = 1
Expand All @@ -80,10 +80,12 @@

@factories_under_test = {}
@failed_factories = {}
@project_build_err_msg = ''
FactoryGirl.factories.each { |factory|
f_name = factory.name
if f_name =~ /^valid_/
# next if f_name.to_s == 'valid_biological_relationship_type'
next if f_name.to_s == 'valid_taxon_name'
begin
if factory.definition.attributes.names.include?(:project_id)
test_factory = FactoryGirl.build(f_name, project_id: @p.id)
Expand All @@ -92,7 +94,7 @@
end
rescue => detail
@failed_factories[f_name] = detail
puts "\"#{f_name}\" build => #{detail}"
@project_build_err_msg += "\n\"#{f_name}\" build => #{detail}"
else
unless test_factory.attributes['project_id'].nil?
test_factory.project = @p
Expand All @@ -105,41 +107,94 @@
test_factory.save
rescue => detail
@failed_factories[f_name] = detail
puts "\"#{f_name}\" save => #{detail}"
@project_build_err_msg += "\n\"#{f_name}\" save => #{detail}"
else
@factories_under_test[f_name] = test_factory
end
else
@failed_factories[f_name] = test_factory.errors
puts "\"#{f_name}\" is not valid: #{test_factory.errors.to_a}"
@project_build_err_msg += "\n\"#{f_name}\" is not valid: #{test_factory.errors.to_a}"
end
end
end
}
if @failed_factories.length > 0
puts "\n#{@failed_factories.length} invalid factor#{@failed_factories.length == 1 ? 'y' : 'ies' }."
length = @failed_factories.length
if length > 0
# puts "\n#{length} invalid factor#{length == 1 ? 'y' : 'ies' }."
@project_build_err_msg += "\n#{length} invalid #{'factory'.pluralize(length)}.\n"
end
}

after(:all) {
FactoryGirl.factories.each { |factory|
f_name = factory.name
if f_name =~ /^valid_/
this_class = factory.build_class.to_s
model = this_class.constantize
case this_class
when 'User', 'Project'
# todo: figure out how to delete all with id greater than 1
else
model.delete_all
end
end
}
# puts
}

specify 'project build goes well' do
expect(@project_build_err_msg.length).to eq(0), @project_build_err_msg
end

specify '#destroy' do
expect(@p.destroy).to be_truthy # confirm this is a really what we want
expect(@p.destroyed?).to be(true)
end

context '#destroy' do
before {
before(:all) {
@p.destroy
}

skip '#destroy nukes "everything"' do
specify '#destroy nukes "everything"' do
# loop through all the valid_ factories, for each find the class that they build
# expect(class_that_was_built.all.reload.count).to eq(0)
# expect(class_that_was_built.all.reload.count).to eq(0)
orphans = {}
project_destroy_err_msg = ''
FactoryGirl.factories.each { |factory|
f_name = factory.name
if f_name =~ /^valid/
this_class = factory.build_class
model = this_class.to_s.constantize
if model.column_names.include?('project_id')
count = model.all.reload.count
if count > 0
project_destroy_err_msg += "\nFactory '#{f_name}': #{this_class.to_s}: #{count} orphan #{'record'.pluralize(count)}."
orphans[model] = count
end
end
end
}
if orphans.length > 0
project_destroy_err_msg += "\n"
end
expect(orphans.length).to eq(0), project_destroy_err_msg
end

skip "#destroy doesn't nuke shared data" do
specify "#destroy doesn't nuke shared data" do
# loop through shared models (e.g. Serial, Person, Source), ensure that any data that was created remains
# We may need a constant that stores a *string* representative of the shared classes to loop through,
# but for now just enumerate a number of them
FactoryGirl.factories.each { |factory|
f_name = factory.name
if f_name =~ /^valid_/
this_class = factory.build_class
model = this_class.to_s.constantize
unless model.column_names.include?('project_id')
expect(model.all.reload.count).to be >= 1
end
end
}
end
end

Expand Down
2 changes: 0 additions & 2 deletions spec/support/geo/geo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ def generate_ce_test_objects

end


def gen_wkt_files_1()
# using the prebuilt RGeo test objects, write out three QGIS-acceptable WKT files, one each for points, linestrings, and polygons.
f_point = File.new('./tmp/RGeoPoints.wkt', 'w+')
Expand Down Expand Up @@ -1551,7 +1550,6 @@ def clean_slate_geo
CollectingEvent.delete_all
end


# A temporary place to put debugging aids. This code is permanently deprecated.
module GeoDev
def point_methods()
Expand Down

0 comments on commit 2669ba9

Please sign in to comment.