assert-moar 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79dfc2889a6758823ab5f567e81a75fb0c5a91ed
4
- data.tar.gz: 8908c3a207234970736e5a95431d8fe3c98f1ef1
3
+ metadata.gz: f530f1dad82d4ffe2b1c1cdee8a186f3b0ba1eb9
4
+ data.tar.gz: 6a65ac645a2ba0b6eeb0ca449162b883e243f868
5
5
  SHA512:
6
- metadata.gz: 9026d5f8b99b17e934a0dac3055b1524731c95d94e66b4c1e79f49939da49988c4222cb523be4939c14aa53d3968e61a7b335d0e08088aeeeab93903d65a9137
7
- data.tar.gz: 49244e50dd6cafdc56359b9bb6e554717ad69cdedd101e8eebcaa029b1b3eb884bd746d1d84e89db8f4f642165b84f86cf3a9c0a82288b2022eb26c275ed92d5
6
+ metadata.gz: 07218e00c8a3309559af3a17a8e4d2ae3627ce18d8422e0c2de3c37e542b3ed406220271c8a547906c8d23128c295948fc5c11fe2dd758c88c2d01a7db138d43
7
+ data.tar.gz: 8923bbad1292e0a4fd13a7ef6d890c62e38058c34cf66566074bde833827126c9652c69fbfd9831604a29dc6cfbfb45b3f0fa06034618ae0d20309c010a4aa08
data/README.md CHANGED
@@ -33,6 +33,8 @@ Available methods:
33
33
  #refute_validates_presence_of
34
34
  #assert_validates_uniqueness_of
35
35
  #refute_validates_uniqueness_of
36
+ #assert_validates_with_callback
37
+ #refute_validates_with_callback
36
38
  ```
37
39
 
38
40
  ## Contributing
@@ -39,6 +39,16 @@ module AssertMoar::Assertions
39
39
  "#{object} validates the acceptance of #{property}"
40
40
  end
41
41
 
42
+ def assert_validates_with_callback(object, callback)
43
+ assert has_callback_validator?(object, callback),
44
+ "#{object} does not validate with #{callback}"
45
+ end
46
+
47
+ def refute_validates_with_callback(object, callback)
48
+ refute has_callback_validator?(object, callback),
49
+ "#{object} does not validate with #{callback}"
50
+ end
51
+
42
52
  def assert_valid(object)
43
53
  assert object.valid?, "Expected object to be valid"
44
54
  end
@@ -55,4 +65,10 @@ module AssertMoar::Assertions
55
65
 
56
66
  validators.any? { |v| v.is_a?(validator_class) }
57
67
  end
68
+
69
+ def has_callback_validator?(object_or_class, callback)
70
+ klass = object_or_class.class
71
+
72
+ klass._validate_callbacks.any? { |v| v.filter == callback }
73
+ end
58
74
  end
@@ -1,3 +1,3 @@
1
1
  module AssertMoar
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -63,6 +63,20 @@ class AssertMoar::AssertionTest < Minitest::Test
63
63
  @tc.refute_validates_acceptance_of(double, :property)
64
64
  end
65
65
 
66
+ def test_assert_validates_with_callback
67
+ validator = ::ActiveSupport::Callbacks::Callback.new(:callback)
68
+ double = ActiveRecordDouble.new(error_map: { callback: validator })
69
+
70
+ @tc.assert_validates_with_callback(double, :callback)
71
+ end
72
+
73
+ def test_refute_validates_with_callback
74
+ validator = ::ActiveSupport::Callbacks::Callback.new(:callback)
75
+ double = ActiveRecordDouble.new()
76
+
77
+ @tc.refute_validates_with_callback(double, :callback)
78
+ end
79
+
66
80
  def teardown
67
81
  assert_equal(@assertion_count, @tc.assertions,
68
82
  "expected #{@assertion_count} assertions to be fired during the test, not #{@tc.assertions}") if @tc.passed?
@@ -0,0 +1,11 @@
1
+ module ActiveSupport
2
+ module Callbacks
3
+ class Callback
4
+ attr_accessor :filter
5
+
6
+ def initialize(filter)
7
+ @filter = filter
8
+ end
9
+ end
10
+ end
11
+ end
data/test/test_helper.rb CHANGED
@@ -10,6 +10,7 @@ require 'mocha/mini_test'
10
10
  require_relative '../lib/assert_moar'
11
11
  require_relative 'support/active_model/validations'
12
12
  require_relative 'support/active_record/validations'
13
+ require_relative 'support/active_support/callbacks'
13
14
 
14
15
  class ActiveRecordDouble
15
16
  attr_accessor :valid, :error_map
@@ -18,6 +19,10 @@ class ActiveRecordDouble
18
19
  @@error_map.inject({}) { |hash, (k, v)| hash.merge(k => Array(v.new)) }
19
20
  end
20
21
 
22
+ def self._validate_callbacks
23
+ Array(@@error_map[:callback])
24
+ end
25
+
21
26
  def initialize(valid: false, error_map: {})
22
27
  @valid = valid
23
28
  @@error_map = error_map.to_h
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert-moar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bohn
@@ -200,6 +200,7 @@ files:
200
200
  - test/lib/assert_moar/version_test.rb
201
201
  - test/support/active_model/validations.rb
202
202
  - test/support/active_record/validations.rb
203
+ - test/support/active_support/callbacks.rb
203
204
  - test/test_helper.rb
204
205
  homepage: https://github.com/jjbohn/assert-moar
205
206
  licenses:
@@ -230,4 +231,5 @@ test_files:
230
231
  - test/lib/assert_moar/version_test.rb
231
232
  - test/support/active_model/validations.rb
232
233
  - test/support/active_record/validations.rb
234
+ - test/support/active_support/callbacks.rb
233
235
  - test/test_helper.rb