sentry 0.2.9 → 0.3

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/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.3* (29 Oct 2005)
2
+
3
+ * added rake task for generating asymmetric keys
4
+ * Switch to migrations and schema for testing setup
5
+
1
6
  *0.2.9* (18 Sep 2005)
2
7
 
3
8
  * First RubyForge release.
data/README CHANGED
@@ -3,21 +3,27 @@
3
3
  Sentry is a simple wrapper around the mostly undocumented OpenSSL encryption classes.
4
4
  For now, look at the pseudo test cases in sentry.rb until I can get more examples written out.
5
5
 
6
- == Install
6
+ == Resources
7
7
 
8
- Gem installation:
8
+ Install
9
9
 
10
- gem install sentry
11
-
12
- Download:
10
+ * gem install sentry
11
+
12
+ Rubyforge project
13
+
14
+ * http://rubyforge.org/projects/sentry
15
+
16
+ RDocs
17
+
18
+ * http://sentry.rubyforge.org
13
19
 
14
- http://rubyforge.org/projects/sentry/
20
+ Subversion
15
21
 
16
- == Documentation
22
+ * http://techno-weenie.net/svn/projects/sentry
17
23
 
18
- RDocs are online at http://sentry.rubyforge.org
24
+ Collaboa
19
25
 
20
- Please email any comments or changes for code to technoweenie AT gmail.com
26
+ * http://collaboa.techno-weenie.net/repository/browse/sentry
21
27
 
22
28
  == Using with ActiveRecord
23
29
 
@@ -45,7 +51,7 @@ This is a shortcut for using an asymmetrical algorithm with a private/public key
45
51
  private key with Sentry::AsymmetricalSentry.save_random_rsa_key(private_key_file, public_key_file). If you want to encrypt the
46
52
  private key file with a symmetrical algorithm, pass a secret key (neither the key nor the decrypted value will be stored).
47
53
 
48
- Sentry::AsymmetricalSentry.save_random_rsa_key(private_key_file, public_key_file, :key => 'secret_password')
54
+ Sentry::AsymmetricSentry.save_random_rsa_key(private_key_file, public_key_file, :key => 'secret_password')
49
55
 
50
56
  What that does, is requires you to pass in that same secret password when accesing the method.
51
57
 
@@ -1,20 +1,21 @@
1
1
  == Creating the test database
2
2
 
3
- The default name for the test databases is "activerecord_sentry". If you
3
+ The default name for the test databases is "sentry_plugin_test". If you
4
4
  want to use another database name then be sure to update the connection
