save_queue 0.2.3 → 0.3.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.
- data/.gitignore +13 -4
- data/.travis.yml +4 -1
- data/CONTRIBUTING.md +120 -0
- data/HISTORY.md +11 -0
- data/LICENSE +13 -4
- data/README.md +282 -55
- data/Rakefile +10 -3
- data/lib/save_queue/exceptions.rb +13 -0
- data/lib/save_queue/object.rb +41 -18
- data/lib/save_queue/object_queue.rb +87 -0
- data/lib/save_queue/plugins/notification/object.rb +35 -0
- data/lib/save_queue/plugins/notification/queue.rb +25 -0
- data/lib/save_queue/plugins/notification.rb +15 -0
- data/lib/save_queue/plugins/validation/exceptions.rb +12 -0
- data/lib/save_queue/plugins/validation/queue.rb +16 -17
- data/lib/save_queue/plugins/validation.rb +4 -17
- data/lib/save_queue/ruby1.9/observer.rb +204 -0
- data/lib/save_queue/uniq_queue.rb +38 -0
- data/lib/save_queue/version.rb +1 -1
- data/lib/save_queue.rb +1 -0
- data/save_queue.gemspec +4 -3
- data/spec/notification/notification_spec.rb +45 -0
- data/spec/notification/object_spec.rb +54 -0
- data/spec/notification/queue_spec.rb +28 -0
- data/spec/object_queue_spec.rb +155 -0
- data/spec/object_spec.rb +208 -0
- data/spec/save_queue_spec.rb +75 -0
- data/spec/support/object_helpers.rb +10 -0
- data/spec/support/queue_helpers.rb +26 -0
- data/spec/uniq_queue_spec.rb +132 -0
- data/spec/validation/queue_spec.rb +139 -0
- data/spec/validation/validation_spec.rb +42 -0
- metadata +35 -20
- data/lib/save_queue/plugins/validation/object.rb +0 -25
- data/lib/save_queue/queue.rb +0 -45
- data/spec/save_queue_usage_spec.rb +0 -311
- data/spec/support/mock_helpers.rb +0 -17
- data/spec/validation_spec.rb +0 -126
data/spec/validation_spec.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "save_queue/plugins/validation"
|
3
|
-
|
4
|
-
describe SaveQueue::Plugins::Validation do
|
5
|
-
before(:each) do
|
6
|
-
@invalid = new_object
|
7
|
-
@invalid.stub(:valid?).and_return(false)
|
8
|
-
@valid = new_object
|
9
|
-
@valid.stub(:valid?).and_return(true)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe SaveQueue::Plugins::Validation::Object do
|
13
|
-
before(:each) do
|
14
|
-
@base = new_object
|
15
|
-
end
|
16
|
-
|
17
|
-
context "valid object and caller" do
|
18
|
-
before(:each) do
|
19
|
-
@base.save_queue.add @valid
|
20
|
-
@base.stub(:valid?).and_return(true)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should save caller" do
|
24
|
-
@base.save.should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should save queue" do
|
28
|
-
@valid.should_receive(:save)
|
29
|
-
|
30
|
-
@base.save
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "invalid caller" do
|
35
|
-
it "should not save queue" do
|
36
|
-
@base.save_queue.add @valid
|
37
|
-
|
38
|
-
@base.stub(:valid?).and_return(false)
|
39
|
-
|
40
|
-
@valid.should_not_receive(:save)
|
41
|
-
@base.save.should be_false
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "invalid object in queue" do
|
46
|
-
before(:each) do
|
47
|
-
@base.save_queue.add @valid
|
48
|
-
@base.save_queue.add @invalid
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should not save caller" do
|
52
|
-
@base.save.should be_false
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should not save queue" do
|
56
|
-
@invalid.should_not_receive(:save)
|
57
|
-
@valid.should_not_receive(:save)
|
58
|
-
|
59
|
-
@base.save
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe SaveQueue::Plugins::Validation::Queue do
|
65
|
-
before(:each) do
|
66
|
-
@save_queue = SaveQueue::Plugins::Validation::Queue.new
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#valid?" do
|
70
|
-
it "should set objects_with_errors" do
|
71
|
-
@save_queue.add @invalid
|
72
|
-
@save_queue.add @valid
|
73
|
-
|
74
|
-
@save_queue.valid?.should be_false
|
75
|
-
|
76
|
-
@save_queue.objects_with_errors.should include @invalid
|
77
|
-
@save_queue.objects_with_errors.should_not include @valid
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "#validate!" do
|
82
|
-
it "should raise FailedValidationError if failed to save objects" do
|
83
|
-
@save_queue.add @invalid
|
84
|
-
@save_queue.add @valid
|
85
|
-
|
86
|
-
expect{ @save_queue.validate! }.to raise_error SaveQueue::Plugins::Validation::FailedValidationError
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should return true if objects were valid" do
|
90
|
-
@save_queue.add @valid
|
91
|
-
|
92
|
-
expect{ @save_queue.validate! }.to_not raise_error SaveQueue::Plugins::Validation::FailedValidationError
|
93
|
-
|
94
|
-
@save_queue.validate!.should be_true
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#integration" do
|
100
|
-
before(:each) do
|
101
|
-
@klass = Class.new
|
102
|
-
@klass.send :include, SaveQueue
|
103
|
-
@klass.send :include, SaveQueue::Plugins::Validation
|
104
|
-
end
|
105
|
-
it "should set query_class to SaveQueue::Plugins::Validation::Queue" do
|
106
|
-
@klass.queue_class.should == SaveQueue::Plugins::Validation::Queue
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should mix SaveQueue::Plugins::Validation::Object" do
|
110
|
-
@klass.should include SaveQueue::Plugins::Validation::Object
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
def new_object
|
116
|
-
klass = Class.new
|
117
|
-
klass.send :include, SaveQueue
|
118
|
-
klass.send :include, SaveQueue::Plugins::Validation
|
119
|
-
|
120
|
-
object = klass.new
|
121
|
-
object.stub(:valid?).and_return(true)
|
122
|
-
object.mark_as_changed
|
123
|
-
|
124
|
-
object
|
125
|
-
end
|
126
|
-
end
|