remockable 0.3.7 → 0.3.8

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: 0d522b220b5d639c5cd9285a9a8f5159453ffe89f2939c8bc027e031912df157
4
- data.tar.gz: 785fb2bf78e0bcab7a199c9e9818ba76e280205adad1447a2a04dc484780da76
3
+ metadata.gz: cd890b89ca6632cc7b8461f13e0ef884369eaba7aeeec9a60f9ce7e416d39842
4
+ data.tar.gz: c38b42c84ca19e6a25a79583ea485bc5ce2443b18b12a1bc5755942d6cf07bed
5
5
  SHA512:
6
- metadata.gz: a7dc58ccf2dfa5dfc0e8f1a50afe59aad5bc5e35c3c6d77d0056a6662ac44454cd1dbc69a614a460ef9620607c7c86633d39778ead1551440e8a416056f2e0f9
7
- data.tar.gz: 978f77d8ba97d08df0b37776488f5280411647d838467ec36b9bb628ca8cdb8ef71ca64eb07cff91b6190a45949ba29887a32d1418d3be8afa39d09c6fe495a9
6
+ metadata.gz: db7c72e95d189e453a5d65aad26a11f20d4995e28ca0809d1d821fc232891ef4991d62f4a355df4e5d9ef54072017325aa59bfbcde1258abac04f845c63938c7
7
+ data.tar.gz: 908cb59b56057aa44417ed2e6219577cddf7a50607f07afbda28d700b1bece69ec0c3f4c7eb26a9177016f187efd5b92f289873f09e63a7246ba06f3ea3d6544
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.8 (2021-07-23)
4
+
5
+ * Add `:where` option to `have_index` ([Tyler Hunt][tylerhunt])
6
+
3
7
  ## 0.3.7 (2021-01-12)
4
8
 
5
9
  * Support Rails 6.0, 6.1 ([AGuyNamedRyan][])
@@ -1,15 +1,14 @@
1
1
  RSpec::Matchers.define(:have_index) do
2
2
  include Remockable::ActiveRecord::Helpers
3
3
 
4
- valid_options %w(name unique)
4
+ valid_options %w(name unique where)
5
5
 
6
6
  def column_names
7
7
  @column_names ||= expected_as_array.flatten.collect(&:to_s)
8
8
  end
9
9
 
10
10
  match do |actual|
11
- name = options[:name]
12
- unique = options[:unique]
11
+ name, unique, where = options.values_at(:name, :unique, :where)
13
12
  indexes = ActiveRecord::Base.connection.indexes(subject.class.table_name)
14
13
 
15
14
  index = indexes.detect do |index|
@@ -23,8 +22,9 @@ RSpec::Matchers.define(:have_index) do
23
22
  if index
24
23
  name_matches = name.nil? || matches_name?(index, name)
25
24
  unique_matches = unique.nil? || index.unique == unique
25
+ where_matches = where.nil? || index.where == where
26
26
 
27
- name_matches && unique_matches
27
+ name_matches && unique_matches && where_matches
28
28
  end
29
29
  end
30
30
 
@@ -1,3 +1,3 @@
1
1
  module Remockable
2
- VERSION = '0.3.7'
2
+ VERSION = '0.3.8'
3
3
  end
@@ -45,6 +45,28 @@ describe :have_index do
45
45
  end
46
46
  end
47
47
 
48
+ context 'with option :name' do
49
+ it 'matches if the index exists' do
50
+ ActiveRecord::Base.connection.add_index :users, :one, name: :oneness
51
+ expect(model).to have_index :one, name: :oneness
52
+ end
53
+
54
+ it 'does not match if the index does not exist' do
55
+ expect(model).to_not have_index :one, name: :oneness
56
+ end
57
+ end
58
+
59
+ context 'with option :name and without :one' do
60
+ it 'matches if the index exists' do
61
+ ActiveRecord::Base.connection.add_index :users, :one, name: :oneness
62
+ expect(model).to have_index name: :oneness
63
+ end
64
+
65
+ it 'does not match if the index does not exist' do
66
+ expect(model).to_not have_index name: :oneness
67
+ end
68
+ end
69
+
48
70
  context 'with option :unique' do
49
71
  it 'matches if the index exists' do
50
72
  ActiveRecord::Base.connection.add_index :users, :one, unique: true
@@ -61,25 +83,19 @@ describe :have_index do
61
83
  end
62
84
  end
63
85
 
64
- context 'with option :name' do
86
+ context 'with option :where' do
65
87
  it 'matches if the index exists' do
66
- ActiveRecord::Base.connection.add_index :users, :one, name: :oneness
67
- expect(model).to have_index :one, name: :oneness
88
+ ActiveRecord::Base.connection.add_index :users, :one, where: 'two = 2'
89
+ expect(model).to have_index :one, where: 'two = 2'
68
90
  end
69
91
 
70
- it 'does not match if the index does not exist' do
71
- expect(model).to_not have_index :one, name: :oneness
72
- end
73
- end
74
-
75
- context 'with option :name and without :one' do
76
- it 'matches if the index exists' do
77
- ActiveRecord::Base.connection.add_index :users, :one, name: :oneness
78
- expect(model).to have_index name: :oneness
92
+ it 'does not match if the index conditions are different' do
93
+ ActiveRecord::Base.connection.add_index :users, :one, where: 'two = 2'
94
+ expect(model).to_not have_index :one, where: 'two = 1'
79
95
  end
80
96
 
81
97
  it 'does not match if the index does not exist' do
82
- expect(model).to_not have_index name: :oneness
98
+ expect(model).to_not have_index :one, where: 'two = 2'
83
99
  end
84
100
  end
85
101
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remockable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Hunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  - !ruby/object:Gem::Version
254
254
  version: '0'
255
255
  requirements: []
256
- rubygems_version: 3.1.2
256
+ rubygems_version: 3.1.6
257
257
  signing_key:
258
258
  specification_version: 4
259
259
  summary: A collection of RSpec matchers for web apps.