5
- adapter setups you want to test with in test/connections/<your database>/connection.rb.
6
- When you have the database online, you can import the fixture tables with
7
- the test/fixtures/db_definitions/*.sql files.
5
+ adapter setups you want to test with in test/database.yml.
8
6
 
9
7
  Make sure that you create database objects with the same user that you specified in i
10
- connection.rb otherwise (on Postgres, at least) tests for default values will fail.
8
+ database.yml otherwise (on Postgres, at least) tests for default values will fail.
11
9
 
12
10
  == Running with Rake
13
11
 
14
12
  The easiest way to run the unit tests is through Rake. The default task runs
15
- the entire test suite for all the adapters. You can also run the suite on just
16
- one adapter by using the tasks test_mysql_ruby, test_ruby_mysql, test_sqlite,
17
- or test_postresql. For more information, checkout the full array of rake tasks with "rake -T"
13
+ the entire test suite for the sqlite adapter. You can also run the suite on just
14
+ one adapter by passing the DB environment variable.
15
+
16
+ rake test DB=mysql
17
+
18
+ For more information, checkout the full array of rake tasks with "rake -T"
18
19
 
19
20
  Rake can be found at http://rake.rubyforge.org
20
21
 
@@ -23,9 +24,9 @@ Rake can be found at http://rake.rubyforge.org
23
24
  Unit tests are located in test directory. If you only want to run a single test suite,
24
25
  or don't want to bother with Rake, you can do so with something like:
25
26
 
26
- cd test; ruby -I "connections/native_mysql" base_test.rb
27
+ cd test; DB=mysql ruby base_test.rb
27
28
 
28
- That'll run the base suite using the MySQL-Ruby adapter. Change the adapter
29
+ That'll run the base suite using the MySQL adapter. Change the adapter
29
30
  and test suite name as needed.
30
31
 
31
32
  == Faster tests
@@ -60,9 +60,11 @@ module Sentry
60
60
  def save_random_rsa_key(private_key_file, public_key_file, options = {})
61
61
  rsa = OpenSSL::PKey::RSA.new(512)
62
62
  public_key = rsa.public_key
63
- private_key = options[:key] ?
64
- SymmetricSentry.new(:algorithm => options[:symmetric_algorithm]).encrypt_to_base64(rsa.to_s, options[:key]) :
65
- rsa.to_s
63
+ private_key = options[:key].to_s.empty? ?
64
+ rsa.to_s :
65
+ SymmetricSentry.new(:algorithm => options[:symmetric_algorithm]).encrypt_to_base64(rsa.to_s, options[:key])
66
+ require 'breakpoint'
67
+ breakpoint
66
68
  File.open(public_key_file, 'w') { |f| f.write(public_key) }
67
69
  File.open(private_key_file, 'w') { |f| f.write(private_key) }
68
70
  end
@@ -6,20 +6,28 @@ require 'active_record'
6
6
  require 'active_record/fixtures'
7
7
  require 'active_support/binding_of_caller'
8
8
  require 'active_support/breakpoint'
9
- require 'connection'
10
- require 'sentry'
9
+ require "#{File.dirname(__FILE__)}/../lib/sentry"
10
+
11
+ config_location = File.dirname(__FILE__) + '/database.yml'
12
+
13
+ config = YAML::load(IO.read(config_location))
14
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
15
+ ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
16
+
17
+ load(File.dirname(__FILE__) + "/schema.rb")
18
+
19
+ Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
20
+ Test::Unit::TestCase.use_instantiated_fixtures = false
21
+ Test::Unit::TestCase.use_transactional_fixtures = (ENV['AR_TX_FIXTURES'] == "yes")
22
+ $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
11
23
 
12
24
  class Test::Unit::TestCase #:nodoc:
13
25
  def create_fixtures(*table_names)
14
26
  if block_given?
15
- Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names) { yield }
27
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
16
28
  else
17
- Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names)
29
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
18
30
  end
19
31
  end
20
32
  end
21
33
 
22
- Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
23
- Test::Unit::TestCase.use_instantiated_fixtures = false
24
- Test::Unit::TestCase.use_transactional_fixtures = (ENV['AR_TX_FIXTURES'] == "yes")
25
-
@@ -0,0 +1,18 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :dbfile: sentry_plugin.sqlite.db
4
+ sqlite3:
5
+ :adapter: sqlite3
6
+ :dbfile: sentry_plugin.sqlite3.db
7
+ postgresql:
8
+ :adapter: postgresql
9
+ :username: postgres
10
+ :password: postgres
11
+ :database: sentry_plugin_test
12
+ :min_messages: ERROR
13
+ mysql:
14
+ :adapter: mysql
15
+ :host: localhost
16
+ :username: rails
17
+ :password:
18
+ :database: sentry_plugin_test
@@ -0,0 +1,86 @@
1
+ # Logfile created on Sat Oct 29 09:08:51 CDT 2005 by logger.rb/1.5.2.4
2
+ SQL (0.191909) DROP TABLE users
3
+ SQL (0.002950) CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, crypted_password varchar(255), crypted_creditcard varchar(255), login varchar(50), type varchar(20)) 
4
+ SQL (0.000000) table schema_info already exists: CREATE TABLE schema_info (version integer)
5
+ SQL (0.000688) PRAGMA table_info(schema_info)
6
+ SQL (0.003226) UPDATE schema_info SET version = 1
7
+ User Load (0.001195) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
8
+ SQL (0.001331) PRAGMA table_info(users)
9
+ User Load (0.001179) SELECT * FROM users WHERE (users.id = 2) LIMIT 1
10
+ SQL (0.001179) PRAGMA table_info(users)
11
+ SQL (0.000573) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES(NULL, NULL, NULL, 'jones')
12
+ User Update (0.001806) UPDATE users SET 'login' = 'jones', 'type' = NULL, 'crypted_password' = NULL, 'crypted_creditcard' = 'KUOKbSP2XPiYKSzxcopQBLnJD+IyhHycAAerMdzDahbg3u99l4YpuYfezO8C
13
+ DQOvyxZ45VjD/7L1rvHcXlkyYw==
14
+ ' WHERE id = 3
15
+ SQL (0.000540) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES(NULL, NULL, NULL, 'jones')
16
+ User Update (0.001746) UPDATE users SET 'login' = 'jones', 'type' = NULL, 'crypted_password' = NULL, 'crypted_creditcard' = 'B5cvT3e38Mf2Ck44ld3ZGpaM8ubnzLuri+zHqaPQUmEU9SkD4/Ff9idx7LJF
17
+ 5Zv9wchYUzG7vh0++25TU3e7cg==
18
+ ' WHERE id = 3
19
+ User Load (0.001146) SELECT * FROM users WHERE (users.id = 2) LIMIT 1
20
+ User Load (0.001099) SELECT * FROM users WHERE (users.id = 2) LIMIT 1
21
+ User Load (0.001175) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
22
+ SQL (0.001334) PRAGMA table_info(users)
23
+ SQL (0.000558) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'ShaUser', NULL, 'bob')
24
+ SQL (0.001294) PRAGMA table_info(users)
25
+ SQL (0.000570) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'DangerousUser', NULL, 'bob')
26
+ User Load (0.001139) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
27
+ SQL (0.000537) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('0XlmUuNpE2k=
28
+ ', 'SymmetricUser', NULL, 'bob')
29
+ User Load (0.001262) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
30
+ User Load (0.001121) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
31
+ SQL (0.119978) DROP TABLE users
32
+ SQL (0.026073) CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, crypted_password varchar(255), crypted_creditcard varchar(255), login varchar(50), type varchar(20)) 
33
+ SQL (0.000000) table schema_info already exists: CREATE TABLE schema_info (version integer)
34
+ SQL (0.000674) PRAGMA table_info(schema_info)
35
+ SQL (0.004633) UPDATE schema_info SET version = 1
36
+ User Load (0.001196) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
37
+ SQL (0.001339) PRAGMA table_info(users)
38
+ User Load (0.001147) SELECT * FROM users WHERE (users.id = 2) LIMIT 1
39
+ SQL (0.001198) PRAGMA table_info(users)
40
+ SQL (0.000582) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES(NULL, NULL, NULL, 'jones')
41
+ User Update (0.001720) UPDATE users SET 'login' = 'jones', 'type' = NULL, 'crypted_password' = NULL, 'crypted_creditcard' = 'DLIh4equrhSTs6yK2f+w82K4xt7bROoHbkYXp+eynjF0FD9WRv4Ont5bOSDZ
42
+ QjyBWLYsekOqbR+EbIkEmNcHeA==
43
+ ' WHERE id = 3
44
+ SQL (0.000573) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES(NULL, NULL, NULL, 'jones')
45
+ User Update (0.001698) UPDATE users SET 'login' = 'jones', 'type' = NULL, 'crypted_password' = NULL, 'crypted_creditcard' = 'eQOiEbqm6S9YylKEIY/uKIamJoNWmb0x2Zth+N8LCEoZRh66bQFfyh4H1k5r
46
+ p5HUIZpNnol1bMhVtqWG31lWjw==
47
+ ' WHERE id = 3
48
+ User Load (0.001134) SELECT * FROM users WHERE (users.id = 2) LIMIT 1
49
+ User Load (0.001122) SELECT * FROM users WHERE (users.id = 2) LIMIT 1
50
+ User Load (0.001154) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
51
+ SQL (0.001791) PRAGMA table_info(users)
52
+ SQL (0.000602) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'ShaUser', NULL, 'bob')
53
+ SQL (0.001591) PRAGMA table_info(users)
54
+ SQL (0.000550) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'DangerousUser', NULL, 'bob')
55
+ User Load (0.003733) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
56
+ SQL (0.000532) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('0XlmUuNpE2k=
57
+ ', 'SymmetricUser', NULL, 'bob')
58
+ User Load (0.001268) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
59
+ User Load (0.001492) SELECT * FROM users WHERE (users.id = 1) LIMIT 1
60
+ SQL (0.208598) DROP TABLE users
61
+ SQL (0.003186) CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, crypted_password varchar(255), crypted_creditcard varchar(255), login varchar(50), type varchar(20)) 
62
+ SQL (0.000000) table schema_info already exists: CREATE TABLE schema_info (version integer)
63
+ SQL (0.000686) PRAGMA table_info(schema_info)
64
+ SQL (0.003169) UPDATE schema_info SET version = 1
65
+ SQL (0.001369) PRAGMA table_info(users)
66
+ SQL (0.000543) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'ShaUser', NULL, 'bob')
67
+ SQL (0.001211) PRAGMA table_info(users)
68
+ SQL (0.000614) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'DangerousUser', NULL, 'bob')
69
+ SQL (0.208579) DROP TABLE users
70
+ SQL (0.003693) CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, crypted_password varchar(255), crypted_creditcard varchar(255), login varchar(50), type varchar(20)) 
71
+ SQL (0.000000) table schema_info already exists: CREATE TABLE schema_info (version integer)
72
+ SQL (0.000644) PRAGMA table_info(schema_info)
73
+ SQL (0.003024) UPDATE schema_info SET version = 1
74
+ SQL (0.002309) PRAGMA table_info(users)
75
+ SQL (0.000523) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'ShaUser', NULL, 'bob')
76
+ SQL (0.001247) PRAGMA table_info(users)
77
+ SQL (0.000551) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'DangerousUser', NULL, 'bob')
78
+ SQL (0.004938) DROP TABLE users
79
+ SQL (0.003801) CREATE TABLE users (id INTEGER PRIMARY KEY NOT NULL, crypted_password varchar(255), crypted_creditcard varchar(255), login varchar(50), type varchar(20)) 
80
+ SQL (0.000000) table schema_info already exists: CREATE TABLE schema_info (version integer)
81
+ SQL (0.000648) PRAGMA table_info(schema_info)
82
+ SQL (0.003591) UPDATE schema_info SET version = 1
83
+ SQL (0.001882) PRAGMA table_info(users)
84
+ SQL (0.000592) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'ShaUser', NULL, 'bob')
85
+ SQL (0.001319) PRAGMA table_info(users)
86
+ SQL (0.000643) INSERT INTO users ('crypted_password', 'type', 'crypted_creditcard', 'login') VALUES('f438229716cab43569496f3a3630b3727524b81b', 'DangerousUser', NULL, 'bob')
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Schema.define(:version => 1) do
2
+
3
+ create_table "users", :force => true do |t|
4
+ t.column :crypted_password, :string, :limit => 255
5
+ t.column :crypted_creditcard, :string, :limit => 255
6
+ t.column :login, :string, :limit => 50
7
+ t.column :type, :string, :limit => 20
8
+ end
9
+
10
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: sentry
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.9
7
- date: 2005-09-18
6
+ version: "0.3"
7
+ date: 2005-10-29
8
8
  summary: Sentry provides painless encryption services with a wrapper around some OpenSSL classes
9
9
  require_paths:
10
10
  - lib
@@ -39,38 +39,18 @@ files:
39
39
  - test/abstract_unit.rb
40
40
  - test/asymmetric_sentry_callback_test.rb
41
41
  - test/asymmetric_sentry_test.rb
42
- - test/connections
42
+ - test/database.yml
43
+ - test/debug.log
43
44
  - test/fixtures
44
45
  - test/keys
46
+ - test/schema.rb
47
+ - test/sentry_plugin.sqlite.db
45
48
  - test/sha_sentry_test.rb
46
49
  - test/symmetric_sentry_callback_test.rb
47
50
  - test/symmetric_sentry_test.rb
48
51
  - test/tests.rb
49
- - test/connections/native_db2
50
- - test/connections/native_mysql
51
- - test/connections/native_oci
52
- - test/connections/native_postgresql
53
- - test/connections/native_sqlite
54
- - test/connections/native_sqlite3
55
- - test/connections/native_sqlserver
56
- - test/connections/native_sqlserver_odbc
57
- - test/connections/native_db2/connection.rb
58
- - test/connections/native_mysql/connection.rb
59
- - test/connections/native_oci/connection.rb
60
- - test/connections/native_postgresql/connection.rb
61
- - test/connections/native_sqlite/connection.rb
62
- - test/connections/native_sqlite3/connection.rb
63
- - test/connections/native_sqlserver/connection.rb
64
- - test/connections/native_sqlserver_odbc/connection.rb
65
- - test/fixtures/activerecord_sentry.sqlite
66
- - test/fixtures/activerecord_sentry.sqlite3
67
- - test/fixtures/db_definitions
68
52
  - test/fixtures/user.rb
69
53
  - test/fixtures/users.yml
70
- - test/fixtures/db_definitions/postgresql.drop.sql
71
- - test/fixtures/db_definitions/postgresql.sql
72
- - test/fixtures/db_definitions/sqlite.drop.sql
73
- - test/fixtures/db_definitions/sqlite.sql
74
54
  - test/keys/encrypted_private
75
55
  - test/keys/encrypted_public
76
56
  - test/keys/private
@@ -1,14 +0,0 @@
1
- print "Using native DB2\n"
2
- require 'logger'
3
-
4
- ActiveRecord::Base.logger = Logger.new("debug.log")
5
-
6
- db1 = 'arsentry'
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => "db2",
10
- :host => "localhost",
11
- :username => "arunit",
12
- :password => "arunit",
13
- :database => db1
14
- )
@@ -1,14 +0,0 @@
1
- print "Using native MySQL\n"
2
- require 'logger'
3
-
4
- ActiveRecord::Base.logger = Logger.new("debug.log")
5
-
6
- db1 = 'activerecord_sentry'
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => "mysql",
10
- :host => "localhost",
11
- :username => "rails",
12
- :password => "",
13
- :database => db1
14
- )
@@ -1,15 +0,0 @@
1
- print "Using OCI Oracle\n"
2
- require 'logger'
3
-
4
- ActiveRecord::Base.logger = Logger.new STDOUT
5
- ActiveRecord::Base.logger.level = Logger::WARN
6
-
7
- db1 = 'activerecord_sentry'
8
-
9
- ActiveRecord::Base.establish_connection(
10
- :adapter => 'oci',
11
- :host => '', # can use an oracle SID
12
- :username => 'arunit',
13
- :password => 'arunit',
14
- :database => db1
15
- )
@@ -1,14 +0,0 @@
1
- print "Using native PostgreSQL\n"
2
- require 'logger'
3
-
4
- ActiveRecord::Base.logger = Logger.new("debug.log")
5
-
6
- db1 = 'activerecord_sentry'
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => "postgresql",
10
- :host => nil,
11
- :username => "postgres",
12
- :password => "postgres",
13
- :database => db1
14
- )
@@ -1,34 +0,0 @@
1
- print "Using native SQlite\n"
2
- require 'logger'
3
- ActiveRecord::Base.logger = Logger.new("debug.log")
4
-
5
- class SqliteError < StandardError
6
- end
7
-
8
- BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
9
- sqlite_test_db = "#{BASE_DIR}/activerecord_sentry.sqlite"
10
-
11
- def make_connection(clazz, db_file, db_definitions_file)
12
- unless File.exist?(db_file)
13
- puts "SQLite database not found at #{db_file}. Rebuilding it."
14
- sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"}
15
- puts "Executing '#{sqlite_command}'"
16
- raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command)
17
- clazz.establish_connection(
18
- :adapter => "sqlite",
19
- :dbfile => db_file)
20
- script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
21
- # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
22
- script.split(';').each do
23
- |command|
24
- clazz.connection.execute(command) unless command.strip.empty?
25
- end
26
- else
27
- clazz.establish_connection(
28
- :adapter => "sqlite",
29
- :dbfile => db_file)
30
- end
31
- end
32
-
33
- make_connection(ActiveRecord::Base, sqlite_test_db, 'sqlite.sql')
34
-
@@ -1,33 +0,0 @@
1
- print "Using native SQLite3\n"
2
- require 'logger'
3
- ActiveRecord::Base.logger = Logger.new("debug.log")
4
-
5
- class SqliteError < StandardError
6
- end
7
-
8
- BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
9
- sqlite_test_db = "#{BASE_DIR}/activerecord_sentry.sqlite3"
10
-
11
- def make_connection(clazz, db_file, db_definitions_file)
12
- unless File.exist?(db_file)
13
- puts "SQLite3 database not found at #{db_file}. Rebuilding it."
14
- sqlite_command = %Q{sqlite3 #{db_file} "create table a (a integer); drop table a;"}
15
- puts "Executing '#{sqlite_command}'"
16
- raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command)
17
- clazz.establish_connection(
18
- :adapter => "sqlite3",
19
- :dbfile => db_file)
20
- script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}")
21
- # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time
22
- script.split(';').each do
23
- |command|
24
- clazz.connection.execute(command) unless command.strip.empty?
25
- end
26
- else
27
- clazz.establish_connection(
28
- :adapter => "sqlite3",
29
- :dbfile => db_file)
30
- end
31
- end
32
-
33
- make_connection(ActiveRecord::Base, sqlite_test_db, 'sqlite.sql')
@@ -1,14 +0,0 @@
1
- print "Using native SQLServer\n"
2
- require 'logger'
3
-
4
- ActiveRecord::Base.logger = Logger.new("debug.log")
5
-
6
- db1 = 'activerecord_sentry'
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => "sqlserver",
10
- :host => "localhost",
11
- :username => "sa",
12
- :password => "",
13
- :database => db1
14
- )
@@ -1,15 +0,0 @@
1
- print "Using native SQLServer via ODBC\n"
2
- require 'logger'
3
-
4
- ActiveRecord::Base.logger = Logger.new("debug.log")
5
-
6
- dsn1 = 'activerecord_sentry'
7
-
8
- ActiveRecord::Base.establish_connection(
9
- :adapter => "sqlserver",
10
- :mode => "ODBC",
11
- :host => "localhost",
12
- :username => "sa",
13
- :password => "",
14
- :dsn => dsn1
15
- )
@@ -1 +0,0 @@
1
- drop table users;
@@ -1,8 +0,0 @@
1
- CREATE TABLE users (
2
- id SERIAL,
3
- crypted_password VARCHAR(255),
4
- crypted_creditcard VARCHAR(255),
5
- login VARCHAR(50),
6
- type VARCHAR(20)
7
- );
8
- SELECT setval('users_id_seq', 100);
@@ -1 +0,0 @@
1
- DROP TABLE 'pages';
@@ -1,7 +0,0 @@
1
- CREATE TABLE 'users' (
2
- 'id' INTEGER NOT NULL PRIMARY KEY,
3
- 'crypted_password' VARCHAR(255),
4
- 'crypted_creditcard' VARCHAR(255),
5
- 'login' VARCHAR(50),
6
- 'type' VARCHAR(20)
7
- );