curation_concerns 0.11.0 → 0.12.0.pre1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5316df9b39e54e4daa22c70a6c3b29792b5c34f5
4
- data.tar.gz: 3bfc5ebcffca4b90f451bc5ff6939f7ba710b6ab
3
+ metadata.gz: e539e04a127fef5b331cbc4b51495b386f473ab8
4
+ data.tar.gz: 2706ea39d092ae8ae4e7a969ec5f0d6ac40e8f75
5
5
  SHA512:
6
- metadata.gz: 999744a175fde9f98b998ecb7da9a6ebd617d93ecac848d5ddeb8c5d0ebaf314e838dc6914bbf7619b191b4cfefd66ff8900948b8a7c3c186e0af0e6921491c5
7
- data.tar.gz: 25caa2a90d520913508b28b7a7e695100ed53ed1257f1a88d1eead24e8869e0dd5612776ff0c5a6fb4c0d0aadbdd579661ef962744492ee033b9ff2956e5d045
6
+ metadata.gz: 4cb327b7af8c5e54d1b42ce2fc0784541e8f1aaaea7b19b172cc77615bec6ea8f7ffd49fa059e38a8132d6f759dcac3aca1c220d72b2ae5aedb65abc55e78f47
7
+ data.tar.gz: 806dad8e1e5ed014956c1c9df81eaf3c7f43117081b9877a017e08509988ae5c2eeaf038dd5220fabc14c8e8a6e27ef8dd113a3025ab2c7f02791dbe19fd32b1
data/.rubocop.yml CHANGED
@@ -26,6 +26,7 @@ Performance/RedundantMerge:
26
26
  Lint/AssignmentInCondition:
27
27
  Exclude:
28
28
  - 'curation_concerns-models/app/services/curation_concerns/persist_derivatives.rb'
29
+ - 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb'
29
30
 
30
31
  Metrics/LineLength:
31
32
  Enabled: false
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.12.0.pre1
@@ -41,7 +41,7 @@ module CurationConcerns::CurationConcernController
41
41
 
42
42
  def create
43
43
  # return unless verify_acceptance_of_user_agreement!
44
- if actor.create
44
+ if actor.create(attributes_for_actor)
45
45
  after_create_response
46
46
  else
47
47
  respond_to do |wants|
@@ -77,7 +77,7 @@ module CurationConcerns::CurationConcernController
77
77
  end
78
78
 
79
79
  def update
80
- if actor.update
80
+ if actor.update(attributes_for_actor)
81
81
  after_update_response
82
82
  else
83
83
  respond_to do |wants|
@@ -115,7 +115,7 @@ module CurationConcerns::CurationConcernController
115
115
  end
116
116
 
117
117
  def actor
118
- @actor ||= CurationConcerns::CurationConcern.actor(curation_concern, current_user, attributes_for_actor)
118
+ @actor ||= CurationConcerns::CurationConcern.actor(curation_concern, current_user)
119
119
  end
120
120
 
121
121
  def presenter
@@ -135,7 +135,7 @@ module CurationConcerns::CurationConcernController
135
135
 
136
136
  def after_update_response
137
137
  # TODO: visibility or lease/embargo status
138
- if actor.visibility_changed? && curation_concern.file_sets.present?
138
+ if curation_concern.visibility_changed? && curation_concern.file_sets.present?
139
139
  redirect_to main_app.confirm_curation_concerns_permission_path(curation_concern)
140
140
  else
141
141
  respond_to do |wants|
@@ -1,9 +1,46 @@
1
1
  module CurationConcerns
2
2
  module CurationConcern
3
- def self.actor(curation_concern, *args)
3
+ # Returns the top-level actor on the stack
4
+ def self.actor(curation_concern, current_user)
5
+ ActorStack.new(curation_concern, current_user,
6
+ [AddToCollectionActor,
7
+ AssignRepresentativeActor,
8
+ AttachFilesActor,
9
+ ApplyOrderActor,
10
+ InterpretVisibilityActor,
11
+ model_actor(curation_concern),
12
+ AssignIdentifierActor])
13
+ end
14
+
15
+ def self.model_actor(curation_concern)
4
16
  actor_identifier = curation_concern.class.to_s.split('::').last
