unidom-common-rspec 0.6.2 → 0.7

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: a24751bce0e821610da99c8c6a045fd9dc3090be
4
- data.tar.gz: 6a51b465d327824e09fca1bf74339e86293f7fe5
3
+ metadata.gz: 904a67634287dbac121b5b35d210f433ae536d91
4
+ data.tar.gz: c6060dde237712fffd523537e010b589bc28c513
5
5
  SHA512:
6
- metadata.gz: c2c96579a57600c9de43e4c9bad7e3881977d4d980008b7662d45d5d103150133a38356bef9754ef1f263d4703e63bc6e5a428ecb09d33804a17d0d49283fab3
7
- data.tar.gz: 785a786a4f58a1ec03a6cec9e73958d81c4f899f3f3c3502aff6ede535f5c7f9db12f357b0f181a0b0e8c3a0dcb7e5d2fda74502f41dec5726c6df3f6a540c5d
6
+ metadata.gz: 1c8abef5dec7fa64af1b5585cea81935e7495438a3e42f7e595b68536c9d55e9c78d68d01b81c28df814ce875ae2255f7a49309c37324979bb55cadcae778f92
7
+ data.tar.gz: 17a555307a90a719361d8808d8e84a9b4aad5d4edb633ac716a6cd3443a3d56233fcf5cdcc63a65a23497b251e2d42c8cb788bc3d92d45c57976c91693328dc9
data/CHANGELOG.md CHANGED
@@ -26,3 +26,6 @@
26
26
 
27
27
  ## v0.6.2
28
28
  1. Improve the Has Many shared examples for the #collection.build method, the #collection.create method, & the #collection.create! method
