Skip to content

Commit

Permalink
Merge pull request #756 from govdelivery/rspec-cleanup
Browse files Browse the repository at this point in the history
Clean up specs and test documentation
  • Loading branch information
yahonda committed Jan 6, 2016
2 parents 3c42131 + 47022d8 commit dffa00d
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 79 deletions.
14 changes: 8 additions & 6 deletions RUNNING_TESTS.md
Expand Up @@ -16,7 +16,9 @@ to increase process limit and then restart the database (this will be necessary
Ruby versions
-------------

It is recommended to use [RVM](http://rvm.beginrescueend.com) to run tests with different Ruby implementations. oracle_enhanced is mainly tested with MRI 1.8.7 (all Rails versions) and 1.9.2 (Rails 3) and JRuby 1.6.
oracle_enhanced is tested with MRI 2.1.x and 2.2.x, and JRuby 1.7.x and 9.0.x.x.

It is recommended to use [RVM](http://rvm.beginrescueend.com) to run tests with different Ruby implementations.

Running tests
-------------
Expand All @@ -29,19 +31,19 @@ Running tests
SQL> CREATE USER oracle_enhanced_schema IDENTIFIED BY oracle_enhanced_schema;
SQL> GRANT unlimited tablespace, create session, create table, create sequence, create procedure, create trigger, create view, create materialized view, create database link, create synonym, create type, ctxapp TO oracle_enhanced_schema;

* If you use RVM then switch to corresponding Ruby (1.8.7, 1.9.2 or JRuby) and it is recommended to create isolated gemset for test purposes (e.g. rvm create gemset oracle_enhanced)
* If you use RVM then switch to corresponding Ruby. It is recommended to create isolated gemsets for test purposes (e.g. rvm create gemset oracle_enhanced)

* Install bundler with

gem install bundler

* Set RAILS_GEM_VERSION to Rails version that you would like to use in oracle_enhanced tests, e.g.

export RAILS_GEM_VERSION=3.0.3

* Install necessary gems with

bundle install
* Configure database credentials in one of two ways:
* copy spec/spec_config.yaml.template to spec/config.yaml and modify as needed
* set required environment variables (see DATABASE_NAME in spec_helper.rb)

* Run tests with

Expand Down
Expand Up @@ -171,7 +171,7 @@ class ::TestEmployee2 < ActiveRecord::Base
end

it 'should identify virtual columns as such' do
pending "Not supported in this database version" unless @oracle11g_or_higher
skip "Not supported in this database version" unless @oracle11g_or_higher
te = TestEmployee.connection.columns('test_employees').detect(&:virtual?)
te.name.should == 'full_name'
end
Expand Down Expand Up @@ -274,7 +274,7 @@ class ::TestEmployee < ActiveRecord::Base
end

it "should tell ActiveRecord that count distinct is supported" do
ActiveRecord::Base.connection.supports_count_distinct?.should be_true
ActiveRecord::Base.connection.supports_count_distinct?.should be true
end

it "should execute correct SQL COUNT DISTINCT statement" do
Expand Down Expand Up @@ -345,56 +345,56 @@ class ::TestReservedWord < ActiveRecord::Base; end
end

it "should be valid with letters and digits" do
@adapter.valid_table_name?("abc_123").should be_true
@adapter.valid_table_name?("abc_123").should be true
end

it "should be valid with schema name" do
@adapter.valid_table_name?("abc_123.def_456").should be_true
@adapter.valid_table_name?("abc_123.def_456").should be true
end

it "should be valid with $ in name" do
@adapter.valid_table_name?("sys.v$session").should be_true
@adapter.valid_table_name?("sys.v$session").should be true
end

it "should be valid with upcase schema name" do
@adapter.valid_table_name?("ABC_123.DEF_456").should be_true
@adapter.valid_table_name?("ABC_123.DEF_456").should be true
end

it "should be valid with irregular schema name and database links" do
@adapter.valid_table_name?('abc$#_123.abc$#_123@abc$#@._123').should be_true
@adapter.valid_table_name?('abc$#_123.abc$#_123@abc$#@._123').should be true
end

it "should not be valid with two dots in name" do
@adapter.valid_table_name?("abc_123.def_456.ghi_789").should be_false
@adapter.valid_table_name?("abc_123.def_456.ghi_789").should be false
end

it "should not be valid with invalid characters" do
@adapter.valid_table_name?("warehouse-things").should be_false
@adapter.valid_table_name?("warehouse-things").should be false
end

it "should not be valid with for camel-case" do
@adapter.valid_table_name?("Abc").should be_false
@adapter.valid_table_name?("aBc").should be_false
@adapter.valid_table_name?("abC").should be_false
@adapter.valid_table_name?("Abc").should be false
@adapter.valid_table_name?("aBc").should be false
@adapter.valid_table_name?("abC").should be false
end

it "should not be valid for names > 30 characters" do
@adapter.valid_table_name?("a" * 31).should be_false
@adapter.valid_table_name?("a" * 31).should be false
end

it "should not be valid for schema names > 30 characters" do
@adapter.valid_table_name?(("a" * 31) + ".validname").should be_false
@adapter.valid_table_name?(("a" * 31) + ".validname").should be false
end

it "should not be valid for database links > 128 characters" do
@adapter.valid_table_name?("name@" + "a" * 129).should be_false
@adapter.valid_table_name?("name@" + "a" * 129).should be false
end

it "should not be valid for names that do not begin with alphabetic characters" do
@adapter.valid_table_name?("1abc").should be_false
@adapter.valid_table_name?("_abc").should be_false
@adapter.valid_table_name?("abc.1xyz").should be_false
@adapter.valid_table_name?("abc._xyz").should be_false
@adapter.valid_table_name?("1abc").should be false
@adapter.valid_table_name?("_abc").should be false
@adapter.valid_table_name?("abc.1xyz").should be false
@adapter.valid_table_name?("abc._xyz").should be false
end
end

Expand Down Expand Up @@ -554,7 +554,7 @@ class ::TestPost < ActiveRecord::Base
@conn.create_table :foos, :temporary => true, :id => false do |t|
t.integer :id
end
@conn.temporary_table?("foos").should be_true
@conn.temporary_table?("foos").should be true
end
end

Expand Down Expand Up @@ -600,7 +600,7 @@ class ::TestComment < ActiveRecord::Base
posts.size.should == @ids.size
end

end if ENV['RAILS_GEM_VERSION'] >= '3.1'
end

describe "with statement pool" do
before(:all) do
Expand Down Expand Up @@ -654,7 +654,7 @@ class ::TestPost < ActiveRecord::Base
@conn.exec_update("UPDATE test_posts SET id = 1", "SQL", binds)
}.should_not change(@statements, :length)
end
end if ENV['RAILS_GEM_VERSION'] >= '3.1'
end

describe "explain" do
before(:all) do
Expand Down Expand Up @@ -688,7 +688,7 @@ class ::TestPost < ActiveRecord::Base
explain.should include("Cost")
explain.should include("INDEX UNIQUE SCAN")
end
end if ENV['RAILS_GEM_VERSION'] >= '3.2'
end

describe "using offset and limit" do
before(:all) do
Expand Down
Expand Up @@ -16,7 +16,7 @@
end

it "should ping active connection" do
@conn.ping.should be_true
@conn.ping.should be true
end

it "should not ping inactive connection" do
Expand Down Expand Up @@ -149,7 +149,7 @@
import 'org.apache.commons.dbcp.PoolableConnectionFactory'
import 'org.apache.commons.dbcp.DriverManagerConnectionFactory'
rescue NameError => e
return pending e.message
return skip e.message
end

class InitialContextMock
Expand All @@ -170,7 +170,7 @@ def lookup(path)
end
end

javax.naming.InitialContext.stub!(:new).and_return(InitialContextMock.new)
javax.naming.InitialContext.stub(:new).and_return(InitialContextMock.new)

params = {}
params[:jndi] = 'java:comp/env/jdbc/test'
Expand All @@ -185,7 +185,7 @@ def lookup(path)
params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "//#{DATABASE_HOST}#{DATABASE_PORT && ":#{DATABASE_PORT}"}/"}#{DATABASE_NAME}"
params[:host] = nil
params[:database] = nil
java.sql.DriverManager.stub!(:getConnection).and_raise('no suitable driver found')
java.sql.DriverManager.stub(:getConnection).and_raise('no suitable driver found')
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
@conn.should be_active
end
Expand Down
Expand Up @@ -103,7 +103,7 @@ class ::Post < ActiveRecord::Base

it "should not include text index secondary tables in user tables list" do
@conn.add_context_index :posts, :title
@conn.tables.any?{|t| t =~ /^dr\$/i}.should be_false
@conn.tables.any?{|t| t =~ /^dr\$/i}.should be false
@conn.remove_context_index :posts, :title
end

Expand Down
Expand Up @@ -52,7 +52,7 @@ class ::JobHistory < ActiveRecord::Base
end

it "should tell ActiveRecord that count distinct is not supported" do
ActiveRecord::Base.connection.supports_count_distinct?.should be_false
ActiveRecord::Base.connection.supports_count_distinct?.should be false
end

it "should execute correct SQL COUNT DISTINCT statement on table with composite primary keys" do
Expand Down
Expand Up @@ -474,8 +474,8 @@ class ::Test3Employee < ActiveRecord::Base
it "should get default value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
columns = @conn.columns('test3_employees')
columns.detect{|c| c.name == 'has_phone'}.default.should be_true
columns.detect{|c| c.name == 'manager_yn'}.default.should be_false
columns.detect{|c| c.name == 'has_phone'}.default.should eq 'Y'
columns.detect{|c| c.name == 'manager_yn'}.default.should be false
end

describe "/ VARCHAR2 boolean values from ActiveRecord model" do
Expand Down
Expand Up @@ -42,14 +42,14 @@ def fake_terminal(input)
describe "drop" do
before { ActiveRecord::Tasks::DatabaseTasks.drop(config) }
it "drops all tables" do
ActiveRecord::Base.connection.table_exists?(:test_posts).should be_false
ActiveRecord::Base.connection.table_exists?(:test_posts).should be false
end
end

describe "purge" do
before { ActiveRecord::Tasks::DatabaseTasks.purge(config) }
it "drops all tables" do
ActiveRecord::Base.connection.table_exists?(:test_posts).should be_false
ActiveRecord::Base.connection.table_exists?(:test_posts).should be false
ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM RECYCLEBIN").should == 0
end
end
Expand Down Expand Up @@ -77,7 +77,7 @@ def fake_terminal(input)
ActiveRecord::Tasks::DatabaseTasks.structure_load(config, temp_file)
end
it "loads the database structure from a file" do
ActiveRecord::Base.connection.table_exists?(:test_posts).should be_true
ActiveRecord::Base.connection.table_exists?(:test_posts).should be true
end
end

Expand Down
Expand Up @@ -110,7 +110,7 @@ class TestEmployee < ActiveRecord::Base
it "should not mark integer as changed when reassigning it" do
@employee = TestEmployee.new
@employee.job_id = 0
@employee.save!.should be_true
@employee.save.should be true

@employee.should_not be_changed

Expand All @@ -122,15 +122,15 @@ class TestEmployee < ActiveRecord::Base
@employee = TestEmployee.create!(
:comments => "initial"
)
@employee.save!.should be_true
@employee.save.should be true
@employee.reload
@employee.comments.should == 'initial'

oci_conn = @conn.instance_variable_get('@connection')
class << oci_conn
def write_lob(lob, value, is_binary = false); raise "don't do this'"; end
end
@employee.save!.should_not raise_exception(RuntimeError, "don't do this'")
expect { @employee.save! }.to_not raise_error
class << oci_conn
remove_method :write_lob
end
Expand Down
Expand Up @@ -12,7 +12,7 @@
it "should be an OracleAdapter" do
@conn = ActiveRecord::Base.establish_connection(CONNECTION_PARAMS.merge(:emulate_oracle_adapter => true))
ActiveRecord::Base.connection.should_not be_nil
ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::OracleAdapter).should be_true
ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::OracleAdapter).should be true
end