5
- klass = "CurationConcerns::#{actor_identifier}Actor".constantize
6
- klass.new(curation_concern, *args)
17
+ "CurationConcerns::#{actor_identifier}Actor".constantize
18
+ end
19
+
20
+ class ActorStack
21
+ attr_reader :curation_concern, :user, :first_actor_class, :more_actors
22
+ def initialize(curation_concern, user, more_actors)
23
+ @curation_concern = curation_concern
24
+ @user = user
25
+ @more_actors = more_actors
26
+ @first_actor_class = @more_actors.shift || RootActor
27
+ end
28
+
29
+ def inner_stack
30
+ ActorStack.new(curation_concern, user, more_actors)
31
+ end
32
+
33
+ def actor
34
+ first_actor_class.new(curation_concern, user, inner_stack)
35
+ end
36
+
37
+ def create(attributes)
38
+ actor.create(attributes.with_indifferent_access)
39
+ end
40
+
41
+ def update(attributes)
42
+ actor.update(attributes.with_indifferent_access)
43
+ end
7
44
  end
8
45
  end
9
46
  end
@@ -1,3 +1,3 @@
1
1
  module CurationConcerns
2
- VERSION = "0.11.0".freeze
2
+ VERSION = "0.12.0.pre1".freeze
3
3
  end
@@ -2,6 +2,5 @@
2
2
  # `rails generate curation_concerns:work <%= class_name %>`
3
3
  module CurationConcerns
4
4
  class <%= class_name %>Actor < CurationConcerns::BaseActor
5
- include ::CurationConcerns::WorkActorBehavior
6
5
  end
7
6
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ describe CurationConcerns::AddToCollectionActor do
3
+ let(:user) { create(:user) }
4
+ let(:curation_concern) { GenericWork.new }
5
+ let(:attributes) { {} }
6
+ subject do
7
+ CurationConcerns::CurationConcern::ActorStack.new(curation_concern,
8
+ user,
9
+ [described_class,
10
+ CurationConcerns::GenericWorkActor])
11
+ end
12
+ describe 'the next actor' do
13
+ let(:root_actor) { double }
14
+ before do
15
+ allow(CurationConcerns::RootActor).to receive(:new).and_return(root_actor)
16
+ end
17
+
18
+ let(:attributes) do
19
+ { collection_ids: ['123'], title: ['test'] }
20
+ end
21
+
22
+ it 'does not receive the collection_ids' do
23
+ expect(root_actor).to receive(:create).with(title: ['test'])
24
+ subject.create(attributes)
25
+ end
26
+ end
27
+
28
+ describe 'create' do
29
+ let(:collection) { create(:collection) }
30
+ let(:attributes) do
31
+ { collection_ids: [collection.id], title: ['test'] }
32
+ end
33
+
34
+ it 'adds it to the collection' do
35
+ expect(subject.create(attributes)).to be true
36
+ expect(collection.reload.members).to eq [curation_concern]
37
+ end
38
+ end
39
+ end
@@ -138,6 +138,13 @@ describe CurationConcerns::FileSetActor do
138
138
  end
139
139
  end
140
140
 
141
+ describe "#update_metadata" do
142
+ it "is successful" do
143
+ expect(actor.update_metadata("title" => ["updated title"])).to be true
144
+ expect(file_set.reload.title).to eq ["updated title"]
145
+ end
146
+ end
147
+
141
148
  describe "#destroy" do
142
149
  it "destroys the object" do
