rspec-active_record 0.3.1 → 0.4.0

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: 477cc04c406d2859bf5164e5e5ecc39245ba7b7ba0b8bfcbcb91040387288748
4
- data.tar.gz: 1142fe363be3b106f53d7a2c7e2ab45fb022a497bf802a133da615ded4a6f479
3
+ metadata.gz: 7554766e4cdb7debbfac3df8d43b4b2f211fa47fa848e518e3d0e2c5aec0df42
4
+ data.tar.gz: 81925b6f2cd75bfde8d747ae62d4b1365af0ec580063c520418f3fc61a556e0b
5
5
  SHA512:
6
- metadata.gz: 5bbe4cac926b21ab4321d481f5f56e18b9d17fe37f9b59fe03ab8b37c535ac8546b4363857a2f6364d83621a8099ddf8a585dc071fa854a23ba722f33d1087d7
7
- data.tar.gz: df7845335fc2b759d426e611878efa57212a15db348e73b81e79e63dff7a9aab977a0508be7396d12f067822850cc907b6c7db12fcc4af6e899bdd5757df9cb6
6
+ metadata.gz: 4f927093f62c81b0403d035f6a49bd89620d5a4c9ecedb00f0a408adbee02f00a39b1f01df83875e4c26c5f22da50ac8930606df92a0af490fca9006864ed524
7
+ data.tar.gz: 19962a9c8758128a346982c5927fbfb6bcd2f42e1f1b3d9ff058aaf58e659b40dc1b57962b185304730013ae12884b10bab9dc0d2258096c3cbd94f531486c14
data/.rubocop.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Layout/LineLength:
6
+ Max: 120
3
7
 
4
8
  Metrics/BlockLength:
5
9
  Exclude:
@@ -9,6 +13,10 @@ Metrics/BlockLength:
9
13
  Metrics/MethodLength:
10
14
  Enabled: false
11
15
 
16
+ Naming/PredicatePrefix:
17
+ AllowedMethods:
18
+ - does_not_match?
19
+
12
20
  Style/StringLiterals:
13
21
  Enabled: true
14
22
  EnforcedStyle: double_quotes
@@ -16,6 +24,3 @@ Style/StringLiterals:
16
24
  Style/StringLiteralsInInterpolation:
17
25
  Enabled: true
18
26
  EnforcedStyle: double_quotes
19
-
20
- Layout/LineLength:
21
- Max: 120
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2026-10-02
4
+
5
+ - Allow `create_record.matching` to take multiple attribute hashes
6
+ - Fix query cache causing issues between differently structured tables
7
+
8
+ ## [0.3.2] - 2025-03-12
9
+
10
+ - Fix negative `change_record` to fail if at least 1 attribute changed from initial
11
+
3
12
  ## [0.3.1] - 2024-08-26
4
13
 
5
14
  - Fix `change_record` to work when STI type changes
data/Gemfile CHANGED
@@ -4,3 +4,9 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in rspec-active_record.gemspec
6
6
  gemspec
7
+
8
+ gem "database_cleaner-active_record"
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "rubocop"
12
+ gem "sqlite3"
data/README.md CHANGED
@@ -43,6 +43,8 @@ You can also make sure that attributes match, if it fails you'll get RSpec diff
43
43
 
44
44
  ```ruby
45
45
  expect { User.create!(name: "RSpec User") }.to create_record(User).matching(name: "RSpec User")
46
+ expect { User.create!([{name: "RSpec User"}, {name: "Test User"}]) }
47
+ .to create_record(User).matching({name: "RSpec User"}, {name: "Test User"})
46
48
  ```
47
49
 
48
50
  You can also achieve similar results using a scope, but not that in this case you won't see a diff:
@@ -20,13 +20,13 @@ module RSpec
20
20
 
21
21
  def matches?(block)
22
22
  @from_diff = diff_unless_match(@record, @from)
23
- @to_pre_match = !does_not_match_attributes?(@record, @to)
23
+ @to_pre_match = !not_match_attributes?(@record, @to)
24
24
 
25
25
  block.call
26
26
  @updated_record = @record.class.base_class.find(@record.id)
27
27
 
28
28
  @to_diff = diff_unless_match(@updated_record, @to)
29
- @from_post_match = !does_not_match_attributes?(@updated_record, @from)
29
+ @from_post_match = !not_match_attributes?(@updated_record, @from)
30
30
 
31
31
  (@from || @to) && !@from_diff && !@to_pre_match && !@to_diff && !@from_post_match
32
32
  end
@@ -40,7 +40,7 @@ module RSpec
40
40
  block.call
41
41
  @updated_record = @record.class.find(@record.id)
42
42
 
43
- @from_post_match = !does_not_match_attributes?(@updated_record, @from)
43
+ @from_post_match = match_attributes?(@updated_record, @from)
44
44
  end
45
45
 
46
46
  def description
@@ -92,7 +92,7 @@ module RSpec
92
92
  RSpec::Matchers::BuiltIn::HaveAttributes.new(attributes).matches?(record)
93
93
  end
94
94
 
95
- def does_not_match_attributes?(record, attributes)
95
+ def not_match_attributes?(record, attributes)
96
96
  return true unless attributes
97
97
 
98
98
  RSpec::Matchers::BuiltIn::HaveAttributes.new(attributes).does_not_match?(record)
@@ -8,11 +8,12 @@ module RSpec
8
8
 
9
9
  def initialize(scope)
10
10
  @scope = scope
11
+ @attributes = []
11
12
  super()
