ActiveRecord-JDBC 0.2.2 → 0.2.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.
@@ -0,0 +1,19 @@
1
+ require 'jdbc_adapter'
2
+ require 'rubygems'
3
+ require 'active_record'
4
+
5
+ class CreateAutoIds < ActiveRecord::Migration
6
+ def self.up
7
+ create_table "auto_ids", :force => true do |t|
8
+ t.column :value, :integer
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table "auto_ids"
14
+ end
15
+ end
16
+
17
+ class AutoId < ActiveRecord::Base
18
+ def self.table_name () "auto_ids" end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'jdbc_adapter'
2
+ require 'rubygems'
3
+ require 'active_record'
4
+
5
+ class DbTypeMigration < ActiveRecord::Migration
6
+ def self.up
7
+ create_table "db_types", :force => true do |t|
8
+ t.column :sample_timestamp, :timestamp
9
+ t.column :sample_decimal, :decimal, :precision=> 15, :scale => 0
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table "db_types"
15
+ end
16
+ end
17
+
18
+ class DbType < ActiveRecord::Base
19
+ end
data/test/models/entry.rb CHANGED
@@ -1,7 +1,5 @@
1
- if RUBY_PLATFORM =~ /java/
2
- RAILS_CONNECTION_ADAPTERS = ['abstract', 'jdbc']
3
- end
4
-
1
+ require 'jdbc_adapter'
2
+ require 'rubygems'
5
3
  require 'active_record'
6
4
 
7
5
  class CreateEntries < ActiveRecord::Migration
@@ -10,6 +8,7 @@ class CreateEntries < ActiveRecord::Migration
10
8
  t.column :title, :string, :limit => 100
11
9
  t.column :updated_on, :datetime
12
10
  t.column :content, :text
11
+ t.column :rating, :decimal, :precision => 10
13
12
  end
14
13
  end
15
14
 
@@ -5,6 +5,7 @@
5
5
  # grant all on weblog_development.* to blog@localhost;
6
6
 
7
7
 
8
+ require 'models/auto_id'
8
9
  require 'models/entry'
9
10
  require 'db/mysql'
10
11
  require 'simple'
data/test/simple.rb CHANGED
@@ -1,10 +1,14 @@
1
1
  module MigrationSetup
2
2
  def setup
3
3
  CreateEntries.up
4
+ CreateAutoIds.up
5
+
6
+ @connection = ActiveRecord::Base.connection
4
7
  end
5
8
 
6
9
  def teardown
7
10
  CreateEntries.down
11
+ CreateAutoIds.down
8
12
  end
9
13
  end
10
14
 
@@ -15,7 +19,8 @@ module FixtureSetup
15
19
  @title = "First post!"
16
20
  @content = "Hello from JRuby on Rails!"
17
21
  @new_title = "First post updated title"
18
- Entry.create :title => @title, :content => @content
22
+ @rating = 205
23
+ Entry.create :title => @title, :content => @content, :rating => @rating
19
24
  end
20
25
  end
21
26
 
@@ -23,36 +28,43 @@ module SimpleTestMethods
23
28
  include FixtureSetup
24
29
 
25
30
  def test_entries_created
26
- assert ActiveRecord::Base.connection.tables.include?('entries'), "entries not created"
27
- end
31
+ assert ActiveRecord::Base.connection.tables.find{|t| t =~ /^entries$/i}, "entries not created"
32
+ end
28
33
 
29
- def test_entries_empty
30
- Entry.delete_all
31
- assert_equal 0, Entry.count
32
- end
34
+ def test_entries_empty
35
+ Entry.delete_all
36
+ assert_equal 0, Entry.count
37
+ end
33
38
 
34
- def test_create_new_entry
35
- Entry.delete_all
39
+ def test_create_new_entry
40
+ Entry.delete_all
36
41
 
37
- post = Entry.new
38
- post.title = @title
39
- post.content = @content
40
- post.save
42
+ post = Entry.new
43
+ post.title = @title
44
+ post.content = @content
45
+ post.rating = @rating
46
+ post.save
41
47
 
42
- assert_equal 1, Entry.count
43
- end
48
+ assert_equal 1, Entry.count
49
+ end
44
50
 
45
- def test_find_and_update_entry
46
- post = Entry.find(:first)
47
- assert_equal @title, post.title
48
- assert_equal @content, post.content
51
+ def test_create_partial_new_entry
52
+ new_entry = Entry.create(:title => "Blah")
53
+ new_entry2 = Entry.create(:title => "Bloh")
54
+ end
49
55
 
