Sha256: 84176bc7a3be1c1e4f86ab19a01a0c40ef864e5fadeeeaa11d4c498e4619cb27

Contents?: true

Size: 1.99 KB

Versions: 12

Compression:

Stored size: 1.99 KB

Contents

#!/usr/bin/env ruby

require 'TestSetup'
require 'test/unit'
require 'rubygems'
require 'fireruby'

include FireRuby

class RoleTest < Test::Unit::TestCase
   CURDIR      = "#{Dir.getwd}"
   DB_FILE     = "#{CURDIR}#{File::SEPARATOR}role_unit_test.fdb"

   def setup
      puts "#{self.class.name} started." if TEST_LOGGING
      # Remove existing database files.
      @database = Database.new(DB_FILE)
      if File.exist?(DB_FILE)
         @database.drop(DB_USER_NAME, DB_PASSWORD)
      end
      Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD)

      @sm = ServiceManager.new('localhost')
      @sm.connect(DB_USER_NAME, DB_PASSWORD)

      au = AddUser.new('user1', 'password', 'first', 'middle', 'last')
      au.execute(@sm)
      sleep(3)
   end

   def teardown
      ru = RemoveUser.new('user1')
      ru.execute(@sm)
      sleep(3)

      @sm.disconnect

      # Remove existing database files.
      if File.exist?(DB_FILE)
         @database.drop(DB_USER_NAME, DB_PASSWORD)
      end
      puts "#{self.class.name} finished." if TEST_LOGGING
   end

   def test01
      cxn = @database.connect(DB_USER_NAME, DB_PASSWORD)
      cxn.execute_immediate('CREATE TABLE TEST (field1 INTEGER)')
      cxn.execute_immediate('CREATE role myrole')
      cxn.execute_immediate('GRANT myrole to user1')
      cxn.execute_immediate('GRANT ALL on TEST to myrole')
      cxn.close

      cxn = @database.connect('user1', 'password')      
      assert_raise FireRubyException do
        t1 = cxn.start_transaction
        r = ResultSet.new(cxn, t1, "select * from test", 3, nil)
        r.fetch
        r.close
        t1.commit
      end
      cxn.close

      cxn = @database.connect('user1', 'password', {Connection::SQL_ROLE_NAME => "myrole"})
      assert_nothing_raised do
        t1 = cxn.start_transaction
        r = ResultSet.new(cxn, t1, "select * from test", 3, nil)
        r.fetch
        r.close
        t1.commit
      end
      cxn.close
   end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rubyfb-0.5.4-x86-mswin32-60 test/RoleTest.rb
rubyfb-0.5.4-x86-linux test/RoleTest.rb
rubyfb-0.5.4 test/RoleTest.rb
rubyfb-0.5.3-x86-mswin32-60 test/RoleTest.rb
rubyfb-0.5.3-x86-linux test/RoleTest.rb
rubyfb-0.5.3 test/RoleTest.rb
rubyfb-0.5.2-x86-mswin32-60 test/RoleTest.rb
rubyfb-0.5.2-x86-linux test/RoleTest.rb
rubyfb-0.5.2 test/RoleTest.rb
fireruby-0.4.3-mswin32 test/RoleTest.rb
fireruby-0.4.3-i586-linux test/RoleTest.rb
fireruby-0.4.2-mswin32 test/RoleTest.rb