after(:all) do
Expand Down
Expand Up @@ -186,7 +186,7 @@ def raise_make_transaction_rollback
lambda {
@employee.save
}.should raise_error("Make the transaction rollback")
@employee.id.should == nil
@employee.new_record?.should be true
TestEmployee.count.should == employees_count
end

Expand Down Expand Up @@ -263,7 +263,6 @@ def raise_make_transaction_rollback
end

it "should delete record and set destroyed flag" do
return pending("Not in this ActiveRecord version (requires >= 2.3.5)") unless TestEmployee.method_defined?(:destroyed?)
@employee = TestEmployee.create(
:first_name => "First",
:last_name => "Last",
Expand Down Expand Up @@ -360,7 +359,7 @@ def raise_make_transaction_rollback
:last_name => "Last",
:hire_date => @today
)
@employee.save.should be_false
@employee.save.should be false
@employee.errors[:first_name].should_not be_blank
end

Expand All @@ -371,7 +370,7 @@ def raise_make_transaction_rollback
:hire_date => @today
)
@employee.first_name = nil
@employee.save.should be_false
@employee.save.should be false
@employee.errors[:first_name].should_not be_blank
end

Expand Down
Expand Up @@ -226,7 +226,7 @@ def drop_test_posts_table
end

it "should include composite foreign keys" do
pending "Composite foreign keys are not supported in this version"
skip "Composite foreign keys are not supported in this version"
schema_define do
add_column :test_posts, :baz_id, :integer
add_column :test_posts, :fooz_id, :integer
Expand Down Expand Up @@ -341,7 +341,7 @@ def drop_test_posts_table

