isbn_validation 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Nick Plante
1
+ Copyright (c) 2013 Nick Plante
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -33,4 +33,4 @@ support, please use v0.1.2.
33
33
  * Nick Plante
34
34
  * Omer Jakobinsky - Rails 3.0 compatibility
35
35
 
36
- Copyright © 2011 Nick Plante, released under the MIT license
36
+ Copyright © 2013 Nick Plante, released under the MIT license
@@ -1,3 +1,3 @@
1
1
  module IsbnValidation
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -25,8 +25,8 @@ require "isbn_validation/version"
25
25
  # method, proc or string should return or evaluate to a true or false value.
26
26
  module ValidationExtensions
27
27
  module IsbnValidation
28
- ISBN10_REGEX = /^(?:\d[\ |-]?){9}[\d|X]$/
29
- ISBN13_REGEX = /^(?:\d[\ |-]?){13}$/
28
+ ISBN10_REGEX = /^(?:\d[\ |-]?){9}[\d|X]$/i
29
+ ISBN13_REGEX = /^(?:\d[\ |-]?){13}$/i
30
30
 
31
31
  def self.included(base)
32
32
  base.extend(ClassMethods)
@@ -61,7 +61,7 @@ module ValidationExtensions
61
61
  if (isbn || '').match(ISBN10_REGEX)
62
62
  isbn_values = isbn.upcase.gsub(/\ |-/, '').split('')
63
63
  check_digit = isbn_values.pop # last digit is check digit
64
- check_digit = (check_digit == 'X') ? 10 : check_digit.to_i
64
+ check_digit = (check_digit.upcase == 'X') ? 10 : check_digit.to_i
65
65
 
66
66
  sum = 0
67
67
  isbn_values.each_with_index do |value, index|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isbn_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2009-09-10 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2013-04-01 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
- requirement: &2153258500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,15 @@ dependencies:
22
21
  version: '3'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2153258500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3'
26
30
  - !ruby/object:Gem::Dependency
27
31
  name: sqlite3
28
- requirement: &2153258080 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
29
33
  none: false
30
34
  requirements:
31
35
  - - ! '>='
@@ -33,32 +37,29 @@ dependencies:
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
- version_requirements: *2153258080
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
37
46
  description: isbn_validation adds an isbn validation routine to active record models.
38
- email: nap@zerosum.org
47
+ email:
48
+ - nap@zerosum.org
39
49
  executables: []
40
50
  extensions: []
41
51
  extra_rdoc_files:
42
52
  - README.md
43
- files:
44
53
  - MIT-LICENSE
45
- - Rakefile
46
- - README.md
54
+ files:
47
55
  - lib/isbn_validation/version.rb
48
56
  - lib/isbn_validation.rb
49
- - test/isbn_validation_test.rb
50
- - test/models.rb
51
- - test/schema.rb
52
- - test/test_helper.rb
53
- has_rdoc: true
57
+ - README.md
58
+ - MIT-LICENSE
54
59
  homepage:
55
60
  licenses: []
56
61
  post_install_message:
57
- rdoc_options:
58
- - --line-numbers
59
- - --inline-source
60
- - --main
61
- - README.md
62
+ rdoc_options: []
62
63
  require_paths:
63
64
  - lib
64
65
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -67,17 +68,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
68
  - - ! '>='
68
69
  - !ruby/object:Gem::Version
69
70
  version: '0'
71
+ segments:
72
+ - 0
73
+ hash: -239021533232196791
70
74
  required_rubygems_version: !ruby/object:Gem::Requirement
71
75
  none: false
72
76
  requirements:
73
77
  - - ! '>='
74
78
  - !ruby/object:Gem::Version
75
79
  version: '0'
80
+ segments:
81
+ - 0
82
+ hash: -239021533232196791
76
83
  requirements: []
77
84
  rubyforge_project:
78
- rubygems_version: 1.6.2
85
+ rubygems_version: 1.8.25
79
86
  signing_key:
80
87
  specification_version: 3
81
88
  summary: isbn_validation adds an isbn validation routine to active record models.
