simple-sql 0.3.2 → 0.3.3

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
  SHA1:
3
- metadata.gz: 8f45fc27ee92d2023cdcd3eb2b5a0cfbd1a05672
4
- data.tar.gz: 8036ee0f56cd039cf1555f8f3fbe323dbaf76a09
3
+ metadata.gz: 04497955a6185ca1fe0d3d75e30daa7e39e1de2a
4
+ data.tar.gz: 71e54b945961921b96f3a8bf45333200b3b49de1
5
5
  SHA512:
6
- metadata.gz: fcef39ebaa97f2807ea6812257b22775d70b3ac21620bdfcf508e4a06340c4142791d7bb6a93d7a17a1c40950236aa3431691afe7c3fcd4072cd1b78d199e1fe
7
- data.tar.gz: af8c3af9c817824a76e89c2ed5e7cb9856ad87a696da7e87c26c5cad8a0b9d48d5df92841484e8c27a33a48152069be9a22a0e4269ae7bfb8043a00938cac8d5
6
+ metadata.gz: d9145018af24cf8c373aeada3b319da669f51d886a0886d1e2f71b2776adf08d6c76e5306313b24448f5c609de23469711cffc482dc13e1bf9bcfca0c9ca23f0
7
+ data.tar.gz: 0288c8e8d9543799086345b344c3d55d25913d50233cdb143450393c17172b07084631e50787ad6ddfd43957c1106e67fbc40127e95881d7cf7c79b97800e148
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple-sql (0.3.2)
4
+ simple-sql (0.3.3)
5
5
  pg (~> 0.20)
6
6
  pg_array_parser (~> 0)
7
7
 
@@ -28,8 +28,6 @@ GEM
28
28
  database_cleaner (1.6.2)
29
29
  diff-lcs (1.3)
30
30
  docile (1.1.5)
31
- factory_girl (4.8.0)
32
- activesupport (>= 3.0.0)
33
31
  i18n (0.9.1)
34
32
  concurrent-ruby (~> 1.0)
35
33
  json (2.1.0)
@@ -81,7 +79,6 @@ DEPENDENCIES
81
79
  activerecord (~> 4)
82
80
  awesome_print (~> 0)
83
81
  database_cleaner (~> 1)
84
- factory_girl (= 4.8.0)
85
82
  pg (= 0.20)
86
83
  rake (~> 11)
87
84
  rspec (~> 3.7)
data/Rakefile CHANGED
@@ -1,9 +1,7 @@
1
- require "rubocop/rake_task"
2
- require "rspec/core/rake_task"
3
-
4
1
  Dir.glob("tasks/*.rake").each { |r| import r }
5
2
 
6
- RSpec::Core::RakeTask.new(:spec)
7
- RuboCop::RakeTask.new(:rubocop)
8
-
9
- task default: [:spec, :rubocop]
3
+ task :default do
4
+ sh "rspec"
5
+ sh "USE_ACTIVE_RECORD=1 rspec"
6
+ sh "rubocop -D"
7
+ end
@@ -3,32 +3,20 @@
3
3
 
4
4
  # private
5
5
  module Simple::SQL::Connection
6
- def self.new(connection)
7
- if defined?(ActiveRecord)
8
- if connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
9
- return ActiveRecordConnection.new(connection)
10
- end
11
- end
12
-
13
- SimpleConnection.new(connection)
6
+ def self.active_record_connection
7
+ ActiveRecordConnection
14
8
  end
15
9
 
16
- class RawConnection
17
- def initialize(raw_connection)
18
- @raw_connection = raw_connection
19
- end
10
+ def self.pg_connection(connection)
11
+ PgConnection.new(connection)
12
+ end
20
13
 
14
+ class PgConnection
21
15
  extend Forwardable
22
16
  delegate %w(exec_params exec escape wait_for_notify) => :@raw_connection
23
17
 
24
- def transaction(&_block)
25
- raise ArgumentError, "Implementation missing for #transaction"
26
- end
27
- end
28
-
29
- class SimpleConnection < RawConnection
30
18
  def initialize(raw_connection)
31
- super(raw_connection)
19
+ @raw_connection = raw_connection
32
20
  @tx_nesting_level = 0
33
21
  end
34
22
 
