simple-sql 0.4.3 → 0.4.4

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: 5fcb2c111a8c6dc399a0f901c00c3bfcc03389d4
4
- data.tar.gz: c49d0bed25fdeba1bda89b40ed26b750b3243e02
3
+ metadata.gz: 8dc4e5192271e99151c59877f89671f27f3333e6
4
+ data.tar.gz: 986e1c338ed8c7c9571ea85797fd0f6444a8d8b3
5
5
  SHA512:
6
- metadata.gz: aa83158d75e583871e008e6a7b04b29ad2c428aa4572dec3f97aebaf5a321c5d8fd0f0a50844290f618f0e49ef2317e2f8b49ac5b25602353b0e6eb93959dee7
7
- data.tar.gz: 0a4b31bb554bc1db1e01bc6f52cf5bbc7d904721702e4f87d2e10458e59b0f3d6e56f9e77a2cd16e08dd34e80592ab05e61dee2a7a993339ea63f28b9a9e31b4
6
+ metadata.gz: 84e6f1f3e6bad60ca3611d103a84db49069132c07f3142a88764b8fd402daea2dff9b77ac2c1d2cd72eeddf4934b1441400486eeed430744423e65be014ca866
7
+ data.tar.gz: 4d41a55a04b5f24cb0088fc4dd89badfdf510c7a2c06d8c64cafc3a50b3a414c8a01e66c75e245a179e527c561f5aa079f46454836cb1c5de88194ac0a7afd1c
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  coverage
2
2
  rdoc
3
3
  pkg
4
- log/test.log
4
+ log/test.log
5
+ .rspec.data
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple-sql (0.4.3)
4
+ simple-sql (0.4.4)
5
5
  pg (~> 0.20)
6
6
  pg_array_parser (~> 0)
7
7
 
@@ -54,7 +54,14 @@ class Simple::SQL::Scope
54
54
 
55
55
  def where!(sql_fragment, arg = :__dummy__no__arg, placeholder: "?")
56
56
  if arg == :__dummy__no__arg
57
- @filters << sql_fragment
57
+ if sql_fragment.is_a?(Hash)
58
+ sql_fragment.each do |key, value|
59
+ @args << value
60
+ @filters << "#{key} = $#{@args.length}"
61
+ end
62
+ else
63
+ @filters << sql_fragment
64
+ end
58
65
  else
59
66
  @args << arg
60
67
  @filters << sql_fragment.gsub(placeholder, "$#{@args.length}")
@@ -1,5 +1,5 @@
1
1
  module Simple
2
2
  module SQL
3
- VERSION = "0.4.3"
3
+ VERSION = "0.4.4"
4
4
  end
5
5
  end
@@ -1,2 +1,2 @@
1
1
  #!/bin/bash
2
- watchr lib,spec rspec
2
+ watchr lib,spec 'rspec --only-failures ; [[ $? == 2 ]] && rspec'
@@ -25,6 +25,31 @@ describe "Simple::SQL::Scope" do
25
25
  end
26
26
  end
27
27
 
28
+ context "with hash conditions" do
29
+ let(:user_id) { SQL.ask "SELECT id FROM users LIMIT 1" }
30
+ let(:scope) { SQL::Scope.new "SELECT 1 FROM users" }
31
+
32
+ context "that do not match" do
33
+ it "does not match with string keys" do
34
+ expect(SQL.ask(scope.where(id: -1))).to be_nil
35
+ end
36
+
37
+ it "does not match with symbol keys" do
38
+ expect(SQL.ask(scope.where("id" => -1))).to be_nil
39
+ end
40
+ end
41
+
42
+ context "that match" do
43
+ it "matches with string keys" do
44
+ expect(SQL.ask(scope.where("id" => user_id))).to eq(1)
45
+ end
46
+
47
+ it "matches with symbol keys" do
48
+ expect(SQL.ask(scope.where(id: user_id))).to eq(1)
49
+ end
50
+ end
51
+ end
52
+
28
53
  context "with non-argument conditions" do
29
54
  context "that do not match" do
30
55
  let(:scope) do
@@ -27,6 +27,8 @@ RSpec.configure do |config|
27
27
  config.filter_run focus: (ENV["CI"] != "true")
28
28
  config.expect_with(:rspec) { |c| c.syntax = :expect }
29
29
  config.order = "random"
30
+ config.example_status_persistence_file_path = ".rspec.data"
31
+
30
32
  config.around(:each) do |example|
31
33
  Simple::SQL.ask "DELETE FROM users"
32
34
  Simple::SQL.ask "DELETE FROM unique_users"
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.4.3
4
+ version: 0.4.4
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-04-30 00:00:00.000000000 Z
12
+ date: 2018-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser