sql_matchers 0.0.1 → 1.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -60
- data/lib/sql_matchers/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f5583348852121bc9ee574e0e49d9de9dc236775b4cf1866add7764441daa43
|
4
|
+
data.tar.gz: 919504f62d430ce28d581b46d85db5dc1343f1183dc3bf2f8a61ef720ecb6106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc9a5fcf7dbcd8f781d2ec262c5794356f44731f8196c9cbddad3678c614cd739dd2c5b8055b3487c8626dc038fd5d27d13d536e052e345a4ddd8aae9ddd23d
|
7
|
+
data.tar.gz: 622ef54ecd313324d49c1e10ecf95fafcb81382d8006a205f1657cb499e4619b21fd1e2cc122ec353e26f30df028fbd62c7c338b3fea8bfa7668a440597a19a8
|
data/README.md
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
[![CI](https://github.com/keygen-sh/sql_matchers/actions/workflows/test.yml/badge.svg)](https://github.com/keygen-sh/sql_matchers/actions)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/sql_matchers.svg)](https://badge.fury.io/rb/sql_matchers)
|
5
5
|
|
6
|
-
Use `sql_matchers` to
|
7
|
-
|
8
|
-
constants.
|
6
|
+
Use `sql_matchers` to assert number of queries as well as SQL-level assertions
|
7
|
+
in RSpec.
|
9
8
|
|
10
9
|
This gem was extracted from [Keygen](https://keygen.sh).
|
11
10
|
|
@@ -41,68 +40,28 @@ $ gem install sql_matchers
|
|
41
40
|
|
42
41
|
## Usage
|
43
42
|
|
44
|
-
### `temporary_table`
|
45
|
-
|
46
|
-
To define a temporary table:
|
47
|
-
|
48
43
|
```ruby
|
49
|
-
|
50
|
-
|
51
|
-
t.string :email
|
52
|
-
t.string :first_name
|
53
|
-
t.string :last_name
|
54
|
-
t.index :email, unique: true
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should define a table' do
|
58
|
-
expect(ActiveRecord::Base.connection.table_exists?(:user)).to be true
|
59
|
-
end
|
44
|
+
it 'should assert query count' do
|
45
|
+
expect { User.count }.to match_query(count: 1)
|
60
46
|
end
|
61
|
-
```
|
62
|
-
|
63
|
-
The full Active Record schema API is available.
|
64
47
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
expect(const_defined?(:User)).to be true
|
77
|
-
end
|
48
|
+
it 'should assert query matches' do
|
49
|
+
expect { 3.times { User.find_by(id: _1 + 1) } }.to(
|
50
|
+
match_queries(count: 3) do |queries|
|
51
|
+
first, second, third, *rest = queries
|
52
|
+
|
53
|
+
expect(first).to eq %(SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1)
|
54
|
+
expect(second).to eq %(SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1)
|
55
|
+
expect(third).to eq %(SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1)
|
56
|
+
expect(rest).to be_empty
|
57
|
+
end
|
58
|
+
)
|
78
59
|
end
|
79
|
-
```
|
80
60
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
temporary_model :guest_user, table_name: nil, base_class: nil do
|
86
|
-
include ActiveModel::Model
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should define a model' do
|
90
|
-
expect(const_defined?(:GuestUser)).to be true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
```
|
94
|
-
|
95
|
-
To define a PORO:
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
describe Example do
|
99
|
-
temporary_model :null_user, table_name: nil, base_class: nil do
|
100
|
-
# ...
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should define a PORO' do
|
104
|
-
expect(const_defined?(:NullUser)).to be true
|
105
|
-
end
|
61
|
+
it 'should assert SQL matches' do
|
62
|
+
expect(User.where(id: 42).to_sql).to match_sql <<~SQL.squish
|
63
|
+
SELECT "users".* FROM "users" WHERE "users"."id" = 42
|
64
|
+
SQL
|
106
65
|
end
|
107
66
|
```
|
108
67
|
|
data/lib/sql_matchers/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 1.0.0.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Gabrielse
|
@@ -101,9 +101,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '3.1'
|
102
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- - "
|
104
|
+
- - ">"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
106
|
+
version: 1.3.1
|
107
107
|
requirements: []
|
108
108
|
rubygems_version: 3.4.13
|
109
109
|
signing_key:
|