@@ -68,12 +56,19 @@ module Simple::SQL::Connection
68
56
  end
69
57
  end
70
58
 
71
- class ActiveRecordConnection < RawConnection
72
- def initialize(connection)
73
- super(connection.raw_connection)
74
- @connection = connection
59
+ module ActiveRecordConnection
60
+ extend self
61
+
62
+ extend Forwardable
63
+ delegate %w(exec_params exec escape wait_for_notify) => :raw_connection
64
+ delegate [:transaction] => :connection
65
+
66
+ def raw_connection
67
+ connection.raw_connection
75
68
  end
76
69
 
77
- delegate [:transaction] => :@connection
70
+ def connection
71
+ ActiveRecord::Base.connection
72
+ end
78
73
  end
79
74
  end
@@ -48,7 +48,9 @@ module Simple
48
48
  # all values in there are SQL::Fragments
49
49
  def validated_overrides(overrides)
50
50
  overrides.inject({}) do |hsh, (key, value)|
51
- raise ArgumentError, "Unknown value #{value.inspect}" unless value.is_a?(Fragment)
51
+ unless value.is_a?(Fragment)
52
+ raise ArgumentError, "Pass in override values via SQL.fragment (for #{value.inspect})"
53
+ end
52
54
  hsh.update key.to_s => value.to_sql
53
55
  end
54
56
  end
@@ -1,5 +1,5 @@
1
1
  module Simple
2
2
  module SQL
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
data/lib/simple/sql.rb CHANGED
@@ -25,13 +25,12 @@ module Simple
25
25
  end
26
26
 
27
27
  def default_logger
28
- if defined?(ActiveRecord)
29
- ActiveRecord::Base.logger
30
- else
31
- logger = Logger.new(STDERR)
32
- logger.level = Logger::INFO
33
- logger
34
- end
28
+ logger = ActiveRecord::Base.logger if defined?(ActiveRecord)
29
+ return logger if logger
30
+
31
+ logger = Logger.new(STDERR)
32
+ logger.level = Logger::INFO
33
+ logger
35
34
  end
36
35
 
37
36
  # execute one or more sql statements. This method does not allow to pass in
@@ -148,12 +147,12 @@ module Simple
148
147
  }
149
148
 
150
149
  def connect_to_active_record
151
- return Connection.new(ActiveRecord::Base.connection) if defined?(ActiveRecord)
150
+ return Connection.active_record_connection if defined?(ActiveRecord)
152
151
 
153
152
  STDERR.puts <<~SQL
154
153
  Simple::SQL works out of the box with ActiveRecord-based postgres connections, reusing the current connection.
155
154
  To use without ActiveRecord you must connect to a database via Simple::SQL.connect!.
156
- SQL
155
+ SQL
157
156
 
158
157
  raise ArgumentError, "simple-sql: missing connection"
159
158
  end
@@ -171,7 +170,7 @@ SQL
171
170
  config = Config.parse_url(database_url)
172
171
 
173
172
  require "pg"
174
- connection = Connection.new(PG::Connection.new(config))
173
+ connection = Connection.pg_connection(PG::Connection.new(config))
175
174
  self.connector = lambda { connection }
176
175
  end
177
176
  end
data/simple-sql.gemspec CHANGED
@@ -38,7 +38,6 @@ Gem::Specification.new do |gem|
38
38
  gem.add_development_dependency 'rake', '~> 11'
39
39
  gem.add_development_dependency 'rspec', '~> 3.7'
40
40
  gem.add_development_dependency 'rubocop', '~> 0.52.1'
41
- gem.add_development_dependency 'factory_girl', '4.8.0'
42
41
  gem.add_development_dependency 'database_cleaner', '~> 1'
43
42
  gem.add_development_dependency 'simplecov', '~> 0'
44
43
  gem.add_development_dependency 'awesome_print', '~> 0'
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,11 @@ Dir.glob("./spec/support/**/*.rb").sort.each { |path| load path }
12
12
 
13
13
  require "simple/sql"
14
14
 
15
+ unless ENV["USE_ACTIVE_RECORD"]
16
+ Simple::SQL.connect!
17
+ Simple::SQL.ask "DELETE FROM users"
18
+ end
19
+
15
20
  SQL = Simple::SQL
16
21
  USER_COUNT = 2
17
22
 
@@ -21,6 +26,10 @@ RSpec.configure do |config|
21
26
  config.run_all_when_everything_filtered = true
22
27
  config.filter_run focus: (ENV["CI"] != "true")
23
28
  config.expect_with(:rspec) { |c| c.syntax = :expect }
24
- config.include FactoryGirl::Syntax::Methods
25
29
  config.order = "random"
30
+ config.around(:each) do |example|
31
+ Simple::SQL.ask "DELETE FROM users"
32
+ Simple::SQL.ask "DELETE FROM unique_users"
33
+ example.run
34
+ end
26
35
  end
@@ -1,3 +1,33 @@
1
- require "factory_girl"
1
+ $sequence_counter = 0
2
2
 
3
- # factories are loaded from support/factories automatically
3
+ def sequence(pattern)
4
+ # pattern.gsub(/\{\{sequence\}\}/) do
5
+ pattern.gsub(/\{\{sequence\}\}/) do "JH"
6
+ $sequence_counter += 1
7
+ end
8
+ end
9
+
10
+ def attrs(table)
11
+ case table
12
+ when :user
13
+ {
14
+ role_id: 123,
15
+ first_name: sequence("First {{sequence}}"),
16
+ last_name: sequence("Last {{sequence}}"),
17
+ access_level: "viewable"
18
+ }
19
+ when :unique_user
20
+ {
21
+ first_name: sequence("First {{sequence}}"),
22
+ last_name: sequence("Last {{sequence}}")
23
+ }
24
+ else
25
+ raise ArgumentError, "Invalid table for factory: #{table.inspect}"
26
+ end
27
+ end
28
+
29
+ def create(table)
30
+ table_name = table.to_s.pluralize
31
+ id = Simple::SQL.insert(table_name, attrs(table))
32
+ Simple::SQL.record("SELECT * FROM #{table_name} WHERE id=$1", id, into: OpenStruct)
33
+ end
@@ -1,10 +1,14 @@
1
1
  require "simplecov"
2
2
 
3
+ # make sure multiple runs result in multiple result set. SimpleCov will take
4
+ # care of merging these results automatically.
5
+ SimpleCov.command_name "test:#{ENV['USE_ACTIVE_RECORD']}"
6
+
3
7
  SimpleCov.start do
4
8
  # return true to remove src from coverage
5
9
  add_filter do |src|
6
10
  src.filename =~ /\/spec\//
7
11
  end
8
12
 
9
- minimum_coverage 96
13
+ minimum_coverage 90
10
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-20 00:00:00.000000000 Z
12
+ date: 2018-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -109,20 +109,6 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: 0.52.1
112
- - !ruby/object:Gem::Dependency
113
- name: factory_girl
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - '='
117
- - !ruby/object:Gem::Version
118
- version: 4.8.0
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - '='
124
- - !ruby/object:Gem::Version
125
- version: 4.8.0
126
112
  - !ruby/object:Gem::Dependency
127
113
  name: database_cleaner
128
114
  requirement: !ruby/object:Gem::Requirement
@@ -207,7 +193,6 @@ files:
207
193
  - spec/support/002_database_cleaner.rb
208
194
  - spec/support/003_factories.rb
209
195
  - spec/support/004_simplecov.rb
210
- - spec/support/factories/user_factory.rb
211
196
  - spec/support/model/user.rb
212
197
  - tasks/release.rake
213
198
  homepage: http://github.com/radiospiel/simple-sql
@@ -248,5 +233,4 @@ test_files:
248
233
  - spec/support/002_database_cleaner.rb
249
234
  - spec/support/003_factories.rb
250
235
  - spec/support/004_simplecov.rb
251
- - spec/support/factories/user_factory.rb
252
236
  - spec/support/model/user.rb
@@ -1,14 +0,0 @@
1
- FactoryGirl.define do
2
- factory :user do
3
- role_id 123
4
-
5
- sequence :first_name do |n| "First #{n}" end
6
- sequence :last_name do |n| "Last #{n}" end
7
- access_level "viewable"
8
- end
9
-
10
- factory :unique_user do
11
- sequence :first_name do |n| "First #{n}" end
12
- sequence :last_name do |n| "Last #{n}" end
13
- end
14
- end