Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/improve specs #161

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions spec/aruba/dbconsole_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
#
unless Bundler.default_gemfile.to_s =~ /rails_5.0/

require 'spec_helper'

require 'spec_helper'
describe 'rails dbconsole' do
before do
write_file(
'config/database.yml',
File.read(File.expand_path('fixtures/database_without_username_and_password.yml', __dir__)))
end

describe 'rails dbconsole' do
before do
write_file(
'config/database.yml',
File.read(File.expand_path('fixtures/database_without_username_and_password.yml', __dir__)))
end

describe 'rails dbconsole', type: :aruba do
let(:action) { run_command("bash -c \"echo 'select 1 as foo_column; \\q' | bundle exec rails db\"") }
let(:last_command) { action && last_command_started }
describe 'rails dbconsole', type: :aruba do
let(:action) { run_command("bash -c \"echo 'select 1 as foo_column; \\q' | bundle exec rails db\"") }
let(:last_command) { action && last_command_started }

specify { expect(last_command).to be_successfully_executed }
specify { expect(last_command).to have_output(/\bfoo_column\b/) }
specify { expect(last_command).to be_successfully_executed }
specify { expect(last_command).to have_output(/\bfoo_column\b/) }
end
end
end


end
1 change: 0 additions & 1 deletion spec/aruba/migrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
end
end


describe 'rerun bundle exec rake db:drop db:create db:migrate', issue: 56 do
let(:command) { 'bundle exec rake db:drop db:create db:migrate' }
before do
Expand Down
43 changes: 20 additions & 23 deletions spec/chrono_model/adapter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
end

context do
before { expect(adapter).to receive(:postgresql_version).and_return(90300) }
before { expect(adapter).to receive(:postgresql_version).and_return(90_300) }
it { is_expected.to be_chrono_supported }
end

context do
before { expect(adapter).to receive(:postgresql_version).and_return(90000) }
before { expect(adapter).to receive(:postgresql_version).and_return(90_000) }
it { is_expected.to_not be_chrono_supported }
end

Expand All @@ -31,42 +31,42 @@
end

with_temporal_table(&assert)
with_plain_table( &assert)
with_plain_table(&assert)
end

describe '.indexes' do
subject { adapter.indexes(table) }

assert = proc do
before(:all) do
adapter.add_index table, :foo, :name => 'foo_index'
adapter.add_index table, [:bar, :baz], :name => 'bar_index'
adapter.add_index table, :foo, name: 'foo_index'
adapter.add_index table, %i[bar baz], name: 'bar_index'
end

it { expect(subject.map(&:name)).to match_array %w( foo_index bar_index ) }
it { expect(subject.map(&:columns)).to match_array [['foo'], ['bar', 'baz']] }
it { expect(subject.map(&:name)).to match_array %w[foo_index bar_index] }
it { expect(subject.map(&:columns)).to match_array [['foo'], %w[bar baz]] }
end

with_temporal_table(&assert)
with_plain_table( &assert)
with_plain_table(&assert)
end

describe '.column_definitions' do
subject { adapter.column_definitions(table).map {|d| d.take(2)} }
subject { adapter.column_definitions(table).map { |d| d.take(2) } }

assert = proc do
it { expect(subject & columns).to eq columns }
it { is_expected.to include(['id', pk_type]) }
end

with_temporal_table(&assert)
with_plain_table( &assert)
with_plain_table(&assert)
end

describe '.on_schema' do
before(:all) do
adapter.execute 'BEGIN'
5.times {|i| adapter.execute "CREATE SCHEMA test_#{i}"}
5.times { |i| adapter.execute "CREATE SCHEMA test_#{i}" }
end

after(:all) do
Expand All @@ -78,12 +78,12 @@
is_expected.to be_in_schema(:default)

adapter.on_schema('test_1') { is_expected.to be_in_schema('test_1')
adapter.on_schema('test_2') { is_expected.to be_in_schema('test_2')
adapter.on_schema('test_3') { is_expected.to be_in_schema('test_3')
}
is_expected.to be_in_schema('test_2')
}
is_expected.to be_in_schema('test_1')
adapter.on_schema('test_2') { is_expected.to be_in_schema('test_2')
adapter.on_schema('test_3') { is_expected.to be_in_schema('test_3')
}
is_expected.to be_in_schema('test_2')
}
is_expected.to be_in_schema('test_1')
}

is_expected.to be_in_schema(:default)
Expand All @@ -92,12 +92,10 @@
context 'when errors occur' do
subject do
adapter.on_schema('test_1') do

