change_manager 0.1.5 → 0.2.0

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: 04869266d59b398a40c9cfc421769bf7c9177dc4
4
- data.tar.gz: 60950b44a16edaa95b8ed7015f55a9b0c11ac151
3
+ metadata.gz: eaef00e1eb69b31268ab24e359ea02a343db52c6
4
+ data.tar.gz: 66624dafb2f25dd2f1000dee0db38302ba065b16
5
5
  SHA512:
6
- metadata.gz: a3a30a6561ee6c5f3e38231269e50f7f877ab08920e5e6c901415615e9fd4e39a2ed66bf82f9bf1eb43cc670a0c244e5851e46e6fbbc6227e83bb1ba800fc324
7
- data.tar.gz: c661dc1f0a1fd3b897634d149c0df4d7fe023a5746895dad498d927db3c6199ef9d512799f6847acc8196af9a3d90c01b885d7f790d84585d66907fc319e3970
6
+ metadata.gz: 4c6e6dc30d5565d0a67b89ea76a31746f169700b7e7a1156526eb60c523e7d3e0c2eeced999e19f5a539ab60868bb93a4a141c381fdd342cd5f9d160cfeb67f4
7
+ data.tar.gz: cc12a9ede04b38dedd74d274d3f83b7baad529e5c03703342496483cf2ec8a426e4603d9c9725c242f1f119a23bea8a852b82b4bf73789961dcf143651d30880
@@ -1,3 +1,4 @@
1
+ require 'yaml'
1
2
  module ChangeManager
2
3
  class BeginChange
3
4
  def self.queue
@@ -5,7 +6,9 @@ module ChangeManager
5
6
  end
6
7
 
7
8
  def self.perform(change_id)
8
- ChangeManager::Manager.process_change(change_id)
9
+ puts 'job started'
10
+ config ||= YAML.load_file(File.join(Curate::Engine.root, 'config/change_manager_config.yml'))
11
+ config['manager_class'].constantize.process_change(change_id)
9
12
  end
10
13
  end
11
14
  end
@@ -37,6 +37,18 @@ module ChangeManager
37
37
  self.notified
38
38
  end
39
39
 
40
+ def is_group_change?
41
+ self.change_type == 'added_to_group' || self.change_type == 'removed_from_group'
42
+ end
43
+
44
+ def is_delegate_change?
45
+ self.change_type == 'added_as_delegate' || self.change_type == 'removed_as_delegate'
46
+ end
47
+
48
+ def is_editor_change?
49
+ self.change_type == 'added_as_editor' || self.change_type == 'removed_as_editor'
50
+ end
51
+
40
52
  def inverse_of?(possible_inverse_change)
41
53
  @change_types ||= YAML.load_file(File.join(ChangeManager::Engine.root, 'config/change_types.yaml'))
42
54
  if self.context == possible_inverse_change.context
@@ -0,0 +1,5 @@
1
+ module ChangeManager
2
+ class LocalManager
3
+ extend Manager
4
+ end
5
+ end
@@ -1,12 +1,12 @@
1
1
  module ChangeManager
2
- class Manager
3
- def self.queue_change(owner, change_type, context, target)
2
+ module Manager
3
+ def queue_change(owner, change_type, context, target)
4
4
  change_id = Change.new_change(owner, change_type, context, target)
5
- # Resque.enqueue(MakeChange, change_id)
6
- Resque.enqueue_in(5.minutes, ChangeManager::BeginChange, change_id)
5
+ Resque.enqueue(ChangeManager::BeginChange, change_id)
6
+ # Resque.enqueue_in(5.minutes, ChangeManager::BeginChange, change_id)
7
7
  end
8
8
 
9
- def self.process_change(change_id)
9
+ def process_change(change_id)
10
10
  unless Change.find(change_id).cancelled?
11
11
  change = Change.find change_id
12
12
  verified_changes = process_changes change
@@ -14,12 +14,11 @@ module ChangeManager
14
14
  end
15
15
  end
16
16
 
17
- private
18
- def self.process_changes(change)
17
+ def process_changes(change)
19
18
  cancel_all_changes(group_similar_changes(change.owner, change.target))
20
19
  end
21
20
 
22
- def self.group_similar_changes(owner, target)
21
+ def group_similar_changes(owner, target)
23
22
  similar_changes = Change.where(owner: owner, target: target, cancelled: false)
24
23
  if similar_changes.length > 1
25
24
  cancel_inverse_changes(similar_changes)
