mimoco 0.3.2 → 1.0.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: 1d005db7d29601313d32a107b3e0f4c5c2a97cf57458208c48f3647b8504310f
4
- data.tar.gz: 6e2eadc55c6d207ca53b5dfc1208093ca5099c731fcf8ccbaca700a6d4736cac
3
+ metadata.gz: 9410e1d42f9675bc7e26b423c3a74796d70834af501e169df0016a6ad3cdd427
4
+ data.tar.gz: 50ec876f43843b9846bed7f5491976ba685b758e56a2bfd753472d05cacae20b
5
5
  SHA512:
6
- metadata.gz: eb42f23837494c9c0811b94d95304d01364394d396de5e58338b5aa1025fdfbacb8bdddfc71398612e641ebc2f5d41bded49ac578cff36eb7afecf26476932b1
7
- data.tar.gz: 41eb22c914323da8eb91b72111c0bccad4a8c7f1f86ce1ba399c8ddf3656e8219631a25a34e19788fb12973265cfd352496366b44d631c4b74f3cc85f668a556
6
+ metadata.gz: efa7bd3f3089f895727970c11dfaf55a3f121755feed3bf0fe9b9fd44461e56b5957fe0787c94100231c4083df6c393d2f2d1c7bdd0a80f567e8b79234875bb6
7
+ data.tar.gz: 2eaf0e98b508eb891e55f90c0ceacc2be5de45c2b3c3313b8ec87596ffde5f7aabee8e5dfb7724d494cb0cea1d015315a3636f5be37217ded98592a43c36c97b
data/.gitignore CHANGED
@@ -6,4 +6,4 @@ coverage/
6
6
  *.log
7
7
  *.lock
8
8
 
9
- **/db/*.sqlite3
9
+ **/db/test.sqlite3*
data/README.md CHANGED
@@ -73,9 +73,21 @@ class ControllersTest < ActionDispatch::IntegrationTest
73
73
  end
