coupon_code 0.0.1 → 0.0.2

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: 135fb183f47db7cf01f192063d01aa2b215da141
4
- data.tar.gz: 336135ed4bb5531220cb533fc2081c24f1815268
3
+ metadata.gz: 66c35baf6d4c13f6943b85c3558e9a22c830b400
4
+ data.tar.gz: b983fe59c933ede4c5351fd9875b66365ed2f471
5
5
  SHA512:
6
- metadata.gz: 4654f9a3b3b68f39509b038e5c877ca30e03c3c37fe2f38c56585c46254b725c0259ff62e2457010b4a82ad2e1d62fefe9a1358a688d29ab67d11b493fa0d036
7
- data.tar.gz: bb8f29e3932e5e2c2f97cab42e4af463bda8fd4382e2d5bf996d905185cc60eb6b445dcac3fa3cf79b0995cdcfc6f757109c19c1088f733103e967cc3c8d9aee
6
+ metadata.gz: b85ea82fc307464cd877a2fc7cc1c856576765a81bb090b8c0bcf94bd8e97685978b3779f46c393b6b199881af4b9b75b9857b95c65019d3bc5c70cc0fb61d3b
7
+ data.tar.gz: 55fa61617a7b1d012ab6a86704c79d82d2f9a3b143ba0f7b4d7e5787e52ef8fd88e428d1bc203353628a89e03f673077ca666d968a7377724ec9f53a1e87f405
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop.yml
@@ -0,0 +1,5 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ Style/FileName:
5
+ Exclude: ['bin/coupon-code']
@@ -5,6 +5,8 @@ rvm:
5
5
  - 2.0.0
6
6
  - 2.1.1
7
7
  script: 'bundle exec rake'
8
+ before_install:
9
+ - gem update bundler
8
10
  addons:
9
11
  code_climate:
10
12
  repo_token: 8a7079440da500bd46bff928386a4a512cf5a3c314b4882a2ce7e6fe160b4f45
@@ -0,0 +1,7 @@
1
+ ## CHANGELOG
2
+
3
+ ### 0.0.1
4
+ - Implement CouponCode.generate(parts: n)/validate().
5
+
6
+ ### 0.0.2
7
+ - Bug fix `.validate` can't handle invalid characters and produces an error. (mrclmrvn)
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in coupon_code.gemspec
4
4
  gemspec
5
5
 
6
- gem 'codeclimate-test-reporter', group: :test, require: nil
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
@@ -1,10 +1,19 @@
1
1
  # CouponCode
2
2
 
3
- 루비 젬(Ruby Gem)은 쿠폰 코드를 만들고 검증하는 기능을 제공합니다.
3
+ [CouponCode 루비 젬][rubygems](Ruby Gem)은 전자상거래 서비스 등에서 사용하기 적합한 쿠폰 코드를 만들고 검증하는 기능을 제공합니다.
4
4
 
