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 +1 -1
- data/lib/sid/class_methods.rb +1 -1
- data/lib/sid/instance_methods.rb +4 -3
- data/sid.gemspec +2 -2
- data/spec/sid_spec.rb +14 -8
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/sid/class_methods.rb
CHANGED
data/lib/sid/instance_methods.rb
CHANGED
@@ -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
|
18
|
-
|
18
|
+
self.sid_column = if last
|
19
|
+
last.sid_column + 1
|
19
20
|
else
|
20
|
-
|
21
|
+
1
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/sid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sid}
|
8
|
-
s.version = "0.0.
|
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-
|
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 = [
|
data/spec/sid_spec.rb
CHANGED
@@ -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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2011-07-31 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|