Skip to content

Ensured that adapter checks work if the adapter name contains extra space #131

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions capistrano-db-tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]

gem.add_runtime_dependency "capistrano", ">= 3.0.0"
gem.add_development_dependency "rspec"

end
5 changes: 3 additions & 2 deletions lib/capistrano-db-tasks/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ def initialize(cap_instance)
end

def mysql?
@config['adapter'] =~ /^mysql/
@config['adapter'].strip =~ /^mysql/
end

def postgresql?
%w(postgresql pg postgis chronomodel).include? @config['adapter']
adapter = @config['adapter'].strip
%{postgresql pg}.include? adapter
end

def credentials
Expand Down
95 changes: 95 additions & 0 deletions spec/ensure_adapters_work_with_extra_space_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'spec_helper'
require "capistrano"

describe Database::Base do

let(:base) {
Database::Base.new({})
}

describe "identifying mysql adapter" do

context "when mysql" do
it "it is positive" do
base.config = { "adapter" => "mysql" }
expect(base.mysql?).to be_truthy
end
end

context "when mysql with extra space" do
it "it is positive" do
base.config = { "adapter" => " mysql " }
expect(base.mysql?).to be_truthy
end
end

context "when postgresql" do
it "it is positive" do
base.config = { "adapter" => "postgresql" }
expect(base.mysql?).to be_falsey
end
end

context "when pg" do
it "it is positive" do
base.config = { "adapter" => "pg" }
expect(base.mysql?).to be_falsey
end
end

context "when something else" do
it "it is positive" do
base.config = { "adapter" => "foo" }
expect(base.mysql?).to be_falsey
end
end

end

describe "identifying postgres adapter" do

context "when postgresql" do
it "it is positive" do
base.config = { "adapter" => "postgresql" }
expect(base.postgresql?).to be_truthy
end
end

context "when postgresql with extra space" do
it "it is positive" do
base.config = { "adapter" => " postgresql " }
expect(base.postgresql?).to be_truthy
end
end

context "when pg" do
it "it is positive" do
base.config = { "adapter" => "pg" }
expect(base.postgresql?).to be_truthy
end
end

context "when pg with extra space" do
it "it is positive" do
base.config = { "adapter" => " pg " }
expect(base.postgresql?).to be_truthy
end
end

context "when mysql" do
it "it is positive" do
base.config = { "adapter" => "mysq" }
expect(base.postgresql?).to be_falsey
end
end

context "when something else" do
it "it is positive" do
base.config = { "adapter" => "foo" }
expect(base.postgresql?).to be_falsey
end
end

end

end
27 changes: 27 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'bundler/setup'
Bundler.setup

#
# “Note: May need to be looked at if additional tests added”
#
ENV['RAILS_ENV'] = 'development'

class Object
def fetch(x)
false
end
def set(x, y)
true
end
def namespace(x)
true
end
end
#
# end ”Note: May need to be looked at if additional tests added”
#

require 'capistrano-db-tasks'

RSpec.configure do |config|
end
8 changes: 0 additions & 8 deletions test/capistrano_db_tasks_test.rb

This file was deleted.

3 changes: 0 additions & 3 deletions test/test_helper.rb

This file was deleted.