sequenced 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -3
- data/CHANGELOG.md +14 -2
- data/Gemfile +1 -1
- data/MIT-LICENSE +1 -1
- data/README.md +31 -4
- data/lib/sequenced/generator.rb +3 -3
- data/lib/sequenced/version.rb +1 -1
- data/sequenced.gemspec +2 -3
- metadata +15 -161
- data/test/acts_as_sequenced_test.rb +0 -132
- data/test/concurrency_test.rb +0 -82
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/account.rb +0 -6
- data/test/dummy/app/models/address.rb +0 -4
- data/test/dummy/app/models/answer.rb +0 -4
- data/test/dummy/app/models/comment.rb +0 -8
- data/test/dummy/app/models/concurrent_badger.rb +0 -3
- data/test/dummy/app/models/doppelganger.rb +0 -4
- data/test/dummy/app/models/email.rb +0 -4
- data/test/dummy/app/models/invoice.rb +0 -4
- data/test/dummy/app/models/monster.rb +0 -3
- data/test/dummy/app/models/order.rb +0 -4
- data/test/dummy/app/models/policeman.rb +0 -5
- data/test/dummy/app/models/product.rb +0 -8
- data/test/dummy/app/models/question.rb +0 -4
- data/test/dummy/app/models/rating.rb +0 -3
- data/test/dummy/app/models/subscription.rb +0 -3
- data/test/dummy/app/models/user.rb +0 -4
- data/test/dummy/app/models/werewolf.rb +0 -2
- data/test/dummy/app/models/zombie.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -56
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -29
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -33
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -43
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -58
- data/test/dummy/db/migrate/20120219165346_create_questions.rb +0 -10
- data/test/dummy/db/migrate/20120219165548_create_answers.rb +0 -13
- data/test/dummy/db/migrate/20120219171957_create_accounts.rb +0 -9
- data/test/dummy/db/migrate/20120219172039_create_invoices.rb +0 -12
- data/test/dummy/db/migrate/20120219172922_create_orders.rb +0 -10
- data/test/dummy/db/migrate/20120219174931_create_subscriptions.rb +0 -10
- data/test/dummy/db/migrate/20120219175744_create_users.rb +0 -12
- data/test/dummy/db/migrate/20120219232323_create_addresses.rb +0 -9
- data/test/dummy/db/migrate/20120220000804_create_comments.rb +0 -12
- data/test/dummy/db/migrate/20130411225444_create_emails.rb +0 -12
- data/test/dummy/db/migrate/20130715002029_create_ratings.rb +0 -10
- data/test/dummy/db/migrate/20130730004055_create_products.rb +0 -9
- data/test/dummy/db/migrate/20131226000000_create_monsters.rb +0 -9
- data/test/dummy/db/migrate/20140404195334_create_policemen.rb +0 -9
- data/test/dummy/db/migrate/20151120190645_create_concurrent_badgers.rb +0 -10
- data/test/dummy/db/migrate/20160118182655_create_doppelgangers.rb +0 -10
- data/test/dummy/db/schema.rb +0 -142
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/multiple_sequences_test.rb +0 -20
- data/test/test_helper.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a27946de6bd01c2c4c7d97d929df68f4fa01a34c23f721473eb0b7f2e2c22c5e
|
4
|
+
data.tar.gz: be78bda96414d8bfdc2b45162294263f665c02f43b5135e8ed23f79fa6011b07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c24c3b5c4f4dcc77ea64043dc6afff72a1f2fa38642e9129c5f41f7dfccbbbf06c4438de790fdb6cfcd8695c8abcf923df67cb706f141d36815f81ca622209
|
7
|
+
data.tar.gz: d11ef41c80d7e26c696ee96553ab2b3a0cd272cb24c63880beb4b3fc5d3a4e74e6733e4e58dfbac172947971e4019f6467d811718e5d078164c08e49adb38d10
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,26 @@
|
|
1
|
+
3.2.0 (January 29, 2020)
|
2
|
+
------------------------
|
3
|
+
|
4
|
+
* Support non-default primary key columns (set via `primary_key=`) (#41)
|
5
|
+
* Fix issue with Postgres adapter check when using a subclassed adapter (#42)
|
6
|
+
|
7
|
+
3.1.1 (January 30, 2016)
|
8
|
+
-------------------------
|
9
|
+
|
10
|
+
* Rails 3 compatibility
|
11
|
+
(samphilipd, [#22](https://github.com/derrickreimer/sequenced/pull/22))
|
12
|
+
|
1
13
|
3.1.0 (January 23, 2016)
|
2
14
|
-------------------------
|
3
15
|
|
4
16
|
* Allow multiple sequences on one record
|
5
|
-
(samphilipd, [#19](https://github.com/
|
17
|
+
(samphilipd, [#19](https://github.com/derrickreimer/sequenced/pull/19))
|
6
18
|
|
7
19
|
3.0.0 (November 28, 2015)
|
8
20
|
-------------------------
|
9
21
|
|
10
22
|
* Make this gem thread-safe for PostgreSQL
|
11
|
-
(samphilipd, [#16](https://github.com/
|
23
|
+
(samphilipd, [#16](https://github.com/derrickreimer/sequenced/pull/16))
|
12
24
|
|
13
25
|
2.0.0 (October 24, 2014)
|
14
26
|
------------------------
|
data/Gemfile
CHANGED
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Sequenced
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/
|
4
|
-
[![Code Climate](https://codeclimate.com/github/djreimer/sequenced.
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/sequenced.
|
3
|
+
[![Build Status](https://travis-ci.org/derrickreimer/sequenced.svg)](https://travis-ci.org/derrickreimer/sequenced)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/djreimer/sequenced.svg)](https://codeclimate.com/github/djreimer/sequenced)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/sequenced.svg)](http://badge.fury.io/rb/sequenced)
|
6
6
|
|
7
7
|
Sequenced is a simple gem that generates scoped sequential IDs for
|
8
8
|
ActiveRecord models. This gem provides an `acts_as_sequenced` macro that
|
@@ -106,6 +106,33 @@ class CreateBadgers < ActiveRecord::Migration
|
|
106
106
|
end
|
107
107
|
```
|
108
108
|
|
109
|
+
If you are adding a sequenced column to an existing table, you need to account for that in your migration.
|
110
|
+
|
111
|
+
Here is an example migration that adds and sets the `sequential_id` column based on the current database records:
|
112
|
+
```ruby
|
113
|
+
# app/db/migrations/20151120190645_add_sequental_id_to_badgers.rb
|
114
|
+
class AddSequentalIdToBadgers < ActiveRecord::Migration
|
115
|
+
add_column :badgers, :sequential_id, :integer
|
116
|
+
|
117
|
+
execute <<~SQL
|
118
|
+
UPDATE badgers
|
119
|
+
SET sequential_id = old_badgers.next_sequential_id
|
120
|
+
FROM (
|
121
|
+
SELECT id, ROW_NUMBER()
|
122
|
+
OVER(
|
123
|
+
PARTITION BY burrow_id
|
124
|
+
ORDER BY id
|
125
|
+
) AS next_sequential_id
|
126
|
+
FROM badgers
|
127
|
+
) old_badgers
|
128
|
+
WHERE badgers.id = old_badgers.id
|
129
|
+
SQL
|
130
|
+
|
131
|
+
change_column :badgers, :sequential_id, :integer, null: false
|
132
|
+
add_index :badgers, [:sequential_id, :burrow_id], unique: true
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
109
136
|
## Configuration
|
110
137
|
|
111
138
|
### Overriding the default sequential ID column
|
@@ -166,7 +193,7 @@ class Answer < ActiveRecord::Base
|
|
166
193
|
|
167
194
|
# Automatically use the sequential ID in URLs
|
168
195
|
def to_param
|
169
|
-
self.sequential_id
|
196
|
+
self.sequential_id.to_s
|
170
197
|
end
|
171
198
|
end
|
172
199
|
|
data/lib/sequenced/generator.rb
CHANGED
@@ -11,7 +11,7 @@ module Sequenced
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def set
|
14
|
-
return if
|
14
|
+
return if skip? || id_set?
|
15
15
|
lock_table
|
16
16
|
record.send(:"#{column}=", next_id)
|
17
17
|
end
|
@@ -39,7 +39,7 @@ module Sequenced
|
|
39
39
|
def unique?(id)
|
40
40
|
build_scope(*scope) do
|
41
41
|
rel = base_relation
|
42
|
-
rel = rel.where(
|
42
|
+
rel = rel.where.not(record.class.primary_key => record.id) if record.persisted?
|
43
43
|
rel.where(column => id)
|
44
44
|
end.count == 0
|
45
45
|
end
|
@@ -54,7 +54,7 @@ module Sequenced
|
|
54
54
|
|
55
55
|
def postgresql?
|
56
56
|
defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
|
57
|
-
record.class.connection.
|
57
|
+
record.class.connection.kind_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
58
58
|
end
|
59
59
|
|
60
60
|
def base_relation
|
data/lib/sequenced/version.rb
CHANGED
data/sequenced.gemspec
CHANGED
@@ -7,12 +7,11 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.authors = ["Derrick Reimer"]
|
8
8
|
s.licenses = ['MIT']
|
9
9
|
s.email = ["derrickreimer@gmail.com"]
|
10
|
-
s.homepage = "https://github.com/
|
10
|
+
s.homepage = "https://github.com/derrickreimer/sequenced"
|
11
11
|
s.summary = "Generate scoped sequential IDs for ActiveRecord models"
|
12
12
|
s.description = "Sequenced is a gem that generates scoped sequential IDs for ActiveRecord models."
|
13
13
|
|
14
|
-
s.files = `git ls-files`.split("\
|
15
|
-
s.test_files = Dir["test/**/*"]
|
14
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
15
|
|
17
16
|
s.add_dependency "activesupport", ">= 3.0"
|
18
17
|
s.add_dependency "activerecord", ">= 3.0"
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequenced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Reimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
55
|
description: Sequenced is a gem that generates scoped sequential IDs for ActiveRecord
|
@@ -60,8 +60,8 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
64
|
-
- .travis.yml
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
65
|
- CHANGELOG.md
|
66
66
|
- Gemfile
|
67
67
|
- MIT-LICENSE
|
@@ -72,82 +72,7 @@ files:
|
|
72
72
|
- lib/sequenced/generator.rb
|
73
73
|
- lib/sequenced/version.rb
|
74
74
|
- sequenced.gemspec
|
75
|
-
|
76
|
-
- test/concurrency_test.rb
|
77
|
-
- test/dummy/README.rdoc
|
78
|
-
- test/dummy/Rakefile
|
79
|
-
- test/dummy/app/assets/javascripts/application.js
|
80
|
-
- test/dummy/app/assets/stylesheets/application.css
|
81
|
-
- test/dummy/app/controllers/application_controller.rb
|
82
|
-
- test/dummy/app/helpers/application_helper.rb
|
83
|
-
- test/dummy/app/mailers/.gitkeep
|
84
|
-
- test/dummy/app/models/.gitkeep
|
85
|
-
- test/dummy/app/models/account.rb
|
86
|
-
- test/dummy/app/models/address.rb
|
87
|
-
- test/dummy/app/models/answer.rb
|
88
|
-
- test/dummy/app/models/comment.rb
|
89
|
-
- test/dummy/app/models/concurrent_badger.rb
|
90
|
-
- test/dummy/app/models/doppelganger.rb
|
91
|
-
- test/dummy/app/models/email.rb
|
92
|
-
- test/dummy/app/models/invoice.rb
|
93
|
-
- test/dummy/app/models/monster.rb
|
94
|
-
- test/dummy/app/models/order.rb
|
95
|
-
- test/dummy/app/models/policeman.rb
|
96
|
-
- test/dummy/app/models/product.rb
|
97
|
-
- test/dummy/app/models/question.rb
|
98
|
-
- test/dummy/app/models/rating.rb
|
99
|
-
- test/dummy/app/models/subscription.rb
|
100
|
-
- test/dummy/app/models/user.rb
|
101
|
-
- test/dummy/app/models/werewolf.rb
|
102
|
-
- test/dummy/app/models/zombie.rb
|
103
|
-
- test/dummy/app/views/layouts/application.html.erb
|
104
|
-
- test/dummy/config.ru
|
105
|
-
- test/dummy/config/application.rb
|
106
|
-
- test/dummy/config/boot.rb
|
107
|
-
- test/dummy/config/database.yml
|
108
|
-
- test/dummy/config/environment.rb
|
109
|
-
- test/dummy/config/environments/development.rb
|
110
|
-
- test/dummy/config/environments/production.rb
|
111
|
-
- test/dummy/config/environments/test.rb
|
112
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
113
|
-
- test/dummy/config/initializers/inflections.rb
|
114
|
-
- test/dummy/config/initializers/mime_types.rb
|
115
|
-
- test/dummy/config/initializers/secret_token.rb
|
116
|
-
- test/dummy/config/initializers/session_store.rb
|
117
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
118
|
-
- test/dummy/config/locales/en.yml
|
119
|
-
- test/dummy/config/routes.rb
|
120
|
-
- test/dummy/db/development.sqlite3
|
121
|
-
- test/dummy/db/migrate/20120219165346_create_questions.rb
|
122
|
-
- test/dummy/db/migrate/20120219165548_create_answers.rb
|
123
|
-
- test/dummy/db/migrate/20120219171957_create_accounts.rb
|
124
|
-
- test/dummy/db/migrate/20120219172039_create_invoices.rb
|
125
|
-
- test/dummy/db/migrate/20120219172922_create_orders.rb
|
126
|
-
- test/dummy/db/migrate/20120219174931_create_subscriptions.rb
|
127
|
-
- test/dummy/db/migrate/20120219175744_create_users.rb
|
128
|
-
- test/dummy/db/migrate/20120219232323_create_addresses.rb
|
129
|
-
- test/dummy/db/migrate/20120220000804_create_comments.rb
|
130
|
-
- test/dummy/db/migrate/20130411225444_create_emails.rb
|
131
|
-
- test/dummy/db/migrate/20130715002029_create_ratings.rb
|
132
|
-
- test/dummy/db/migrate/20130730004055_create_products.rb
|
133
|
-
- test/dummy/db/migrate/20131226000000_create_monsters.rb
|
134
|
-
- test/dummy/db/migrate/20140404195334_create_policemen.rb
|
135
|
-
- test/dummy/db/migrate/20151120190645_create_concurrent_badgers.rb
|
136
|
-
- test/dummy/db/migrate/20160118182655_create_doppelgangers.rb
|
137
|
-
- test/dummy/db/schema.rb
|
138
|
-
- test/dummy/db/test.sqlite3
|
139
|
-
- test/dummy/lib/assets/.gitkeep
|
140
|
-
- test/dummy/log/.gitkeep
|
141
|
-
- test/dummy/log/development.log
|
142
|
-
- test/dummy/log/test.log
|
143
|
-
- test/dummy/public/404.html
|
144
|
-
- test/dummy/public/422.html
|
145
|
-
- test/dummy/public/500.html
|
146
|
-
- test/dummy/public/favicon.ico
|
147
|
-
- test/dummy/script/rails
|
148
|
-
- test/multiple_sequences_test.rb
|
149
|
-
- test/test_helper.rb
|
150
|
-
homepage: https://github.com/djreimer/sequenced
|
75
|
+
homepage: https://github.com/derrickreimer/sequenced
|
151
76
|
licenses:
|
152
77
|
- MIT
|
153
78
|
metadata: {}
|
@@ -157,89 +82,18 @@ require_paths:
|
|
157
82
|
- lib
|
158
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
159
84
|
requirements:
|
160
|
-
- -
|
85
|
+
- - ">="
|
161
86
|
- !ruby/object:Gem::Version
|
162
87
|
version: '0'
|
163
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
89
|
requirements:
|
165
|
-
- -
|
90
|
+
- - ">="
|
166
91
|
- !ruby/object:Gem::Version
|
167
92
|
version: '0'
|
168
93
|
requirements: []
|
169
94
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.3
|
95
|
+
rubygems_version: 2.7.3
|
171
96
|
signing_key:
|
172
97
|
specification_version: 4
|
173
98
|
summary: Generate scoped sequential IDs for ActiveRecord models
|
174
|
-
test_files:
|
175
|
-
- test/acts_as_sequenced_test.rb
|
176
|
-
- test/concurrency_test.rb
|
177
|
-
- test/dummy/app/assets/javascripts/application.js
|
178
|
-
- test/dummy/app/assets/stylesheets/application.css
|
179
|
-
- test/dummy/app/controllers/application_controller.rb
|
180
|
-
- test/dummy/app/helpers/application_helper.rb
|
181
|
-
- test/dummy/app/models/account.rb
|
182
|
-
- test/dummy/app/models/address.rb
|
183
|
-
- test/dummy/app/models/answer.rb
|
184
|
-
- test/dummy/app/models/comment.rb
|
185
|
-
- test/dummy/app/models/concurrent_badger.rb
|
186
|
-
- test/dummy/app/models/doppelganger.rb
|
187
|
-
- test/dummy/app/models/email.rb
|
188
|
-
- test/dummy/app/models/invoice.rb
|
189
|
-
- test/dummy/app/models/monster.rb
|
190
|
-
- test/dummy/app/models/order.rb
|
191
|
-
- test/dummy/app/models/policeman.rb
|
192
|
-
- test/dummy/app/models/product.rb
|
193
|
-
- test/dummy/app/models/question.rb
|
194
|
-
- test/dummy/app/models/rating.rb
|
195
|
-
- test/dummy/app/models/subscription.rb
|
196
|
-
- test/dummy/app/models/user.rb
|
197
|
-
- test/dummy/app/models/werewolf.rb
|
198
|
-
- test/dummy/app/models/zombie.rb
|
199
|
-
- test/dummy/app/views/layouts/application.html.erb
|
200
|
-
- test/dummy/config/application.rb
|
201
|
-
- test/dummy/config/boot.rb
|
202
|
-
- test/dummy/config/database.yml
|
203
|
-
- test/dummy/config/environment.rb
|
204
|
-
- test/dummy/config/environments/development.rb
|
205
|
-
- test/dummy/config/environments/production.rb
|
206
|
-
- test/dummy/config/environments/test.rb
|
207
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
208
|
-
- test/dummy/config/initializers/inflections.rb
|
209
|
-
- test/dummy/config/initializers/mime_types.rb
|
210
|
-
- test/dummy/config/initializers/secret_token.rb
|
211
|
-
- test/dummy/config/initializers/session_store.rb
|
212
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
213
|
-
- test/dummy/config/locales/en.yml
|
214
|
-
- test/dummy/config/routes.rb
|
215
|
-
- test/dummy/config.ru
|
216
|
-
- test/dummy/db/development.sqlite3
|
217
|
-
- test/dummy/db/migrate/20120219165346_create_questions.rb
|
218
|
-
- test/dummy/db/migrate/20120219165548_create_answers.rb
|
219
|
-
- test/dummy/db/migrate/20120219171957_create_accounts.rb
|
220
|
-
- test/dummy/db/migrate/20120219172039_create_invoices.rb
|
221
|
-
- test/dummy/db/migrate/20120219172922_create_orders.rb
|
222
|
-
- test/dummy/db/migrate/20120219174931_create_subscriptions.rb
|
223
|
-
- test/dummy/db/migrate/20120219175744_create_users.rb
|
224
|
-
- test/dummy/db/migrate/20120219232323_create_addresses.rb
|
225
|
-
- test/dummy/db/migrate/20120220000804_create_comments.rb
|
226
|
-
- test/dummy/db/migrate/20130411225444_create_emails.rb
|
227
|
-
- test/dummy/db/migrate/20130715002029_create_ratings.rb
|
228
|
-
- test/dummy/db/migrate/20130730004055_create_products.rb
|
229
|
-
- test/dummy/db/migrate/20131226000000_create_monsters.rb
|
230
|
-
- test/dummy/db/migrate/20140404195334_create_policemen.rb
|
231
|
-
- test/dummy/db/migrate/20151120190645_create_concurrent_badgers.rb
|
232
|
-
- test/dummy/db/migrate/20160118182655_create_doppelgangers.rb
|
233
|
-
- test/dummy/db/schema.rb
|
234
|
-
- test/dummy/db/test.sqlite3
|
235
|
-
- test/dummy/log/development.log
|
236
|
-
- test/dummy/log/test.log
|
237
|
-
- test/dummy/public/404.html
|
238
|
-
- test/dummy/public/422.html
|
239
|
-
- test/dummy/public/500.html
|
240
|
-
- test/dummy/public/favicon.ico
|
241
|
-
- test/dummy/Rakefile
|
242
|
-
- test/dummy/README.rdoc
|
243
|
-
- test/dummy/script/rails
|
244
|
-
- test/multiple_sequences_test.rb
|
245
|
-
- test/test_helper.rb
|
99
|
+
test_files: []
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Test Models:
|
4
|
-
#
|
5
|
-
# Answer - :scope => :question_id
|
6
|
-
# Comment - :scope => :question_id (with an AR default scope)
|
7
|
-
# Invoice - :scope => :account_id, :start_at => 1000
|
8
|
-
# Product - :scope => :account_id, :start_at => lambda { |r| r.computed_start_value }
|
9
|
-
# Order - :scope => :non_existent_column
|
10
|
-
# User - :scope => :account_id, :column => :custom_sequential_id
|
11
|
-
# Address - :scope => :account_id ('sequential_id' does not exist)
|
12
|
-
# Email - :scope => [:emailable_id, :emailable_type]
|
13
|
-
# Subscription - no options
|
14
|
-
# Rating - :scope => :comment_id, skip: { |r| r.score == 0 }
|
15
|
-
# Monster - no options
|
16
|
-
# Zombie - STI, inherits from Monster
|
17
|
-
# Werewolf - STI, inherits from Monster
|
18
|
-
|
19
|
-
class ActsAsSequencedTest < ActiveSupport::TestCase
|
20
|
-
test "default start_at" do
|
21
|
-
question = Question.create
|
22
|
-
answer = question.answers.create
|
23
|
-
assert_equal 1, answer.sequential_id
|
24
|
-
end
|
25
|
-
|
26
|
-
test "custom start_at" do
|
27
|
-
account = Account.create
|
28
|
-
invoice = account.invoices.create
|
29
|
-
assert_equal 1000, invoice.sequential_id
|
30
|
-
|
31
|
-
another_invoice = account.invoices.create
|
32
|
-
assert_equal 1001, another_invoice.sequential_id
|
33
|
-
end
|
34
|
-
|
35
|
-
test "lambda start_at" do
|
36
|
-
account = Account.create
|
37
|
-
product = Product.create(:account_id => account.id)
|
38
|
-
assert_equal 3, product.sequential_id
|
39
|
-
|
40
|
-
another_product = Product.create(:account_id => account.id)
|
41
|
-
assert_equal 4, another_product.sequential_id
|
42
|
-
end
|
43
|
-
|
44
|
-
test "custom start_at with populated table" do
|
45
|
-
account = Account.create
|
46
|
-
account.invoices.create(:sequential_id => 1)
|
47
|
-
invoice = account.invoices.create
|
48
|
-
assert_equal 1000, invoice.sequential_id
|
49
|
-
end
|
50
|
-
|
51
|
-
test "sequential id increment" do
|
52
|
-
question = Question.create
|
53
|
-
question.answers.create(:sequential_id => 10)
|
54
|
-
another_answer = question.answers.create
|
55
|
-
assert_equal 11, another_answer.sequential_id
|
56
|
-
end
|
57
|
-
|
58
|
-
test "default scope" do
|
59
|
-
Subscription.create(:sequential_id => 1)
|
60
|
-
subscription = Subscription.create
|
61
|
-
assert_equal 2, subscription.sequential_id
|
62
|
-
end
|
63
|
-
|
64
|
-
test "undefined scope method" do
|
65
|
-
account = Account.create
|
66
|
-
order = account.orders.build
|
67
|
-
assert_raises(NoMethodError) { order.save }
|
68
|
-
end
|
69
|
-
|
70
|
-
test "custom sequential id column" do
|
71
|
-
account = Account.create
|
72
|
-
user = account.users.create
|
73
|
-
assert_equal 1, user.custom_sequential_id
|
74
|
-
end
|
75
|
-
|
76
|
-
test "sequential id remains on save" do
|
77
|
-
question = Question.create
|
78
|
-
answer = question.answers.create
|
79
|
-
assert_equal 1, answer.sequential_id
|
80
|
-
|
81
|
-
answer.reload
|
82
|
-
answer.body = "Updated body"
|
83
|
-
answer.save
|
84
|
-
assert_equal 1, answer.sequential_id
|
85
|
-
end
|
86
|
-
|
87
|
-
test "undefined sequential id column" do
|
88
|
-
account = Account.create
|
89
|
-
address = account.addresses.build
|
90
|
-
assert_raises(NoMethodError) { address.save }
|
91
|
-
end
|
92
|
-
|
93
|
-
test "manually setting sequential id" do
|
94
|
-
question = Question.create
|
95
|
-
answer = question.answers.build(:sequential_id => 10)
|
96
|
-
another_answer = question.answers.build(:sequential_id => 10)
|
97
|
-
answer.save
|
98
|
-
another_answer.save
|
99
|
-
|
100
|
-
assert_equal 10, answer.sequential_id
|
101
|
-
assert_equal 10, another_answer.sequential_id
|
102
|
-
end
|
103
|
-
|
104
|
-
test "model with a default scope for sorting" do
|
105
|
-
question = Question.create
|
106
|
-
(1..3).each { |id| question.comments.create(:sequential_id => id) }
|
107
|
-
comment = question.comments.create
|
108
|
-
assert_equal 4, comment.sequential_id
|
109
|
-
end
|
110
|
-
|
111
|
-
test "multi-column scopes" do
|
112
|
-
Email.create(:emailable_id => 1, :emailable_type => "User", :sequential_id => 2)
|
113
|
-
Email.create(:emailable_id => 1, :emailable_type => "Question", :sequential_id => 3)
|
114
|
-
email = Email.create(:emailable_id => 1, :emailable_type => "User")
|
115
|
-
assert_equal 3, email.sequential_id
|
116
|
-
end
|
117
|
-
|
118
|
-
test "skip option" do
|
119
|
-
rating = Rating.create(:comment_id => 1, :score => 1)
|
120
|
-
assert_equal 1, rating.sequential_id
|
121
|
-
|
122
|
-
rating = Rating.create(:comment_id => 1, :score => 0)
|
123
|
-
assert_equal nil, rating.sequential_id
|
124
|
-
end
|
125
|
-
|
126
|
-
test "STI" do
|
127
|
-
zombie = Zombie.create
|
128
|
-
werewolf = Werewolf.create
|
129
|
-
assert_equal 1, zombie.sequential_id
|
130
|
-
assert_equal 2, werewolf.sequential_id
|
131
|
-
end
|
132
|
-
end
|