adapter.on_schema('test_2') do
adapter.execute 'BEGIN'
adapter.execute 'ERRORING ON PURPOSE'
end

end
end

Expand All @@ -118,9 +116,9 @@
is_expected.to be_in_schema(:default)

adapter.on_schema('test_1', recurse: :ignore) { is_expected.to be_in_schema('test_1')
adapter.on_schema('test_2', recurse: :ignore) { is_expected.to be_in_schema('test_1')
adapter.on_schema('test_3', recurse: :ignore) { is_expected.to be_in_schema('test_1')
} } }
adapter.on_schema('test_2', recurse: :ignore) { is_expected.to be_in_schema('test_1')
adapter.on_schema('test_3', recurse: :ignore) { is_expected.to be_in_schema('test_1')
} } }

is_expected.to be_in_schema(:default)
end
Expand Down Expand Up @@ -153,5 +151,4 @@
it { expect(adapter.is_chrono?(table)).to be(false) }
end
end

end
21 changes: 9 additions & 12 deletions spec/chrono_model/adapter/ddl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def ids(table)

context 'INSERT multiple values' do
before :all do
adapter.create_table table, :temporal => true, &columns
adapter.create_table table, temporal: true, &columns
end

after :all do
Expand Down Expand Up @@ -73,7 +73,7 @@ def insert

context 'INSERT on NOT NULL columns but with a DEFAULT value' do
before :all do
adapter.create_table table, :temporal => true, &columns
adapter.create_table table, temporal: true, &columns
end

after :all do
Expand All @@ -98,7 +98,7 @@ def select

context 'INSERT with string IDs' do
before :all do
adapter.create_table table, :temporal => true, :id => :string, &columns
adapter.create_table table, temporal: true, id: :string, &columns
end

after :all do
Expand All @@ -117,9 +117,8 @@ def insert
end

context 'redundant UPDATEs' do

before :all do
adapter.create_table table, :temporal => true, &columns
adapter.create_table table, temporal: true, &columns

adapter.execute <<-SQL
INSERT INTO #{table} (test, foo) VALUES ('test1', 1);
Expand All @@ -140,12 +139,11 @@ def insert

it { expect(count(current)).to eq 1 }
it { expect(count(history)).to eq 2 }

end

context 'updates on non-journaled fields' do
before :all do
adapter.create_table table, :temporal => true do |t|
adapter.create_table table, temporal: true do |t|
t.string 'test'
t.timestamps null: false
end
Expand Down Expand Up @@ -180,7 +178,7 @@ def insert
context 'selective journaled fields' do
describe 'basic behaviour' do
specify do
adapter.create_table table, :temporal => true, :journal => %w( foo ) do |t|
adapter.create_table table, temporal: true, journal: %w[foo] do |t|
t.string 'foo'
t.string 'bar'
end
Expand Down Expand Up @@ -210,7 +208,7 @@ def insert
table 'journaled_things'

before do
adapter.create_table table, :temporal => true, :journal => %w( foo ) do |t|
adapter.create_table table, temporal: true, journal: %w[foo] do |t|
t.string 'foo'
t.string 'bar'
t.string 'baz'
Expand All @@ -222,7 +220,7 @@ def insert
end

it 'preserves options upon column change' do
adapter.change_table table, temporal: true, journal: %w(foo bar)
adapter.change_table table, temporal: true, journal: %w[foo bar]

adapter.execute <<-SQL
INSERT INTO #{table} (foo, bar) VALUES ('test foo', 'test bar');
Expand All @@ -240,7 +238,7 @@ def insert
end

it 'changes option upon table change' do
adapter.change_table table, temporal: true, journal: %w(bar)
adapter.change_table table, temporal: true, journal: %w[bar]

adapter.execute <<-SQL
INSERT INTO #{table} (foo, bar) VALUES ('test foo', 'test bar');
Expand All @@ -259,5 +257,4 @@ def insert
end
end
end

end
8 changes: 4 additions & 4 deletions spec/chrono_model/adapter/indexes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
adapter.add_temporal_indexes :meetings, :interval
end

it { expect(adapter.indexes(:meetings).map(&:name)).to eq [
'index_meetings_temporal_on_interval',
'index_meetings_temporal_on_lower_interval',
'index_meetings_temporal_on_upper_interval'
it { expect(adapter.indexes(:meetings).map(&:name)).to eq %w[
index_meetings_temporal_on_interval
index_meetings_temporal_on_lower_interval
index_meetings_temporal_on_upper_interval
] }

after do
Expand Down
Loading