active_fedora-noid 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +13 -13
- data/active_fedora-noid.gemspec +1 -1
- data/app/models/minter_state.rb +9 -0
- data/lib/active_fedora/noid/minter/db.rb +6 -1
- data/lib/active_fedora/noid/version.rb +1 -1
- data/lib/generators/active_fedora/noid/seed_generator.rb +1 -1
- data/spec/support/shared_examples/minter.rb +6 -4
- data/spec/unit/db_minter_spec.rb +35 -23
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77f3bb9f61240306a75e00c8c4fc7d4c314110d7
|
4
|
+
data.tar.gz: 5310a81c3a8b3573d9dd756263de8a5ada773f47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a95ae3bae159006fdf2c89257b939693a77f92a7ee1c3e948e05164e703d7757219bb8a4d95557c74d87c0cb498f3605053398669dbb6886a8cf9fe6c1e1a88c
|
7
|
+
data.tar.gz: e9b5e44da2b1d277891aa75b6e0f3b353e740da925ab53a67f144032ac88995b2d65be96204f70414b6d303e05c72bc3ef02ca590d371da0bd7a0fb3b718170d
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -121,26 +121,26 @@ ActiveFedora::Noid.configure do |config|
|
|
121
121
|
end
|
122
122
|
```
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
``` bash
|
127
|
-
# For migrating minter state from a file to a database
|
128
|
-
$ rake active_fedora:noid:migrate:file_to_database
|
129
|
-
# For migrating minter state from a database to a file
|
130
|
-
$ rake active_fedora:noid:migrate:database_to_file
|
131
|
-
```
|
132
|
-
|
133
|
-
**NOTE 2**: If you decide to use the database-backed minter, you may notice that your test suite now fails miserably if it is configured to clear out the application database between tests. If so, you may add the following to e.g. `spec/spec_helper.rb` to set the default minter in the test suite as the file-backed one:
|
124
|
+
Using the database-backed minter can cause problems with your test suite, where it is often sensible to wipe out database rows between tests (which destroys the database-backed minter's state, which renders it unusable). To deal with this and still get the benefits of using the database-backed minter in development and production environments, you'll also want to add the following helper to your `spec/spec_helper.rb`:
|
134
125
|
|
135
126
|
```ruby
|
136
127
|
require 'active_fedora/noid/rspec'
|
137
128
|
|
138
129
|
RSpec.configure do |config|
|
139
|
-
|
130
|
+
include ActiveFedora::Noid::RSpec
|
131
|
+
|
132
|
+
config.before(:suite) { disable_production_minter! }
|
133
|
+
config.after(:suite) { enable_production_minter! }
|
140
134
|
end
|
135
|
+
```
|
136
|
+
|
137
|
+
If you switch to the new database-backed minter and want to include in that minter the state of your current file-backed minter, AF::Noid 2.0.0 provides a new rake task that will copy your minter's state from the filesystem to the database:
|
141
138
|
|
142
|
-
|
143
|
-
|
139
|
+
```bash
|
140
|
+
# For migrating minter state from a file to a database
|
141
|
+
$ rake active_fedora:noid:migrate:file_to_database
|
142
|
+
# For migrating minter state from a database to a file
|
143
|
+
$ rake active_fedora:noid:migrate:database_to_file
|
144
144
|
```
|
145
145
|
|
146
146
|
### Identifier template
|
data/active_fedora-noid.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
28
28
|
spec.add_development_dependency 'sqlite3'
|
29
29
|
spec.add_development_dependency 'rubocop', '~> 0.42.0'
|
30
|
-
spec.add_development_dependency 'rubocop-rspec', '~> 1.
|
30
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.8.0'
|
31
31
|
spec.add_development_dependency 'engine_cart', '~> 1.0'
|
32
32
|
end
|
data/app/models/minter_state.rb
CHANGED
@@ -3,4 +3,13 @@ class MinterState < ActiveRecord::Base
|
|
3
3
|
validates :namespace, presence: true, uniqueness: true
|
4
4
|
validates :template, presence: true
|
5
5
|
validates :template, format: { with: Object.const_get('Noid::Template::VALID_PATTERN'), message: 'value fails regex' }
|
6
|
+
|
7
|
+
# Creates an initial row for the namespace.
|
8
|
+
# @return [MinterState] the initial minter state
|
9
|
+
def self.seed!(namespace:, template:)
|
10
|
+
create!(
|
11
|
+
namespace: namespace,
|
12
|
+
template: template
|
13
|
+
)
|
14
|
+
end
|
6
15
|
end
|
@@ -44,7 +44,12 @@ module ActiveFedora
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def instance
|
47
|
-
MinterState.lock.find_by(
|
47
|
+
MinterState.lock.find_by!(
|
48
|
+
namespace: ActiveFedora::Noid.config.namespace,
|
49
|
+
template: ActiveFedora::Noid.config.template
|
50
|
+
)
|
51
|
+
rescue ActiveRecord::RecordNotFound
|
52
|
+
MinterState.seed!(
|
48
53
|
namespace: ActiveFedora::Noid.config.namespace,
|
49
54
|
template: ActiveFedora::Noid.config.template
|
50
55
|
)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
shared_examples 'a minter' do
|
3
3
|
describe '#mint' do
|
4
|
-
subject
|
5
|
-
let(:other) { described_class.new('.reedddk') }
|
4
|
+
subject { minter.mint }
|
6
5
|
|
7
6
|
it { is_expected.not_to be_empty }
|
8
7
|
|
@@ -19,8 +18,11 @@ shared_examples 'a minter' do
|
|
19
18
|
expect(described_class.new('.reedddk').valid?(subject)).to be false
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
context 'with a different template' do
|
22
|
+
let(:other) { described_class.new('.reedddk') }
|
23
|
+
it 'is invalid under a different template' do
|
24
|
+
expect(other).not_to be_valid(minter.mint)
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
data/spec/unit/db_minter_spec.rb
CHANGED
@@ -4,6 +4,7 @@ include MinterStateHelper
|
|
4
4
|
describe ActiveFedora::Noid::Minter::Db do
|
5
5
|
before { reset_minter_state_table }
|
6
6
|
after(:all) { reset_minter_state_table }
|
7
|
+
subject(:db_minter) { described_class.new }
|
7
8
|
|
8
9
|
before do
|
9
10
|
# default novel mintings
|
@@ -11,10 +12,8 @@ describe ActiveFedora::Noid::Minter::Db do
|
|
11
12
|
allow(ActiveFedora::Base).to receive(:gone?).and_return(false)
|
12
13
|
end
|
13
14
|
|
14
|
-
let(:other) { described_class.new('.reedddk') }
|
15
|
-
|
16
15
|
it_behaves_like 'a minter' do
|
17
|
-
let(:minter) {
|
16
|
+
let(:minter) { db_minter }
|
18
17
|
end
|
19
18
|
|
20
19
|
describe '#initialize' do
|
@@ -23,41 +22,54 @@ describe ActiveFedora::Noid::Minter::Db do
|
|
23
22
|
expect { described_class.new('') }.to raise_error(Noid::TemplateError)
|
24
23
|
end
|
25
24
|
it 'returns object w/ default template' do
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
expect(
|
29
|
-
expect(
|
25
|
+
expect(db_minter).to be_instance_of described_class
|
26
|
+
expect(db_minter).to be_a Noid::Minter
|
27
|
+
expect(db_minter.template).to be_instance_of Noid::Template
|
28
|
+
expect(db_minter.template.to_s).to eq ActiveFedora::Noid.config.template
|
30
29
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
context 'with a user provided template' do
|
31
|
+
let(:db_minter) { described_class.new('.reedddk') }
|
32
|
+
|
33
|
+
it 'accepts valid template arg' do
|
34
|
+
expect(db_minter).to be_instance_of described_class
|
35
|
+
expect(db_minter).to be_a Noid::Minter
|
36
|
+
expect(db_minter.template).to be_instance_of Noid::Template
|
37
|
+
expect(db_minter.template.to_s).to eq '.reedddk'
|
38
|
+
end
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
39
42
|
describe '#read' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
subject { db_minter.read }
|
44
|
+
|
45
|
+
context 'when the database has been initialized' do
|
46
|
+
it 'has the expected namespace and template' do
|
47
|
+
expect(subject).to include(namespace: ActiveFedora::Noid.config.namespace,
|
48
|
+
template: ActiveFedora::Noid.config.template)
|
49
|
+
end
|
45
50
|
end
|
46
|
-
|
47
|
-
|
51
|
+
|
52
|
+
context 'when the database has not been initialized' do
|
53
|
+
before do
|
54
|
+
MinterState.destroy_all
|
55
|
+
end
|
56
|
+
it 'has the expected namespace and template' do
|
57
|
+
expect(subject).to include(namespace: ActiveFedora::Noid.config.namespace,
|
58
|
+
template: ActiveFedora::Noid.config.template)
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
51
63
|
describe '#write!' do
|
52
|
-
let(:starting_state) {
|
64
|
+
let(:starting_state) { db_minter.read }
|
53
65
|
let(:minter) { Noid::Minter.new(starting_state) }
|
54
66
|
before { minter.mint }
|
55
67
|
it 'changes the state of the minter' do
|
56
|
-
expect {
|
68
|
+
expect { db_minter.write!(minter) }.to change { db_minter.read[:seq] }
|
57
69
|
.from(starting_state[:seq]).to(minter.seq)
|
58
|
-
.and change {
|
70
|
+
.and change { db_minter.read[:counters] }
|
59
71
|
.from(starting_state[:counters]).to(minter.counters)
|
60
|
-
.and change {
|
72
|
+
.and change { db_minter.read[:rand] }
|
61
73
|
.from(starting_state[:rand]).to(Marshal.dump(minter.instance_variable_get(:@rand)))
|
62
74
|
end
|
63
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_fedora-noid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael J. Giarlo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active-fedora
|
@@ -140,14 +140,14 @@ dependencies:
|
|
140
140
|
requirements:
|
141
141
|
- - "~>"
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
143
|
+
version: 1.8.0
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
146
|
version_requirements: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
148
|
- - "~>"
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 1.8.0
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: engine_cart
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
version: '0'
|
228
228
|
requirements: []
|
229
229
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.
|
230
|
+
rubygems_version: 2.6.8
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
233
|
summary: Noid identifier services for ActiveFedora-based applications
|