minitest-sequel 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,160 +1,224 @@
1
- # require "minitest/sequel"
2
-
3
- # reopening to add schema validation functionality
4
- module Minitest::Assertions
5
-
6
- # Conveniently test your Model definitions as follows:
7
- #
8
- # let(:m) { Post.first }
9
- #
10
- # it { assert_have_column(m, :title, type: :string, db_type: 'varchar(250)') }
11
- # it { m.must_have_column(:title, type: :string, db_type: 'varchar(250)') }
12
- #
13
- # # assert_have_column(<instance>, <column_name>, <options>, <custom_error_message>)
14
- #
15
- # # <instance>.must_have_column(<column_name>, <options>, <custom_error_message>)
16
- #
17
- #
18
- # `assert_have_column()` first tests if the column name is defined in the Model and then checks
19
- # all passed options. The following options are valid and checked:
20
- #
21
- # * :type
22
- # * :db_type
23
- # * :allow_null
24
- # * :max_length
25
- # * :default
26
- # * :primary_key
27
- # * :auto_increment
28
- #
29
- # In the event the specs differ from the actual database implementation an extensive error
30
- # message with the differing option(s) is provided to help speed up debugging the issue:
31
- #
32
- # Expected Post model to have column: :title with: \
33
- # { type: 'string', db_type: 'varchar(250)', allow_null: 'false' } \
34
- # but found: { db_type: 'varchar(255)' }
35
- #
36
- #
37
- # **Please NOTE!**
38
- #
39
- # To test options with a value that is either `nil`, `true` or `false`, please use `:nil`,
40
- # `:false` or `:true` and provide numbers as 'strings' instead.
41
- #
42
- #
43
- def assert_have_column(obj, attribute, opts = {}, msg = nil)
44
- msg = msg.nil? ? "" : "#{msg}\n"
45
- msg << "Expected #{obj.class} model to have column: :#{attribute}"
46
- err_msg = []
47
- conf_msg = []
48
- # check if column exists
49
- dcol = obj.db.schema(obj.class.table_name).detect { |c| c[0] == attribute }
50
- matching = !dcol.nil?
51
-
52
- # bail out if no matching column
53
- unless matching
54
- msg << " but no such column exists"
55
- assert(false, msg)
56
- end
1
+ # frozen_string_literal: false
2
+
3
+ require 'minitest/assertions'
4
+ require 'minitest/spec'
5
+
6
+ # reopening to add validations functionality
7
+ module Minitest
8
+ # add support for Assert syntax
9
+ module Assertions
10
+ # Asserts that a given model has a specific column with optional attribute checks
11
+ #
12
+ # @param obj [Object] The model instance to check
13
+ # @param attribute [Symbol] The name of the column to check
14
+ # @param opts [Hash] Optional attributes to verify for the column
15
+ # @param msg [String, nil] Optional custom error message
16
+ #
17
+ # @example Basic usage
18
+ # let(:m) { Post.first }
19
+ # assert_have_column(m, :title, type: :string, db_type: 'varchar(250)')
20
+ #
21
+ # @example Using with Spec syntax
22
+ # m.must_have_column(:title, type: :string, db_type: 'varchar(250)')
23
+ #
24
+ # The method checks if the column exists in the model and then verifies
25
+ # any provided options. Valid options include:
26
+ #
27
+ # * :type - The Ruby type of the column
28
+ # * :db_type - The database-specific type of the column
29
+ # * :allow_null - Whether the column allows NULL values
30
+ # * :max_length - The maximum length for string-type columns
31
+ # * :default - The default value for the column
32
+ # * :primary_key - Whether the column is a primary key
33
+ # * :auto_increment - Whether the column auto-increments
34
+ #
35
+ # If the actual column attributes differ from the specified options,
36
+ # a detailed error message is provided:
37
+ #
38
+ # Expected Post model to have column: :title with: \
39
+ # { type: 'string', db_type: 'varchar(250)', allow_null: 'false' } \
40
+ # but found: { db_type: 'varchar(255)' }
41
+ #
42
+ # @note When testing for `nil`, `true`, or `false` values, use `:nil`,
43
+ # `:true`, or `:false` symbols respectively. For numeric values,
44
+ # provide them as strings.
45
+ #
46
+ # rubocop:disable Metrics/MethodLength
47
+ def assert_have_column(obj, attribute, opts = {}, msg = nil)
48
+ # Prepare the error message
49
+ msg = build_message_column(obj, attribute, msg)
50
+
51
+ # prepare output messages
52
+ msg_conf = []
53
+ msg_err = []
54
+
55
+ # extract the db table information for the column
56
+ dbcol = extract_column_info(obj, attribute)
57
+
58
+ # set matching status
59
+ matching = !dbcol.nil?
60
+
61
+ # bail if there is no matching column
62
+ bail_unless_column_exists(dbcol, msg) unless matching
63
+ # bail if passed options are invalid
64
+ bail_unless_valid_options(opts, msg)
65
+
66
+ # loop through the options passed and check them and report the result
67
+ opts.each do |key, value|
68
+ expected = compare_column_attribute(dbcol, key, value)
69
+ update_messages(msg_conf, msg_err, key, value, dbcol, expected)
70
+ matching &&= expected
71
+ end
57
72
 
