ar_left_over_guardian 0.0.3 → 0.1.0

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: 3d751711240250e9e26a880c0df29a57011ee837
4
- data.tar.gz: 909e6714aab80a46565b4d840f49371956f489b4
3
+ metadata.gz: 7bd41421d24e0733bc844c0f22c975c3844041b4
4
+ data.tar.gz: 7fe50c1c7b834dc750e3097ea1c544f17db27648
5
5
  SHA512:
6
- metadata.gz: 17490e66bf5ac59a56eee3c3cbcfc34d055f815b352dda9e930d5372dd8b685db72253063d67a51afe7d189db139a177c5832c543715c5f79a3173d4dfd30202
7
- data.tar.gz: 39948e4e1ba8daf578baac0dbedb3d1c76b4a81e0128db79793a80654aad8b3052897f8539665f09518b721bccfe0b46a33d3d447e70d34dce37e2e99c08f3e8
6
+ metadata.gz: a7113abaf02efa91c53f2d42548819ffc3d24a1a60fbbc3b4c232a1b23fac30b72a6d8f88c46f766fb0e537b63c1480527af317714f27d8f069c6bccb573ba81
7
+ data.tar.gz: 3124b5c9fd0839350d7ed3fae2af65697d35a15422cc4628c8d5a17932d9f832d1e46791ceadff1ac7a8c1f75ce741ac5167b2527b735294afee01d5af56b752
data/Gemfile CHANGED
@@ -4,3 +4,9 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "rspec"
7
+
8
+ group :development do
9
+ gem "contracts", github: "egonSchiele/contracts.ruby"
10
+ gem "yard"
11
+ gem "yard-contracts", github: "sfcgeorge/yard-contracts"
12
+ end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "contracts-noop"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.7"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  end
@@ -1,18 +1,31 @@
1
1
  require "ar_left_over_guardian/version"
2
+ require "ar_left_over_guardian/custom_contracts"
2
3
 
4
+ # Fails your test suite if tests doesn't clean up any database records
5
+ # after itself. Assumes models have `.count` method.
3
6
  module ARLeftOverGuardian
4
- def self.init(models)
5
- Instance.new(models)
6
- end
7
+ include Contracts
8
+ include CustomContracts
7
9
 
8
10
  class DidntCleanup < StandardError; end
9
11
 
12
+ # Instance of left over guardian, which keeps track of all models
13
+ # counts before test and after test, and expects them to be the same
10
14
  class Instance
15
+ include Contracts
16
+ include CustomContracts
17
+
18
+ # Creates new instance
19
+ Contract ArrayOf[Model] => self
11
20
  def initialize(models)
12
21
  @models = models.reject(&method(:abstract?))
13
22
  @counts = current_counts(false)
23
+ self
14
24
  end
15
25
 
26
+ # Verifies if counts before test and after are the same.
27
+ # @raise [DidntCleanup] When counts don't match
28
+ Contract None => nil
16
29
  def verify
17
30
  left_overs = get_left_overs
18
31
  return if left_overs.empty?
@@ -24,6 +37,7 @@ module ARLeftOverGuardian
24
37
 
25
38
  attr_reader :counts, :models
26
39
 
40
+ Contract None => ArrayOf[Model]
27
41
  def get_left_overs
28
42
  current_counts.each_with_index.inject([]) do |acc, (count, index)|
29
43
  if count != counts[index]
@@ -33,20 +47,30 @@ module ARLeftOverGuardian
33
47
  end
34
48
  end
35
49
 
50
+ Contract Bool => ArrayOf[Num]
36
51
  def current_counts(reset = true)
37
52
  models.map { |model|
38
53
  reset_model(model, reset).count
39
54
  }
40
55
  end
41
56
 
57
+ Contract Model => Bool
42
58
  def abstract?(model)
43
59
  model.respond_to?(:abstract_class?) && model.abstract_class?
44
60
  end
45
61
 
62
+ Contract Model, Bool => Model
46
63
  def reset_model(model, reset)
47
64
  return model unless reset
48
65
  RSpec::Mocks.space.proxy_for(model).reset if defined?(RSpec::Mocks)
49
66
  model
50
67
  end
51
68
  end
69
+
70
+ # Initializes instance of left over guardian with given list of
71
+ # models
72
+ Contract ArrayOf[Model] => Instance
73
+ def self.init(models)
74
+ Instance.new(models)
75
+ end
52
76
  end
@@ -0,0 +1,13 @@
1
+ require "contracts/noop"
2
+
3
+ Contracts::Noop.when_contracts_available do
4
+ puts "Running with contracts in development mode"
5
+ end
6
+
7
+ module ARLeftOverGuardian
8
+ module CustomContracts
9
+ include Contracts
10
+
11
+ Model = RespondTo[:count]
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module ARLeftOverGuardian
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_left_over_guardian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Fedorov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: contracts-noop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -55,6 +69,7 @@ files:
55
69
  - Rakefile
56
70
  - ar_left_over_guardian.gemspec
57
71
  - lib/ar_left_over_guardian.rb
72
+ - lib/ar_left_over_guardian/custom_contracts.rb
58
73
  - lib/ar_left_over_guardian/version.rb
59
74
  - spec/ar_left_over_guardian_spec.rb
60
75
  - spec/spec_helper.rb
@@ -85,3 +100,4 @@ summary: Active Record Left Over Guardian.
85
100
  test_files:
86
101
  - spec/ar_left_over_guardian_spec.rb
87
102
  - spec/spec_helper.rb
103
+ has_rdoc: