active_harmony 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/CHANGELOG +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +20 -0
- data/README.markdown +110 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/active_harmony.gemspec +77 -0
- data/lib/active_harmony.rb +14 -0
- data/lib/active_harmony/queue.rb +50 -0
- data/lib/active_harmony/queue_item.rb +48 -0
- data/lib/active_harmony/service.rb +293 -0
- data/lib/active_harmony/service_manager.rb +31 -0
- data/lib/active_harmony/service_url.rb +18 -0
- data/lib/active_harmony/synchronizable.rb +7 -0
- data/lib/active_harmony/synchronizable/core.rb +50 -0
- data/lib/active_harmony/synchronizable/mongoid.rb +30 -0
- data/lib/active_harmony/synchronizer.rb +131 -0
- data/lib/active_harmony/synchronizer_configuration.rb +71 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/unit/active_harmony/queue_item_spec.rb +41 -0
- data/spec/unit/active_harmony/queue_spec.rb +62 -0
- data/spec/unit/active_harmony/service_manager_spec.rb +44 -0
- data/spec/unit/active_harmony/service_spec.rb +313 -0
- data/spec/unit/active_harmony/synchronizable/core_spec.rb +53 -0
- data/spec/unit/active_harmony/synchronizable/mongoid_spec.rb +26 -0
- data/spec/unit/active_harmony/synchronizer_configuration_spec.rb +71 -0
- data/spec/unit/active_harmony/synchronizer_spec.rb +185 -0
- metadata +104 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# Bacon.
|
4
|
+
class Bacon
|
5
|
+
include ::Mongoid::Document
|
6
|
+
|
7
|
+
include ActiveHarmony::Synchronizable::Core
|
8
|
+
include ActiveHarmony::Synchronizable::Mongoid
|
9
|
+
|
10
|
+
field :tastyness
|
11
|
+
end
|
12
|
+
|
13
|
+
# Wire up connections
|
14
|
+
synchronizer = ActiveHarmony::Synchronizer.new
|
15
|
+
synchronizer.service = ActiveHarmony::Service.new
|
16
|
+
synchronizer.factory = Bacon
|
17
|
+
synchronizer.configure do |config|
|
18
|
+
config.synchronize :tastyness
|
19
|
+
end
|
20
|
+
Bacon.synchronizer = synchronizer
|
21
|
+
|
22
|
+
module ActiveHarmony
|
23
|
+
describe Synchronizer do
|
24
|
+
before :all do
|
25
|
+
# References to wired up objects
|
26
|
+
@synchronizer = Bacon.synchronizer
|
27
|
+
@service = Bacon.synchronizer.service
|
28
|
+
end
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
Bacon.delete_all
|
32
|
+
end
|
33
|
+
|
34
|
+
####################################################
|
35
|
+
# Initialization
|
36
|
+
|
37
|
+
describe "#factory=" do
|
38
|
+
it "should set factory class for finding and creating objects" do
|
39
|
+
synchronizer = Synchronizer.new
|
40
|
+
factory = Class.new
|
41
|
+
synchronizer.factory = factory
|
42
|
+
synchronizer.factory.should == factory
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set service" do
|
46
|
+
synchronizer = Synchronizer.new
|
47
|
+
service = Service.new
|
48
|
+
synchronizer.service = service
|
49
|
+
synchronizer.service.should == service
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
###################################################
|
54
|
+
# Configuration
|
55
|
+
|
56
|
+
describe "#configure" do
|
57
|
+
it "should raise an exception when there's no block" do
|
58
|
+
synchronizer = Synchronizer.new
|
59
|
+
lambda {
|
60
|
+
synchronizer.configure
|
61
|
+
}.should raise_exception LocalJumpError
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should yield synchronizer configuration object" do
|
65
|
+
synchronizer = Synchronizer.new
|
66
|
+
synchronizer.configure do |config|
|
67
|
+
config.should == synchronizer.configuration
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
describe "#object_name" do
|
74
|
+
it "should return object name for our factory class" do
|
75
|
+
# @synchronizer is now reference to Bacon's synchronizer, remember?
|
76
|
+
# If not, take a look at before filter on lines 26-27.
|
77
|
+
@synchronizer.object_name.should == :bacon
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#pull_object" do
|
82
|
+
it "should update local object" do
|
83
|
+
local_bacon = Bacon.create({
|
84
|
+
:_remote_id => 123,
|
85
|
+
:tastyness => 'Meh'
|
86
|
+
})
|
87
|
+
@service.expects(:show).with(:bacon, 123).returns({
|
88
|
+
'id' => 123,
|
89
|
+
'tastyness' => 'Average'
|
90
|
+
})
|
91
|
+
@synchronizer.pull_object(123)
|
92
|
+
local_bacon.reload
|
93
|
+
local_bacon.tastyness.should == 'Average'
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should create a new local object" do
|
97
|
+
# In the Before Block, we're deleting all Bacons.
|
98
|
+
Bacon.count.should == 0 # <-- Do you believe me now?
|
99
|
+
@service.expects(:show).with(:bacon, 123).returns({
|
100
|
+
'id' => 123,
|
101
|
+
'tastyness' => 'Average'
|
102
|
+
})
|
103
|
+
@synchronizer.pull_object(123)
|
104
|
+
bacon = Bacon.last
|
105
|
+
bacon._remote_id.should == 123
|
106
|
+
bacon.tastyness.should == 'Average'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#push_object" do
|
111
|
+
before :each do
|
112
|
+
@bacon = Bacon.create(:tastyness => "Tasty")
|
113
|
+
end
|
114
|
+
|
115
|
+
context "remote object exists" do
|
116
|
+
before :each do
|
117
|
+
@bacon._remote_id = 123
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should update remote object" do
|
121
|
+
@service.expects(:update).with(:bacon, 123, {"tastyness" => "Tasty"})
|
122
|
+
@synchronizer.push_object(@bacon)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "remote object does not exist" do
|
127
|
+
before :each do
|
128
|
+
@bacon._remote_id = nil
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should create a new remote object" do
|
132
|
+
@service.expects(:update).never
|
133
|
+
@service.expects(:create).with(:bacon, {"tastyness" => "Tasty"})
|
134
|
+
@synchronizer.push_object(@bacon)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should save remote id of newly created remote object" do
|
138
|
+
@service.
|
139
|
+
expects(:create).
|
140
|
+
with(:bacon, {"tastyness" => "Tasty"}).
|
141
|
+
returns({"id" => 202, "tastyness" => "Average"})
|
142
|
+
@synchronizer.push_object(@bacon)
|
143
|
+
@bacon.reload
|
144
|
+
@bacon._remote_id.should == 202
|
145
|
+
@bacon.tastyness.should == "Average"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#pull_collection" do
|
151
|
+
before :each do
|
152
|
+
@bacons = [
|
153
|
+
Bacon.create(:_remote_id => 1, :tastyness => 'Meh'),
|
154
|
+
Bacon.create(:_remote_id => 2, :tastyness => 'Average')
|
155
|
+
]
|
156
|
+
|
157
|
+
@service.expects(:list).with(:bacon).returns([
|
158
|
+
{'id' => 1, 'tastyness' => 'Super Meh'},
|
159
|
+
{'id' => 2, 'tastyness' => 'Super Average'},
|
160
|
+
{'id' => 3, 'tastyness' => 'Mmmmmmmmmm'}
|
161
|
+
])
|
162
|
+
|
163
|
+
@synchronizer.pull_collection
|
164
|
+
@bacons.each { |b| b.reload }
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should update objects" do
|
168
|
+
@bacons[0].tastyness.should == 'Super Meh'
|
169
|
+
@bacons[1].tastyness.should == 'Super Average'
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should create new object" do
|
173
|
+
new_bacon = Bacon.last
|
174
|
+
new_bacon.tastyness.should == 'Mmmmmmmmmm'
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should set order' do
|
178
|
+
# bacons = Bacon.all.to_a
|
179
|
+
# bacons[0]._collection_order.should == 0
|
180
|
+
# bacons[1]._collection_order.should == 1
|
181
|
+
# bacons[2]._collection_order.should == 2
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_harmony
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Vojto Rinik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-22 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Active Harmony is a Ruby library that takes care of synchronizing changes between local Ruby objects and remote REST services.
|
23
|
+
email: vojto@rinik.net
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.markdown
|
31
|
+
files:
|
32
|
+
- .bundle/config
|
33
|
+
- CHANGELOG
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- LICENSE
|
37
|
+
- README.markdown
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- active_harmony.gemspec
|
41
|
+
- lib/active_harmony.rb
|
42
|
+
- lib/active_harmony/queue.rb
|
43
|
+
- lib/active_harmony/queue_item.rb
|
44
|
+
- lib/active_harmony/service.rb
|
45
|
+
- lib/active_harmony/service_manager.rb
|
46
|
+
- lib/active_harmony/service_url.rb
|
47
|
+
- lib/active_harmony/synchronizable.rb
|
48
|
+
- lib/active_harmony/synchronizable/core.rb
|
49
|
+
- lib/active_harmony/synchronizable/mongoid.rb
|
50
|
+
- lib/active_harmony/synchronizer.rb
|
51
|
+
- lib/active_harmony/synchronizer_configuration.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- spec/unit/active_harmony/queue_item_spec.rb
|
54
|
+
- spec/unit/active_harmony/queue_spec.rb
|
55
|
+
- spec/unit/active_harmony/service_manager_spec.rb
|
56
|
+
- spec/unit/active_harmony/service_spec.rb
|
57
|
+
- spec/unit/active_harmony/synchronizable/core_spec.rb
|
58
|
+
- spec/unit/active_harmony/synchronizable/mongoid_spec.rb
|
59
|
+
- spec/unit/active_harmony/synchronizer_configuration_spec.rb
|
60
|
+
- spec/unit/active_harmony/synchronizer_spec.rb
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/vojto/active_harmony
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --charset=UTF-8
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Ruby synchronization with REST services
|
95
|
+
test_files:
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/unit/active_harmony/queue_item_spec.rb
|
98
|
+
- spec/unit/active_harmony/queue_spec.rb
|
99
|
+
- spec/unit/active_harmony/service_manager_spec.rb
|
100
|
+
- spec/unit/active_harmony/service_spec.rb
|
101
|
+
- spec/unit/active_harmony/synchronizable/core_spec.rb
|
102
|
+
- spec/unit/active_harmony/synchronizable/mongoid_spec.rb
|
103
|
+
- spec/unit/active_harmony/synchronizer_configuration_spec.rb
|
104
|
+
- spec/unit/active_harmony/synchronizer_spec.rb
|