save_queue 0.3.0 → 0.4.0

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.
@@ -3,7 +3,7 @@ require "save_queue/uniq_queue"
3
3
 
4
4
  describe SaveQueue::UniqQueue do
5
5
  let(:queue) { SaveQueue::UniqQueue.new }
6
- #let(:element) { new_element(:element) }
6
+ let(:element) { new_element(:element) }
7
7
 
8
8
  [:size, :count].each do |method|
9
9
  describe "##{method}" do
@@ -28,30 +28,35 @@ describe SaveQueue::UniqQueue do
28
28
  end
29
29
  end
30
30
 
31
- [:add, :<<, :push].each do |method|
32
- describe "##{method}" do
33
- let(:element) { new_element }
34
- it "should add object to a queue" do
35
- queue.should be_empty
31
+ shared_examples_for "add method" do
32
+ it "should add object to a queue" do
33
+ queue.should be_empty
36
34
 
37
- queue.send(method, new_element)
38
- queue.should_not be_empty
39
- queue.should have(1).elements
35
+ queue.send(method, new_element)
36
+ queue.should_not be_empty
37
+ queue.should have(1).elements
40
38
 
41
- queue.send(method, new_element)
42
- queue.should_not be_empty
43
- queue.should have(2).elements
44
- end
39
+ queue.send(method, new_element)
40
+ queue.should_not be_empty
41
+ queue.should have(2).elements
42
+ end
45
43
 
46
- it "should add object to a queue once" do
47
- queue.should be_empty
44
+ it "should add object to a queue once" do
45
+ queue.should be_empty
48
46
 
49
- queue.send(method, element)
50
- queue.should have(1).elements
47
+ queue.send(method, element)
48
+ queue.should have(1).elements
51
49
 
52
- queue.send(method, element)
53
- queue.should have(1).elements
54
- end
50
+ queue.send(method, element)
51
+ queue.should have(1).elements
52
+ end
53
+ end
54
+
55
+ # TODO is that clear? is refactoring needed here?
56
+ (ADD_METHODS - %w(<<)).each do |add_method|
57
+ describe "##{add_method}" do
58
+ let(:method) { add_method }
59
+ it_behaves_like "add method"
55
60
 
56
61
  it "should return true" do
57
62
  queue.send(method, element).should === true
@@ -60,18 +65,43 @@ describe SaveQueue::UniqQueue do
60
65
  it "should return false if element was not added" do
61
66
  queue.send(method, element)
62
67
  queue.should have(1).elements
63
-
68
+
64
69
  queue.send(method, element).should === false
65
70
  end
66
71
  end
67
72
  end
68
73
 
74
+ describe "#<<" do
75
+ let(:method) { :<< }
76
+ it_behaves_like "add method"
77
+
78
+ it "should be able to add objects in chain" do
79
+ queue << new_element << new_element
80
+ queue.should have(2).elements
81
+ end
82
+ end
83
+
69
84
  describe "#add_all" do
85
+ it "should add a collection to queue" do
86
+ queue.should be_empty
87
+
88
+ collection = [1,2,3]
89
+ queue.add_all collection
90
+
91
+ queue.should have(3).elements
92
+ end
93
+
70
94
  it "should delegate to #add" do
71
95
  queue.should_receive(:add).exactly(3).times
72
96
  queue.add_all [1,2,3]
73
97
  end
74
98
 
99
+ context "not array object passed as parameter" do
100
+ it_behaves_like "add method" do
101
+ let(:method) { "add" }
102
+ end
103
+ end
104
+
75
105
  it "should act as #add if single argument passed" do
76
106
  queue.should_receive(:add).once
77
107
  queue.add_all 1
@@ -1,13 +1,25 @@
1
1
  require "spec_helper"
2
2
  require "save_queue/plugins/validation/queue"
3
3
 
4
- class ValidQueue < SaveQueue::ObjectQueue
4
+ class QueueWithValidation < SaveQueue::ObjectQueue
5
5
  include SaveQueue::Plugins::Validation::Queue
6
6
  end
7
7
 
8
8
 
9
- describe ValidQueue do
10
- let(:queue) { ValidQueue.new }
9
+ describe SaveQueue::Plugins::Validation::Queue do
10
+ let(:queue) { QueueWithValidation.new }
11
+
12
+ context "is empty" do
13
+ specify { queue.should be_valid }
14
+
15
+ describe "#save" do
16
+ specify { queue.save.should be_true }
17
+ end
18
+
19
+ describe "#save!" do
20
+ specify { expect { queue.save! }.to_not raise_error }
21
+ end
22
+ end
11
23
 
12
24
  context "contains valid objects" do
13
25
  let(:valid_objects) do
@@ -21,80 +33,119 @@ describe ValidQueue do
21
33
  end
22
34
 
23
35
  describe "#save" do
24
- it "should save all of them" do
36
+ specify { queue.save.should be_true }
37
+
38
+ it "should save all elements" do
25
39
  valid_objects.each{|o| o.should_receive(:save).once}
26
40
  queue.save.should be_true
27
41
  end
28
-
29
- it "should not has any errors" do
30
- queue.save.should be_true
31
- queue.errors.should be_empty
32
- end
33
42
  end
34
43
 
35
44
  describe "#save!" do
36
- it "should save all of them" do
45
+ specify { expect { queue.save! }.to_not raise_error }
46
+
47
+ it "should save all elements" do
37
48
  valid_objects.each{|o| o.should_receive(:save).once}
38
49
  queue.save!
39
50
  end
51
+ end
40
52
 
41
- it "should not raise any exception" do
42
- expect { queue.save! }.not_to raise_error
43
- end
53
+ describe "#valid?" do
54
+ specify {queue.valid?.should be_true}
44
55
 