5
- 이 젬(Gem)은 [Grant][grant]가 작성한 [Algorithm::CouponCode][couponcode]를 루비(Ruby) 언어로 옮겨 구현한 것입니다.
6
- 하지만 현 시점에는 원작이 가진 기능 중 기본적인 코드 생성/검증 기능만 구현되어 있다는 점을 주지해 주십시오. 평문을 입력해 코드를 생성하는 기능이나
7
- 자동교정, jQuery 플러그인 등은 포함되어있지 않습니다.
5
+ 이 젬(Gem)은 [Grant][grant]가 펄(Perl) 언어로 작성한 [Algorithm::CouponCode][couponcode]를 루비(Ruby) 언어로 옮겨 구현한 것입니다.
6
+
7
+ 젬의 기본 설정으로 생성되는 코드는 XXXX-XXXX-XXXX 형식이며 각 3부분은 4자의 숫자와 알파벳으로 구성됩니다. 원저자가 밝힌 쿠폰코드의 특징은 다음과 같습니다.
8
+
9
+ - 만들어진 코드는 대/소문자를 구분하지 않습니다.
10
+ - 숫자와 알파벳 중 헷갈릴 수 있는 글자를 사용하지 않기 때문에 사용자가 알파벳 O를 입력하면 이것을 숫자 0으로 자동 교정할 수 있습니다. (비슷하게 I는 1, S는 5, Z는 2)
11
+ - 각 부분의 4번째 글자는 검증코드(check-digit)이기 때문에 사용자가 실수로 코드를 잘못 입력했는지 여부를 클라이언트단에서 미리 검증할 수 있습니다.
12
+ - 검증코드 알고리즘은 각 부분의 순서와 연관됩니다. 따라서 '1K7Q'라는 코드는 코드의 첫 번째 부분으로는 유효하지만 코드의 두 번째에 위치하면 유효하지 않게 됩니다.
13
+ - 코트 생성 알고리즘은 원치않는 코드를 제외시킬 수 있습니다. For example any code in which transposed characters happen to result in a valid checkdigit will be skipped. 생성된 부분이 적절하지 않은 4글자 단어(예를 들어 'P00P')에 해당하면 역시 최종 코드에서 제외됩니다.
14
+
15
+ 하지만 현 시점에는 펄 버전이 가진 세심하고 다양한 기능이 모두 구현되어 있지 않다는 점을 기억해 주십시오.
16
+ 평문을 입력해 코드를 생성하는 기능이나 자동교정, 금칙어 설정, 그리고 클라이언트 상에서의 코드 검증을 위한 jQuery 플러그인은 포함되어있지 않습니다.
8
17
 
