Permalink
Browse files

database unit test

  • Loading branch information...
Bettina Steger
Bettina Steger committed Jun 7, 2010
1 parent 76fbda7 commit a4d83ec6e163bf201de54ea9352a876d37142ceb
Showing with 39 additions and 13 deletions.
  1. +0 −1 app/models/connected_database.rb
  2. +2 −2 app/views/domains/index.html.haml
  3. +17 −0 test/test_helper.rb
  4. +20 −10 test/unit/database_test.rb
@@ -11,7 +11,6 @@ def self.create_user(options={})
unless options[:name].blank? && options[:password].blank?
res = connection.execute("SELECT COUNT(*) FROM user WHERE User = '#{options[:name]}';")
row = res.fetch_row
puts "xxxx" + row[0].to_s
if row[0].to_i < 1
connection.execute "CREATE USER '#{options[:name]}'@'localhost' IDENTIFIED BY '#{options[:password]}';"
end
@@ -2,8 +2,8 @@
#workbench
#settings_bubble_blueprint.settings-bubble{:class => 'hidden'}
.domain-settings
hullo
.domain-settings
.browser
- @domains.each do |domain|
- position_style = domain.workbench_x && domain.workbench_x ? "top: #{domain.workbench_y}px; left: #{domain.workbench_x}px" : ""
View
@@ -3,6 +3,23 @@
require 'test_help'
class ActiveSupport::TestCase
setup { Sham.reset }
teardown {
Database.all.each do |d|
d.destroy
end
User.all.each do |u|
u.destroy
end
Domain.all.each do |d|
d.destroy
end
}
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test database remains unchanged so your fixtures don't have to be reloaded
View
@@ -1,17 +1,26 @@
require 'test_helper'
class DatabaseTest < ActiveSupport::TestCase
#ActiveRecord::Base.establish_connection :connected_database
should "save a new database" do
@user = User.make
@db = Database.make(:user_id => @user.id)
assert_equal 1, Database.count
puts @db.name
#res = connection.execute("SELECT COUNT(*) FROM #{@db.name};")
#row = res.fetch_row
#puts row[0].to_s
context "database model" do
setup do
@user = User.make
@db = Database.make_unsaved(:user_id => @user.id, :name => @user.username)
end
should "save a new database" do
assert @db.save
assert_equal 1, Database.count
assert_equal 1, ConnectedDatabase::connection.execute("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = '#{@db.name}';").fetch_row[0].to_i
end
should "destroy a database" do
@db = Database.make(:user_id => @user.id, :name => @user.username)
assert @db.destroy
assert_equal 0, Database.count
assert_equal 0, ConnectedDatabase::connection.execute("SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name = '#{@db.name}';").fetch_row[0].to_i
end
end
context "A Database instance" do
@@ -27,4 +36,5 @@ class DatabaseTest < ActiveSupport::TestCase
should_ensure_length_at_least :name, 3
should_validate_presence_of :user_id
end
end

0 comments on commit a4d83ec

Please sign in to comment.