58
- # bail out if options provided are invalid
59
- val_opts = [:type, :db_type, :allow_null, :max_length, :default, :primary_key, :auto_increment]
60
- invalid_opts = opts.keys.reject { |o| val_opts.include?(o) }
61
- unless invalid_opts.empty?
62
- msg << ", but the following invalid option(s) was found: { "
63
- invalid_opts.each { |o| msg << "#{o.inspect}; " }
64
- msg << " }. Valid options are: #{val_opts.inspect}"
65
- assert(false, msg)
73
+ msg << " with: { #{msg_conf.join(', ')} } but found: { #{msg_err.join(', ')} }"
74
+ assert(matching, msg)
66
75
  end
67
-
68
- # TODO: simplify this mess. quick fix didn't work, so look at it again when time permits.
69
-
70
- unless opts[:type].nil?
71
- expected = (dcol[1][:type].to_s == opts[:type].to_s)
72
- conf_msg << "type: '#{opts[:type]}'"
73
- unless expected
74
- err_msg << "type: '#{dcol[1][:type]}'"
75
- end
76
- matching &&= expected
76
+ # rubocop:enable Metrics/MethodLength
77
+
78
+ # Asserts that a given model does not have a specific column
79
+ #
80
+ # @param obj [Object] The model instance to check
81
+ # @param attribute [Symbol] The name of the column to check for absence
82
+ # @param msg [String, nil] Optional custom error message
83
+ #
84
+ # @example
85
+ # refute_have_column(user, :admin_flag)
86
+ #
87
+ def refute_have_column(obj, attribute, msg = nil)
88
+ # Prepare the error message
89
+ msg = build_message_column(obj, attribute, msg, refute: true)
90
+
91
+ # extract the column information from the database schema
92
+ dbcol = extract_column_info(obj, attribute)
93
+
94
+ # If the column is not found (dcol is nil), the test passes
95
+ matching = dbcol.nil?
96
+
97
+ # Return early if the test passes (column doesn't exist)
98
+ return if matching
99
+
100
+ # If we reach here, it means the column was found when it shouldn't be
101
+ msg << ' but such a column was found'
102
+
103
+ # Assert that matching is true (which it isn't at this point)
104
+ # This will raise an assertion error with the prepared message
105
+ assert(matching, msg)
77
106
  end
78
107
 