9
18
  이 루비 젬은 [https://stripes.co.kr](https://stripes.co.kr)를 위해 개발됐습니다.
10
19
 
@@ -32,6 +41,15 @@
32
41
  >> CouponCode.validate('1K7Q-CTFM-LMTO') # Invalid code
33
42
  => nil
34
43
 
44
+ ## 옵션
45
+
46
+ 쿠폰 코드를 만들 때 아래와 같이 옵션값을 넣어, 기본 설정인 3부분이 아닌 쿠폰 코드를 얻을 수 있습니다.
47
+
48
+ >> CouponCode.generate(parts: 4)
49
+ => "1K7Q-CTFM-LMTC-DLGP"
50
+ >> CouponCode.validate("1K7Q-CTFM-LMTC-DLGP", 4)
51
+ => "1K7Q-CTFM-LMTC-DLGP"
52
+
35
53
  ## 테스팅
36
54
 
37
55
  ```ruby
@@ -58,4 +76,5 @@ MIT. 자세한 내용은 [LICENSE][license]를 읽어주십시오.
58
76
  [couponcode]: https://github.com/grantm/Algorithm-CouponCode
59
77
  [chilts]: https://github.com/chilts
60
78
  [node-couponcode]: https://github.com/chilts/node-coupon-code
61
- [license]: https://raw.github.com/appsattic/node-coupon-code/master/LICENSE
79
+ [license]: https://github.com/baxang/coupon-code/blob/master/LICENSE.txt
80
+ [rubygems]: https://rubygems.org/gems/coupon_code
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
1
  [![Build Status](https://travis-ci.org/baxang/coupon-code.svg)](https://travis-ci.org/baxang/coupon-code)
2
2
  [![Code Climate](https://codeclimate.com/github/baxang/coupon-code/badges/gpa.svg)](https://codeclimate.com/github/baxang/coupon-code)
3
+ [![Test Coverage](https://codeclimate.com/github/baxang/coupon-code/badges/coverage.svg)](https://codeclimate.com/github/baxang/coupon-code/coverage)
4
+ [![Gem Version](https://badge.fury.io/rb/coupon_code.svg)](http://badge.fury.io/rb/coupon_code)
3
5
 
4
6
  # CouponCode
5
7
 
6
- CouponCode gem generates and validates coupon codes.
8
+ [README-한국어][README-kr]
7
9
 
8
- It is a Ruby implementation of [Grant][grant]'s [Algorithm::CouponCode][couponcode],
9
- but please note that only basic generation/validation functionality implemented at the moment and
10
- some of the features the CPAN module provides such as feeding a plaintext, auto-correct, and jQuery plugin are
11
- not yet implemented.
10
+ [CouponCode gem][rubygems] generates and validates coupon codes that are suitable for e-commerce services and businesses.
11
+
12
+ It is a Ruby implementation of [Grant][grant]'s [Algorithm::CouponCode][couponcode]. Please read [the original documentation of Algorithm::CouponCode](http://search.cpan.org/dist/Algorithm-CouponCode/lib/Algorithm/CouponCode.pm) for more details.
13
+
14
+ Please be aware that some of the original CPAN module's features are not implemented yet. For example, generating codes by plaintext, auto correction, and jQuery plugin are missing in this gem.
12
15
 
13
16
  This gem is developed for https://stripes.co.kr
14
17
 
@@ -36,6 +39,15 @@ Or install it yourself as:
36
39
  >> CouponCode.validate('1K7Q-CTFM-LMTO') # Invalid code
37
40
  => nil
38
41
 
42
+ ## Options
43
+
44
+ You can change the number of parts of the generated code by passing an option hash value like:
45
+
46
+ >> CouponCode.generate(parts: 4)
47
+ => "1K7Q-CTFM-LMTC-DLGP"
48
+ >> CouponCode.validate("1K7Q-CTFM-LMTC-DLGP", 4)
49
+ => "1K7Q-CTFM-LMTC-DLGP"
50
+
39
51
  ## Testing
40
52
 
41
53
  ```ruby
@@ -63,4 +75,6 @@ MIT. See [LICENSE][license] for more details.
63
75
  [couponcode]: https://github.com/grantm/Algorithm-CouponCode
64
76
  [chilts]: https://github.com/chilts
65
77
  [node-couponcode]: https://github.com/chilts/node-coupon-code
66
- [license]: https://raw.github.com/appsattic/node-coupon-code/master/LICENSE
78
+ [license]: https://github.com/baxang/coupon-code/blob/master/LICENSE.txt
79
+ [README-kr]: https://github.com/baxang/coupon-code/blob/master/README-ko.md
80
+ [rubygems]: https://rubygems.org/gems/coupon_code
data/Rakefile CHANGED
@@ -1,13 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require 'rake/testtask'
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- t.pattern = "test/*_test.rb"
7
- end
4
+ RSpec::Core::RakeTask.new(:spec)
8
5
 
9
- task :default => :test
6
+ task default: :spec
10
7
 
11
8
  task :console do
12
- exec "irb -r coupon_code -I ./lib"
13
- end
9
+ exec 'irb -r coupon_code -I ./lib'
10
+ end
@@ -3,4 +3,4 @@
3
3
  require 'coupon_code'
4
4
 
5
5
  code = CouponCode.generate
6
- puts code
6
+ puts code
@@ -8,8 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = CouponCode::VERSION
9
9
  spec.authors = ['Sanghyun Park']
10
10
  spec.email = ['sh@baxang.com']
11
- spec.summary = %q{Generate and validate coupon codes.}
12
- spec.description = %q{A Ruby implementation of Perl's Algorithm::CouponCode CPAN module.}
11
+ spec.summary = 'Generate and validate coupon codes.'
12
+ spec.description = 'A Ruby implementation of Perl\'s' \
13
+ ' Algorithm::CouponCode CPAN module.'
13
14
  spec.homepage = 'https://github.com/baxang/coupon-code'
14
15
  spec.license = 'MIT'
15
16
 
@@ -18,7 +19,9 @@ Gem::Specification.new do |spec|
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency 'bundler', '~> 1.7'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
- spec.add_development_dependency 'minitest', '~> 5.5'
22
+ spec.required_ruby_version = '>= 1.9.3'
23
+
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '~> 3.4'
24
27
  end
@@ -1,4 +1,4 @@
1
- require "coupon_code/version"
1
+ require 'coupon_code/version'
2
2
  require 'securerandom'
3
3
  require 'digest/sha1'
4
4
 
@@ -9,13 +9,10 @@ module CouponCode
9
9
 
10
10
  def self.generate(options = { parts: PARTS })
11
11
  num_parts = options.delete(:parts)
12
-
13
12
  parts = []
14
13
  (1..num_parts).each do |i|
15
14
  part = ''
16
- (1...LENGTH).each do |j|
17
- part << randome_symbol
18
- end
15
+ (1...LENGTH).each { part << random_symbol }
19
16
  part << checkdigit_alg_1(part, i)
20
17
  parts << part
21
18
  end
@@ -24,8 +21,8 @@ module CouponCode
24
21
 
25
22
  def self.validate(orig, num_parts = PARTS)
26
23
  code = orig.upcase
27
- code.gsub!(/[^0-9A-Z]+/, '')
28
- parts = code.scan(/[0-9A-Z]{#{LENGTH}}/)
24
+ code.gsub!(/[^#{SYMBOL}]+/, '')
25
+ parts = code.scan(/[#{SYMBOL}]{#{LENGTH}}/)
29
26
  return if parts.length != num_parts
30
27
  parts.each_with_index do |part, i|
31
28
  data = part[0...(LENGTH - 1)]
@@ -36,15 +33,14 @@ module CouponCode
36
33
  end
37
34
 
38
35
  def self.checkdigit_alg_1(orig, check)
39
-
40
- orig.split('').each_with_index do |c, i|
36
+ orig.split('').each_with_index do |c, _|
41
37
  k = SYMBOL.index(c)
42
38
  check = check * 19 + k
43
39
  end
44
- SYMBOL[ check % 31 ]
40
+ SYMBOL[check % 31]
45
41
  end
46
42
 
47
- def self.randome_symbol
48
- SYMBOL[ rand(SYMBOL.length) ]
43
+ def self.random_symbol
44
+ SYMBOL[rand(SYMBOL.length)]
49
45
  end
50
46
  end
@@ -1,3 +1,3 @@
1
1
  module CouponCode
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'.freeze
3
3
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CouponCode do
4
+
5
+ describe '.generate' do
6
+ subject { described_class.generate }
7
+ it { is_expected.not_to be_nil }
8
+ it { is_expected.to match(/^[0-9A-Z-]+$/) }
9
+ it { is_expected.to match(/^\w{4}-\w{4}-\w{4}$/) }
10
+ it 'generates a different code' do
11
+ code2 = described_class.generate
12
+ is_expected.not_to eq(code2)
13
+ end
14
+
15
+ context '2 parts' do
16
+ subject { described_class.generate(parts: 2) }
17
+ it { is_expected.to match(/^\w{4}-\w{4}$/) }
18
+ end
19
+ end
20
+
21
+ describe '.validate' do
22
+
23
+ it 'validates a good code' do
24
+ expect(described_class.validate('1K7Q-CTFM-LMTC')).to eq('1K7Q-CTFM-LMTC')
25
+ end
26
+
27
+ it 'validates and returns the code in uppercase letters' do
28
+ expect(described_class.validate('1K7Q-ctfm-LMTC')).to eq('1K7Q-CTFM-LMTC')
29
+ end
30
+
31
+ it 'returns nil for an invalid code' do
32
+ expect(described_class.validate('1K7Q-CTFM')).to be_nil
33
+ end
34
+
35
+ it 'handles invalid characters' do
36
+ expect(described_class.validate('OK7Q-CTFM-LMTC')).to be_nil
37
+ end
38
+
39
+ context 'valid cases: lowercase, different separator and parts' do
40
+ [
41
+ ['1k7q-ctfm-lmtc'],
42
+ ['1K7Q/CTFM/LMTC'],
43
+ ['1K7Q CTFM LMTC'],
44
+ ['1k7qctfmlmtc'],
45
+ ['1K7Q-CTFM', 2],
46
+ ['7YQH-1FU7-E1HX-0BG9', 4],
47
+ ['YENH-UPJK-PTE0-20U6-QYME', 5],
48
+ ['YENH-UPJK-PTE0-20U6-QYME-RBK1', 6]
49
+ ].each do |args|
50
+ it { expect(described_class.validate(*args)).not_to be_nil }
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,97 @@
1
+ require 'coupon_code'
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
5
+ # this file to always be loaded, without a need to explicitly require it in any
6
+ # files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need
14
+ # it.
15
+ #
16
+ # The `.rspec` file also contains a few flags that are not defaults but that
17
+ # users commonly want.
18
+ #
19
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Allows RSpec to persist some state between runs in order to support
55
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
56
+ # you configure your source control system to ignore this file.
57
+ config.example_status_persistence_file_path = "spec/examples.txt"
58
+
59
+ # Limits the available syntax to the non-monkey patched syntax that is
60
+ # recommended. For more details, see:
61
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
62
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
63
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
64
+ config.disable_monkey_patching!
65
+
66
+ # This setting enables warnings. It's recommended, but in some cases may
67
+ # be too noisy due to issues in dependencies.
68
+ config.warnings = true
69
+
70
+ # Many RSpec users commonly either run the entire suite or an individual
71
+ # file, and it's useful to allow more verbose output when running an
72
+ # individual spec file.
73
+ if config.files_to_run.one?
74
+ # Use the documentation formatter for detailed output,
75
+ # unless a formatter has already been configured
76
+ # (e.g. via a command-line flag).
77
+ config.default_formatter = 'doc'
78
+ end
79
+
80
+ # Print the 10 slowest examples and example groups at the
81
+ # end of the spec run, to help surface which specs are running
82
+ # particularly slow.
83
+ config.profile_examples = 10
84
+
85
+ # Run specs in random order to surface order dependencies. If you find an
86
+ # order dependency and want to debug it, you can fix the order by providing
87
+ # the seed, which is printed after each run.
88
+ # --seed 1234
89
+ config.order = :random
90
+
91
+ # Seed global randomization in this process using the `--seed` CLI option.
92
+ # Setting this allows you to use `--seed` to deterministically reproduce
93
+ # test failures related to randomization by passing the same `--seed` value
94
+ # as the one that triggered the failure.
95
+ Kernel.srand config.seed
96
+ =end
97
+ end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coupon_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanghyun Park
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.5'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.5'
54
+ version: '3.4'
55
55
  description: A Ruby implementation of Perl's Algorithm::CouponCode CPAN module.
56
56
  email:
57
57
  - sh@baxang.com
@@ -61,7 +61,10 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
+ - ".hound.yml"
65
+ - ".rubocop.yml"
64
66
  - ".travis.yml"
67
+ - CHANGELOG.md
65
68
  - Gemfile
66
69
  - LICENSE.txt
67
70
  - README-ko.md
@@ -71,8 +74,8 @@ files:
71
74
  - coupon_code.gemspec
72
75
  - lib/coupon_code.rb
73
76
  - lib/coupon_code/version.rb
74
- - test/coupon_code_test.rb
75
- - test/test_helper.rb
77
+ - spec/coupon_code_spec.rb
78
+ - spec/spec_helper.rb
76
79
  homepage: https://github.com/baxang/coupon-code
77
80
  licenses:
78
81
  - MIT
@@ -85,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
88
  requirements:
86
89
  - - ">="
87
90
  - !ruby/object:Gem::Version
88
- version: '0'
91
+ version: 1.9.3
89
92
  required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  requirements:
91
94
  - - ">="
@@ -93,10 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
96
  version: '0'
94
97
  requirements: []
95
98
  rubyforge_project:
96
- rubygems_version: 2.2.2
99
+ rubygems_version: 2.4.5
97
100
  signing_key:
98
101
  specification_version: 4
99
102
  summary: Generate and validate coupon codes.
100
103
  test_files:
101
- - test/coupon_code_test.rb
102
- - test/test_helper.rb
104
+ - spec/coupon_code_spec.rb
105
+ - spec/spec_helper.rb
@@ -1,98 +0,0 @@
1
- require 'test_helper'
2
-
3
- describe CouponCode do
4
- describe 'Generator' do
5
- def generate(*args)
6
- CouponCode.generate(*args)
7
- end
8
-
9
- it 'should be loaded.' do
10
- CouponCode.must_respond_to(:generate)
11
- end
12
-
13
- it 'should generate a code' do
14
- generate.wont_be_empty
15
- end
16
-
17
- it 'should only contain uppercase letters, digits, and dashes.' do
18
- generate.must_match(/^[0-9A-Z-]+$/)
19
- end
20
-
21
- it 'should look like XXXX-XXXX-XXXX.' do
22
- generate.must_match(/^\w{4}-\w{4}-\w{4}$/)
23
- end
24
-
25
- it 'should generate different codes.' do
26
- code1 = generate
27
- code2 = generate
28
- code1.wont_equal(code2)
29
- end
30
-
31
- it 'should generate an arbitrary number of parts.' do
32
- generate(parts: 2).must_match(/^\w{4}-\w{4}$/)
33
- generate(parts: 5).must_match(/^\w{4}-\w{4}-\w{4}-\w{4}-\w{4}$/)
34
- end
35
- end
36
-
37
- describe 'Validator' do
38
- it 'should be loaded.' do
39
- CouponCode.must_respond_to(:validate)
40
- end
41
-
42
- it 'should fail to validate invalid code.' do
43
- CouponCode.validate('').must_equal(nil)
44
- end
45
-
46
- it 'should accept a valid code.' do
47
- CouponCode.validate('1K7Q-CTFM-LMTC').wont_be_nil
48
- end
49
-
50
- it 'should reject a short code.' do
51
- CouponCode.validate('1K7Q-CTFM').must_be_nil
52
- end
53
-
54
- it 'should accept a short code with correct parts.' do
55
- CouponCode.validate('1K7Q-CTFM', 2).wont_be_nil
56
- end
57
-
58
- it 'should reject a short code with wrong parts.' do
59
- CouponCode.validate('CTFM-1K7Q', 2).must_be_nil
60
- end
61
-
62
- it 'should fix and validate a lowercase code.' do
63
- code = '1k7q-ctfm-lmtc'
64
- CouponCode.validate(code.downcase).must_equal(code.upcase)
65
- end
66
-
67
- it 'should validate alternative separators.' do
68
- code = '1k7q/ctfm/lmtc'
69
- CouponCode.validate(code).must_equal('1K7Q-CTFM-LMTC')
70
-
71
- code = '1k7q ctfm lmtc'
72
- CouponCode.validate(code).must_equal('1K7Q-CTFM-LMTC')
73
-
74
- code = '1k7qctfmlmtc'
75
- CouponCode.validate(code).must_equal('1K7Q-CTFM-LMTC')
76
- end
77
-
78
- it 'should valid code-pretest.' do
79
- CouponCode.validate('1K7Q', 1).wont_be_nil
80
- CouponCode.validate('1K7C', 1).must_be_nil
81
-
82
- CouponCode.validate('1K7Q-CTFM', 2).wont_be_nil
83
- CouponCode.validate('1K7Q-CTFW', 2).must_be_nil
84
-
85
- CouponCode.validate('1K7Q-CTFM-LMTC', 3).wont_be_nil
86
- CouponCode.validate('1K7Q-CTFM-LMT1', 3).must_be_nil
87
-
88
- CouponCode.validate('7YQH-1FU7-E1HX-0BG9', 4).wont_be_nil
89
- CouponCode.validate('7YQH-1FU7-E1HX-0BGP', 4).must_be_nil
90
-
91
- CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME', 5).wont_be_nil
92
- CouponCode.validate('YENH-UPJK-PTE0-20U6-QYMT', 5).must_be_nil
93
-
94
- CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME-RBK1', 6).wont_be_nil
95
- CouponCode.validate('YENH-UPJK-PTE0-20U6-QYME-RBK2', 6).must_be_nil
96
- end
97
- end
98
- end
@@ -1,7 +0,0 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
- require 'coupon_code'
5
- require 'minitest/spec'
6
- require 'minitest/autorun'
7
- require 'minitest/pride'