Browse files

Test ActiveRecord 2.3 and 3.1 compatibility

* remove Gemfile.lock as suggested by Yehuda Katz [1]
* explictely test for ActiveRecord 3.1 support in travis
* make Lhm integration tests more explicit

[1] http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
  • Loading branch information...
1 parent 87f51b1 commit 55673323917706387c985466e863fd8f558377c1 @grobie grobie committed Jan 18, 2012
Showing with 109 additions and 87 deletions.
  1. +1 −0 .gitignore
  2. +5 −2 .travis.yml
  3. +0 −3 Gemfile
  4. +0 −37 Gemfile.lock
  5. +4 −0 gemfiles/ar-2.3.gemfile
  6. +4 −0 gemfiles/ar-3.1.gemfile
  7. +95 −45 spec/integration/lhm_spec.rb
View
1 .gitignore
@@ -1,5 +1,6 @@
*.gem
.bundle
Gemfile.lock
+gemfiles/*.lock
pkg/*
.rvmrc
View
7 .travis.yml
@@ -1,9 +1,12 @@
+before_script:
+ - "mysql -e 'create database lhm;'"
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
-before_script:
- - "mysql -e 'create database lhm;'"
+gemfile:
+ - gemfiles/ar-2.3.gemfile
+ - gemfiles/ar-3.1.gemfile
branches:
only:
- master
View
3 Gemfile
@@ -1,3 +0,0 @@
-source "http://rubygems.org"
-
-gemspec
View
37 Gemfile.lock
@@ -1,37 +0,0 @@
-PATH
- remote: .
- specs:
- lhm (1.0.0.rc2)
- activerecord
-
-GEM
- remote: http://rubygems.org/
- specs:
- activemodel (3.1.3)
- activesupport (= 3.1.3)
- builder (~> 3.0.0)
- i18n (~> 0.6)
- activerecord (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
- arel (~> 2.2.1)
- tzinfo (~> 0.3.29)
- activesupport (3.1.3)
- multi_json (~> 1.0)
- arel (2.2.1)
- builder (3.0.0)
- i18n (0.6.0)
- minitest (2.10.0)
- multi_json (1.0.4)
- mysql (2.8.1)
- rake (0.8.7)
- tzinfo (0.3.31)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- lhm!
- minitest (= 2.10.0)
- mysql (~> 2.8.1)
- rake
View
4 gemfiles/ar-2.3.gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem "activerecord", "~> 2.3.14"
+gemspec :path=>"../"
View
4 gemfiles/ar-3.1.gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem "activerecord", "~> 3.1.3"
+gemspec :path=>"../"
View
140 spec/integration/lhm_spec.rb
@@ -3,13 +3,81 @@
# Schmidt
#
+require 'lhm'
require File.expand_path(File.dirname(__FILE__)) + '/integration_helper'
-require 'lhm'
+class AddColumnTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users) do |t|
+ t.add_column(:logins, "INT(12) DEFAULT '0'")
+ end
+ end
+end
+
+class RemoveColumnTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users) do |t|
+ t.remove_column(:comment)
+ end
+ end
+end
+
+class AddIndexTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users) do |t|
+ t.add_index([:comment, :created_at])
+ end
+ end
+end
+
+class AddUniqueIndexTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users) do |t|
+ t.add_unique_index(:comment)
+ end
+ end
+end
+
+class RemoveIndexTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users) do |t|
+ t.remove_index([:username, :created_at])
+ end
+ end
+end
+
+class DdlTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users) do |t|
+ t.ddl("alter table %s add column flag tinyint(1)" % t.name)
+ end
+ end
+end
+
+class ParallelTestMigration < ActiveRecord::Migration
+ extend Lhm
+
+ def self.up
+ hadron_change_table(:users, :stride => 10, :throttle => 97) do |t|
+ t.add_column(:parallel, "INT(10) DEFAULT '0'")
+ end
+ end
+end
describe Lhm do
include IntegrationHelper
- include Lhm
before(:each) { connect! }
@@ -19,11 +87,9 @@
end
it "should add a column" do
- hadron_change_table("users") do |t|
- t.add_column(:logins, "INT(12) DEFAULT '0'")
- end
+ AddColumnTestMigration.up
- table_read("users").columns["logins"].must_equal({
+ table_read(:users).columns["logins"].must_equal({
:type => "int(12)",
:metadata => "DEFAULT '0'"
})
@@ -32,51 +98,39 @@
it "should copy all rows" do
23.times { |n| execute("insert into users set reference = '#{ n }'") }
- hadron_change_table("users") do |t|
- t.add_column(:logins, "INT(12) DEFAULT '0'")
- end
+ AddColumnTestMigration.up
count_all("users").must_equal(23)
end
it "should remove a column" do
- hadron_change_table("users") do |t|
- t.remove_column(:comment)
- end
+ RemoveColumnTestMigration.up
- table_read("users").columns["comment"].must_equal nil
+ table_read(:users).columns["comment"].must_equal nil
end
it "should add an index" do
- hadron_change_table("users") do |t|
- t.add_index([:comment, :created_at])
- end
+ AddIndexTestMigration.up
- key?(table_read("users"), ["comment", "created_at"]).must_equal(true)
+ key?(table_read(:users), [:comment, :created_at]).must_equal(true)
end
it "should add a unqiue index" do
- hadron_change_table("users") do |t|
- t.add_unique_index(:comment)
- end
+ AddUniqueIndexTestMigration.up
key?(table_read(:users), :comment, :unique).must_equal(true)
end
it "should remove an index" do
- hadron_change_table("users") do |t|
- t.remove_index([:username, :created_at])
- end
+ RemoveIndexTestMigration.up
- key?(table_read("users"), ["username", "created_at"]).must_equal(false)
+ key?(table_read(:users), [:username, :created_at]).must_equal(false)
end
it "should apply a ddl statement" do
- hadron_change_table("users") do |t|
- t.ddl("alter table %s add column flag tinyint(1)" % t.name)
- end
+ DdlTestMigration.up
- table_read("users").columns["flag"].must_equal({
+ table_read(:users).columns["flag"].must_equal({
:type => "tinyint(1)",
:metadata => "DEFAULT NULL"
})
@@ -93,33 +147,29 @@
end
end
- hadron_change_table("users", :stride => 10, :throttle => 97) do |t|
- t.add_column(:parallel, "INT(10) DEFAULT '0'")
- end
+ ParallelTestMigration.up
insert.join
- count_all("users").must_equal(60)
+ count_all(:users).must_equal(60)
end
- end
- it "should perserve deletes during migration" do
- 50.times { |n| execute("insert into users set reference = '#{ n }'") }
+ it "should perserve deletes during migration" do
+ 50.times { |n| execute("insert into users set reference = '#{ n }'") }
- insert = Thread.new do
- 10.times do |n|
- execute("delete from users where id = '#{ n + 1 }'")
- sleep(0.17)
+ delete = Thread.new do
+ 10.times do |n|
+ execute("delete from users where id = '#{ n + 1 }'")
+ sleep(0.17)
+ end
end
- end
- hadron_change_table("users", :stride => 10, :throttle => 97) do |t|
- t.add_column(:parallel, "INT(10) DEFAULT '0'")
- end
+ ParallelTestMigration.up
- insert.join
+ delete.join
- count_all("users").must_equal(40)
+ count_all(:users).must_equal(40)
+ end
end
end
end

0 comments on commit 5567332

Please sign in to comment.