74
74
  ```
75
75
 
76
+ ## Parameter
77
+
78
+ Rails magic adds a few additional methods to a model or a controller
79
+ (e.g. #column_headers).
80
+
81
+ MiMoCo ignores them, but future versions of Rails may add more.
82
+ They can be ignored by:
83
+
84
+ ```ruby
85
+ check_models models, ignore_methods: magic_method
86
+ ...
87
+ check_controllers controllers, ignore_methods: %i[magic2 magic3]
88
+ ```
89
+
76
90
  ## Miscellaneous
77
91
 
78
92
  Copyright (c) 2022-2023 Dittmar Krall (www.matiq.com),
79
- released under the MIT license:
80
-
81
- * https://opensource.org/licenses/MIT
93
+ released under the [MIT license](https://opensource.org/licenses/MIT).
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mimoco
4
- VERSION = "0.3.2" # 2023-04-25
4
+ VERSION = "1.0.0" # 2023-12-06
5
+ # VERSION = "0.3.2" # 2023-04-25
5
6
  # VERSION = "0.3.1" # 2022-12-25
6
7
  # VERSION = "0.3.0" # 2022-02-11
7
8
  # VERSION = "0.2.0" # 2022-01-06
data/lib/mimoco.rb CHANGED
@@ -1,140 +1,20 @@
1
1
  require "minitest"
2
+ require "mimoco_base"
3
+ require "mimoco_valid"
4
+ require "mimoco_models"
5
+ require "mimoco_controllers"
2
6
 
3
7
  module Minitest
4
8
  module Checks
5
- def check_models(data)
6
- Models.run data, self
9
+ def check_models(data, ignore_methods: nil)
10
+ Models.run data, self, ignore_methods
7
11
  end
8
12
 
9
- def check_controllers(data)
10
- Controllers.run data, self
13
+ def check_controllers(data, ignore_methods: nil)
14
+ Controllers.run data, self, ignore_methods
11
15
  end
12
16
 
13
17
  class ValidMissingError < StandardError; end
14
-
15
- class Base
16
- attr_accessor :minitest, :klass, :klass_hash, :where
17
-
18
- def self.run(data, minitest)
19
- @minitest = minitest
20
- data.each do |klass, hash|
21
- @klass = klass
22
- @klass_hash = hash
23
- hash.each do |function, value|
24
- @where = "#{klass}##{function}"
25
- send(function, value)
26
- end
27
- end
28
- end
29
-
30
- def self.check_equal(expected, actual, msg = nil)
31
- expected = expected.sort.map(&:to_sym)
32
- actual = actual.sort.map(&:to_sym)
33
- msg = msg ? "#{@where}: #{msg}" : @where
34
- @minitest.assert_equal expected, actual, msg
35
- end
36
-
37
- def self.check_no_nil(actual, msg = nil)
38
- msg = msg ? "#{@where}: #{msg}" : @where
39
- @minitest.refute_nil actual, msg
40
- end
41
- end
42
-
43
- class Models < Base
44
- def self.valid(params)
45
- valids([params])
46
- end
47
-
48
- def self.valids(arr)
49
- arr.each { |params| one_valid(params) }
50
- end
51
-
52
- def self.invalid(params)
53
- invalids([params])
54
- end
55
-
56
- def self.invalids(arr)
57
- arr.each { |params| one_invalid(params) }
58
- end
59
-
60
- def self.class_methods(expected)
61
- cls = @klass.methods(false).sort
62
- cls.delete_if { |x| /^_/ =~ x }
63
- cls.delete_if { |x| /^(after|before|find_by)_/ =~ x }
64
- cls -= %i[column_headers attribute_type_decorations
65
- attributes_to_define_after_schema_loads
66
- default_scope_override defined_enums]
67
- check_equal expected, cls
68
- end
69
-
70
- # call class methods; don't check result
71
- def self.call_class_methods(methods)
72
- methods.each { |meth|
73
- check_no_nil @klass.send(meth), "<#{meth}> should return no nil"
74
- }
75
- end
76
-
77
- def self.public_methods(expected)
78
- cls = @klass.public_instance_methods(false).sort
79
- cls.delete_if { |x| /.*_associated_records_.*/ =~ x }
80
- # validate_associated_records_for_projects]
81
- check_equal expected, cls
82
- end
83
-
84
- # call_public_methods; don't check result
85
- def self.call_public_methods(methods)
86
- klass_params = @klass_hash[:valid] || @klass_hash[:valids]&.first
87
- raise ValidMissingError unless klass_params
88
-
89
- methods.each { |meth|
90
- row, _msg = @klass.create(klass_params)
91
- check_no_nil row.send(meth), "<#{meth}> should return no nil"
92
- }
93
- end
94
-
95
- def self.one_valid(params)
96
- row, msg = create_model(params)
97
- @minitest.assert row.valid?, "#{msg} #{row.errors.full_messages}"
98
- end
99
-
100
- def self.one_invalid(params)
101
- row, msg = create_model(params)
102
- @minitest.refute row.valid?, "#{msg} expected to be invalid"
103
- end
104
-
105
- def self.create_model(params)
106
- row = @klass.create(params)
107
- [row, "#{@klass}: #{params}"]
108
- end
109
- end
110
-
111
- class Controllers < Base
112
- def self.respond_to(methods)
113
- instance = @klass.new
114
- methods.each { |method|
115
- msg = "#{@klass} should respond to #{method}"
116
- @minitest.assert instance.respond_to?(method), msg
117
- }
118
- end
119
-
120
- def self.class_methods(expected)
121
- cls = @klass.methods(false).sort
122
- cls.delete_if { |x| /^_/ =~ x }
123
- cls -= %i[__callbacks helpers_path middleware_stack]
124
- check_equal expected, cls
125
- end
126
-
127
- def self.call_class_methods(methods)
128
- methods.each { |meth|
129
- check_no_nil @klass.send(meth), "<#{meth}> should return no nil"
130
- }
131
- end
132
-
133
- def self.public_methods(expected)
134
- cls = @klass.new.public_methods(false).sort
135
- check_equal expected, cls
136
- end
137
- end
138
18
  end
139
19
 
140
20
  class Test
@@ -0,0 +1,48 @@
1
+ require "minitest"
2
+
3
+ module Minitest
4
+ module Checks
5
+ class Base
6
+ attr_accessor :minitest, :klass, :klass_hash, :where
7
+
8
+ def self.run(data, minitest, ignore_methods)
9
+ @minitest = minitest
10
+ @ignore = [ignore_methods].flatten
11
+ data.each do |klass, hash|
12
+ @klass = klass
13
+ @klass_hash = hash
14
+ hash.each do |function, value|
15
+ @where = "#{klass}##{function}"
16
+ send(function, value)
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.check_equal(expected, actual, msg = nil)
22
+ expected = expected.sort.map(&:to_sym)
23
+ actual = actual.sort.map(&:to_sym)
24
+ msg = msg ? "#{@where}: #{msg}" : @where
25
+ @minitest.assert_equal expected, actual, msg
26
+ end
27
+
28
+ def self.check_no_nil(actual, msg = nil)
29
+ msg = msg ? "#{@where}: #{msg}" : @where
30
+ @minitest.refute_nil actual, msg
31
+ end
32
+
33
+ def self.delete_methods(which)
34
+ ignore2 = %i[attribute_aliases
35
+ attributes_to_define_after_schema_loads column_headers
36
+ default_scope_override]
37
+ # cls -= %i[__callbacks helpers_path middleware_stack]
38
+ # cls -= %i[attribute_type_decorations defined_enums]
39
+ methods = @klass.send(which, false).sort
40
+ methods.delete_if { |x| /^_/ =~ x }
41
+ methods.delete_if { |x| /^(after|before|find_by)_/ =~ x }
42
+ methods.delete_if { |x| /.*_associated_records_.*/ =~ x }
43
+ methods2 = @klass.superclass.send(which, false).sort
44
+ methods - methods2 - @ignore - ignore2
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ require "minitest"
2
+
3
+ module Minitest
4
+ module Checks
5
+ class Controllers < Base
6
+ def self.respond_to(methods)
7
+ instance = @klass.new
8
+ methods.each { |method|
9
+ msg = "#{@klass} should respond to #{method}"
10
+ @minitest.assert instance.respond_to?(method), msg
11
+ }
12
+ end
13
+
14
+ def self.class_methods(expected)
15
+ meths = delete_methods(:methods)
16
+ check_equal expected, meths
17
+ end
18
+
19
+ def self.call_class_methods(methods)
20
+ methods.each { |meth|
21
+ check_no_nil @klass.send(meth), "<#{meth}> should return no nil"
22
+ }
23
+ end
24
+
25
+ def self.public_methods(expected)
26
+ cls = @klass.new.public_methods(false).sort
27
+ check_equal expected, cls
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require "minitest"
2
+
3
+ module Minitest
4
+ module Checks
5
+ class Models < Base
6
+ def self.class_methods(expected)
7
+ meths = delete_methods(:methods)
8
+ check_equal expected, meths
9
+ end
10
+
11
+ # call class methods; don't check result
12
+ def self.call_class_methods(methods)
13
+ methods.each { |meth|
14
+ check_no_nil @klass.send(meth), "<#{meth}> should return no nil"
15
+ }
16
+ end
17
+
18
+ def self.public_methods(expected)
19
+ meths = delete_methods(:public_instance_methods)
20
+ check_equal expected, meths
21
+ end
22
+
23
+ # call_public_methods; don't check result
24
+ def self.call_public_methods(methods)
25
+ klass_params = @klass_hash[:valid] || @klass_hash[:valids]&.first
26
+ raise ValidMissingError unless klass_params
27
+
28
+ methods.each { |meth|
29
+ row, _msg = @klass.create(klass_params)
30
+ check_no_nil row.send(meth), "<#{meth}> should return no nil"
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ require "minitest"
2
+
3
+ module Minitest
4
+ module Checks
5
+ class Models < Base
6
+ def self.valid(params)
7
+ valids([params])
8
+ end
9
+
10
+ def self.valids(arr)
11
+ arr.each { |params| one_valid(params) }
12
+ end
13
+
14
+ def self.invalid(params)
15
+ invalids([params])
16
+ end
17
+
18
+ def self.invalids(arr)
19
+ arr.each { |params| one_invalid(params) }
20
+ end
21
+
22
+ def self.one_valid(params)
23
+ row, msg = create_model(params)
24
+ @minitest.assert row.valid?, "#{msg} #{row.errors.full_messages}"
25
+ end
26
+
27
+ def self.one_invalid(params)
28
+ row, msg = create_model(params)
29
+ @minitest.refute row.valid?, "#{msg} expected to be invalid"
30
+ end
31
+
32
+ def self.create_model(params)
33
+ row = @klass.create(params)
34
+ [row, "#{@klass}: #{params}"]
35
+ end
36
+ end
37
+ end
38
+ end
data/mimoco.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = "Some testing for models and controllers"
11
11
  s.authors = ["Dittmar Krall"]
12
12
  s.email = ["dittmar.krall@matiq.com"]
13
- s.homepage = "http://matiq.com"
13
+ s.homepage = "https://github.com/matique/mimoco"
14
14
  s.license = "MIT"
15
15
 
16
16
  s.metadata["source_code_uri"] = "https://github.com/matique/mimoco"
@@ -0,0 +1,34 @@
1
+ require "test_helper"
2
+ require "mimoco"
3
+
4
+ class ModelsIgnoreTest < Minitest::Test
5
+ def test_no_ignore_class_methods
6
+ models = {Order => {class_methods: %i[class_method]}}
7
+ check_models models
8
+ end
9
+
10
+ def test_ignore_class_methods
11
+ models = {Order => {class_methods: %i[]}}
12
+ check_models models, ignore_methods: :class_method
13
+ end
14
+
15
+ def test_no_ignore_public_methods
16
+ models = {Order => {public_methods: %i[public_method]}}
17
+ check_models models
18
+ end
19
+
20
+ def test_ignore_public_methods
21
+ models = {Order => {public_methods: %i[]}}
22
+ check_models models, ignore_methods: :public_method
23
+ end
24
+
25
+ def test_controllers_no_ignore_class_methods
26
+ controllers = {OrdersController => {class_methods: %i[class_method]}}
27
+ check_controllers controllers
28
+ end
29
+
30
+ def test_controllers_ignore_class_methods
31
+ controllers = {OrdersController => {class_methods: %i[]}}
32
+ check_controllers controllers, ignore_methods: :class_method
33
+ end
34
+ end
@@ -2,40 +2,6 @@ require "test_helper"
2
2
  require "mimoco"
3
3
 
4
4
  class ModelsTest < Minitest::Test
5
- def test_valid
6
- models = {Order => {valid: {name: "Name", qty: 123}}}
7
- check_models models
8
- end
9
-
10
- def test_valids
11
- models = {
12
- Order => {
13
- valids: [
14
- {name: "Name", qty: 123},
15
- {qty: 123}
16
- ]
17
- }
18
- }
19
- check_models models
20
- end
21
-
22
- def test_invalid
23
- models = {Order => {invalid: {qty: :abc}}}
24
- check_models models
25
- end
26
-
27
- def test_invalids
28
- models = {
29
- Order => {
30
- invalids: [
31
- {qty: :abc},
32
- {name: "Name", qty: :def}
33
- ]
34
- }
35
- }
36
- check_models models
37
- end
38
-
39
5
  def test_class_methods
40
6
  models = {Order => {class_methods: %i[class_method]}}
41
7
  check_models models
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+ require "mimoco"
3
+
4
+ class ModelsTest < Minitest::Test
5
+ def test_valid
6
+ models = {Order => {valid: {name: "Name", qty: 123}}}
7
+ check_models models
8
+ end
9
+
10
+ def test_valids
11
+ models = {
12
+ Order => {
13
+ valids: [
14
+ {name: "Name", qty: 123},
15
+ {qty: 123}
16
+ ]
17
+ }
18
+ }
19
+ check_models models
20
+ end
21
+
22
+ def test_invalid
23
+ models = {Order => {invalid: {qty: :abc}}}
24
+ check_models models
25
+ end
26
+
27
+ def test_invalids
28
+ models = {
29
+ Order => {
30
+ invalids: [
31
+ {qty: :abc},
32
+ {name: "Name", qty: :def}
33
+ ]
34
+ }
35
+ }
36
+ check_models models
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mimoco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-25 00:00:00.000000000 Z
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: combustion
@@ -69,6 +69,10 @@ files:
69
69
  - Rakefile
70
70
  - lib/mimoco.rb
71
71
  - lib/mimoco/version.rb
72
+ - lib/mimoco_base.rb
73
+ - lib/mimoco_controllers.rb
74
+ - lib/mimoco_models.rb
75
+ - lib/mimoco_valid.rb
72
76
  - mimoco.gemspec
73
77
  - test/controllers/controllers_test.rb
74
78
  - test/controllers/orders_controller_test.rb
@@ -89,9 +93,11 @@ files:
89
93
  - test/internal/config/routes.rb
90
94
  - test/internal/db/migrate/20141016161801_create_orders.rb
91
95
  - test/internal/db/schema.rb
96
+ - test/models/models_ignore_test.rb
92
97
  - test/models/models_test.rb
98
+ - test/models/models_valid_test.rb
93
99
  - test/test_helper.rb
94
- homepage: http://matiq.com
100
+ homepage: https://github.com/matique/mimoco
95
101
  licenses:
96
102
  - MIT
97
103
  metadata:
@@ -111,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
117
  - !ruby/object:Gem::Version
112
118
  version: '0'
113
119
  requirements: []
114
- rubygems_version: 3.4.10
120
+ rubygems_version: 3.4.20
115
121
  signing_key:
116
122
  specification_version: 4
117
123
  summary: 'Mimoco: some minitests for models and controllers'