sid 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -3,7 +3,7 @@ module Sid
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  before_create :set_sid_column
6
- validates sid_config[:sid_column], :uniqueness => true
6
+ validates sid_config[:sid_column], :uniqueness => {:scope => sid_config[:scoped_by]}
7
7
  end
8
8
  end
9
9
  end
@@ -13,11 +13,12 @@ module Sid
13
13
  def set_sid_column
14
14
  scoped_by = self.class.sid_config[:scoped_by]
15
15
  collection = self.class.where(scoped_by => self.send(scoped_by))
16
+ last = collection.reorder('id').last
16
17
 
17
- if collection.count.zero?
18
- self.sid_column = 1
18
+ self.sid_column = if last
19
+ last.sid_column + 1
19
20
  else
20
- self.sid_column = collection.reorder('id').last.sid_column + 1
21
+ 1
21
22
  end
22
23
  end
23
24
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sid}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ramon Tayag"]
12
- s.date = %q{2011-07-24}
12
+ s.date = %q{2011-07-31}
13
13
  s.description = %q{Useful for multi-tenant apps where the data lives on the same database, but you want the elements of a tenant to associate with each other via relative ids, not the absolute database id.}
14
14
  s.email = %q{ramon@tayag.net}
15
15
  s.extra_rdoc_files = [
@@ -6,20 +6,26 @@ describe 'Sid' do
6
6
  end
7
7
 
8
8
  it "should auto increment the sid field of a model" do
9
- Page.create(:account_id => 1).sid.should == 1
10
- Page.create(:account_id => 1).sid.should == 2
11
- Page.create(:account_id => 1).destroy
12
- Page.create(:account_id => 1).sid.should == 3
9
+ Page.create!(:account_id => 1).sid.should == 1
10
+ Page.create!(:account_id => 1).sid.should == 2
11
+ Page.create!(:account_id => 1).destroy
12
+ Page.create!(:account_id => 1).sid.should == 3
13
13
 
14
- Page.create(:account_id => 2).sid.should == 1
15
- Page.create(:account_id => 1).sid.should == 4
16
- Page.create(:account_id => 2).sid.should == 2
14
+ Page.create!(:account_id => 2).sid.should == 1
15
+ Page.create!(:account_id => 1).sid.should == 4
16
+ Page.create!(:account_id => 2).sid.should == 2
17
17
 
18
18
  Page.find_by_sid(2).destroy
19
- Page.create(:account_id => 1).sid.should == 5
19
+ Page.create!(:account_id => 1).sid.should == 5
20
20
  end
21
21
 
22
22
  it "should allow setting of sid column" do
23
23
  Category.create(:account_id => 1).alternative_sid.should == 1
24
24
  end
25
+
26
+ it "should validate uniqueness of sid within the scope" do
27
+ Page.new(:account_id => 1, :sid => 1).save
28
+ Page.new(:account_id => 1, :sid => 1).should_not be_valid
29
+ Page.new(:account_id => 2, :sid => 1).should be_valid
30
+ end
25
31
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramon Tayag
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-24 00:00:00 +08:00
18
+ date: 2011-07-31 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency