Skip to content
Newer
Older
100644 128 lines (97 sloc) 3.64 KB
e8114af @sobrinho Use bundler to manage gemspec
sobrinho authored
1 require 'bundler/gem_tasks'
2 require 'rspec/core/rake_task'
42a9a32 @sobrinho Use appraisal to test against rails 2, rails 3 and rails 3.1
sobrinho authored
3 require 'appraisal'
d1696a6 @thiagopradi Starting
thiagopradi authored
4
e8114af @sobrinho Use bundler to manage gemspec
sobrinho authored
5 task :default => :spec
d1696a6 @thiagopradi Starting
thiagopradi authored
6
074e64f @thiagopradi Spec suite now runs on RSpec 2.0.0beta
thiagopradi authored
7 RSpec::Core::RakeTask.new(:spec) do |spec|
d1696a6 @thiagopradi Starting
thiagopradi authored
8 end
9
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
10 namespace :db do
821da32 @thiagopradi Better tasks description
thiagopradi authored
11 desc 'Build the databases for tests'
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
12 task :build_databases do
971be7f @thiagopradi Rakefile refactoring
thiagopradi authored
13 mysql_user = ENV['MYSQL_USER'] || "root"
0a04404 @thiagopradi Starting support for multiple databases
thiagopradi authored
14 postgres_user = ENV['POSTGRES_USER'] || "postgres"
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
15
7da3d1e @gaffneyc Shameless renaming of tables to include an underscore before the number.
gaffneyc authored
16 sql = (1..5).map do |i|
17 "CREATE DATABASE octopus_shard_#{i} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;"
18 end.join
19
20 %x( echo "#{sql}" | mysql -u #{mysql_user} )
21
22 # Postgres
23 %x( createdb -E UTF8 -U #{postgres_user} octopus_shard_1 )
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
24 end
25
821da32 @thiagopradi Better tasks description
thiagopradi authored
26 desc 'Drop the tests databases'
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
27 task :drop_databases do
0a04404 @thiagopradi Starting support for multiple databases
thiagopradi authored
28 mysql_user = ENV['MYSQL_USER'] || "root"
29 postgres_user = ENV['POSTGRES_USER'] || "postgres"
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
30
7da3d1e @gaffneyc Shameless renaming of tables to include an underscore before the number.
gaffneyc authored
31 sql = (1..5).map { |i| "DROP DATABASE IF EXISTS octopus_shard_#{i};" }.join
32
33 %x( echo "#{sql}" | mysql -u "#{mysql_user}" )
34
35 %x( dropdb -U #{postgres_user} octopus_shard_1 )
9539708 @kanevski Added OctopusModel to be able to handle methods previously handled by…
kanevski authored
36 %x( rm -f /tmp/database.sqlite3 )
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
37 end
38
821da32 @thiagopradi Better tasks description
thiagopradi authored
39 desc 'Create tables on tests databases'
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
40 task :create_tables do
2a85a23 @gaffneyc Generalize the require to ActiveSupport class extensions.
gaffneyc authored
41 Dir.chdir(File.expand_path("../spec", __FILE__))
42
3966139 @thiagopradi Support for replicated database! yay!
thiagopradi authored
43 require "octopus"
2a85a23 @gaffneyc Generalize the require to ActiveSupport class extensions.
gaffneyc authored
44 require "support/database_connection"
45
c4e7cae @thiagopradi Sqlite tests
thiagopradi authored
46 [:master, :brazil, :canada, :russia, :alone_shard, :postgresql_shard, :sqlite_shard].each do |shard_symbol|
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
47 # Rails 3.1 needs to do some introspection around the base class, which requires
48 # the model be a descendent of ActiveRecord::Base.
49 class BlankModel < ActiveRecord::Base; end;
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
50
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
51 BlankModel.using(shard_symbol).connection.initialize_schema_migrations_table()
52
53 BlankModel.using(shard_symbol).connection.create_table(:users) do |u|
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
54 u.string :name
5690e06 @thiagopradi Removing unused code
thiagopradi authored
55 u.integer :number
56 u.boolean :admin
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
57 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
58
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
59 BlankModel.using(shard_symbol).connection.create_table(:clients) do |u|
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
60 u.string :country
af0cc99 @thiagopradi Rakefile fix
thiagopradi authored
61 u.string :name
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
62 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
63
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
64 BlankModel.using(shard_symbol).connection.create_table(:cats) do |u|
1e71e09 @thiagopradi Fixing when you have replication and non replicated models
thiagopradi authored
65 u.string :name
66 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
67
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
68 BlankModel.using(shard_symbol).connection.create_table(:items) do |u|
c47443f @thiagopradi Adding item model and minor fixes
thiagopradi authored
69 u.string :name
70 u.integer :client_id
71 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
72
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
73 BlankModel.using(shard_symbol).connection.create_table(:computers) do |u|
c84815e @thiagopradi Specs refactoring, specs for has_one, and new models
thiagopradi authored
74 u.string :name
75 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
76
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
77 BlankModel.using(shard_symbol).connection.create_table(:keyboards) do |u|
c84815e @thiagopradi Specs refactoring, specs for has_one, and new models
thiagopradi authored
78 u.string :name
79 u.integer :computer_id
80 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
81
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
82 BlankModel.using(shard_symbol).connection.create_table(:roles) do |u|
a2cc05f @thiagopradi Renaming columns
thiagopradi authored
83 u.string :name
7ae164e @thiagopradi New models
thiagopradi authored
84 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
85
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
86 BlankModel.using(shard_symbol).connection.create_table(:permissions) do |u|
a2cc05f @thiagopradi Renaming columns
thiagopradi authored
87 u.string :name
7ae164e @thiagopradi New models
thiagopradi authored
88 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
89
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
90 BlankModel.using(shard_symbol).connection.create_table(:permissions_roles, :id => false) do |u|
7ae164e @thiagopradi New models
thiagopradi authored
91 u.integer :role_id
92 u.integer :permission_id
93 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
94
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
95 BlankModel.using(shard_symbol).connection.create_table(:assignments) do |u|
b222837 @thiagopradi Adding has_many :through tests
thiagopradi authored
96 u.integer :programmer_id
97 u.integer :project_id
98 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
99
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
100 BlankModel.using(shard_symbol).connection.create_table(:programmers) do |u|
b222837 @thiagopradi Adding has_many :through tests
thiagopradi authored
101 u.string :name
102 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
103
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
104 BlankModel.using(shard_symbol).connection.create_table(:projects) do |u|
b222837 @thiagopradi Adding has_many :through tests
thiagopradi authored
105 u.string :name
106 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
107
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
108 BlankModel.using(shard_symbol).connection.create_table(:comments) do |u|
2073ca3 @thiagopradi Tests for polymorphic association
thiagopradi authored
109 u.string :name
110 u.string :commentable_type
111 u.integer :commentable_id
112 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
113
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
114 BlankModel.using(shard_symbol).connection.create_table(:parts) do |u|
e20e814 @thiagopradi Specs for joins/includes with two levels
thiagopradi authored
115 u.string :name
116 u.integer :item_id
117 end
c4172ac @thiagopradi Solving issues with set_table_name
thiagopradi authored
118
4121198 @kanevski Addressed issue with getting tests to run with Rails 3.1
kanevski authored
119 BlankModel.using(shard_symbol).connection.create_table(:yummy) do |u|
c4172ac @thiagopradi Solving issues with set_table_name
thiagopradi authored
120 u.string :name
121 end
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
122 end
123 end
572b53c @thiagopradi Use Mysql2 instead of Mysql
thiagopradi authored
124
821da32 @thiagopradi Better tasks description
thiagopradi authored
125 desc 'Prepare the test databases'
23bf6a7 @thiagopradi Rake task to prepare MySQL databases
thiagopradi authored
126 task :prepare => [:drop_databases, :build_databases, :create_tables]
127 end
Something went wrong with that request. Please try again.