79
- unless opts[:db_type].nil?
80
- expected = (dcol[1][:db_type].to_s == opts[:db_type].to_s)
81
- conf_msg << "db_type: '#{opts[:db_type]}'"
82
- unless expected
83
- err_msg << "db_type: '#{dcol[1][:db_type]}'"
84
- end
85
- matching &&= expected
108
+ private
109
+
110
+ # Builds an error message for column assertions
111
+ #
112
+ # @param obj [Object] The model instance to check
113
+ # @param attribute [Symbol] The name of the column to check for absence
114
+ # @param msg [String, nil] Custom error message
115
+ # @param refute [Boolean] Whether this is for a refutation (default: false)
116
+ #
117
+ # @return [String] The formatted error message
118
+ #
119
+ def build_message_column(obj, attribute, msg, refute: false)
120
+ msg = msg.nil? ? '' : "#{msg}\n"
121
+ msg << "Expected #{obj.class} model to #{refute ? 'NOT ' : ''}have column: :#{attribute}"
86
122
  end
87
123
 
88
- unless opts[:max_length].nil?
89
- expected = (dcol[1][:max_length] === opts[:max_length])
90
- conf_msg << "max_length: '#{opts[:max_length]}'"
91
- unless expected
92
- err_msg << "max_length: '#{dcol[1][:max_length]}'"
93
- end
94
- matching &&= expected
124
+ # Extracts the column information for a given attribute in the database schema
125
+ #
126
+ # @param obj [Object] The model instance to check
127
+ # @param attribute [Symbol] The name of the column to find
128
+ #
129
+ # @return [Array, nil] The column information array if found, nil otherwise
130
+ #
131
+ # @example
132
+ # extract_column_info(user, :email)
133
+ # # => [:email, {:type=>:string, :db_type=>"varchar(255)", :allow_null=>true, ...}]
134
+ #
135
+ def extract_column_info(obj, attribute)
136
+ obj.db.schema(obj.class.table_name).detect { |c| c[0] == attribute }
95
137
  end
96
138
 
97
- unless opts[:allow_null].nil?
98
- v = _convert_value(opts[:allow_null])
99
- expected = (dcol[1][:allow_null] === v)
100
- conf_msg << "allow_null: '#{opts[:allow_null]}'"
101
- unless expected
102
- err_msg << "allow_null: '#{dcol[1][:allow_null]}'"
103
- end
104
- matching &&= expected
139
+ # Bail if the specified column does not exist in the database schema
140
+ #
141
+ # @param dcol [Array, nil] The database column information, or nil if the column doesn't exist
142
+ # @param msg [String] The error message to be displayed if the column doesn't exist
143
+ #
144
+ # @raise [Minitest::Assertion] If the column doesn't exist in the database schema
145
+ #
146
+ # @example
147
+ # bail_unless_column_exists(column_info, error_message)
148
+ #
149
+ def bail_unless_column_exists(dbcol, msg)
150
+ return if dbcol
151
+
152
+ msg << ' but no such column exists'
153
+ assert(false, msg)
105
154
  end
106
155
 
107
- unless opts[:default].nil?
108
- v = _convert_value(opts[:default])
109
- expected = (dcol[1][:default] === v)
110
- conf_msg << "default: '#{opts[:default]}'"
111
- unless expected
112
- err_msg << "default: '#{dcol[1][:default].inspect}'"
113
- end
114
- matching &&= expected
115
- end
156
+ # Bail if the options passed to #assert_have_column are invalid
157
+ #
158
+ # @param opts [Hash] The options to validate
159
+ #
160
+ # @raise [Minitest::Assertion] If any invalid options are found
161
+ #
162
+ # @example
163
+ # bail_unless_valid_options(type: :string, db_type: 'varchar(255)')
164
+ #
165
+ def bail_unless_valid_options(opts, msg)
166
+ valid_opts = %i[type db_type allow_null default primary_key auto_increment max_length]
167
+ invalid_opts = opts.keys.reject { |o| valid_opts.include?(o) }
168
+
169
+ return if invalid_opts.empty?
170
+
171
+ msg << ', but the following invalid option(s) was found: { '
172
+ msg << invalid_opts.map(&:inspect).join(', ')
173
+ msg << " }. Valid options are: #{valid_opts.inspect}"
116
174
 
117
- unless opts[:primary_key].nil?
118
- v = _convert_value(opts[:primary_key])
119
- expected = (dcol[1][:primary_key] === v)
120
- conf_msg << "primary_key: '#{opts[:primary_key]}'"
121
- unless expected
122
- err_msg << "primary_key: '#{dcol[1][:primary_key]}'"
123
- end
124
- matching &&= expected
175
+ assert(false, msg)
125
176
  end
126
177
 
127
- unless opts[:auto_increment].nil?
128
- v = _convert_value(opts[:auto_increment])
129
- expected = (dcol[1][:auto_increment] === v)
130
- conf_msg << "auto_increment: '#{opts[:auto_increment]}'"
131
- unless expected
132
- err_msg << "auto_increment: '#{dcol[1][:auto_increment]}'"
178
+ # Compares the actual column attribute with the expected value
179
+ #
180
+ # @param dbcol [Array] The database column information
181
+ # @param key [Symbol] The attribute key to compare
182
+ # @param value [Object] The expected value for the attribute
183
+ #
184
+ # @return [Boolean] True if the attribute matches the expected value, false otherwise
185
+ #
186
+ def compare_column_attribute(dbcol, key, value)
187
+ case key
188
+ when :type, :db_type
189
+ dbcol[1][key].to_s == value.to_s
190
+ when :allow_null, :default, :primary_key, :auto_increment
191
+ dbcol[1][key] == _convert_value(value)
192
+ when :max_length
193
+ dbcol[1][key] == value
133
194
  end
134
- matching &&= expected
135
195
  end
136
196
 
137
- msg = msg << " with: { #{conf_msg.join(', ')} } but found: { #{err_msg.join(', ')} }"
138
- assert(matching, msg)
139
- end
140
-
141
- #
142
- def refute_have_column(obj, attribute, msg = nil)
143
- msg = msg.nil? ? "" : "#{msg}\n"
144
- msg << "Expected #{obj.class} model to NOT have column: :#{attribute}"
145
- # check if column exists
146
- dcol = obj.db.schema(obj.class.table_name).detect { |col| col[0] == attribute }
147
- matching = dcol.nil?
148
- unless matching
149
- msg << " but such a column was found"
150
- assert(matching, msg)
197
+ # Updates the confirmation and error messages based on column attribute comparison
198
+ #
199
+ # @param msg_conf [Array] Array to store confirmation messages
200
+ # @param msg_err [Array] Array to store error messages
201
+ # @param key [Symbol] The attribute key being compared
202
+ # @param value [Object] The expected value for the attribute
203
+ # @param dbcol [Array] The database column information
204
+ # @param expected [Boolean] Whether the attribute matches the expected value
205
+ #
206
+ # @example
207
+ # update_messages(msg_conf, msg_err, :type, 'string', column_info, true)
208
+ #
209
+ # rubocop:disable Metrics/ParameterLists
210
+ def update_messages(msg_conf, msg_err, key, value, dbcol, expected)
211
+ msg_conf << "#{key}: '#{value}'"
212
+ val = key == 'default' ? dbcol[1][key].inspect : dbcol[1][key]
213
+ msg_err << "#{key}: '#{val}'" unless expected
151
214
  end
215
+ # rubocop:enable Metrics/ParameterLists
152
216
  end
217
+ # /module Assertions
153
218
 
154
- end
155
-
156
- # add support for Spec syntax
157
- module Minitest::Expectations
158
- infect_an_assertion :assert_have_column, :must_have_column, :reverse
159
- infect_an_assertion :refute_have_column, :wont_have_column, :reverse
219
+ # add support for Spec syntax
220
+ module Expectations
221
+ infect_an_assertion :assert_have_column, :must_have_column, :reverse
222
+ infect_an_assertion :refute_have_column, :wont_have_column, :reverse
223
+ end
160
224
  end
@@ -1,7 +1,150 @@
1
- # require "minitest/sequel"
1
+ # frozen_string_literal: false
2
+
3
+ require 'minitest/assertions'
4
+ require 'minitest/spec'
5
+
6
+ # reopening to add validations functionality
7
+ module Minitest
8
+ # add support for Assert syntax
9
+ module Assertions
10
+ # Asserts that a model can be created successfully.
11
+ #
12
+ # @param model [Class] The model class to test.
13
+ #
14
+ # This method attempts to create a new instance of the given model
15
+ # using the :make method (typically provided by a factory).
16
+ # It then asserts that:
17
+ # 1. The created instance is of the correct type.
18
+ # 2. The instance has no errors after creation.
19
+ #
20
+ # @raise [Minitest::Assertion] If the assertions fail.
21
+ #
22
+ def assert_crud_can_create(model)
23
+ m = model.send(:make)
24
+
25
+ msg = "CRUD:create - expected #{m.class} to be an instance of #{model}"
26
+ assert_instance_of(model, m, msg)
27
+
28
+ msg = "CRUD:create - expected .errors to be empty, but was: [#{m.errors.inspect}]"
29
+ assert_empty(m.errors, msg)
30
+ end
31
+
32
+ # Asserts that a model can be read successfully.
33
+ #
34
+ # @param model [Class] The model class to test.
35
+ #
36
+ # This method attempts to create a new instance of the given model
37
+ # using the :make method, then retrieves the first record from the database.
38
+ # It then asserts that:
39
+ # 1. The created instance is of the correct type.
40
+ # 2. The retrieved record is equal to the created instance.
41
+ #
42
+ # @raise [Minitest::Assertion] If the assertions fail.
43
+ #
44
+ def assert_crud_can_read(model)
45
+ m = model.send(:make)
46
+ res = model.send(:first)
47
+
48
+ msg = "CRUD:read - expected #{res.class} to be an instance of #{model}"
49
+ assert_instance_of(model, m, msg)
50
+
51
+ assert_equal(m, res, "CRUD:read - expected [#{m.inspect}] to equal [#{res.inspect}]")
52
+ end
53
+
54
+ # Asserts that a model can be updated successfully.
55
+ #
56
+ # @param model [Class] The model class to test.
57
+ # @param attr [Symbol, String] The attribute to update.
58
+ #
59
+ # This method attempts to create a new instance of the given model,
60
+ # update a specific attribute, and then verify the update.
61
+ #
62
+ # @raise [Minitest::Assertion] If the assertions fail.
63
+ #
64
+ def assert_crud_can_update(model, attr)
65
+ # Create a new instance of the model
66
+ m = model.send(:make)
67
+
68
+ # Generate a new value for the attribute by appending " Updated" to its current value
69
+ tmp_str = "#{m.send(attr.to_sym)} Updated"
70
+
71
+ # Retrieve the first record from the database
72
+ res = model.send(:first)
73
+
74
+ # Assert that the retrieved record matches the created instance
75
+ assert_equal(m, res, "CRUD:update - expected [#{m.inspect}] to equal [#{res.inspect}]")
76
+
77
+ # Update the attribute with the new value
78
+ res.send(:"#{attr}=", tmp_str)
79
+ res.save
80
+
81
+ # Retrieve the updated record from the database
82
+ res2 = model.send(:first)
83
+
84
+ # Assert that the updated attribute matches the new value
85
+ msg = "CRUD:update - expected [#{res2.send(attr.to_sym)}] to equal "
86
+ msg << "the updated string: [#{tmp_str}]"
87
+
88
+ assert_equal(tmp_str, res2.send(attr.to_sym), msg)
89
+ end
90
+
91
+ # Asserts that a model can be destroyed successfully.
92
+ #
93
+ # @param model [Class] The model class to test.
94
+ #
95
+ # This method tests the destroy functionality of a model, considering both
96
+ # hard delete and soft delete (using :deleted_at) scenarios.
97
+ #
98
+ # @raise [Minitest::Assertion] If the assertions fail.
99
+ #
100
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
101
+ def assert_crud_can_destroy(model)
102
+ # Create a new instance of the model
103
+ m = model.send(:make)
104
+
105
+ # 1. test for Paranoid plugin
106
+ plugs = model.instance_variable_get(:@plugins).map(&:to_s)
107
+ paranoid = plugs.include?('Sequel::Plugins::Paranoid')
108
+
109
+ if paranoid
110
+ # If the model uses soft delete (has :deleted_at), ensure it's initially nil
111
+ msg = "CRUD:destroy - expected :deleted_at to be nil, but was [#{m.deleted_at}]"
112
+ assert_nil(m.deleted_at, msg)
113
+
114
+ assert(m.soft_delete, 'CRUD:soft_delete - expected m.soft_delete to return true')
115
+
116
+ # For soft delete, :deleted_at should be set to a timestamp
117
+ refute_nil(m.deleted_at, 'CRUD:destroy - expected m.deleted_at to be NOT be nil')
118
+
119
+ msg = 'CRUD:destroy - expected m.deleted_at to be an instance of Time'
120
+ assert_instance_of(Time, m.deleted_at, msg)
121
+ else
122
+ # Attempt to destroy the model instance
123
+ assert(m.destroy, 'CRUD:destroy - expected m.destroy to return true')
124
+ end
125
+
126
+ # Try to retrieve the first record from the database after destruction
127
+ res = model.send(:first)
128
+
129
+ if paranoid
130
+ # By default the paranoid record should be returned from the database
131
+ msg = "CRUD:destroy - expected #{model}.first to NOT return nil, but was: [#{res.inspect}]"
132
+ refute_nil(res, msg)
133
+ else
134
+ # By default the record should not be returned from the database
135
+ msg = "CRUD:destroy - expected #{model}.first to return nil, but was: [#{res.inspect}]"
136
+ assert_nil(res, msg)
137
+ end
138
+ end
139
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
140
+ end
141
+ # /module Assertions
142
+ end
2
143
 
