public_uid 1.0.1.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/lib/public_uid/set_public_uid.rb +3 -3
- data/lib/public_uid/version.rb +1 -1
- data/public_uid.gemspec +1 -0
- data/test/lib/set_public_uid_test.rb +57 -43
- data/test/support/orm/active_record.rb +4 -0
- data/test/test_helper.rb +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd4cccc86e11b76e1a46d7cc471dace3bc5a8c3
|
4
|
+
data.tar.gz: 815f34a839ea4b11419fd11c44b24a6325a396f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c4c3b9ba948a19a316c4dc24a57b04a65718415de4e7353f964980ec80f3b99e34a4642fb1547d467fcbde377f4e3b62873b67e62914eb7f6e9e37a4595135f
|
7
|
+
data.tar.gz: ec5c68da6ce0135e8ef1266b847f2d40d3570a34369235050f4be92614aae1729d42e979f109af01cfb7fd0491d1fb9762025ffb753a6928e9e83b337a8c3f67
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# PublicUid
|
2
2
|
|
3
|
-
|
4
|
-
[![Build Status](https://api.travis-ci.org/equivalent/lpgrid.png?branch=master)](http://travis-ci.org/equivalent/public_uid)
|
3
|
+
[![Build Status](https://travis-ci.org/equivalent/public_uid.svg?branch=master)](https://travis-ci.org/equivalent/public_uid)
|
5
4
|
[![Code Climate](https://codeclimate.com/github/equivalent/public_uid.png)](https://codeclimate.com/github/equivalent/public_uid)
|
6
5
|
|
7
6
|
|
@@ -48,7 +47,7 @@ And then execute:
|
|
48
47
|
|
49
48
|
## Usage
|
50
49
|
|
51
|
-
Create database column for public unique id
|
50
|
+
Create database column for public unique id. It have to be string.
|
52
51
|
|
53
52
|
```ruby
|
54
53
|
class AddPublicUidToUsers < ActiveRecord::Migration
|
@@ -6,7 +6,6 @@ module PublicUid
|
|
6
6
|
@record = options[:record] || raise(NoRecordSpecified)
|
7
7
|
@column = options[:column] || raise(NoPublicUidColumnSpecified)
|
8
8
|
@klass = @record.class
|
9
|
-
@new_uid = nil
|
10
9
|
check_column_existance
|
11
10
|
end
|
12
11
|
|
@@ -17,12 +16,13 @@ module PublicUid
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def set
|
20
|
-
|
19
|
+
new_uid || raise(NewUidNotSetYet)
|
20
|
+
@record.send("#{@column}=", new_uid )
|
21
21
|
end
|
22
22
|
private
|
23
23
|
|
24
24
|
def similar_uid_exist?
|
25
|
-
@klass.where(public_uid:
|
25
|
+
@klass.where(public_uid: new_uid.to_s).count > 0
|
26
26
|
end
|
27
27
|
|
28
28
|
def check_column_existance
|
data/lib/public_uid/version.rb
CHANGED
data/public_uid.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "minitest", "~> 5"
|
25
|
+
spec.add_development_dependency "rr", "~> 1.1.2"
|
25
26
|
spec.add_development_dependency "sqlite3"
|
26
27
|
spec.add_development_dependency "activerecord", '~> 3.2'
|
27
28
|
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class User < ActiveRecord::Base
|
4
|
-
self.table_name = 'users'
|
5
|
-
end
|
6
|
-
|
7
3
|
class DummyGenerator
|
8
4
|
def initialize
|
9
5
|
@counter = 0
|
@@ -18,58 +14,76 @@ class DummyGenerator
|
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
TestConf.orm_modules.each do |orm_module|
|
18
|
+
describe orm_module.description do
|
19
|
+
describe 'PublicUid::SetPublicUid' do
|
20
|
+
|
21
|
+
let(:options) { {record: record, column: :public_uid} }
|
22
|
+
let(:instance) { PublicUid::SetPublicUid.new options }
|
23
|
+
let(:record) { record_class.new }
|
24
|
+
let(:record_class) { "#{orm_module}::User".constantize }
|
25
|
+
|
26
|
+
describe 'initialization' do
|
27
|
+
context 'when column not specified' do
|
28
|
+
let(:options) { { record: record } }
|
29
|
+
it{ ->{ instance } .must_raise(PublicUid::SetPublicUid::NoPublicUidColumnSpecified) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when record not specified' do
|
33
|
+
let(:options) { {column: :foo} }
|
34
|
+
it{ ->{ instance } .must_raise(PublicUid::SetPublicUid::NoRecordSpecified) }
|
35
|
+
end
|
36
|
+
end
|
24
37
|
|
25
|
-
|
38
|
+
describe "#generate" do
|
39
|
+
subject { instance.new_uid }
|
26
40
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
41
|
+
it "should ask generator to generate random string" do
|
42
|
+
instance.generate(DummyGenerator.new)
|
43
|
+
subject.must_equal 'first try'
|
44
|
+
end
|
32
45
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
46
|
+
context 'when record match random' do
|
47
|
+
before{ record_class.create public_uid: 'first try' }
|
48
|
+
after { record_class.destroy_all }
|
38
49
|
|
39
|
-
|
40
|
-
|
50
|
+
it "should generate string once again" do
|
51
|
+
instance.generate(DummyGenerator.new)
|
52
|
+
subject.must_equal 'second try'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
41
56
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
describe '#set' do
|
58
|
+
subject { instance.new_uid }
|
59
|
+
|
60
|
+
context 'when @new id is not set' do
|
61
|
+
it{ ->{ instance.set }.must_raise(PublicUid::SetPublicUid::NewUidNotSetYet) }
|
62
|
+
end
|
46
63
|
|
47
|
-
|
48
|
-
|
49
|
-
after { User.destroy_all }
|
64
|
+
context 'when @new id is set' do
|
65
|
+
before { instance.instance_variable_set '@new_uid', '123' }
|
50
66
|
|
51
|
-
|
52
|
-
|
53
|
-
|
67
|
+
it 'must set new_uid for record pubilc_uid column' do
|
68
|
+
instance.set
|
69
|
+
subject.must_equal '123'
|
70
|
+
end
|
71
|
+
end
|
54
72
|
end
|
55
|
-
end
|
56
|
-
end
|
57
73
|
|
58
|
-
|
59
|
-
|
74
|
+
describe '#similar_uid_exist?' do
|
75
|
+
let(:trigger) { instance.send :similar_uid_exist? }
|
60
76
|
|
61
|
-
|
62
|
-
it{ ->{ instance.set }.must_raise(PublicUid::SetPublicUid::NewUidNotSetYet) }
|
63
|
-
end
|
77
|
+
before { mock(instance).new_uid { 567 } }
|
64
78
|
|
65
|
-
|
66
|
-
|
79
|
+
# Due to PostgreSQL type check feature
|
80
|
+
it 'must look for integer generated numbers as a string' do
|
81
|
+
count_mock = stub(record_class).count { 123 }
|
82
|
+
stub(record_class).where( { public_uid: "567" } ) { count_mock }
|
67
83
|
|
68
|
-
|
69
|
-
|
70
|
-
subject.must_equal '123'
|
84
|
+
trigger.must_equal true
|
85
|
+
end
|
71
86
|
end
|
72
87
|
end
|
73
88
|
end
|
74
|
-
|
75
89
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: public_uid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Valent
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.1.2
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sqlite3
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|