82
- test_files:
83
- - test/isbn_validation_test.rb
89
+ test_files: []
data/Rakefile DELETED
@@ -1,15 +0,0 @@
1
- require 'bundler'
2
- require 'rake'
3
- require 'rake/testtask'
4
-
5
- Bundler::GemHelper.install_tasks
6
-
7
- desc 'Default: run unit tests.'
8
- task :default => :test
9
-
10
- desc 'Test the isbn_validation plugin.'
11
- Rake::TestTask.new(:test) do |t|
12
- t.libs << 'lib'
13
- t.pattern = 'test/**/*_test.rb'
14
- t.verbose = true
15
- end
@@ -1,120 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
- require File.dirname(__FILE__) + '/models'
3
-
4
- class IsbnValidationTest < Test::Unit::TestCase
5
- def test_isbn10_should_match_regex
6
- isbn = '1590599934'
7
- assert isbn.match(ValidationExtensions::IsbnValidation::ISBN10_REGEX)
8
- end
9
-
10
- def test_isbn10_should_not_match_regex
11
- isbn = 'abc123ab3344'
12
- assert !isbn.match(ValidationExtensions::IsbnValidation::ISBN10_REGEX)
13
- end
14
-
15
- def test_isbn10_with_dashes_and_spaces_should_match_regex
16
- isbn = '159-059 9934'
17
- assert isbn.match(ValidationExtensions::IsbnValidation::ISBN10_REGEX)
18
- end
19
-
20
- def test_isbn13_should_match_regex
21
- isbn = '9781590599938'
22
- assert isbn.match(ValidationExtensions::IsbnValidation::ISBN13_REGEX)
23
- end
24
-
25
- def test_isbn13_should_not_match_regex
26
- isbn = '9991a9010599938'
27
- assert !isbn.match(ValidationExtensions::IsbnValidation::ISBN13_REGEX)
28
- end
29
-
30
- def test_isbn13_with_dashes_and_spaces_should_match_regex
31
- isbn = '978-159059 9938'
32
- assert isbn.match(ValidationExtensions::IsbnValidation::ISBN13_REGEX)
33
- end
34
-
35
- def test_isbn_should_match_either_isbn10_or_isbn13
36
- book = Book.new
37
- book.isbn = 'invalid'
38
- assert !book.valid?
39
- book.isbn = '1590599934'
40
- assert book.valid?
41
- book.isbn = '9781590599938'
42
- assert book.valid?
43
- end
44
-
45
- def test_isbn10_should_pass_check_digit_verification
46
- book = Book10.new
47
- book.isbn = '159059993-4'
48
- assert book.valid?
49
- end
50
-
51
- def test_isbn10_should_fail_check_digit_verification
52
- book = Book10.new
53
- book.isbn = '159059993-0'
54
- assert !book.valid?
55
- end
56
-
57
- def test_isbn10_should_handle_x_character_checksum
58
- book = Book10.new
59
- book.isbn = '0-9722051-1-X'
60
- assert book.valid?
61
- end
62
-
63
- def test_isbn13_should_pass_check_digit_verification
64
- book = Book13.new
65
- book.isbn = '978-1590599938'
66
- assert book.valid?
67
- end
68
-
69
- def test_isbn13_should_fail_check_digit_verification
70
- book = Book13.new
71
- book.isbn = '978-1590599934'
72
- assert !book.valid?
73
- end
74
-
75
- def test_isbn13_with_zero_check_digit_should_validate
76
- book = Book13.new
77
- book.isbn = '978-1-60746-006-0'
78
- assert book.valid?
79
- end
80
-
81
- def test_isbn_should_be_valid_to_isbn10_by_default
82
- book = Book.new
83
- book.isbn = '1590599934'
84
- assert book.valid?
85
- end
86
-
87
- def test_should_have_custom_error_message
88
- book = Book.new
89
- book.isbn = '978-159059AAAAAA'
90
- book.valid?
91
- assert_equal 'is too fantastical!', book.errors[:isbn].first
92
- end
93
-
94
- def test_blank_should_not_be_valid_by_default
95
- book = Book13.new
96
- book.isbn = ''
97
- book.valid?
98
- assert_equal 'is not a valid ISBN code', book.errors[:isbn].first
99
- end
100
-
101
- def test_should_have_an_option_to_allow_nil
102
- book = Book13.new
103
- book.isbn = nil
104
- assert book.valid?
105
- end
106
-
107
- def test_should_have_an_option_to_allow_blank
108
- book = Book10.new
109
- book.isbn = ''
110
- assert book.valid?
111
- end
112
-
113
- def test_should_support_old_syntax
114
- book = OldBook.new
115
- book.isbn = ''
116
- assert !book.valid?
117
- book.isbn = '1590599934'
118
- assert book.valid?
119
- end
120
- end
data/test/models.rb DELETED
@@ -1,18 +0,0 @@
1
- class Book < ActiveRecord::Base
2
- validates :isbn, :isbn_format => { :message => 'is too fantastical!' }
3
- end
4
-
5
- class Book10 < ActiveRecord::Base
6
- set_table_name 'books'
7
- validates :isbn, :isbn_format => { :with => :isbn10, :allow_blank => true }
8
- end
9
-
10
- class Book13 < ActiveRecord::Base
11
- set_table_name 'books'
12
- validates :isbn, :isbn_format => { :with => :isbn13, :allow_nil => true }
13
- end
14
-
15
- class OldBook < ActiveRecord::Base
16
- set_table_name 'books'
17
- validates_isbn :isbn
18
- end
data/test/schema.rb DELETED
@@ -1,5 +0,0 @@
1
- ActiveRecord::Schema.define(:version => 1) do
2
- create_table :books, :force => true do |t|
3
- t.string :isbn
4
- end
5
- end
data/test/test_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- RAILS_ROOT = File.dirname(__FILE__)
3
-
4
- require 'logger'
5
- require 'rubygems'
6
- require 'test/unit'
7
- require 'active_record'
8
- require "active_record/test_case"
9
- require "#{File.dirname(__FILE__)}/../init"
10
-
11
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
12
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
13
- ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
14
-
15
- load(File.dirname(__FILE__) + "/schema.rb") if File.exist?(File.dirname(__FILE__) + "/schema.rb")