50
- post.title = @new_title
51
- post.save
56
+ def test_find_and_update_entry
57
+ post = Entry.find(:first)
58
+ assert_equal @title, post.title
59
+ assert_equal @content, post.content
60
+ assert_equal @rating, post.rating
61
+
62
+ post.title = @new_title
63
+ post.save
52
64
 
53
- post = Entry.find(:first)
54
- assert_equal @new_title, post.title
55
- end
65
+ post = Entry.find(:first)
66
+ assert_equal @new_title, post.title
67
+ end
56
68
 
57
69
  def test_destroy_entry
58
70
  prev_count = Entry.count
@@ -62,4 +74,43 @@ module SimpleTestMethods
62
74
  assert_equal prev_count - 1, Entry.count
63
75
  end
64
76
 
77
+ def test_indexes
78
+ # Only test indexes if we have implemented it for the particular adapter
79
+ if @connection.respond_to?(:indexes)
80
+ indexes = @connection.indexes(:entries)
81
+ assert_equal(0, indexes.size)
82
+
83
+ index_name = "entries_index"
84
+ @connection.add_index(:entries, :updated_on, :name => index_name)
85
+
86
+ indexes = @connection.indexes(:entries)
87
+ assert_equal(1, indexes.size)
88
+ assert_equal "entries", indexes.first.table
89
+ assert_equal index_name, indexes.first.name
90
+ assert !indexes.first.unique
91
+ assert_equal ["updated_on"], indexes.first.columns
92
+ end
93
+ end
94
+
95
+ def test_dumping_schema
96
+ require 'active_record/schema_dumper'
97
+ @connection.add_index :entries, :title
98
+ stio = StringIO.open('', 'w') do |io|
99
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
100
+ end
101
+ assert_match(/add_index "entries",/, stio.string)
102
+ @connection.remove_index :entries, :title
103
+
104
+ end
105
+
106
+ def test_nil_values
107
+ test = AutoId.create('value' => '')
108
+ assert_nil AutoId.find(test.id).value
109
+ end
110
+
111
+ def test_invalid
112
+ e = Entry.new(:title => @title, :content => @content, :rating => ' ')
113
+ p e.valid?
114
+ end
115
+
65
116
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ActiveRecord-JDBC
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.2
7
- date: 2006-10-03 00:00:00 +02:00
8
- summary: JDBC support for ActiveRecord. Only usable within JRuby
6
+ version: 0.2.3
7
+ date: 2007-03-05 00:00:00 -06:00
8
+ summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
9
9
  require_paths:
10
10
  - lib
11
- email: ola@ologix.com
12
- homepage: http://jruby-extras.rubyforge.org/
13
- rubyforge_project:
14
- description:
15
- autorequire: active_record/connection_adapters/jdbc_adapter
11
+ email: nick@nicksieger.com, ola.bini@ki.se
12
+ homepage: http://jruby-extras.rubyforge.org/ActiveRecord-JDBC
13
+ rubyforge_project: jruby-extras
14
+ description: ActiveRecord-JDBC is a database adapter for Rails' ActiveRecord component that can be used with JRuby[http://www.jruby.org/]. It allows use of virtually any JDBC-compliant database with your JRuby on Rails application.
15
+ autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
@@ -27,49 +27,49 @@ signing_key:
27
27
  cert_chain:
28
28
  post_install_message:
29
29
  authors:
30
- - JRuby-extras
30
+ - Nick Sieger, Ola Bini and JRuby contributors
31
31
  files:
32
- - lib/active_record
33
- - lib/jdbc_adapter
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - LICENSE
34
37
  - lib/jdbc_adapter.rb
35
- - lib/active_record/connection_adapters
36
- - lib/active_record/connection_adapters/jdbc_adapter_spec.rb
37
38
  - lib/active_record/connection_adapters/jdbc_adapter.rb
38
- - lib/jdbc_adapter/jdbc_postgre.rb
39
- - lib/jdbc_adapter/jdbc_oracle.rb
40
- - lib/jdbc_adapter/jdbc_mimer.rb
41
- - lib/jdbc_adapter/jdbc_hsqldb.rb
42
- - lib/jdbc_adapter/jdbc_firebird.rb
43
- - lib/jdbc_adapter/jdbc_derby.rb
44
- - lib/jdbc_adapter/jdbc_mysql.rb
39
+ - lib/active_record/connection_adapters/jdbc_adapter_spec.rb
40
+ - lib/active_record/connection_adapters/jndi_adapter.rb
45
41
  - lib/jdbc_adapter/jdbc_db2.rb