3
144
  # reopening to add helpers functionality
4
- class Minitest::Spec
145
+ # rubocop:disable Style/ClassAndModuleChildren
146
+ class Minitest::Spec < Minitest::Test
147
+ # module MinitestSequelCRUD
5
148
 
6
149
  # Enables quick tests to ensure that the basic CRUD functionality is working correctly for a Model
7
150
  #
@@ -19,51 +162,77 @@ class Minitest::Spec
19
162
  # this test depends upon being able to create a new model instance for each test via using
20
163
  # Sequel Factory's `#make()` method
21
164
  #
22
- def self.ensure_working_CRUD(model, attr)
23
-
24
- describe "a valid CRUD model" do
25
-
165
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
166
+ def self.ensure_working_crud(model, attr)
167
+ # rubocop:disable Metrics/BlockLength
168
+ describe 'a valid CRUD model' do
26
169
  it "can create a #{model}" do
27
170
  m = model.send(:make)
28
- assert_instance_of(_model, m, "CRUD:create - expected #{m.class} to be an instance of #{model}")
29
- assert_empty(m.errors, "CRUD:create - expected .errors to be empty, but was: [#{m.errors.inspect}]")
171
+
172
+ msg = "CRUD:create - expected #{m.class} to be an instance of #{model}"
173
+ assert_instance_of(model, m, msg)
174
+
175
+ msg = "CRUD:create - expected .errors to be empty, but was: [#{m.errors.inspect}]"
176
+ assert_empty(m.errors, msg)
30
177
  end