45
56
  it "should not has any errors" do
46
- queue.save!
57
+ queue.valid?
47
58
  queue.errors.should be_empty
48
59
  end
49
60
  end
50
- end
51
61
 
62
+ describe "#validate!" do
63
+ it "should not raise any exception" do
64
+ expect { queue.validate! }.not_to raise_error
65
+ end
52
66
 
53
- describe "contains invalid objects" do
54
- let(:invalid_objects) do
55
- 3.times.map do
56
- new_velement(:valid => false)
67
+ it "should not has any errors" do
68
+ queue.validate!
69
+ queue.errors.should be_empty
57
70
  end
58
71
  end
72
+ end
59
73
 
74
+ shared_context "queue with invalid objects" do
60
75
  before(:each) do
61
- queue.add_all invalid_objects
76
+ queue.add_all objects
62
77
  end
63
78
 
64
79
  describe "#save" do
65
- it "should not saved them" do
66
- invalid_objects.each{|o| o.should_not_receive(:save)}
80
+ specify { queue.save.should be_false }
81
+
82
+ it "should not save elements" do
83
+ objects.each{|o| o.should_not_receive(:save)}
67
84
  queue.save.should be_false
68
85
  end
69
-
70
- it "should set errors" do
71
- queue.save.should be_false
72
- queue.errors[:validation].should_not be_empty
73
- end
74
86
  end
75
87
 
76
88
  describe "#save!" do
77
- it "should not saved them" do
78
- invalid_objects.each do |o|
89
+ specify { expect {queue.save!}.to raise_error(SaveQueue::FailedValidationError) }
90
+
91
+ it "should not save elements" do
92
+ objects.each do |o|
79
93
  o.as_null_object
80
94
  o.should_not_receive(:save)
81
95
  end
96
+ end
97
+ end
98
+
99
+ describe "#valid?" do
100
+ specify {queue.valid?.should be_false}
82
101
 
83
- expect {queue.save!}.to raise_error
102
+ it "should set errors" do
103
+ queue.valid?
104
+ queue.errors[:validation].should_not be_empty
84
105
  end
106
+ end
85
107
 
108
+ describe "#validate!" do
86
109
  it "should raise SaveQueue::FailedValidationError exception" do
87
- expect { queue.save! }.to raise_error(SaveQueue::FailedValidationError)
110
+ expect { queue.validate! }.to raise_error(SaveQueue::FailedValidationError)
88
111
  end
89
112
 
90
113
  it "should set errors" do
91
- expect{queue.save!}.to raise_error
114
+ expect{queue.validate!}.to raise_error
92
115
  queue.errors[:validation].should_not be_empty
93
116
  end
94
117
  end
118
+
95
119
  end
96
120
 
121
+ context "contains invalid objects" do
122
+ it_behaves_like "queue with invalid objects" do
123
+ let(:objects) do
124
+ 3.times.map { new_velement(:valid => false) }
125
+ end
126
+ end
127
+ end
97
128
 
129
+ context"contains mix of valid and invalid objects" do
130
+ it_behaves_like "queue with invalid objects" do
131
+ let(:objects) do
132
+ 2.times.map do
133
+ new_velement(:valid => true)
134
+ new_velement(:valid => false)
135
+ end
136
+ end
137
+ end
138
+
139
+ it "#save should call #valid?" do
140
+ queue.should_receive(:valid?)
141
+ queue.save
142
+ end
143
+
144
+ it "#save! should call #validate!" do
145
+ queue.should_receive(:validate!)
146
+ queue.save!
147
+ end
148
+ end
98
149
  #before(:each) do
99
150
  # @invalid = new_object
100
151
  # @invalid.stub(:valid?).and_return(false)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: save_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-23 00:00:00.000000000 Z
12
+ date: 2012-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &7350280 !ruby/object:Gem::Requirement
16
+ requirement: &8163240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *7350280
24
+ version_requirements: *8163240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &7366200 !ruby/object:Gem::Requirement
27
+ requirement: &8162240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *7366200
35
+ version_requirements: *8162240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hooks
38
- requirement: &7365720 !ruby/object:Gem::Requirement
38
+ requirement: &8161700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *7365720
46
+ version_requirements: *8161700
47
47
  description: ! 'Save Queue allows to push objects to other object''s queue for a delayed
48
48
  save.
49
49
 
@@ -66,7 +66,10 @@ files:
66
66
  - lib/save_queue.rb
67
67
  - lib/save_queue/exceptions.rb
68
68
  - lib/save_queue/object.rb
69
+ - lib/save_queue/object/queue_class_management.rb
69
70
  - lib/save_queue/object_queue.rb
71
+ - lib/save_queue/plugins/dirty.rb
72
+ - lib/save_queue/plugins/dirty/object.rb
70
73
  - lib/save_queue/plugins/notification.rb
71
74
  - lib/save_queue/plugins/notification/object.rb
72
75
  - lib/save_queue/plugins/notification/queue.rb
@@ -77,9 +80,12 @@ files:
77
80
  - lib/save_queue/uniq_queue.rb
78
81
  - lib/save_queue/version.rb
79
82
  - save_queue.gemspec
83
+ - spec/dirty/dirty_spec.rb
84
+ - spec/dirty/object_spec.rb
80
85
  - spec/notification/notification_spec.rb
81
86
  - spec/notification/object_spec.rb
82
87
  - spec/notification/queue_spec.rb
88
+ - spec/object/queue_class_management_spec.rb
83
89
  - spec/object_queue_spec.rb
84
90
  - spec/object_spec.rb
85
91
  - spec/save_queue_spec.rb