12
13
  end
13
14
 
14
15
  # Make sure that created record matches attributes
15
- def matching(attributes)
16
+ def matching(*attributes)
16
17
  @attributes = attributes
17
18
  self
18
19
  end
@@ -44,22 +45,26 @@ module RSpec
44
45
 
45
46
  @new_records = @scope.where.not(@scope.primary_key => existing_ids).to_a
46
47
 
47
- match_times? && match_attributes? && @new_records.present?
48
+ match_times? && @attributes.all? { |attrs| match_attributes?(attrs) } && @new_records.present?
48
49
  end
49
50
 
50
51
  def description
52
+ match_messages = @attributes.map do |attrs|
53
+ " matching #{format_hash(attrs)}"
54
+ end
55
+
51
56
  message = "create #{scope_name}"
52
57
  message += " #{@times} time#{"s" if @times != 1}" if @times
53
- message += " matching #{format_hash(@attributes)}" if @attributes
58
+ message += match_messages.join(",")
54
59
  improve_hash_formatting message
55
60
  end
56
61
 
57
62
  def failure_message
58
63
  failure = "expected to #{description} but"
59
- if !match_times?
60
- "#{failure} created #{@new_records.size}"
61
- else
64
+ if match_times?
62
65
  add_diff "#{failure} did not"
66
+ else
67
+ "#{failure} created #{@new_records.size}"
63
68
  end
64
69
  end
65
70
 
@@ -70,7 +75,9 @@ module RSpec
70
75
  private
71
76
 
72
77
  def add_diff(message)
73
- message += "\n\n#{DiffForMultipleRecords.new(@attributes, @new_records).call}" if @attributes
78
+ @attributes.each do |attrs|
79
+ message += "\n\n#{DiffForMultipleRecords.new(attrs, @new_records).call}" unless match_attributes?(attrs)
80
+ end
74
81
  message
75
82
  end
76
83
 
@@ -78,9 +85,8 @@ module RSpec
78
85
  @times.nil? || @times == @new_records.size
79
86
  end
80
87
 
81
- def match_attributes?
82
- @attributes.nil? ||
83
- @new_records.any? { |record| RSpec::Matchers::BuiltIn::HaveAttributes.new(@attributes).matches?(record) }
88
+ def match_attributes?(attrs)
89
+ @new_records.any? { |record| RSpec::Matchers::BuiltIn::HaveAttributes.new(attrs).matches?(record) }
84
90
  end
85
91
 
86
92
  def scope_name
@@ -40,6 +40,7 @@ module RSpec
40
40
  # Creates temporary table. Only works correctly if DDL transactions are enabled.
41
41
  # Takes same arguments as `create_table` in ActiveRecord migration.
42
42
  def create_temporary_table(*args, **options, &block)
43
+ ::ActiveRecord::Base.connection.clear_cache!
43
44
  ::ActiveRecord::Base.connection.create_table(*args, **options, &block)
44
45
  end
45
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module ActiveRecord
5
- VERSION = "0.3.1"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -45,7 +45,7 @@ module RSpec
45
45
 
46
46
  # Allows matching that code inside a block destroyed specific record.
47
47
  # @param record [ActiveRecord::Base] Model that should be destroyed
48
- # @return [ChangeRecord]
48
+ # @return [DestroyRecord]
49
49
  # @example Block destroyed record
50
50
  # expect { user.destroy! }.to destroy_record(user)
51
51
  def destroy_record(record)
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
16
16
 
17
+ spec.metadata["rubygems_mfa_required"] = "true"
17
18
  spec.metadata["homepage_uri"] = spec.homepage
18
19
  spec.metadata["source_code_uri"] = spec.homepage
19
20
  spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
@@ -33,12 +34,6 @@ Gem::Specification.new do |spec|
33
34
  spec.add_dependency "rspec-expectations"
34
35
  spec.add_dependency "rspec-mocks"
35
36
 
36
- spec.add_development_dependency "database_cleaner-active_record"
37
- spec.add_development_dependency "rake"
38
- spec.add_development_dependency "rspec"
39
- spec.add_development_dependency "rubocop"
40
- spec.add_development_dependency "sqlite3"
41
-
42
37
  # For more information and examples about making a new gem, check out our
43
38
  # guide at: https://bundler.io/guides/creating_gem.html
44
39
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrius Chamentauskas
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -52,76 +51,6 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: database_cleaner-active_record
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: sqlite3
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
54
  description: RSpec matchers to check when ActiveRecord objects are created/updated/destroyed
126
55
  email:
127
56
  - andrius.chamentauskas@gmail.com
@@ -151,10 +80,10 @@ homepage: https://github.com/andriusch/rspec-active_record
151
80
  licenses:
152
81
  - MIT
153
82
  metadata:
83
+ rubygems_mfa_required: 'true'
154
84
  homepage_uri: https://github.com/andriusch/rspec-active_record
155
85
  source_code_uri: https://github.com/andriusch/rspec-active_record
156
86
  changelog_uri: https://github.com/andriusch/rspec-active_record/CHANGELOG.md
157
- post_install_message:
158
87
  rdoc_options: []
159
88
  require_paths:
160
89
  - lib
@@ -169,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
98
  - !ruby/object:Gem::Version
170
99
  version: '0'
171
100
  requirements: []
172
- rubygems_version: 3.3.26
173
- signing_key:
101
+ rubygems_version: 4.0.19
174
102
  specification_version: 4
175
103
  summary: RSpec matchers for ActiveRecord
176
104
  test_files: []