31
178
 
32
179
  it "can read a #{model}" do
33
180
  m = model.send(:make)
34
- res = model.send :first
35
- assert_instance_of(model, m, "CRUD:read - expected #{res.class} to be an instance of #{model}")
36
- assert_equal(m, res, "CRUD:read - expected [#{m.inspect}] to equal [#{res.inspect}]")
181
+ # res = model.send(:where, id: m.id)
182
+ res = model.send(:first)
183
+ # res = model[m.id]
184
+
185
+ msg = "CRUD:read - expected #{res.class} to be an instance of #{model}"
186
+ assert_instance_of(model, m, msg)
187
+
188
+ msg = "CRUD:read - expected [#{m.inspect}] to equal [#{res.inspect}]"
189
+ assert_equal(m, res, msg)
37
190
  end
38
191
 
39
192
  it "can update a #{model}" do
40
193
  m = model.send(:make)
41
194
  tmp_str = "#{m.send(attr.to_sym)} Updated"
42
195
  res = model.send(:first)
196
+ # res = model[m.id]
43
197
 
44
- assert_equal(m, res, "CRUD:update - expected [#{m.inspect}] to equal [#{res.inspect}]")
45
- res.send("#{attr}=", tmp_str)
198
+ msg = "CRUD:update - expected [#{m.inspect}] to equal [#{res.inspect}]"
199
+ assert_equal(m, res, msg)
200
+ res.send(:"#{attr}=", tmp_str)
46
201
  res.save
47
202
 
48
203
  res2 = model.send(:first)
49
- assert_equal(tmp_str, res2.send(attr.to_sym), "CRUD:update - expected [#{res2.send(attr.to_sym)}] to equal the updated string: [#{tmp_str}]")
204
+ # res2 = model[m.id]
205
+
206
+ msg = "CRUD:update - expected [#{res2.send(attr.to_sym)}] to equal the "
207
+ msg << "updated string: [#{tmp_str}]"
208
+
209
+ assert_equal(tmp_str, res2.send(attr.to_sym), msg)
50
210
  end
51
211
 
52
212
  it "can destroy a #{model}" do
53
213
  m = model.send(:make)
214
+
54
215
  if m.respond_to?(:deleted_at)
55
- assert_nil(m.deleted_at, "CRUD:delete - expected m.deleted_at to be nil, but was [#{m.deleted_at}]")
216
+ msg = "CRUD:delete - expected m.deleted_at to be nil, but was [#{m.deleted_at}]"
217
+ assert_nil(m.deleted_at, msg)
56
218
  end
57
- assert(m.destroy, "CRUD:delete - expected m.destroy to return true")
219
+
220
+ assert(m.destroy, 'CRUD:delete - expected m.destroy to return true')
58
221
  res = model.send(:first)
59
- assert_nil(res, "CRUD:delete - expected #{model}.first to return nil, but was: [#{res.inspect}]")
222
+
60
223
  if m.respond_to?(:deleted_at)
61
- refute_nil(m.deleted_at, "CRUD:delete - expected m.deleted_at to be NOT be nil")
62
- assert_instance_of(Time, m.deleted_at, "CRUD:delete - expected m.deleted_at to be an instance of Time")
224
+ refute_nil(m.deleted_at, 'CRUD:delete - expected m.deleted_at to be NOT be nil')
225
+
226
+ msg = 'CRUD:delete - expected m.deleted_at to be an instance of Time'
227
+ assert_instance_of(Time, m.deleted_at, msg)
228
+ else
229
+ msg = "CRUD:delete - expected #{model}.first to return nil, but was: [#{res.inspect}]"
230
+ assert_nil(res, msg)
63
231
  end
64
232
  end
65
-
66
233
  end
234
+ # rubocop:enable Metrics/BlockLength
67
235
  end
68
-
236
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
69
237
  end
238
+ # rubocop:enable Style/ClassAndModuleChildren