8000 Config search path by dividedmind · Pull Request #36 · TalentBox/sequel-rails · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Config search path #36

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

Merged
merged 2 commits into from
Jul 15, 2013
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 fi 8000 le
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/sequel_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ def normalize_repository_config(hash)

# override max connections if requested in app configuration
config['max_connections'] = max_connections if max_connections
config['search_path'] = search_path if search_path

# some adapters only support an url
if config['adapter'] && config['adapter'] =~ /^(jdbc|do):/
params = {}
config.each do |k, v|
next if ['adapter', 'host', 'port', 'database'].include?(k)
if k == 'search_path'
v = v.split(',').map &:strip unless v.is_a? Array
v = URI::escape(v.join(','))
end
params[k] = v
end
params_str = params.map { |k, v| "#{k}=#{v}" }.join('&')
Expand Down
64 changes: 38 additions & 26 deletions spec/lib/sequel_rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,21 @@

describe ".setup" do

shared_context "max_connections" do
let(:max_connections) { 31337 }
before do
environments[environment]["max_connections"] = 7
SequelRails.configuration.max_connections = max_connections
end
end

shared_examples "max_connections_c" do
shared_examples "max_connections" do
context "with max_connections config option" do
include_context "max_connections"
it "overrides the option from the configuration" do
::Sequel.should_receive(:connect) do |hash|
hash['max_connections'].should == max_connections
end
subject
let(:max_connections) { 31337 }
before do
environments[environment]["max_connections"] = 7
SequelRails.configuration.max_connections = max_connections
end
end
end

shared_examples "max_connections_j" do
context "with max_connections config option" do
include_context "max_connections"
it "overrides the option from the configuration" do
::Sequel.should_receive(:connect) do |url, hash|
url.should include("max_connections=#{max_connections}")
::Sequel.should_receive(:connect) do |hash_or_url, *_|
if hash_or_url.is_a? Hash
hash_or_url['max_connections'].should == max_connections
else
hash_or_url.should include("max_connections=#{max_connections}")
end
end
subject
end
Expand All @@ -76,11 +65,33 @@

context "for a postgres connection" do

shared_examples "search_path" do
context "with search_path config option" do
let(:search_path) { ['secret', 'private', 'public'] }
before do
environments[environment]["search_path"] = "private, public"
SequelRails.configuration.search_path = search_path
end

it "overrides the option from the configuration" do
::Sequel.should_receive(:connect) do |hash_or_url, *_|
if hash_or_url.is_a? Hash
hash_or_url['search_path'].should == search_path
else
hash_or_url.should include("search_path=secret,private,public")
end
end
subject
end
end
end

let(:environment) { 'development' }

context "in C-Ruby" do

include_examples "max_connections_c"
include_examples "max_connections"
include_examples "search_path"

it "produces a sane config without url" do
::Sequel.should_receive(:connect) do |hash|
Expand All @@ -93,7 +104,8 @@

context "in JRuby" do

include_examples "max_connections_j"
include_examples "max_connections"
include_examples "search_path"

let(:is_jruby) { true }

Expand All @@ -114,7 +126,7 @@

context "in C-Ruby" do

include_examples "max_connections_c"
include_examples "max_connections"

it "produces a config without url" do
::Sequel.should_receive(:connect) do |hash|
Expand All @@ -126,7 +138,7 @@

context "in JRuby" do

include_examples "max_connections_j"
include_examples "max_connections"

let(:is_jruby) { true }

Expand Down
0