143
150
  actor.destroy
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+ describe CurationConcerns::InterpretVisibilityActor do
3
+ let(:user) { create(:user) }
4
+ let(:curation_concern) { GenericWork.new }
5
+ let(:attributes) { {} }
6
+ subject do
7
+ CurationConcerns::CurationConcern::ActorStack.new(curation_concern,
8
+ user,
9
+ [described_class,
10
+ CurationConcerns::GenericWorkActor])
11
+ end
12
+ let(:date) { Date.today + 2 }
13
+
14
+ describe 'the next actor' do
15
+ let(:root_actor) { double }
16
+ before do
17
+ allow(CurationConcerns::RootActor).to receive(:new).and_return(root_actor)
18
+ end
19
+
20
+ context 'when visibility is set to open' do
21
+ let(:attributes) do
22
+ { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
23
+ visibility_during_embargo: 'restricted',
24
+ visibility_after_embargo: 'open',
25
+ embargo_release_date: date.to_s }
26
+ end
27
+
28
+ it 'does not receive the embargo attributes' do
29
+ expect(root_actor).to receive(:create).with(visibility: 'open')
30
+ subject.create(attributes)
31
+ end
32
+ end
33
+
34
+ context 'when visibility is set to embargo' do
35
+ let(:attributes) do
36
+ { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
37
+ visibility_during_embargo: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE,
38
+ visibility_after_embargo: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
39
+ embargo_release_date: date.to_s }
40
+ end
41
+
42
+ it 'does not receive the visibility attribute' do
43
+ expect(root_actor).to receive(:create).with(hash_excluding(:visibility))
44
+ subject.create(attributes)
45
+ end
46
+
47
+ context 'when embargo_release_date is not set' do
48
+ let(:attributes) { { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO } }
49
+ it 'does not clear the visibility attributes' do
50
+ expect(subject.create(attributes)).to be false
51
+ expect(attributes).to eq(visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO)
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'when visibility is set to lease' do
57
+ let(:attributes) do
58
+ { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE,
59
+ visibility_during_lease: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE,
60
+ visibility_after_lease: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
61
+ lease_expiration_date: date.to_s }
62
+ end
63
+
64
+ it 'removes lease attributes' do
65
+ expect(root_actor).to receive(:create).with(hash_excluding(:visibility))
66
+ subject.create(attributes)
67
+ end
68
+
69
+ context 'when lease_expiration_date is not set' do
70
+ let(:attributes) { { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE } }
71
+ it 'sets error on curation_concern and return false' do
72
+ expect(subject.create(attributes)).to be false
73
+ expect(attributes).to eq(visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE)
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ describe 'create' do
80
+ context 'with embargo' do
81
+ let(:attributes) do
82
+ { title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
83
+ visibility_during_embargo: 'authenticated', embargo_release_date: date.to_s,
84
+ visibility_after_embargo: 'open', visibility_during_lease: 'open',
85
+ lease_expiration_date: '2014-06-12', visibility_after_lease: 'restricted',
86
+ rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
87
+ end
88
+
89
+ context 'with a valid embargo date' do
90
+ let(:date) { Date.today + 2 }
91
+ it 'interprets and apply embargo and lease visibility settings' do
92
+ subject.create(attributes)
93
+ expect(curation_concern.visibility_during_embargo).to eq 'authenticated'
94
+ expect(curation_concern.visibility_after_embargo).to eq 'open'
95
+ expect(curation_concern.visibility).to eq 'authenticated'
96
+ end
97
+ end
98
+
99
+ context 'when embargo_release_date is in the past' do
100
+ let(:date) { Date.today - 2 }
101
+ it 'sets error on curation_concern and return false' do
102
+ expect(subject.create(attributes)).to be false
103
+ expect(subject.curation_concern.errors[:embargo_release_date].first).to eq 'Must be a future date'
104
+ end
105
+ end
106
+ end
107
+
108
+ context 'with lease' do
109
+ let(:attributes) do
110
+ { title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE,
111
+ visibility_during_embargo: 'authenticated', embargo_release_date: '2099-05-12',
112
+ visibility_after_embargo: 'open', visibility_during_lease: 'open',
113
+ lease_expiration_date: date.to_s, visibility_after_lease: 'restricted',
114
+ rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
115
+ end
116
+
117
+ context 'with a valid lease date' do
118
+ let(:date) { Date.today + 2 }
119
+ it 'interprets and apply embargo and lease visibility settings' do
120
+ subject.create(attributes)
121
+ expect(curation_concern.embargo_release_date).to be_nil
122
+ expect(curation_concern.visibility_during_lease).to eq 'open'
123
+ expect(curation_concern.visibility_after_lease).to eq 'restricted'
124
+ expect(curation_concern.visibility).to eq 'open'
125
+ end
126
+ end
127
+
128
+ context 'when lease_expiration_date is in the past' do
129
+ let(:date) { Date.today - 2 }
130
+ it 'sets error on curation_concern and return false' do
131
+ expect(subject.create(attributes)).to be false
132
+ expect(subject.curation_concern.errors[:lease_expiration_date].first).to eq 'Must be a future date'
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -4,7 +4,7 @@ require 'redlock'
4
4
  describe CurationConcerns::GenericWorkActor do
5
5
  include ActionDispatch::TestProcess
6
6
 
7
- let(:user) { FactoryGirl.create(:user) }
7
+ let(:user) { create(:user) }
8
8
  let(:file) { curation_concerns_fixture_file_upload('files/image.png', 'image/png') }
9
9
 
10
10
  let(:redlock_client_stub) { # stub out redis connection
@@ -15,7 +15,7 @@ describe CurationConcerns::GenericWorkActor do
15
15
  }
16
16
 
17
17
  subject do
18
- CurationConcerns::CurationConcern.actor(curation_concern, user, attributes)
18
+ CurationConcerns::CurationConcern.actor(curation_concern, user)
19
19
  end
20
20
 
21
21
  describe '#create' do
@@ -28,7 +28,7 @@ describe CurationConcerns::GenericWorkActor do
28
28
  it 'returns false' do
29
29
  expect_any_instance_of(described_class).to receive(:save).and_return(false)
30
30
  allow(subject).to receive(:attach_files).and_return(true)
31
- expect(subject.create).to be false
31
+ expect(subject.create(attributes)).to be false
32
32
  end
33
33
  end
34
34
 
@@ -36,88 +36,32 @@ describe CurationConcerns::GenericWorkActor do
36
36
  let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
37
37
 
38
38
  context 'with embargo' do
39
- let(:attributes) do
40
- { title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
41
- visibility_during_embargo: 'authenticated', embargo_release_date: date.to_s,
42
- visibility_after_embargo: 'open', visibility_during_lease: 'open',
43
- lease_expiration_date: '2014-06-12', visibility_after_lease: 'restricted',
44
- rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
45
- end
46
-
47
- context 'with a valid embargo date' do
39
+ context "with attached files" do
48
40
  let(:date) { Date.today + 2 }
49
- it 'interprets and apply embargo and lease visibility settings' do
50
- subject.create
51
- expect(curation_concern).to be_persisted
52
- expect(curation_concern.visibility_during_embargo).to eq 'authenticated'
53
- expect(curation_concern.visibility_after_embargo).to eq 'open'
54
- expect(curation_concern.visibility).to eq 'authenticated'
55
- end
56
- context "with attached files" do
57
- let(:attributes) do
58
- { title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
59
- visibility_during_embargo: 'authenticated', embargo_release_date: date.to_s,
60
- visibility_after_embargo: 'open', visibility_during_lease: 'open',
61
- lease_expiration_date: '2014-06-12', visibility_after_lease: 'restricted',
62
- files: [
63
- file
64
- ],
65
- rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
66
- end
67
-
68
- before { redlock_client_stub }
69
-
70
- it "applies it to attached files" do
71
- allow(CharacterizeJob).to receive(:perform_later).and_return(true)
72
- subject.create
73
- file = curation_concern.file_sets.first
74
- expect(file).to be_persisted
75
- expect(file.visibility_during_embargo).to eq 'authenticated'
76
- expect(file.visibility_after_embargo).to eq 'open'
77
- expect(file.visibility).to eq 'authenticated'
78
- end
79
- end
80
- end
81
-
82
- context 'when embargo_release_date is in the past' do
83
- let(:date) { Date.today - 2 }
84
- it 'sets error on curation_concern and return false' do
85
- expect(subject.create).to be false
86
- expect(subject.curation_concern.errors[:embargo_release_date].first).to eq 'Must be a future date'
41
+ let(:attributes) do
42
+ { title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
43
+ visibility_during_embargo: 'authenticated', embargo_release_date: date.to_s,
44
+ visibility_after_embargo: 'open', visibility_during_lease: 'open',
45
+ lease_expiration_date: '2014-06-12', visibility_after_lease: 'restricted',
46
+ files: [
47
+ file
48
+ ],
49
+ rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
87
50
  end
88
- end
89
- end
90
-
91
- context 'with lease' do
92
- let(:attributes) do
93
- { title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE,
94
- visibility_during_embargo: 'authenticated', embargo_release_date: '2099-05-12',
95
- visibility_after_embargo: 'open', visibility_during_lease: 'open',
96
- lease_expiration_date: date.to_s, visibility_after_lease: 'restricted',
97
- rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
98
- end
99
51
 
100
- context 'with a valid lease date' do
101
- let(:date) { Date.today + 2 }
102
- it 'interprets and apply embargo and lease visibility settings' do
103
- subject.create
104
- expect(curation_concern).to be_persisted
105
- expect(curation_concern.embargo_release_date).to be_nil
106
- expect(curation_concern.visibility_during_lease).to eq 'open'
107
- expect(curation_concern.visibility_after_lease).to eq 'restricted'
108
- expect(curation_concern.visibility).to eq 'open'
109
- end
110
- end
52
+ before { redlock_client_stub }
111
53
 
112
- context 'when lease_expiration_date is in the past' do
113
- let(:date) { Date.today - 2 }
114
- it 'sets error on curation_concern and return false' do
115
- expect(subject.create).to be false
116
- expect(subject.curation_concern.errors[:lease_expiration_date].first).to eq 'Must be a future date'
54
+ it "applies embargo to attached files" do
55
+ allow(CharacterizeJob).to receive(:perform_later).and_return(true)
56
+ subject.create(attributes)
57
+ file = curation_concern.file_sets.first
58
+ expect(file).to be_persisted
59
+ expect(file.visibility_during_embargo).to eq 'authenticated'
60
+ expect(file.visibility_after_embargo).to eq 'open'
61
+ expect(file.visibility).to eq 'authenticated'
117
62
  end
118
63
  end
119
64
  end
120
-
121
65
  context 'with a file' do
122
66
  let(:attributes) do
123
67
  FactoryGirl.attributes_for(:generic_work, visibility: visibility).tap do |a|
@@ -133,7 +77,7 @@ describe CurationConcerns::GenericWorkActor do
133
77
 
134
78
  it 'stamps each file with the access rights' do
135
79
  expect(CharacterizeJob).to receive(:perform_later)
136
- expect(subject.create).to be true
80
+ expect(subject.create(attributes)).to be true
137
81
  expect(curation_concern).to be_persisted
138
82
  expect(curation_concern.date_uploaded).to eq xmas
139
83
  expect(curation_concern.date_modified).to eq xmas
@@ -167,7 +111,7 @@ describe CurationConcerns::GenericWorkActor do
167
111
  it 'stamps each file with the access rights' do
168
112
  expect(CharacterizeJob).to receive(:perform_later).twice
169
113
 
170
- expect(subject.create).to be true
114
+ expect(subject.create(attributes)).to be true
171
115
  expect(curation_concern).to be_persisted
172
116
  expect(curation_concern.date_uploaded).to eq xmas
173
117
  expect(curation_concern.date_modified).to eq xmas
@@ -187,7 +131,7 @@ describe CurationConcerns::GenericWorkActor do
187
131
  end
188
132
 
189
133
  it 'stamps each link with the access rights' do
190
- expect(subject.create).to be true
134
+ expect(subject.create(attributes)).to be true
191
135
  expect(curation_concern).to be_persisted
192
136
  expect(curation_concern.title).to eq ['this is present']
193
137
  end
@@ -196,29 +140,20 @@ describe CurationConcerns::GenericWorkActor do
196
140
  end
197
141
 
198
142
  describe '#update' do
199
- let(:curation_concern) { FactoryGirl.create(:generic_work, user: user) }
143
+ let(:curation_concern) { create(:generic_work, user: user) }
200
144
 
201
145
  context 'failure' do
202
146
  let(:attributes) { {} }
203
147
 
204
148
  it 'returns false' do
205
149
  expect_any_instance_of(described_class).to receive(:save).and_return(false)
206
- expect(subject.update).to be false
207
- end
208
- end
209
-
210
- context 'valid attributes' do
211
- let(:attributes) { {} }
212
- it 'interprets and apply embargo and lease visibility settings' do
213
- expect(subject).to receive(:interpret_lease_visibility).and_return(true)
214
- expect(subject).to receive(:interpret_embargo_visibility).and_return(true)
215
- subject.update
150
+ expect(subject.update(attributes)).to be false
216
151
  end
217
152
  end
218
153
 
219
154
  context 'adding to collections' do
220
- let!(:collection1) { FactoryGirl.create(:collection, user: user) }
221
- let!(:collection2) { FactoryGirl.create(:collection, user: user) }
155
+ let!(:collection1) { create(:collection, user: user) }
156
+ let!(:collection2) { create(:collection, user: user) }
222
157
  let(:attributes) do
223
158
  FactoryGirl.attributes_for(:generic_work, collection_ids: [collection2.id])
224
159
  end
@@ -234,7 +169,7 @@ describe CurationConcerns::GenericWorkActor do
234
169
  expect(curation_concern.in_collections).to eq [collection1]
235
170
  # before running actor.update, the work is in collection1
236
171
 
237
- expect(subject.update).to be true
172
+ expect(subject.update(attributes)).to be true
238
173
 
239
174
  curation_concern.reload
240
175
  expect(curation_concern.identifier).to be_blank
@@ -247,14 +182,13 @@ describe CurationConcerns::GenericWorkActor do
247
182
  context 'with multiple file sets' do
248
183
  let(:file_set1) { create(:file_set) }
249
184
  let(:file_set2) { create(:file_set) }
250
- let(:curation_concern) { FactoryGirl.create(:generic_work, user: user, ordered_members: [file_set1, file_set2]) }
185
+ let(:curation_concern) { create(:generic_work, user: user, ordered_members: [file_set1, file_set2]) }
251
186
  let(:attributes) do
252
187
  FactoryGirl.attributes_for(:generic_work, ordered_member_ids: [file_set2.id, file_set1.id])
253
188
  end
254
189
  it 'updates the order of file sets' do
255
190
  expect(curation_concern.ordered_members.to_a).to eq [file_set1, file_set2]
256
-
257
- expect(subject.update).to be true
191
+ expect(subject.update(attributes)).to be true
258
192
 
259
193
  curation_concern.reload
260
194
  expect(curation_concern.ordered_members.to_a).to eq [file_set2, file_set1]
@@ -267,7 +201,7 @@ describe CurationConcerns::GenericWorkActor do
267
201
  it "works" do
268
202
  expect(curation_concern.ordered_members.to_a).to eq [file_set1, file_set2]
269
203
 
270
- expect(subject.update).to be true
204
+ expect(subject.update(attributes)).to be true
271
205
 
272
206
  curation_concern.reload
273
207
  expect(curation_concern.ordered_members.to_a).to eq [file_set2]
@@ -90,11 +90,16 @@ describe CurationConcerns::FileSetsController do
90
90
  end
91
91
 
92
92
  describe 'updated' do
93
- before { put :update, id: resource, file_set: { title: ['updated title'] }, format: :json }
93
+ let(:actor) { double }
94
+ before do
95
+ allow(controller).to receive(:actor).and_return(actor)
96
+ end
94
97
  it "returns json of updated work and sets location header" do
98
+ expect(actor).to receive(:update_metadata).with(title: ['updated title']).and_return(true)
99
+ put :update, id: resource, file_set: { title: ['updated title'] }, format: :json
95
100
  expect(assigns[:file_set]).to be_instance_of ::FileSet # this object is used by the jbuilder template
96
- expect(controller).to render_template('curation_concerns/file_sets/show')
97
101
  expect(response.status).to eq 200
102
+ expect(controller).to render_template('curation_concerns/file_sets/show')
98
103
  created_resource = assigns[:file_set]
99
104
  expect(response.location).to eq main_app.curation_concerns_file_set_path(created_resource)
100
105
  end
@@ -106,10 +106,9 @@ describe CurationConcerns::FileSetsController do
106
106
 
107
107
  describe 'update' do
108
108
  let!(:file_set) do
109
- file_set = FileSet.new.tap do |gf|
109
+ file_set = FileSet.create do |gf|
110
110
  gf.apply_depositor_metadata(user)
111
111
  gf.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
112
- gf.save!
113
112
  end
114
113
  parent.ordered_members << file_set
115
114
  parent.save
@@ -62,19 +62,24 @@ describe CurationConcerns::GenericWorksController do
62
62
  end
63
63
 
64
64
  describe '#create' do
65
+ let(:actor) { double(create: create_status) }
66
+ before do
67
+ allow(CurationConcerns::CurationConcern).to receive(:actor).and_return(actor)
68
+ end
69
+ let(:create_status) { true }
70
+
65
71
  context 'when create is successful' do
66
72
  let(:work) { stub_model(GenericWork) }
67
73
  it 'creates a work' do
68
74
  allow(controller).to receive(:curation_concern).and_return(work)
69
- expect_any_instance_of(CurationConcerns::GenericWorkActor).to receive(:create).and_return(true)
70
75
  post :create, generic_work: { title: ['a title'] }
71
76
  expect(response).to redirect_to main_app.curation_concerns_generic_work_path(work)
72
77
  end
73
78
  end
74
79
 
75
80
  context 'when create fails' do
81
+ let(:create_status) { false }
76
82
  it 'draws the form again' do
77
- expect_any_instance_of(CurationConcerns::GenericWorkActor).to receive(:create).and_return(false)
78
83
  post :create, generic_work: { title: ['a title'] }
79
84
  expect(response.status).to eq 422
80
85
  expect(assigns[:form]).to be_kind_of CurationConcerns::GenericWorkForm
@@ -136,8 +141,10 @@ describe CurationConcerns::GenericWorksController do
136
141
  let(:a_work) { create(:private_generic_work, user: user) }
137
142
  before do
138
143
  allow(CurationConcerns::CurationConcern).to receive(:actor).and_return(actor)
144
+ allow_any_instance_of(GenericWork).to receive(:visibility_changed?).and_return(visibility_changed)
139
145
  end
140
- let(:actor) { double(update: true, visibility_changed?: false) }
146
+ let(:visibility_changed) { false }
147
+ let(:actor) { double(update: true) }
141
148
 
142
149
  it 'updates the work' do
143
150
  patch :update, id: a_work, generic_work: {}
@@ -145,14 +152,13 @@ describe CurationConcerns::GenericWorksController do
145
152
  end
146
153
 
147
154
  it "can update file membership" do
148
- file = create(:file_set, user: user)
149
-
150
- patch :update, id: a_work, generic_work: { ordered_member_ids: [file.id] }
151
- expect(CurationConcerns::CurationConcern).to have_received(:actor).with(anything, anything, ordered_member_ids: [file.id])
155
+ patch :update, id: a_work, generic_work: { ordered_member_ids: ['foo_123'] }
156
+ expect(actor).to have_received(:update).with(ordered_member_ids: ['foo_123'])
152
157
  end
153
158
 
154
159
  describe 'changing rights' do
155
- let(:actor) { double(update: true, visibility_changed?: true) }
160
+ let(:visibility_changed) { true }
161
+ let(:actor) { double(update: true) }
156
162
 
157
163
  context 'when there are children' do
158
164
  let(:a_work) { create(:work_with_one_file, user: user) }
@@ -172,7 +178,7 @@ describe CurationConcerns::GenericWorksController do
172
178
  end
173
179
 
174
180
  describe 'failure' do
175
- let(:actor) { double(update: false, visibility_changed?: false) }
181
+ let(:actor) { double(update: false) }
176
182
 
177
183
  it 'renders the form' do
178
184
  patch :update, id: a_work, generic_work: {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curation_concerns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-03-31 00:00:00.000000000 Z
13
+ date: 2016-04-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hydra-head
@@ -88,14 +88,14 @@ dependencies:
88
88
  requirements:
89
89
  - - '='
90
90
  - !ruby/object:Gem::Version
91
- version: 0.11.0
91
+ version: 0.12.0.pre1
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - '='
97
97
  - !ruby/object:Gem::Version
98
- version: 0.11.0
98
+ version: 0.12.0.pre1
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: hydra-editor
101
101
  requirement: !ruby/object:Gem::Requirement
@@ -733,11 +733,12 @@ files:
733
733
  - spec/abilities/embargo_and_lease_ability_spec.rb
734
734
  - spec/abilities/file_set_abilities_spec.rb
735
735
  - spec/abilities/generic_work_abilities_spec.rb
736
+ - spec/actors/curation_concerns/add_to_collections_actor_spec.rb
736
737
  - spec/actors/curation_concerns/embargo_actor_spec.rb
737
738
  - spec/actors/curation_concerns/file_actor_spec.rb
738
739
  - spec/actors/curation_concerns/file_set_actor_spec.rb
740
+ - spec/actors/curation_concerns/interpret_visibility_actor_spec.rb
739
741
  - spec/actors/curation_concerns/lease_actor_spec.rb
740
- - spec/actors/curation_concerns/manages_embargoes_actor_spec.rb
741
742
  - spec/actors/curation_concerns/work_actor_spec.rb
742
743
  - spec/controllers/catalog_controller_spec.rb
743
744
  - spec/controllers/curation_concerns/classify_concerns_controller_spec.rb
@@ -912,9 +913,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
912
913
  version: '0'
913
914
  required_rubygems_version: !ruby/object:Gem::Requirement
914
915
  requirements:
915
- - - ">="
916
+ - - ">"
916
917
  - !ruby/object:Gem::Version
917
- version: '0'
918
+ version: 1.3.1
918
919
  requirements: []
919
920
  rubyforge_project:
920
921
  rubygems_version: 2.5.1
@@ -927,11 +928,12 @@ test_files:
927
928
  - spec/abilities/embargo_and_lease_ability_spec.rb
928
929
  - spec/abilities/file_set_abilities_spec.rb
929
930
  - spec/abilities/generic_work_abilities_spec.rb
931
+ - spec/actors/curation_concerns/add_to_collections_actor_spec.rb
930
932
  - spec/actors/curation_concerns/embargo_actor_spec.rb
931
933
  - spec/actors/curation_concerns/file_actor_spec.rb
932
934
  - spec/actors/curation_concerns/file_set_actor_spec.rb
935
+ - spec/actors/curation_concerns/interpret_visibility_actor_spec.rb
933
936
  - spec/actors/curation_concerns/lease_actor_spec.rb
934
- - spec/actors/curation_concerns/manages_embargoes_actor_spec.rb
935
937
  - spec/actors/curation_concerns/work_actor_spec.rb
936
938
  - spec/controllers/catalog_controller_spec.rb
937
939
  - spec/controllers/curation_concerns/classify_concerns_controller_spec.rb
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
- describe CurationConcerns::ManagesEmbargoesActor do
3
- let(:model) do
4
- Class.new(CurationConcerns::BaseActor) do
5
- include CurationConcerns::ManagesEmbargoesActor
6
- end
7
- end
8
-
9
- let(:user) { User.new }
10
- let(:curation_concern) { GenericWork.new }
11
- let(:attributes) { {} }
12
- subject do
13
- model.new(curation_concern, user, attributes)
14
- end
15
- let(:date) { Date.today + 2 }
16
-
17
- context '#interpret_visibility' do
18
- it 'interprets lease and embargo visibility' do
19
- expect(subject).to receive(:interpret_lease_visibility).and_return(true)
20
- expect(subject).to receive(:interpret_embargo_visibility).and_return(true)
21
- expect(subject.interpret_visibility).to be true
22
- end
23
- it 'collects failures from interpreting lease & embargo visibility' do
24
- expect(subject).to receive(:interpret_embargo_visibility).and_return(true)
25
- expect(subject).to receive(:interpret_lease_visibility).and_return(false)
26
- expect(subject.interpret_visibility).to be false
27
- end
28
- end
29
-
30
- context '#interpret_embargo_visibility' do
31
- context 'when visibility is not set to embargo' do
32
- let(:attributes) do
33
- { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
34
- visibility_during_embargo: 'restricted', visibility_after_embargo: 'open' }
35
- end
36
- it 'removes the embargo attributes and returns true' do
37
- expect(subject.interpret_embargo_visibility).to be true
38
- expect(subject.attributes.keys).to eq ['visibility']
39
- end
40
- end
41
-
42
- context 'when visibility is set to embargo' do
43
- let(:attributes) do
44
- { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
45
- visibility_during_embargo: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE,
46
- visibility_after_embargo: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
47
- embargo_release_date: date.to_s }
48
- end
49
-
50
- it 'applies the embargo remove embargo attributes except for embargo_release_date and return true' do
51
- expect(subject.curation_concern).to receive(:apply_embargo).with(date.to_s, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC)
52
- expect(subject.interpret_embargo_visibility).to be true
53
- expect(subject.attributes.keys).to eq ['embargo_release_date']
54
- end
55
-
56
- context 'when embargo_release_date is not set' do
57
- let(:attributes) { { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO } }
58
- it 'sets error on curation_concern and return false' do
59
- expect(subject.interpret_embargo_visibility).to be false
60
- expect(subject.curation_concern.errors[:visibility].first).to eq 'When setting visibility to "embargo" you must also specify embargo release date.'
61
- end
62
- end
63
- end
64
- end
65
-
66
- context '#interpret_lease_visibility' do
67
- context 'when visibility is not set to lease' do
68
- let(:attributes) do
69
- { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
70
- visibility_during_lease: 'open', visibility_after_lease: 'restricted' }
71
- end
72
- it 'removes the lease attributes and returns true' do
73
- expect(subject.interpret_lease_visibility).to be true
74
- expect(subject.attributes.keys).to eq ['visibility']
75
- end
76
- end
77
-
78
- context 'when visibility is set to lease' do
79
- let(:attributes) do
80
- { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE,
81
- visibility_during_lease: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE,
82
- visibility_after_lease: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
83
- lease_expiration_date: date.to_s }
84
- end
85
-
86
- it 'applies the lease, remove lease attributes except for lease_expiration_date and return true' do
87
- expect(subject.curation_concern).to receive(:apply_lease).with(date.to_s, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC)
88
- expect(subject.interpret_lease_visibility).to be true
89
- expect(subject.attributes.keys).to eq ['lease_expiration_date']
90
- end
91
-
92
- context 'when lease_expiration_date is not set' do
93
- let(:attributes) { { visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE } }
94
- it 'sets error on curation_concern and return false' do
95
- expect(subject.interpret_lease_visibility).to be false
96
- expect(subject.curation_concern.errors[:visibility].first).to eq 'When setting visibility to "lease" you must also specify lease expiration date.'
97
- end
98
- end
99
- end
100
- end
101
- end