42
+ - lib/jdbc_adapter/jdbc_derby.rb
43
+ - lib/jdbc_adapter/jdbc_firebird.rb
44
+ - lib/jdbc_adapter/jdbc_hsqldb.rb
45
+ - lib/jdbc_adapter/jdbc_mimer.rb
46
46
  - lib/jdbc_adapter/jdbc_mssql.rb
47
- - test/activerecord
48
- - test/minirunit
49
- - test/models
50
- - test/minirunit.rb
51
- - test/manualTestDatabase.rb
52
- - test/db
47
+ - lib/jdbc_adapter/jdbc_mysql.rb
48
+ - lib/jdbc_adapter/jdbc_oracle.rb
49
+ - lib/jdbc_adapter/jdbc_postgre.rb
50
+ - test/derby_simple_test.rb
51
+ - test/h2_simple_test.rb
53
52
  - test/hsqldb_simple_test.rb
53
+ - test/manualTestDatabase.rb
54
+ - test/minirunit.rb
54
55
  - test/mysql_simple_test.rb
55
56
  - test/simple.rb
56
- - test/activerecord/connections
57
- - test/activerecord/jtest.sh
58
- - test/activerecord/jall.sh
59
- - test/activerecord/connections/native_jdbc_mysql
57
+ - test/activerecord/connection_adapters/type_conversion_test.rb
60
58
  - test/activerecord/connections/native_jdbc_mysql/connection.rb
59
+ - test/db/derby.rb
60
+ - test/db/h2.rb
61
+ - test/db/hsqldb.rb
62
+ - test/db/logger.rb
63
+ - test/db/mysql.rb
64
+ - test/minirunit/testConnect.rb
65
+ - test/minirunit/testH2.rb
61
66
  - test/minirunit/testHsqldb.rb
67
+ - test/minirunit/testLoadActiveRecord.rb
62
68
  - test/minirunit/testMysql.rb
63
- - test/minirunit/testConnect.rb
64
69
  - test/minirunit/testRawSelect.rb
65
- - test/minirunit/testLoadActiveRecord.rb
70
+ - test/models/auto_id.rb
71
+ - test/models/data_types.rb
66
72
  - test/models/entry.rb
67
- - test/db/hsqldb.rb
68
- - test/db/logger.rb
69
- - test/db/mysql.rb
70
- - LICENSE
71
- - init.rb
72
- - install.rb
73
73
  test_files: []
74
74
 
75
75
  rdoc_options: []
data/init.rb DELETED
@@ -1,8 +0,0 @@
1
- RAILS_CONNECTION_ADAPTERS << 'jdbc'
2
- require 'active_record/connection_adapters/jdbc_adapter'
3
-
4
- [:initialize_database, :initialize_framework_logging, :initialize_framework_settings].each do |cmd|
5
- Rails::Initializer.run(cmd) do |config|
6
- config.frameworks = [:active_record]
7
- end
8
- end
data/install.rb DELETED
@@ -1,25 +0,0 @@
1
-
2
- require 'fileutils'
3
-
4
- from_d=File.expand_path(File.join(File.dirname(__FILE__),'lib','active_record'))
5
- to_d=File.expand_path(File.join(RAILS_ROOT,'lib','active_record'))
6
-
7
- FileUtils.cp_r from_d, to_d
8
-
9
- env_file = File.expand_path(File.join(RAILS_ROOT,"config","environment.rb"))
10
- bck_file = File.expand_path(File.join(RAILS_ROOT,"config","~.environment.rb.before_jdbc"))
11
-
12
- FileUtils.mv env_file,bck_file
13
-
14
- File.open(bck_file,"r") {|inf|
15
- File.open(env_file,"w") {|out|
16
- inf.each_line do |ln|
17
- if ln =~ /^Rails::Initializer\.run/
18
- out.puts "# Added by ActiveRecord JDBC plugin"
19
- out.puts "require 'jdbc_adapter'"
20
- out.puts
21
- end
22
- out.puts ln
23
- end
24
- }
25
- }
@@ -1,7 +0,0 @@
1
- #!/bin/sh
2
-
3
- for test in *_test.rb; do
4
- ./jtest.sh $test
5
- done
6
-
7
- #jruby.sh -I connections/native_jdbc_mysql -e 'Dir.foreach(".") { |file| require file if file =~ /_test.rb$/ }' | tee all.log
@@ -1,3 +0,0 @@
1
- #!/bin/sh
2
-
3
- jruby.sh -I connections/native_jdbc_mysql $1 | tee $1.log