@@ -27,7 +26,7 @@ module ChangeManager
27
26
  return similar_changes
28
27
  end
29
28
 
30
- def self.cancel_inverse_changes(similar_changes)
29
+ def cancel_inverse_changes(similar_changes)
31
30
  similar_changes.each do |change|
32
31
  similar_changes.each do |next_change|
33
32
  if change.inverse_of?(next_change)
@@ -41,14 +40,14 @@ module ChangeManager
41
40
  return similar_changes
42
41
  end
43
42
 
44
- def self.cancel_all_changes(verified_changes)
43
+ def cancel_all_changes(verified_changes)
45
44
  verified_changes.each do |change|
46
45
  change.cancel
47
46
  end
48
47
  verified_changes
49
48
  end
50
49
 
51
- def self.notify(changes)
50
+ def notify(changes)
52
51
  mailer = ChangeManager::NotificationMailer
53
52
  if mailer.send_email(mailer.construct_email(changes))
54
53
  changes.each do |change|
@@ -0,0 +1 @@
1
+ manager_class: LocalManager
@@ -22,50 +22,3 @@ removed_from_group:
22
22
  print: removed_from_group
23
23
  inverse: added_to_group
24
24
  human_readable: Removed from a group
25
-
26
- # added_as_delegate:
27
- # - added_as_delegate
28
- # - inverse: removed_as_delegate
29
- # - Added as a delegate
30
- # removed_as_delegate:
31
- # - removed_as_delegate
32
- # - inverse: added_as_delegate
33
- # - Removed as a delegate
34
- # added_as_editor:
35
- # - added_as_editor
36
- # - inverse: removed_as_editor
37
- # - Added as an editor
38
- # removed_as_editor:
39
- # - removed_as_editor
40
- # - inverse: added_as_editor
41
- # - Removed as an editor
42
- # added_to_group:
43
- # - added_to_group
44
- # - inverse: removed_from_group
45
- # - Added to a group
46
- # removed_from_group:
47
- # - removed_from_group
48
- # - inverse: added_to_group
49
- # - Removed from a group
50
-
51
-
52
-
53
-
54
- # - added_as_delegate
55
- # - removed_as_delegate
56
- # - added_as_editor
57
- # - removed_as_editor
58
- # - added_to_group
59
- # - removed_from_group
60
-
61
-
62
-
63
- # delegates:
64
- # - added_as_delegate
65
- # - removed_as_delegate
66
- # editors:
67
- # - added_as_editor
68
- # - removed_as_delegate
69
- # groups:
70
- # - added_to_group
71
- # - removed_from_group
@@ -1,3 +1,3 @@
1
1
  module ChangeManager
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module ChangeManager
4
- describe Manager do
4
+ describe LocalManager do
5
5
  describe '#queue_change' do
6
- let(:queued_change) { Manager.queue_change('test', 'removed_as_delegate', 'work_id1', 'testemail@gmail.com') }
6
+ let(:queued_change) { LocalManager.queue_change('test', 'removed_as_delegate', 'work_id1', 'testemail@gmail.com') }
7
7
  it 'should spawn a background worker' do
8
8
  queued_change.should be_true
9
9
  end
@@ -12,15 +12,15 @@ module ChangeManager
12
12
  let(:cancelled_change) { FactoryGirl.create(:change, cancelled: true)}
13
13
  let(:change) { FactoryGirl.create(:change) }
14
14
  it 'should do nothing if initial change is cancelled' do
15
- Manager.process_change(cancelled_change.id).should be_nil
15
+ LocalManager.process_change(cancelled_change.id).should be_nil
16
16
  end
17
17
  it 'should execute if initial change isn\'t cancelled' do
18
- Manager.process_change(change.id).should_not be_nil
18
+ LocalManager.process_change(change.id).should_not be_nil
19
19
  end
20
20
  end
21
21
  describe '#group_similar_changes:' do
22
22
  let!(:initial_change) { Change.find(Change.new_change('owner', 'added_as_editor', 'work_id1', 'target'))}
23
- let(:possible_similar_changes) { Manager.group_similar_changes(initial_change.owner, initial_change.target) }
23
+ let(:possible_similar_changes) { LocalManager.group_similar_changes(initial_change.owner, initial_change.target) }
24
24
  # describe the different changes
25
25
  # unrelated changes (owner and target aren't the same as initial - cancelled doesnt matter)
26
26
  context 'unrelated changes' do