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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7053ed97886ba613915252ff2a773d3355577aa
4
- data.tar.gz: b5c5d8f381ee2d0c78d1ee5d3fa4c97e281d91d6
3
+ metadata.gz: 77f3bb9f61240306a75e00c8c4fc7d4c314110d7
4
+ data.tar.gz: 5310a81c3a8b3573d9dd756263de8a5ada773f47
5
5
  SHA512:
6
- metadata.gz: 06e120b319deeb12f6d92de5c5d9d9bb1c8765fcf23c7bcdcfe2310685b83869193c8995aa808bf10191f68ba2854c0e3ca574935a9694b92cba4559ee0ed1bb
7
- data.tar.gz: 777c190afa32118fc4f0ab931aec01b9df8309c0fd29ffaafd8d71ff8e13bf31c3b99b390c72685b82d3f67cf117386537ac7633d7a17ea19ebe0837b7435d00
6
+ metadata.gz: a95ae3bae159006fdf2c89257b939693a77f92a7ee1c3e948e05164e703d7757219bb8a4d95557c74d87c0cb498f3605053398669dbb6886a8cf9fe6c1e1a88c
7
+ data.tar.gz: e9b5e44da2b1d277891aa75b6e0f3b353e740da925ab53a67f144032ac88995b2d65be96204f70414b6d303e05c72bc3ef02ca590d371da0bd7a0fb3b718170d
@@ -7,3 +7,6 @@ AllCops:
7
7
 
8
8
  Rails:
9
9
  Enabled: true
10
+
11
+ RSpec/NestedGroups:
12
+ MaxNesting: 4
data/README.md CHANGED
@@ -121,26 +121,26 @@ ActiveFedora::Noid.configure do |config|
121
121
  end
122
122
  ```
123
123
 
124
- **NOTE 1**: If you switch to a new minter, it will not automatically start with the same state as the old minter. AF::Noid does include a couple of rake tasks for copying state from database-backed minters to file-backed ones and vice versa:
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
- config.include(ActiveFedora::Noid::RSpec)
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
- before(:suite) { disable_production_minter! }
143
- after(:suite) { enable_production_minter! }
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
@@ -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.5'
30
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.8.0'
31
31
  spec.add_development_dependency 'engine_cart', '~> 1.0'
32
32
  end
@@ -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,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveFedora
3
3
  module Noid
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
6
6
  end
@@ -20,7 +20,7 @@ Seeds DB from ActiveFedora::Noid.config (or command-line overrides)
20
20
  end
21
21
 
22
22
  def seed_row
23
- MinterState.create!(
23
+ MinterState.seed!(
24
24
  namespace: namespace,
25
25
  template: template
26
26
  )
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  shared_examples 'a minter' do
3
3
  describe '#mint' do
4
- subject { minter.mint }
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
- it 'is invalid under a different template' do
23
- expect(other).not_to be_valid(minter.mint)
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
 
@@ -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) { described_class.new }
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(subject).to be_instance_of described_class
27
- expect(subject).to be_a Noid::Minter
28
- expect(subject.template).to be_instance_of Noid::Template
29
- expect(subject.template.to_s).to eq ActiveFedora::Noid.config.template
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
- it 'accepts valid template arg' do
32
- expect(other).to be_instance_of described_class
33
- expect(other).to be_a Noid::Minter
34
- expect(other.template).to be_instance_of Noid::Template
35
- expect(other.template.to_s).to eq '.reedddk'
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
- it 'returns a hash' do
41
- expect(subject.read).to be_a(Hash)
42
- end
43
- it 'has the expected namespace' do
44
- expect(subject.read[:namespace]).to eq ActiveFedora::Noid.config.namespace
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
- it 'has the expected template' do
47
- expect(subject.read[:template]).to eq ActiveFedora::Noid.config.template
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) { subject.read }
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 { subject.write!(minter) }.to change { subject.read[:seq] }
68
+ expect { db_minter.write!(minter) }.to change { db_minter.read[:seq] }
57
69
  .from(starting_state[:seq]).to(minter.seq)
58
- .and change { subject.read[:counters] }
70
+ .and change { db_minter.read[:counters] }
59
71
  .from(starting_state[:counters]).to(minter.counters)
60
- .and change { subject.read[:rand] }
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.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: 2016-11-29 00:00:00.000000000 Z
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: '1.5'
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: '1.5'
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.5.1
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