mysql_framework 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 889fe8ccc0b85df3fe457ceeacaf4ac66a8953fe6d68a62a066d0700c26d05fc
4
- data.tar.gz: 619ace891bdf1d809774628ab8322298cb019ffa92d260467a13835fff4359d3
3
+ metadata.gz: 1464cd256c24c61d853fbcfe1fdb4d784fe4ec4ee4453c327502aceed7912f83
4
+ data.tar.gz: 9e4d0f30d3aba04788c8d12eeffb81cd3d8973f7dcffc38ea1abb6fd683e0be7
5
5
  SHA512:
6
- metadata.gz: a6303e0423b54b92e7bf02dcd651a9da14b6a707b6848e046221ea769428e6633308da95389a83a16c1bc26343fcb106b15cb75cc1d79b2ee29c6c4cfe26c07b
7
- data.tar.gz: 9f4c4372b49495c9660e269eec2eec9d3df901d15c4566c5694c2f463453eeeeb2a0f1eabd68e145aabf0d007249bdb1e5a1a963ddb942be4742544725a2b7a0
6
+ metadata.gz: e5ed2afe2631ff18469da0665dad07bb2e94ca7154548940297870c50a726de8261dfc66a0e6be65fb2411b00246a087d300d65af4bceff78094effe0a5cc840
7
+ data.tar.gz: 4e3f86db50a7a555b273776da36d1de80bd6872df1181a889e007c4e0364d981b1f68f6d636e44bd3c0068a89f30bc728eaf9d080b9ddf9e11bb90f4ad186f2c
@@ -24,11 +24,11 @@ module MysqlFramework
24
24
  end
25
25
 
26
26
  # This method is called to use a client from the connection pool.
27
- def with_client
28
- client = check_out
27
+ def with_client(provided = nil)
28
+ client = provided || check_out
29
29
  yield client
30
30
  ensure
31
- check_in(client) unless client.nil?
31
+ check_in(client) unless provided
32
32
  end
33
33
 
34
34
  # This method is called to execute a prepared statement
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MysqlFramework
2
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
3
5
  end
@@ -66,7 +66,12 @@ describe MysqlFramework::Connector do
66
66
  end
67
67
 
68
68
  describe '#with_client' do
69
- it 'obtains a client from the pool to use' do
69
+ it 'uses the client that is provided, if passed one' do
70
+ expect(subject).not_to receive(:check_out)
71
+ expect { |b| subject.with_client(client, &b) }.to yield_with_args(client)
72
+ end
73
+
74
+ it 'obtains a client from the pool to use, if no client is provided' do
70
75
  allow(subject).to receive(:check_out).and_return(client)
71
76
  expect { |b| subject.with_client(&b) }.to yield_with_args(client)
72
77
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
4
+
2
5
  SimpleCov.start do
3
6
  add_filter 'spec/'
4
7
  end
5
8
 
6
- ENV['MYSQL_DATABASE'] ||= 'test_database'
7
- ENV['MYSQL_HOST'] ||= '127.0.0.1'
9
+ ENV['MYSQL_DATABASE'] ||= 'test_database'
10
+ ENV['MYSQL_HOST'] ||= '127.0.0.1'
8
11
  ENV['MYSQL_PARTITIONS'] ||= '5'
9
- ENV['MYSQL_PASSWORD'] ||= ''
10
- ENV['MYSQL_PORT'] ||= '3306'
11
- ENV['MYSQL_USERNAME'] ||= 'root'
12
- ENV['REDIS_URL'] ||= 'redis://127.0.0.1:6379'
12
+ ENV['MYSQL_PASSWORD'] ||= ''
13
+ ENV['MYSQL_PORT'] ||= '3306'
14
+ ENV['MYSQL_USERNAME'] ||= 'root'
15
+ ENV['REDIS_URL'] ||= 'redis://127.0.0.1:6379'
13
16
 
14
17
  require 'bundler'
15
18
  require 'mysql_framework'
@@ -22,6 +25,8 @@ require_relative 'support/tables/test'
22
25
  require_relative 'support/tables/demo'
23
26
 
24
27
  RSpec.configure do |config|
28
+ config.before(:each) { MysqlFramework.logger.level = Logger::ERROR }
29
+
25
30
  config.expect_with :rspec do |expectations|
26
31
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
27
32
  end
@@ -31,22 +36,24 @@ RSpec.configure do |config|
31
36
  end
32
37
  end
33
38
 
34
- client = Mysql2::Client.new({
35
- host: ENV.fetch('MYSQL_HOST'),
36
- port: ENV.fetch('MYSQL_PORT'),
37
- username: ENV.fetch('MYSQL_USERNAME'),
38
- password: ENV.fetch('MYSQL_PASSWORD'),
39
- })
39
+ client = Mysql2::Client.new(
40
+ host: ENV.fetch('MYSQL_HOST'),
41
+ port: ENV.fetch('MYSQL_PORT'),
42
+ username: ENV.fetch('MYSQL_USERNAME'),
43
+ password: ENV.fetch('MYSQL_PASSWORD')
44
+ )
40
45
  client.query("DROP DATABASE IF EXISTS `#{ENV.fetch('MYSQL_DATABASE')}`;")
41
46
  client.query("CREATE DATABASE `#{ENV.fetch('MYSQL_DATABASE')}`;")
42
47
 
43
48
  connector = MysqlFramework::Connector.new
44
49
  connector.query("DROP TABLE IF EXISTS `#{ENV.fetch('MYSQL_DATABASE')}`.`gems`")
45
- connector.query("CREATE TABLE `#{ENV.fetch('MYSQL_DATABASE')}`.`gems` (
46
- `id` CHAR(36) NOT NULL,
47
- `name` VARCHAR(255) NULL,
48
- `author` VARCHAR(255) NULL,
49
- `created_at` DATETIME,
50
- `updated_at` DATETIME,
51
- PRIMARY KEY (`id`)
52
- )")
50
+ connector.query(<<~SQL)
51
+ CREATE TABLE `#{ENV.fetch('MYSQL_DATABASE')}`.`gems` (
52
+ `id` CHAR(36) NOT NULL,
53
+ `name` VARCHAR(255) NULL,
54
+ `author` VARCHAR(255) NULL,
55
+ `created_at` DATETIME,
56
+ `updated_at` DATETIME,
57
+ PRIMARY KEY (`id`)
58
+ )
59
+ SQL
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.7.3
153
+ rubygems_version: 2.7.7
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: A lightweight framework to provide managers for working with MySQL.