29
+
30
+ ## v0.7
31
+ 1. Each Validator shared examples
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unidom-common-rspec (0.6.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (5.0.1)
10
+ actionview (= 5.0.1)
11
+ activesupport (= 5.0.1)
12
+ rack (~> 2.0)
13
+ rack-test (~> 0.6.3)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
16
+ actionview (5.0.1)
17
+ activesupport (= 5.0.1)
18
+ builder (~> 3.1)
19
+ erubis (~> 2.7.0)
20
+ rails-dom-testing (~> 2.0)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
+ activesupport (5.0.1)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (~> 0.7)
25
+ minitest (~> 5.1)
26
+ tzinfo (~> 1.1)
27
+ builder (3.2.2)
28
+ concurrent-ruby (1.0.3)
29
+ diff-lcs (1.2.5)
30
+ erubis (2.7.0)
31
+ i18n (0.7.0)
32
+ loofah (2.0.3)
33
+ nokogiri (>= 1.5.9)
34
+ method_source (0.8.2)
35
+ mini_portile2 (2.1.0)
36
+ minitest (5.10.1)
37
+ nokogiri (1.6.8.1)
38
+ mini_portile2 (~> 2.1.0)
39
+ rack (2.0.1)
40
+ rack-test (0.6.3)
41
+ rack (>= 1.0)
42
+ rails-dom-testing (2.0.1)
43
+ activesupport (>= 4.2.0, < 6.0)
44
+ nokogiri (~> 1.6.0)
45
+ rails-html-sanitizer (1.0.3)
46
+ loofah (~> 2.0)
47
+ railties (5.0.1)
48
+ actionpack (= 5.0.1)
49
+ activesupport (= 5.0.1)
50
+ method_source
51
+ rake (>= 0.8.7)
52
+ thor (>= 0.18.1, < 2.0)
53
+ rake (10.5.0)
54
+ rspec (3.5.0)
55
+ rspec-core (~> 3.5.0)
56
+ rspec-expectations (~> 3.5.0)
57
+ rspec-mocks (~> 3.5.0)
58
+ rspec-core (3.5.4)
59
+ rspec-support (~> 3.5.0)
60
+ rspec-expectations (3.5.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.5.0)
63
+ rspec-mocks (3.5.0)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.5.0)
66
+ rspec-rails (3.5.2)
67
+ actionpack (>= 3.0)
68
+ activesupport (>= 3.0)
69
+ railties (>= 3.0)
70
+ rspec-core (~> 3.5.0)
71
+ rspec-expectations (~> 3.5.0)
72
+ rspec-mocks (~> 3.5.0)
73
+ rspec-support (~> 3.5.0)
74
+ rspec-support (3.5.0)
75
+ thor (0.19.4)
76
+ thread_safe (0.3.5)
77
+ tzinfo (1.2.2)
78
+ thread_safe (~> 0.1)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ bundler (~> 1.12)
85
+ rake (~> 10.0)
86
+ rspec (~> 3.0)
87
+ rspec-rails (~> 3.5)
88
+ unidom-common-rspec!
89
+
90
+ BUNDLED WITH
91
+ 1.12.5
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Unidom Common RSpec Unidom Common RSpec 库
2
2
 
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/unidom-common-rspec/frames)
3
4
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
5
+
4
6
  [![Gem Version](https://badge.fury.io/rb/unidom-common-rspec.svg)](https://badge.fury.io/rb/unidom-common-rspec)
5
7
  [![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-common-rspec.svg)](https://gemnasium.com/github.com/topbitdu/unidom-common-rspec)
6
8
 
@@ -35,7 +37,7 @@ Or install it yourself as:
35
37
 
36
38
  ## Usage
37
39
 
38
- Assume we have the Person model, the Pet model, & the Identity Card model as the following:
40
+ Assume we have the Person model, the Pet model, the Identity Card model, & the Identification Number validator as the following:
39
41
  ```ruby
40
42
  # person.rb
41
43
  class Person < ApplicationRecord
@@ -61,8 +63,28 @@ class IdentityCard < ApplicationRecord
61
63
 
62
64
  include Unidom::Common::Concerns::ModelExtension
63
65
 
66
+ validates :identification_number, presence: true, identification_number: true
67
+
64
68
  belongs_to :person
65
69
 
70
+ end
71
+
72
+ # identification_number_validator.rb
73
+ class IdentificationNumberValidator < ActiveModel::EachValidator
74
+
75
+ WEIGHTS = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ].freeze
76
+ CHECK_DIGITS = %w{1 0 X 9 8 7 6 5 4 3 2}.freeze
77
+
78
+ def validate_each(record, attribute, value)
79
+
80
+ value = value.to_s
81
+ sum = 0
82
+ value[0..16].chars.each_with_index do |char, index| sum += char.to_i*WEIGHTS[index] end
83
+
84
+ record.errors[attribute] << (options[:message]||'is invalid') unless CHECK_DIGITS[sum%11]==value[17]
85
+
86
+ end
87
+
66
88
  end
67
89
  ```
68
90
 
@@ -231,6 +253,33 @@ end
231
253
  ```
232
254
 
233
255
 
256
+ ### Each Validator shared examples Each Validator 共享用例
257
+
258
+ The ``identification_number_validator_spec.rb`` looks like the following:
259
+ ```ruby
260
+ RSpec.describe IdentificationNumberValidator, type: :validator do
261
+
262
+ valid_values = %w{
263
+ 231024198506186916
264
+ 231024198506188110
265
+ 231024198506185470
266
+ 231024198506182851
267
+ 231024198506187193
268
+ }
269
+ invalid_values = %w{
270
+ 231024198506186917
271
+ 231024198506188111
272
+ 231024198506185471
273
+ 231024198506182852
274
+ 231024198506187194
275
+ }
276
+
277
+ it_behaves_like 'ActiveModel::EachValidator', valid_values, invalid_values
278
+
279
+ end
280
+ ```
281
+
282
+
234
283
 
235
284
  ## Development
236
285
 
@@ -0,0 +1,36 @@
1
+ shared_examples 'ActiveModel::EachValidator' do |valid_values, invalid_values|
2
+
3
+ mock_model_class_name = "#{described_class.name}MockModel"
4
+ mock_model_namespace = mock_model_class_name.deconstantize.constantize
5
+ mock_model_name = mock_model_class_name.demodulize
6
+ validator_name = described_class.to_s.underscore.chomp('_validator').to_sym
7
+ mock_model_namespace.const_set mock_model_name, Class.new
8
+ class_instance = mock_model_namespace.const_get mock_model_name
9
+
10
+ class_instance.class_eval do
11
+ include ActiveModel::Model
12
+ attr_accessor :mock_attribute
13
+ validates :mock_attribute, :allow_blank => true, validator_name => true
14
+ end
15
+
16
+ subject(:model) do class_instance.new end
17
+
18
+ describe '#validate_each' do
19
+
20
+ valid_values.each do |value|
21
+ it "should validate valid #{value}" do
22
+ model.mock_attribute = value
23
+ expect(model.valid?).to be_truthy
24
+ end
25
+ end
26
+
27
+ invalid_values.each do |value|
28
+ it "should validate invalid #{value}" do
29
+ model.mock_attribute = value
30
+ expect(model.valid?).to be_falsey
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Common
3
3
  module RSpec
4
- VERSION = '0.6.2'
4
+ VERSION = '0.7'
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,7 @@
1
1
  require "unidom/common/rspec/version"
2
2
 
3
+ require 'unidom/common/rspec/each_validator_shared_examples'
4
+
3
5
  require 'unidom/common/rspec/scope_shared_examples'
4
6
  require 'unidom/common/rspec/validates_shared_examples'
5
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-common-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails
@@ -80,6 +80,7 @@ files:
80
80
  - CHANGELOG.md
81
81
  - CODE_OF_CONDUCT.md
82
82
  - Gemfile
83
+ - Gemfile.lock
83
84
  - LICENSE.txt
84
85
  - README.md
85
86
  - ROADMAP.md
@@ -88,6 +89,7 @@ files:
88
89
  - bin/setup
89
90
  - lib/unidom/common/rspec.rb
90
91
  - lib/unidom/common/rspec/belongs_to_shared_examples.rb
92
+ - lib/unidom/common/rspec/each_validator_shared_examples.rb
91
93
  - lib/unidom/common/rspec/has_many_shared_examples.rb
92
94
  - lib/unidom/common/rspec/has_one_shared_examples.rb
93
95
  - lib/unidom/common/rspec/model_extension_shared_examples.rb