問題が解決したので改めてメモしなおします。
実行環境:CentOS5.2, Rails2.1, PostgreSQL8.3.3 ---- 0.PostGISはインストール済み。 PostGISインストールメモ。参照
1.postgres-prとGeoRubyをインストール。
gem install postgres-pr gem install GeoRuby
2.railsプロジェクトを作成。(「sample」プロジェクトとする。)
rails sample --database=postgresql cd sample
3.Spatial Adapter for Railsプラグインをインストール。 ruby script/plugin install svn://rubyforge.org/var/svn/georuby/SpatialAdapter/trunk/spatial_adapter または ruby script/plugin install http://georuby.rubyforge.org/svn/SpatialAdapter/trunk/spatial_adapter/
4.開発用とテスト用データベースを作る。
su - postgres # posturesユーザに移動 createdb sample_development #開発用 development createlang plpgsql sample_development psql -d sample_test -f /usr/share/lwpostgis.sql psql -d sample_test -f /usr/share/spatial_ref_sys.sql
createdb sample_test #テスト用 test
☆5.テスト用DBの初期化方法をSQLに変更する
(config/environment.rb の以下のコメントをはずす。) config.active_record.schema_format = :sql
6.config/database.ymlを適宜編集。
7.諸々ソースをcaffoldで生成する。
ruby script/generate scaffold table_point data:string geom:point
8.db/migrate/*_create_table_points.rbを編集する。
class CreateTablePoints < ActiveRecord::Migration def self.up create_table :table_points, :force => true do |t| t.string :data t.point :geom, :srid => 4326, :with_z => false end add_index :table_points, :geom, :spatial=>true end def self.down drop_table :table_points end end SRID=4326はWGS 84 空間参照系
9.開発用DBにマイグレーション
rake db:migrate
10.テスト用fixtureはこんなかんじ。
one: id: 1 data: MyString geom: <%= Point.from_x_y(0.0, 0.0, 4326).to_fixture_format %>
11.テスト準備。
rake db:test:clone_structure # 開発用DBからスキーマを複製 rake db:test:prepare # テスト用 DB を準備
12.テスト実行。
rake test
■参考 http://georuby.rubyforge.org/spatialadapter-doc/index.html http://github.com/melriffe/spatial_adapter/tree/master/README
|