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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a31599fa3aa29faf3a86df0a77aee9d2b9b2cb4f
4
- data.tar.gz: e544912942f5b8faae225bae4c9e820cc7a809ea
3
+ metadata.gz: 7cd4cccc86e11b76e1a46d7cc471dace3bc5a8c3
4
+ data.tar.gz: 815f34a839ea4b11419fd11c44b24a6325a396f9
5
5
  SHA512:
6
- metadata.gz: ba3666a7f34f4e389553044a60f8e89195ed6c6d878d74998c96936e6440ce2c06299813bc7652e9616e80209220910dd9e1d5f3bb1cdb9044c2b7b35cf015a9
7
- data.tar.gz: 251ed4921e5e9c6bbf59ad8639451fff7b50b8451d9c74abf8455a7b4d2f33863488d6a88adc745a4747887fe37a9712c15a207f48ac2c2b2f103a96822b3499
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
- @record.send("#{@column}=", @new_uid || raise(NewUidNotSetYet))
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: @new_uid).count > 0
25
+ @klass.where(public_uid: new_uid.to_s).count > 0
26
26
  end
27
27
 
28
28
  def check_column_existance
@@ -1,3 +1,3 @@
1
1
  module PublicUid
2
- VERSION = "1.0.1.1"
2
+ VERSION = "1.0.2"
3
3
  end
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
- describe 'PublicUid::SetPublicUid' do
22
- let(:options) { {record: record, column: :public_uid} }
23
- let(:instance){ PublicUid::SetPublicUid.new options }
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
- let(:record){ User.new }
38
+ describe "#generate" do
39
+ subject { instance.new_uid }
26
40
 
27
- describe 'initialization' do
28
- context 'when column not specified' do
29
- let(:options) { {record: record} }
30
- it{ ->{ instance }.must_raise(PublicUid::SetPublicUid::NoPublicUidColumnSpecified) }
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
- context 'when record not specified' do
34
- let(:options) { {column: :foo} }
35
- it{ ->{ instance }.must_raise(PublicUid::SetPublicUid::NoRecordSpecified) }
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
- describe "#generate" do
40
- subject{ instance.new_uid }
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
- it "should ask generator to generate random string" do
43
- instance.generate(DummyGenerator.new)
44
- subject.must_equal 'first try'
45
- end
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
- context 'when record match random' do
48
- before{ User.create public_uid: 'first try' }
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
- it "should generate string once again" do
52
- instance.generate(DummyGenerator.new)
53
- subject.must_equal 'second try'
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
- describe '#set' do
59
- subject{ instance.new_uid }
74
+ describe '#similar_uid_exist?' do
75
+ let(:trigger) { instance.send :similar_uid_exist? }
60
76
 
61
- context 'when @new id is not set' do
62
- it{ ->{ instance.set }.must_raise(PublicUid::SetPublicUid::NewUidNotSetYet) }
63
- end
77
+ before { mock(instance).new_uid { 567 } }
64
78
 
65
- context 'when @new id is set' do
66
- before{ instance.instance_variable_set '@new_uid', '123' }
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
- it 'must set new_uid for record pubilc_uid column' do
69
- instance.set
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
@@ -24,6 +24,10 @@ module ActRec
24
24
  self.table_name = "users"
25
25
  generate_public_uid
26
26
  end
27
+
28
+ class User < ActiveRecord::Base
29
+ self.table_name = 'users'
30
+ end
27
31
  end
28
32
 
29
33
  TestConf.add_orm_module(ActRec)
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
2
  require 'bundler/setup'
3
3
  require 'minitest/autorun'
4
+ require 'rr'
4
5
 
5
6
  class Minitest::Spec
6
7
  class << self
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.1.1
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