it "should specify non-default tablespace in add index" do
tablespace_name = @conn.default_tablespace
@conn.stub!(:default_tablespace).and_return('dummy')
@conn.stub(:default_tablespace).and_return('dummy')
create_test_posts_table
standard_dump.should =~ /add_index "test_posts", \["title"\], name: "index_test_posts_on_title", tablespace: "#{tablespace_name}"$/
end
Expand Down Expand Up @@ -369,21 +369,18 @@ def drop_test_posts_table

describe 'virtual columns' do
before(:all) do
if @oracle11g_or_higher
schema_define do
create_table :test_names, :force => true do |t|
t.string :first_name
t.string :last_name
t.virtual :full_name, :as => "first_name || ', ' || last_name"
t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
t.virtual :name_ratio, :as=>'(LENGTH(first_name)*10/LENGTH(last_name)*10)'
t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
end
skip "Not supported in this database version" unless @oracle11g_or_higher
schema_define do
create_table :test_names, :force => true do |t|
t.string :first_name
t.string :last_name
t.virtual :full_name, :as => "first_name || ', ' || last_name"
t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
t.virtual :name_ratio, :as => '(LENGTH(first_name)*10/LENGTH(last_name)*10)'
t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
end
else
pending "Not supported in this database version"
end
end

Expand Down

0 comments on commit dffa00d

Please sign in to comment.