referehencible 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/lib/referehencible.rb +31 -0
- data/lib/referehencible/version.rb +3 -0
- data/spec/reference_number.rb +36 -0
- metadata +56 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeff Felchner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'referehencible/version'
|
2
|
+
|
3
|
+
module Referehencible
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
###
|
7
|
+
# Validations
|
8
|
+
#
|
9
|
+
validates :reference_number,
|
10
|
+
presence: true,
|
11
|
+
uniqueness: true,
|
12
|
+
length: {
|
13
|
+
is: 16 }
|
14
|
+
|
15
|
+
###
|
16
|
+
# Hooks
|
17
|
+
#
|
18
|
+
before_create :generate_reference_number
|
19
|
+
|
20
|
+
###
|
21
|
+
# ActiveRecord Overrides
|
22
|
+
#
|
23
|
+
def reference_number; generate_reference_number; end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def generate_reference_number
|
29
|
+
read_attribute(:reference_number) || write_attribute('reference_number', SecureRandom.hex(8))
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples 'something with a reference number' do
|
2
|
+
describe '#reference_number' do
|
3
|
+
it { should have_valid(:reference_number).when ('*' * 16) }
|
4
|
+
it { should_not have_valid(:reference_number).when ('*' * 15), ('*' * 17), '' }
|
5
|
+
|
6
|
+
it 'should be unique' do
|
7
|
+
send("create_#{subject.class.name.underscore}".to_sym)
|
8
|
+
|
9
|
+
should validate_uniqueness_of(:reference_number)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not have a reference number until it is accessed' do
|
14
|
+
order = build_processing_order
|
15
|
+
order.send(:read_attribute, :reference_number).should be_nil
|
16
|
+
order.reference_number.should match Chirrpy::FORMATS[:order_reference_number]
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'generates a reference number on create' do
|
20
|
+
order = build_processing_order
|
21
|
+
order.send(:read_attribute, :reference_number).should be_nil
|
22
|
+
order.event.save!
|
23
|
+
order.occurrence.schedulee_id = order.event.id
|
24
|
+
recursively_save order.tickets.first
|
25
|
+
order.reference_number.should match Chirrpy::FORMATS[:order_reference_number]
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does not overwrite a reference number that already exists' do
|
29
|
+
order = build_processing_order
|
30
|
+
reference_number_before_save = order.reference_number
|
31
|
+
order.event.save!
|
32
|
+
order.occurrence.schedulee_id = order.event.id
|
33
|
+
recursively_save order.tickets.first
|
34
|
+
order.reference_number.should eql reference_number_before_save
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: referehencible
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jfelchner
|
9
|
+
- m5rk
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: ''
|
16
|
+
email: support@chirrpy.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- LICENSE
|
22
|
+
files:
|
23
|
+
- lib/referehencible/version.rb
|
24
|
+
- lib/referehencible.rb
|
25
|
+
- Rakefile
|
26
|
+
- README.md
|
27
|
+
- LICENSE
|
28
|
+
- spec/reference_number.rb
|
29
|
+
homepage: https://github.com/chirrpy/referehencible
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options:
|
33
|
+
- --charset = UTF-8
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: referehencible
|
50
|
+
rubygems_version: 1.8.24
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Enable unique reference numbers on all the things
|
54
|
+
test_files:
|
55
|
+
- spec/reference_number.rb
|
56
|
+
has_rdoc:
|