Skip to content

Commit

Permalink
test with schemas instead of raw sql
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.techno-weenie.net/projects/acts_as_versioned@229 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information
technoweenie committed Nov 13, 2005
1 parent ffd8ff5 commit 9f692b5
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 181 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*0.2.3*

* (12 Nov 2005) fixed bug with old behavior of #blank? [Michael Schuerig]

*0.2.2*

* (3 Nov 2005) added documentation note to #acts_as_versioned [Martin Jul]
Expand Down
24 changes: 13 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@ require 'rake/testtask'
require 'rake/contrib/rubyforgepublisher'

PKG_NAME = 'acts_as_versioned'
PKG_VERSION = '0.2.2'
PKG_VERSION = '0.2.3'
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
PROD_HOST = "technoweenie@bidwell.textdrive.com"
RUBY_FORGE_PROJECT = 'ar-versioned'
RUBY_FORGE_USER = 'technoweenie'

for adapter in %w( mysql postgresql sqlite sqlite3 sqlserver sqlserver_odbc db2 oci )
Rake::TestTask.new("test_#{adapter}") do |t|
t.libs << "test" << "test/connections/native_#{adapter}"
t.pattern = "test/*_test{,_#{adapter}}.rb"
t.verbose = true
end
desc 'Default: run unit tests.'
task :default => :test

desc 'Test the calculations plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'html'
desc 'Generate documentation for the calculations plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "#{PKG_NAME} -- Simple versioning with active record models"
rdoc.options << '--line-numbers --inline-source --accessor cattr_accessor=object'
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
rdoc.options << '--line-numbers --inline-source'
rdoc.rdoc_files.include('README', 'CHANGELOG', 'RUNNING_UNIT_TESTS')
rdoc.rdoc_files.include('lib/**/*.rb')
end
Expand Down
35 changes: 27 additions & 8 deletions test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,39 @@
require 'active_record/fixtures'
require 'active_support/binding_of_caller'
require 'active_support/breakpoint'
require 'connection'
require 'acts_as_versioned'
require "#{File.dirname(__FILE__)}/../init"

config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])

load(File.dirname(__FILE__) + "/schema.rb")

# set up custom sequence on widget_versions for DBs that support sequences
if ENV['DB'] == 'postgresql'
ActiveRecord::Base.connection.execute "DROP SEQUENCE widgets_seq;" rescue nil
ActiveRecord::Base.connection.remove_column :widget_versions, :id
ActiveRecord::Base.connection.execute "CREATE SEQUENCE widgets_seq START 101;"
ActiveRecord::Base.connection.execute "ALTER TABLE widget_versions ADD COLUMN id INTEGER PRIMARY KEY DEFAULT nextval('widgets_seq');"
end

Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)

class Test::Unit::TestCase #:nodoc:
def create_fixtures(*table_names)
if block_given?
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names) { yield }
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
else
Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", table_names)
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
end
end
end

Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
Test::Unit::TestCase.use_instantiated_fixtures = false
Test::Unit::TestCase.use_transactional_fixtures = (ENV['AR_TX_FIXTURES'] == "yes")
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
self.use_transactional_fixtures = true

# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
self.use_instantiated_fixtures = false

# Add more helper methods to be used by all tests here...
end
14 changes: 0 additions & 14 deletions test/connections/native_db2/connection.rb

This file was deleted.

14 changes: 0 additions & 14 deletions test/connections/native_mysql/connection.rb

This file was deleted.

15 changes: 0 additions & 15 deletions test/connections/native_oci/connection.rb

This file was deleted.

14 changes: 0 additions & 14 deletions test/connections/native_postgresql/connection.rb

This file was deleted.

34 changes: 0 additions & 34 deletions test/connections/native_sqlite/connection.rb

This file was deleted.

33 changes: 0 additions & 33 deletions test/connections/native_sqlite3/connection.rb

This file was deleted.

14 changes: 0 additions & 14 deletions test/connections/native_sqlserver/connection.rb

This file was deleted.

15 changes: 0 additions & 15 deletions test/connections/native_sqlserver_odbc/connection.rb

This file was deleted.

18 changes: 18 additions & 0 deletions test/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sqlite:
:adapter: sqlite
:dbfile: acts_as_versioned_plugin.sqlite.db
sqlite3:
:adapter: sqlite3
:dbfile: acts_as_versioned_plugin.sqlite3.db
postgresql:
:adapter: postgresql
:username: postgres
:password: postgres
:database: acts_as_versioned_plugin_test
:min_messages: ERROR
mysql:
:adapter: mysql
:host: localhost
:username: rails
:password:
:database: acts_as_versioned_plugin_test
Binary file removed test/fixtures/activerecord_versioned.sqlite3
Binary file not shown.
3 changes: 1 addition & 2 deletions test/fixtures/widget.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class Widget < ActiveRecord::Base
set_sequence_name 'widgets_seq'
acts_as_versioned
acts_as_versioned :sequence_name => 'widgets_seq'
end
3 changes: 2 additions & 1 deletion test/migration_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'abstract_unit'
require File.join(File.dirname(__FILE__), 'abstract_unit')

if ActiveRecord::Base.connection.supports_migrations?
class Thing < ActiveRecord::Base
Expand All @@ -7,6 +7,7 @@ class Thing < ActiveRecord::Base
end

class MigrationTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
def teardown
ActiveRecord::Base.connection.initialize_schema_information
ActiveRecord::Base.connection.update "UPDATE schema_info SET version = 0"
Expand Down
43 changes: 43 additions & 0 deletions test/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ActiveRecord::Schema.define(:version => 0) do
create_table :pages, :force => true do |t|
t.column :version, :integer
t.column :title, :string, :limit => 255
t.column :body, :text
t.column :updated_on, :datetime
end

create_table :page_versions, :force => true do |t|
t.column :page_id, :integer
t.column :version, :integer
t.column :title, :string, :limit => 255
t.column :body, :text
t.column :updated_on, :datetime
end

create_table :locked_pages, :force => true do |t|
t.column :lock_version, :integer
t.column :title, :string, :limit => 255
t.column :type, :string, :limit => 255
end

create_table :locked_pages_revisions, :force => true do |t|
t.column :page_id, :integer
t.column :version, :integer
t.column :title, :string, :limit => 255
t.column :version_type, :string, :limit => 255
t.column :updated_at, :datetime
end

create_table :widgets, :force => true do |t|
t.column :name, :string, :limit => 50
t.column :version, :integer
t.column :updated_at, :datetime
end

create_table :widget_versions, :force => true do |t|
t.column :widget_id, :integer
t.column :name, :string, :limit => 50
t.column :version, :integer
t.column :updated_at, :datetime
end
end
2 changes: 0 additions & 2 deletions test/tests.rb

This file was deleted.

8 changes: 4 additions & 4 deletions test/versioned_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'abstract_unit'
require 'fixtures/page'
require 'fixtures/widget'
require File.join(File.dirname(__FILE__), 'abstract_unit')
require File.join(File.dirname(__FILE__), 'fixtures/page')
require File.join(File.dirname(__FILE__), 'fixtures/widget')

class VersionedTest < Test::Unit::TestCase
fixtures :pages, :page_versions, :locked_pages, :locked_pages_revisions
Expand Down Expand Up @@ -233,6 +233,6 @@ def test_with_sequence
Widget.create :name => 'new widget'
Widget.create :name => 'new widget'
assert_equal 3, Widget.count
assert_equal 3, Widget.versions.size
assert_equal 3, Widget.versioned_class.count
end
end

0 comments on commit 9f692b5

Please sign in to comment.