Skip to content

Commit

Permalink
fix disable ref integrity thing
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Feb 26, 2010
1 parent b2b0301 commit 76a7329
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/postgis_adapter.rb
Expand Up @@ -253,7 +253,7 @@ def columns(table_name, name = nil) #:nodoc:
#Pete Deffendol's patch
alias :original_disable_referential_integrity :disable_referential_integrity
def disable_referential_integrity(&block) #:nodoc:
ignore_tables = %w{ geometry_columns spatial_ref_sys }
ignore_tables = %w{ geometry_columns spatial_ref_sys geography_columns }
execute(tables.select { |name| !ignore_tables.include?(name) }.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
yield
ensure
Expand Down
10 changes: 5 additions & 5 deletions postgis_adapter.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{postgis_adapter}
s.version = "0.7.7"
s.version = "0.7.8"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
s.date = %q{2010-01-29}
s.date = %q{2010-02-26}
s.description = %q{Execute PostGIS functions on Active Record}
s.email = %q{x@nofxx.com}
s.extra_rdoc_files = [
Expand Down Expand Up @@ -55,12 +55,12 @@ Gem::Specification.new do |s|
"spec/db/schema_postgis.rb",
"spec/postgis_adapter/acts_as_geom_spec.rb",
"spec/postgis_adapter/common_spatial_adapter_spec.rb",
"spec/postgis_functions_spec.rb",
"spec/spec_helper.rb",
"spec/postgis_adapter_spec.rb",
"spec/postgis_functions/bbox_spec.rb",
"spec/postgis_functions/class_spec.rb",
"spec/postgis_functions/common_spec.rb",
"spec/postgis_functions_spec.rb",
"spec/spec_helper.rb"
"spec/postgis_functions/bbox_spec.rb"
]

if s.respond_to? :specification_version then
Expand Down
48 changes: 32 additions & 16 deletions spec/postgis_adapter_spec.rb
Expand Up @@ -22,7 +22,8 @@
end

it "should est_3dz_points" do
pt = Table3dzPoint.create!(:data => "Hello!",:geom => Point.from_x_y_z(-1.6,2.8,-3.4))
pt = Table3dzPoint.create!(:data => "Hello!",
:geom => Point.from_x_y_z(-1.6,2.8,-3.4))
pt = Table3dzPoint.find(:first)
pt.geom.should be_instance_of(Point)
pt.geom.z.should eql(-3.4)
Expand All @@ -36,7 +37,7 @@
end

it "should est_4d_points" do
pt = Table4dPoint.create!(:geom => Point.from_x_y_z_m(-1.6,2.8,-3.4,15))
pt = Table4dPoint.create!(:geom => Point.from_x_y_z_m(-1,2.8,-3.4,15))
pt = Table4dPoint.find(:first)
pt.geom.should be_instance_of(Point)
pt.geom.z.should eql(-3.4)
Expand All @@ -59,7 +60,8 @@

describe "LineString" do
it "should record a linestring nicely" do
@ls = TableLineString.new(:value => 3, :geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]]))
@ls = TableLineString.new(:value => 3,
:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]]))
@ls.save.should be_true
end

Expand All @@ -70,7 +72,8 @@
end

it "should test_srid_line_string" do
ls = TableSridLineString.create!(:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326))
ls = TableSridLineString.create!(
:geom => LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326))
ls = TableSridLineString.find(:first)
ls_e = LineString.from_coordinates([[1.4,2.5],[1.5,6.7]],4326)
ls.geom.should be_instance_of(LineString)
Expand Down Expand Up @@ -143,20 +146,22 @@ class Area < ActiveRecord::Base

it "should create some points" do
Area.create!(:data => "Point1", :geom => Point.from_x_y(1.2,0.75,4326))
Area.create!(:data => "Point2",:geom => Point.from_x_y(0.6,1.3,4326))
Area.create!(:data => "Point2", :geom => Point.from_x_y(0.6,1.3,4326))
Area.create!(:data => "Point3", :geom => Point.from_x_y(2.5,2,4326))
end

it "should find by geom" do
pts = Area.find_all_by_geom(LineString.from_coordinates([[0,0],[2,2]],4326))
pts = Area.find_all_by_geom(LineString.
from_coordinates([[0,0],[2,2]],4326))
pts.should be_instance_of(Array)
pts.length.should eql(2)
pts[0].data.should match(/Point/)
pts[1].data.should match(/Point/)
end

it "should find by geom again" do
pts = Area.find_all_by_geom(LineString.from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
pts = Area.find_all_by_geom(LineString.
from_coordinates([[2.49,1.99],[2.51,2.01]],4326))
pts[0].data.should eql("Point3")
end

Expand All @@ -175,14 +180,12 @@ class Area < ActiveRecord::Base

end

# Verify that a non-NULL column with a default value is handled correctly. # Additionally, if the database uses UTF8, set the binary (bytea)
# column value to an illegal UTF8 string; it should be stored as the
# specified binary string and not as a text string. (The binary data test
# cannot fail if the database uses SQL_ASCII or LATIN1 encoding.)
describe "PostgreSQL-specific types and default values" do

# Verify that a non-NULL column with a default value is handled correctly.
# Additionally, if the database uses UTF8 encoding, set the binary (bytea)
# column value to an illegal UTF8 string; it should be stored as the
# specified binary string and not as a text string. (The binary data test
# cannot fail if the database uses SQL_ASCII or LATIN1 encoding.)

ActiveRecord::Schema.define() do
create_table :binary_defaults, :force => true do |t|
t.string :name, :null => false
Expand All @@ -196,10 +199,13 @@ class BinaryDefault < ActiveRecord::Base

it "should create some records" do
if BinaryDefault.connection.encoding == "UTF8"
# fôo as ISO-8859-1 (i.e., not valid UTF-8 data)
BinaryDefault.create!(:name => "foo", :data => "baz",
:value => "f\xf4o") # fôo as ISO-8859-1 (i.e., not valid UTF-8 data)
BinaryDefault.create!(:name => "bar", # data value not specified, should use default
:value => "b\xe5r") # bår as ISO-8859-1 (i.e., not valid UTF-8 data)
:value => "f\xf4o")
# data value not specified, should use default
# bår as ISO-8859-1 (i.e., not valid UTF-8 data)
BinaryDefault.create!(:name => "bar",
:value => "b\xe5r")
else
BinaryDefault.create!(:name => "foo", :data => "baz")
BinaryDefault.create!(:name => "bar")
Expand All @@ -221,4 +227,14 @@ class BinaryDefault < ActiveRecord::Base

end

describe "Extras" do
it "should disable referencial integrity" do
lambda do
Area.connection.disable_referential_integrity do
Area.delete_all
end
end.should_not raise_error
end
end

end

0 comments on commit 76a7329

Please sign in to comment.