rhoconnect 4.0.4 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +5 -13
  2. data/CHANGELOG.md +54 -5
  3. data/CREDITS +219 -219
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +68 -79
  6. data/Rakefile +1 -2
  7. data/bench/benchapp/spec/models/ruby/mock_adapter_spec.rb +17 -17
  8. data/bench/benchapp/spec/models/ruby/queue_mock_adapter_spec.rb +17 -17
  9. data/bench/benchapp/spec/spec_helper.rb +3 -3
  10. data/bench/blobapp/spec/models/ruby/blob_adapter_spec.rb +17 -17
  11. data/bench/blobapp/spec/spec_helper.rb +3 -3
  12. data/bench/lib/bench/runner.rb +1 -69
  13. data/bench/lib/bench.rb +18 -18
  14. data/bench/spec/mock_adapter_spec.rb +54 -55
  15. data/bench/spec/mock_client_spec.rb +47 -48
  16. data/bench/spec/result_spec.rb +41 -44
  17. data/bench/spec/utils_spec.rb +24 -25
  18. data/commands/generators/app.rb +7 -5
  19. data/commands/generators/controller.rb +7 -5
  20. data/commands/generators/model.rb +7 -5
  21. data/commands/generators/source.rb +7 -5
  22. data/commands/parser.rb +1 -1
  23. data/commands/redis/redis_download.rb +1 -1
  24. data/doc/async-jobs.txt +9 -9
  25. data/doc/supported-platforms.txt +0 -2
  26. data/generators/rhoconnect.rb +92 -212
  27. data/generators/templates/application/rcgemfile +3 -3
  28. data/generators/templates/application/spec/application_controller_spec.rb +14 -16
  29. data/generators/templates/application/spec/js_spec.rb +20 -20
  30. data/generators/templates/application/spec/spec_helper.rb +1 -1
  31. data/generators/templates/source/controllers/ruby/controller_spec.rb +18 -19
  32. data/generators/templates/source/models/ruby/model_spec.rb +17 -17
  33. data/install.sh +10 -21
  34. data/installer/unix-like/rho_connect_install_constants.rb +5 -5
  35. data/installer/unix-like/rho_connect_install_installers.rb +4 -4
  36. data/installer/utils/constants.rb +6 -6
  37. data/installer/utils/nix_install_test.rb +29 -29
  38. data/installer/utils/package_upload/repos.rake +16 -26
  39. data/js-adapters/node.rb +4 -4
  40. data/js-adapters/node_channel.rb +4 -8
  41. data/lib/rhoconnect/db_adapter.rb +13 -13
  42. data/lib/rhoconnect/handler/changes/engine.rb +1 -1
  43. data/lib/rhoconnect/jobs/bulk_data_job.rb +29 -29
  44. data/lib/rhoconnect/license.rb +7 -7
  45. data/lib/rhoconnect/model/helpers/find_duplicates_on_update.rb +13 -13
  46. data/lib/rhoconnect/ping/apple.rb +4 -4
  47. data/lib/rhoconnect/server.rb +2 -2
  48. data/lib/rhoconnect/source.rb +2 -2
  49. data/lib/rhoconnect/store.rb +12 -6
  50. data/lib/rhoconnect/utilities.rb +2 -2
  51. data/lib/rhoconnect/version.rb +1 -1
  52. data/lib/rhoconnect.rb +6 -4
  53. data/rhoconnect.gemspec +5 -6
  54. data/spec/api/api_helper.rb +1 -1
  55. data/spec/api/app/fast_delete_spec.rb +22 -22
  56. data/spec/api/app/fast_insert_spec.rb +23 -23
  57. data/spec/api/app/fast_update_spec.rb +63 -63
  58. data/spec/api/app/push_deletes_spec.rb +11 -13
  59. data/spec/api/app/push_objects_spec.rb +39 -39
  60. data/spec/api/client/client_get_db_doc_spec.rb +29 -29
  61. data/spec/api/client/client_set_db_doc_spec.rb +11 -11
  62. data/spec/api/client/get_client_params_spec.rb +29 -29
  63. data/spec/api/client/list_client_docs_spec.rb +32 -34
  64. data/spec/api/client/reset_spec.rb +30 -30
  65. data/spec/api/readstate/set_refresh_time_spec.rb +43 -43
  66. data/spec/api/source/get_source_params_spec.rb +32 -34
  67. data/spec/api/source/list_sources_spec.rb +13 -13
  68. data/spec/api/source/update_source_params_spec.rb +19 -19
  69. data/spec/api/store/get_db_doc_spec.rb +27 -27
  70. data/spec/api/store/set_db_doc_spec.rb +38 -38
  71. data/spec/api/system/adapter_spec.rb +27 -29
  72. data/spec/api/system/get_license_info_spec.rb +11 -11
  73. data/spec/api/system/login_spec.rb +37 -37
  74. data/spec/api/system/reset_spec.rb +15 -15
  75. data/spec/api/system/stats_spec.rb +70 -71
  76. data/spec/api/user/create_user_spec.rb +37 -37
  77. data/spec/api/user/delete_client_spec.rb +7 -7
  78. data/spec/api/user/delete_user_spec.rb +62 -62
  79. data/spec/api/user/list_clients_spec.rb +24 -24
  80. data/spec/api/user/list_source_docs_spec.rb +29 -29
  81. data/spec/api/user/list_users_spec.rb +22 -22
  82. data/spec/api/user/ping_spec.rb +18 -18
  83. data/spec/api/user/show_user_spec.rb +10 -10
  84. data/spec/api/user/update_user_spec.rb +43 -43
  85. data/spec/api/user/user_get_db_doc_spec.rb +12 -12
  86. data/spec/api/user/user_set_db_doc_spec.rb +37 -37
  87. data/spec/api_token_spec.rb +8 -8
  88. data/spec/app_spec.rb +18 -17
  89. data/spec/apps/jstestapp/settings/settings.yml +2 -0
  90. data/spec/async_spec.rb +9 -11
  91. data/spec/bulk_data/bulk_data_spec.rb +120 -120
  92. data/spec/cli/cli_spec.rb +50 -53
  93. data/spec/client_spec.rb +105 -105
  94. data/spec/client_sync_spec.rb +529 -528
  95. data/spec/controllers/js_base_spec.rb +147 -141
  96. data/spec/doc/doc_spec.rb +51 -52
  97. data/spec/document_spec.rb +58 -58
  98. data/spec/dynamic_adapter_spec.rb +33 -36
  99. data/spec/generator/generator_spec.rb +76 -42
  100. data/spec/jobs/bulk_data_job_spec.rb +101 -102
  101. data/spec/jobs/ping_job_spec.rb +176 -177
  102. data/spec/jobs/source_job_spec.rb +24 -25
  103. data/spec/license_spec.rb +54 -55
  104. data/spec/models/js_base_spec.rb +121 -120
  105. data/spec/perf/bulk_data_perf_spec.rb +23 -24
  106. data/spec/perf/perf_spec_helper.rb +7 -7
  107. data/spec/perf/store_perf_spec.rb +139 -140
  108. data/spec/ping/apple_spec.rb +65 -65
  109. data/spec/ping/gcm_spec.rb +83 -84
  110. data/spec/ping/rhoconnect_push_spec.rb +52 -53
  111. data/spec/predefined_adapters/rho_internal_bench_adapter_controller_js_spec.rb +100 -101
  112. data/spec/predefined_adapters/rho_internal_js_bench_adapter_js_spec.rb +29 -31
  113. data/spec/read_state_spec.rb +24 -25
  114. data/spec/rhoconnect_spec.rb +7 -7
  115. data/spec/server/server_spec.rb +664 -662
  116. data/spec/server/stats_spec.rb +12 -12
  117. data/spec/source_adapter_spec.rb +124 -125
  118. data/spec/source_spec.rb +148 -149
  119. data/spec/source_sync_spec.rb +736 -736
  120. data/spec/spec_helper.rb +4 -5
  121. data/spec/stats/record_spec.rb +22 -21
  122. data/spec/store_orm_spec.rb +48 -48
  123. data/spec/store_spec.rb +428 -426
  124. data/spec/support/shared_examples.rb +5 -7
  125. data/spec/sync_states_spec.rb +67 -67
  126. data/spec/test_methods_spec.rb +121 -123
  127. data/spec/testdata/10000-data.txt +0 -0
  128. data/spec/testdata/5000-data.txt +0 -0
  129. data/spec/user_spec.rb +102 -102
  130. data/tasks/redis.rake +3 -3
  131. metadata +154 -195
  132. data/bench/benchapp/tmp/pids/passenger.9292.pid.lock +0 -0
  133. data/bench/benchapp/tmp/restart.txt +0 -0
  134. data/bench/blobapp/settings/license.key.bak +0 -2
  135. data/bench/blobapp/tmp/restart.txt +0 -0
  136. data/bench/lib/testdata/1-data.txt +0 -0
  137. data/bench/lib/testdata/10-data.txt +0 -0
  138. data/bench/lib/testdata/2-data.txt +0 -0
  139. data/bench/lib/testdata/250-data.txt +0 -0
  140. data/bench/lib/testdata/5-blob_data.txt +0 -0
  141. data/bench/lib/testdata/5-data.txt +0 -0
  142. data/bench/lib/testdata/50-data.txt +0 -0
  143. data/bench/lib/testdata/500-data.txt +0 -0
  144. data/doc/protocol.html +0 -1993
  145. data/spec/coverage/rcov/assets/0.2.3/jquery-1.3.2.min.js +0 -19
  146. data/spec/coverage/rcov/assets/0.2.3/jquery.tablesorter.min.js +0 -15
  147. data/spec/coverage/rcov/assets/0.2.3/print.css +0 -12
  148. data/spec/coverage/rcov/assets/0.2.3/rcov.js +0 -42
  149. data/spec/coverage/rcov/assets/0.2.3/screen.css +0 -270
  150. data/spec/coverage/rcov/index.html +0 -88
  151. data/spec/generator/generator_spec_helper.rb +0 -9
@@ -8,18 +8,18 @@ STATS_RECORD_SIZE = 8 unless defined? STATS_RECORD_SIZE
8
8
  include Rhoconnect
9
9
 
10
10
  describe "Middleware" do
11
-
11
+
12
12
  before(:each) do
13
13
  @now = 10.0
14
14
  Store.flush_all
15
- app = mock('app')
16
- app.stub!(:call)
15
+ app = double('app')
16
+ app.stub(:call)
17
17
  Rhoconnect.stats = true
18
18
  Rhoconnect::Server.enable :stats
19
19
  @middleware_new_routes = Rhoconnect::Middleware::Stats.new(app)
20
- Store.stub!(:lock).and_yield
20
+ Store.stub(:lock).and_yield
21
21
  end
22
-
22
+
23
23
  after(:each) do
24
24
  Rhoconnect.stats = false
25
25
  Rhoconnect::Server.disable :stats
@@ -27,7 +27,7 @@ describe "Middleware" do
27
27
 
28
28
  it "should compute http average" do
29
29
  @incr = 0
30
- Time.stub!(:now).and_return do
30
+ Time.stub(:now).and_return do
31
31
  if @incr > 0
32
32
  @now += 0.3
33
33
  @incr -= 1
@@ -45,13 +45,13 @@ describe "Middleware" do
45
45
  metric = 'http:GET:/api/application/query:SampleAdapter'
46
46
  Rhoconnect::Stats::Record.key(metric).should == "stat:#{metric}"
47
47
 
48
- # The conversion algorithm (float to string) currently checks two precisions.
49
- # it tries 16 digits and if that's not enough it then uses 17.
48
+ # The conversion algorithm (float to string) currently checks two precisions.
49
+ # it tries 16 digits and if that's not enough it then uses 17.
50
50
  Rhoconnect::Stats::Record.range(metric, 0, -1).should == [
51
- "2.0,0.6000000000000014:12",
52
- "2.0,0.6000000000000014:14",
53
- "2.0,0.6000000000000014:16",
51
+ "2.0,0.6000000000000014:12",
52
+ "2.0,0.6000000000000014:14",
53
+ "2.0,0.6000000000000014:16",
54
54
  "2.0,0.6000000000000014:18"
55
55
  ]
56
- end
56
+ end
57
57
  end
@@ -1,154 +1,153 @@
1
1
  require File.join(File.dirname(__FILE__),'spec_helper')
2
2
 
3
3
  describe "loading Model" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
5
- it "should load Model instance from user name" do
6
- username = 'testuser'
7
- model_instance = SimpleAdapter.load(username)
8
- model_instance.class.name.should == 'SimpleAdapter'
9
- model_instance.source.name.should == 'SimpleAdapter'
10
- end
4
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
5
+
6
+ it "should load Model instance from user name" do
7
+ username = 'testuser'
8
+ model_instance = SimpleAdapter.load(username)
9
+ model_instance.class.name.should == 'SimpleAdapter'
10
+ model_instance.source.name.should == 'SimpleAdapter'
11
11
  end
12
12
  end
13
13
 
14
14
  describe "Model" do
15
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => true do
16
- before(:each) do
17
- @s = Source.load('SimpleAdapter',@s_params)
18
- @sa = Rhoconnect::Model::Base.create(@s)
19
- end
15
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
20
16
 
21
- def setup_adapter(name)
22
- fields = {
23
- :name => name,
24
- :url => 'http://example.com',
25
- :login => 'testuser',
26
- :password => 'testpass',
27
- }
28
- Source.create(fields,@s_params)
29
- end
17
+ before(:each) do
18
+ @s = Source.load('SimpleAdapter',@s_params)
19
+ @sa = Rhoconnect::Model::Base.create(@s)
20
+ end
30
21
 
31
- it "should create model with source" do
32
- @sa.class.name.should == @s.name
33
- end
34
-
35
- it "should create all existing pre-defined models" do
36
- Rhoconnect.predefined_sources.keys.sort.should == ['RhoInternalBenchmarkAdapter'].sort
37
- Rhoconnect.predefined_sources.each do |adapter_name, filename|
38
- pas = Source.load(adapter_name, @s_params)
39
- pas.should_not == nil
40
- pa = Rhoconnect::Model::Base.create(pas)
41
- pa.class.name.should == "Rhoconnect::#{adapter_name}"
42
- end
43
- end
44
-
45
- it "should create DynamicAdapterModel" do
46
- @sa1 = Rhoconnect::Model::Base.create(@s2)
47
- @sa1.class.name.should == 'Rhoconnect::Model::DynamicAdapterModel'
48
- end
49
-
50
- it "should capture exception in create" do
51
- Rhoconnect::Model::DynamicAdapterModel.should_receive(:new).once.and_raise(Exception)
52
- lambda { @sa1 = Rhoconnect::Model::Base.create(@s2) }.should raise_error(Exception)
53
- end
22
+ def setup_adapter(name)
23
+ fields = {
24
+ :name => name,
25
+ :url => 'http://example.com',
26
+ :login => 'testuser',
27
+ :password => 'testpass',
28
+ }
29
+ Source.create(fields,@s_params)
30
+ end
54
31
 
55
- it "should fail to create Bro-ken model" do
56
- broken_source = setup_adapter('Bro-ken')
57
- lambda { Rhoconnect::Model::Base.create(broken_source) }.should raise_error(Exception)
58
- broken_source.delete
59
- end
32
+ it "should create model with source" do
33
+ @sa.class.name.should == @s.name
34
+ end
60
35
 
61
- it "should create model with trailing spaces" do
62
- s = setup_adapter('SimpleAdapter ')
63
- Rhoconnect::Model::Base.create(s).is_a?(SimpleAdapter).should be_true
36
+ it "should create all existing pre-defined models" do
37
+ Rhoconnect.predefined_sources.keys.sort.should == ['RhoInternalBenchmarkAdapter'].sort
38
+ Rhoconnect.predefined_sources.each do |adapter_name, filename|
39
+ pas = Source.load(adapter_name, @s_params)
40
+ pas.should_not == nil
41
+ pa = Rhoconnect::Model::Base.create(pas)
42
+ pa.class.name.should == "Rhoconnect::#{adapter_name}"
64
43
  end
44
+ end
65
45
 
66
- describe "model methods" do
67
- it "should execute Model login method with source vars" do
68
- @sa.login.should == true
69
- end
46
+ it "should create DynamicAdapterModel" do
47
+ @sa1 = Rhoconnect::Model::Base.create(@s2)
48
+ @sa1.class.name.should == 'Rhoconnect::Model::DynamicAdapterModel'
49
+ end
70
50
 
71
- it "should get Model data (:md)" do
72
- expected = {'1'=>@product1,'2'=>@product2}
73
- @s.put_data(:md, expected)
74
- @sa.get_data.should == expected
75
- end
51
+ it "should capture exception in create" do
52
+ Rhoconnect::Model::DynamicAdapterModel.should_receive(:new).once.and_raise(Exception)
53
+ lambda { @sa1 = Rhoconnect::Model::Base.create(@s2) }.should raise_error(Exception)
54
+ end
76
55
 
77
- it "should get Model data from specific document" do
78
- expected = {'4'=>@product1,'5'=>@product2}
79
- Source.define_valid_doctypes([:md_custom])
80
- @s.put_data(:md_custom, expected)
81
- @sa.get_data(:md_custom).should == expected
82
- Source.valid_doctypes.delete(:md_custom)
83
- end
56
+ it "should fail to create Bro-ken model" do
57
+ broken_source = setup_adapter('Bro-ken')
58
+ lambda { Rhoconnect::Model::Base.create(broken_source) }.should raise_error(Exception)
59
+ broken_source.delete
60
+ end
84
61
 
85
- it "should execute Model query method" do
86
- expected = {'1'=>@product1,'2'=>@product2}
87
- @sa.inject_result expected
88
- @sa.query.should == expected
89
- end
62
+ it "should create model with trailing spaces" do
63
+ s = setup_adapter('SimpleAdapter ')
64
+ Rhoconnect::Model::Base.create(s).is_a?(SimpleAdapter).should be_true
65
+ end
90
66
 
91
- it "should execute Model search method and modify params" do
92
- params = {:hello => 'world'}
93
- expected = {'1'=>@product1,'2'=>@product2}
94
- @sa.inject_result expected
95
- @sa.search(params).should == expected
96
- params.should == {:hello => 'world', :foo => 'bar'}
97
- end
67
+ describe "model methods" do
68
+ it "should execute Model login method with source vars" do
69
+ @sa.login.should == true
70
+ end
98
71
 
99
- it "should execute Model login with current_user" do
100
- @sa.should_receive(:current_user).with(no_args()).and_return(@u)
101
- @sa.login
102
- end
72
+ it "should get Model data (:md)" do
73
+ expected = {'1'=>@product1,'2'=>@product2}
74
+ @s.put_data(:md, expected)
75
+ @sa.get_data.should == expected
76
+ end
103
77
 
104
- it "should execute Model sync method" do
105
- expected = {'1'=>@product1,'2'=>@product2}
106
- @sa.inject_result expected
107
- @sa.do_query
108
- Store.get_data(@s.docname(:md)).should == expected
109
- Store.get_value(@s.docname(:md_size)).to_i.should == 2
110
- end
78
+ it "should get Model data from specific document" do
79
+ expected = {'4'=>@product1,'5'=>@product2}
80
+ Source.define_valid_doctypes([:md_custom])
81
+ @s.put_data(:md_custom, expected)
82
+ @sa.get_data(:md_custom).should == expected
83
+ Source.valid_doctypes.delete(:md_custom)
84
+ end
111
85
 
112
- it "should execute Model sync method with nil result" do
113
- @sa.inject_result nil
114
- @sa.do_query
115
- Store.get_data(@s.docname(:md)).should == {}
116
- end
86
+ it "should execute Model query method" do
87
+ expected = {'1'=>@product1,'2'=>@product2}
88
+ @sa.inject_result expected
89
+ @sa.query.should == expected
90
+ end
117
91
 
118
- it "should fail gracefully if @result is missing" do
119
- @sa.inject_result nil
120
- lambda { @sa.query }.should_not raise_error
121
- end
92
+ it "should execute Model search method and modify params" do
93
+ params = {:hello => 'world'}
94
+ expected = {'1'=>@product1,'2'=>@product2}
95
+ @sa.inject_result expected
96
+ @sa.search(params).should == expected
97
+ params.should == {:hello => 'world', :foo => 'bar'}
98
+ end
122
99
 
123
- it "should reset count if @result is empty" do
124
- @sa.inject_result({'1'=>@product1,'2'=>@product2})
125
- @sa.do_query
126
- Store.get_value(@s.docname(:md_size)).to_i.should == 2
127
- @sa.inject_result({})
128
- @sa.do_query
129
- Store.get_value(@s.docname(:md_size)).to_i.should == 0
130
- end
100
+ it "should execute Model login with current_user" do
101
+ @sa.should_receive(:current_user).with(no_args()).and_return(@u)
102
+ @sa.login
103
+ end
131
104
 
132
- it "should execute Model create method" do
133
- @sa.create(@product4).should == 'obj4'
134
- end
105
+ it "should execute Model sync method" do
106
+ expected = {'1'=>@product1,'2'=>@product2}
107
+ @sa.inject_result expected
108
+ @sa.do_query
109
+ Store.get_data(@s.docname(:md)).should == expected
110
+ Store.get_value(@s.docname(:md_size)).to_i.should == 2
111
+ end
135
112
 
136
- it "should stash @result in store and set it to nil" do
137
- expected = {'1'=>@product1,'2'=>@product2}
138
- Source.define_valid_doctypes(['tmpdoc'.to_sym])
139
- @sa.inject_result(expected)
140
- @sa.inject_tmpdoc('tmpdoc')
141
- @sa.stash_result
142
- @s.get_data('tmpdoc').should == expected
143
- Source.valid_doctypes.delete('tmpdoc'.to_sym)
144
- end
113
+ it "should execute Model sync method with nil result" do
114
+ @sa.inject_result nil
115
+ @sa.do_query
116
+ Store.get_data(@s.docname(:md)).should == {}
117
+ end
118
+
119
+ it "should fail gracefully if @result is missing" do
120
+ @sa.inject_result nil
121
+ lambda { @sa.query }.should_not raise_error
122
+ end
145
123
 
146
- describe "Model metadata method" do
124
+ it "should reset count if @result is empty" do
125
+ @sa.inject_result({'1'=>@product1,'2'=>@product2})
126
+ @sa.do_query
127
+ Store.get_value(@s.docname(:md_size)).to_i.should == 2
128
+ @sa.inject_result({})
129
+ @sa.do_query
130
+ Store.get_value(@s.docname(:md_size)).to_i.should == 0
131
+ end
132
+
133
+ it "should execute Model create method" do
134
+ @sa.create(@product4).should == 'obj4'
135
+ end
136
+
137
+ it "should stash @result in store and set it to nil" do
138
+ expected = {'1'=>@product1,'2'=>@product2}
139
+ Source.define_valid_doctypes(['tmpdoc'.to_sym])
140
+ @sa.inject_result(expected)
141
+ @sa.inject_tmpdoc('tmpdoc')
142
+ @sa.stash_result
143
+ @s.get_data('tmpdoc').should == expected
144
+ Source.valid_doctypes.delete('tmpdoc'.to_sym)
145
+ end
147
146
 
148
- it "should execute Model metadata method" do
149
- mock_metadata_method([SimpleAdapter]) do
150
- @sa.metadata.should == "{\"foo\":\"bar\"}"
151
- end
147
+ describe "Model metadata method" do
148
+ it "should execute Model metadata method" do
149
+ mock_metadata_method([SimpleAdapter]) do
150
+ @sa.metadata.should == "{\"foo\":\"bar\"}"
152
151
  end
153
152
  end
154
153
  end
data/spec/source_spec.rb CHANGED
@@ -1,157 +1,156 @@
1
1
  require File.join(File.dirname(__FILE__),'spec_helper')
2
2
 
3
3
  describe "Source" do
4
- it_behaves_like "SharedRhoconnectHelper", :rhoconnect_data => false do
5
-
6
- before(:each) do
7
- @s = Source.load(@s_fields[:name],@s_params)
8
- end
9
-
10
- it "should create and load source with @s_fields and @s_params" do
11
- @s.name.should == @s_fields[:name]
12
- @s.url.should == @s_fields[:url]
13
- @s.login.should == @s_fields[:login]
14
- @s.app.name.should == @a_fields[:name]
15
- @s.priority.should == 1
16
- @s.callback_url.should be_nil
17
- @s.queue.should be_nil
18
- @s.query_queue.should be_nil
19
- @s.cud_queue.should be_nil
20
- @s.app_id.should == @s_params[:app_id]
21
- @s.user_id.should == @s_params[:user_id]
22
- @s.sync_type.should == :incremental
23
- @s.partition_type.should == :user
24
- @s.poll_interval.should == 300
25
-
26
- @s1 = Source.load(@s.id,@s_params)
27
- @s1.name.should == @s_fields[:name]
28
- @s1.url.should == @s_fields[:url]
29
- @s1.login.should == @s_fields[:login]
30
- @s1.app.name.should == @a_fields[:name]
31
- @s1.priority.should == 1
32
- @s1.callback_url.should be_nil
33
- @s1.poll_interval.should == 300
34
- @s1.app_id.should == @s_params[:app_id]
35
- @s1.user_id.should == @s_params[:user_id]
36
- end
37
-
38
- it "should create source with user" do
39
- @s.user.login.should == @u_fields[:login]
40
- end
41
-
42
- it "should create source with app and document" do
43
- @s.app.name.should == @a_fields[:name]
44
- @s.docname(:md).should == "source:#{@s.app.id}:#{@u.id}:#{@s_fields[:name]}:md"
45
- end
46
-
47
- it 'should return values that set by setter method' do
48
- @s.login = "shurab"
49
- @s.login.should == "shurab"
50
- @s.poll_interval = 350
51
- @s.poll_interval.should == 350
52
- @s.poll_interval = nil
53
- @s.poll_interval.should == nil
54
- @s.url = nil
55
- @s.url.should be_nil
56
- end
57
-
58
- it "should delete source" do
59
- @s.delete
60
- Source.is_exist?(@s_fields[:name]).should == false
61
- @s = Source.create(@s_fields,@s_params)
62
- end
63
-
64
- it "should delete master and all documents associated with source" do
65
- key = @s.docname('*')
66
- Source.define_valid_doctypes([:md_source])
67
- set_doc_state(@s, {:md_source => @data})
68
- @s.delete
69
- i = 0
70
- while i < Store.num_stores do
71
- Store.get_store(i).keys(key).should == []
72
- i += 1
73
- end
74
- Source.valid_doctypes.delete(:md_source)
75
- @s = Source.create(@s_fields,@s_params)
76
- end
77
-
78
- it "should create source with default partition user" do
79
- @s1 = Source.load(@s_fields[:name],{:app_id => @a.id,:user_id => '*'})
80
- @s1.partition.should == :user
81
- end
82
-
83
- it "should create correct docname based on partition scheme" do
84
- @s.partition = :app
85
- @s.docname(:md).should == "source:#{@s.app.id}:__shared__:#{@s_fields[:name]}:md"
86
- end
87
-
88
- it "should create source with default read/write queue" do
89
- @s.delete
90
- @s_fields[:queue] = :default
91
- @s_fields[:query_queue] = :query
92
- @s_fields[:cud_queue] = :cud
93
- @s = Source.create(@s_fields,@s_params)
94
- s = Source.load(@s_fields[:name],@s_params)
95
- s.queue.should == :default
96
- s.query_queue.should == :query
97
- s.cud_queue.should == :cud
98
- end
99
-
100
- it "should add associations based on belongs_to field for a source" do
101
- @s2 = Source.create({:name => 'SimpleAdapter'}, @s_params)
102
- @s2.belongs_to = [{'product_id' => 'SampleAdapter'}].to_json
103
- sf = Source.load(@s1.name,{:app_id => @a.id,:user_id => '*'})
104
- Source.update_associations([@s.name,@s1.name, @s2.name])
105
- s = Source.load(@s.name,{:app_id => @a.id,:user_id => '*'})
106
- s.has_many.should == "#{@s1.name},brand,#{@s2.name},product_id"
107
- end
108
-
109
- it "should log warning about incorrect belongs_to format for a source" do
110
- @s2 = Source.create({:name => 'SimpleAdapter'}, @s_params)
111
- @s2.belongs_to = {'product_id' => 'SampleAdapter'}.to_json
112
- Source.should_receive(:log).once.with(
113
- "WARNING: Incorrect belongs_to format for SimpleAdapter, belongs_to should be an array."
114
- )
115
- Source.update_associations([@s.name,@s1.name, @s2.name])
116
- end
4
+ include_examples "SharedRhoconnectHelper", :rhoconnect_data => false
117
5
 
118
- # check custom partitions
119
- it "should return custom partition for users if defined in the model" do
120
- u1_fields = {:login => 'cus_user1'}
121
- u1 = User.create(u1_fields)
122
- u2_fields = {:login => 'cus_user2'}
123
- u2 = User.create(u2_fields)
124
- u3_fields = {:login => 'other_user'}
125
- u3 = User.create(u3_fields)
126
-
127
- s = Source.load('SampleAdapter', {:user_id => u1.login, :app_id => APP_NAME})
128
- s.user_by_partition.should == 'custom_partition'
129
- s.docname(:md).should == "source:#{s.app.id}:custom_partition:SampleAdapter:md"
130
- s = Source.load('FixedSchemaAdapter', {:user_id => u1.login, :app_id => APP_NAME})
131
- s.user_by_partition.should == 'cus_user1'
132
- s = Source.load('SampleAdapter', {:user_id => u2.login, :app_id => APP_NAME})
133
- s.user_by_partition.should == 'custom_partition'
134
- s = Source.load('SampleAdapter', {:user_id => u3.login, :app_id => APP_NAME})
135
- s.user_by_partition.should == 'other_user'
136
- end
6
+ before(:each) do
7
+ @s = Source.load(@s_fields[:name],@s_params)
8
+ end
9
+
10
+ it "should create and load source with @s_fields and @s_params" do
11
+ @s.name.should == @s_fields[:name]
12
+ @s.url.should == @s_fields[:url]
13
+ @s.login.should == @s_fields[:login]
14
+ @s.app.name.should == @a_fields[:name]
15
+ @s.priority.should == 1
16
+ @s.callback_url.should be_nil
17
+ @s.queue.should be_nil
18
+ @s.query_queue.should be_nil
19
+ @s.cud_queue.should be_nil
20
+ @s.app_id.should == @s_params[:app_id]
21
+ @s.user_id.should == @s_params[:user_id]
22
+ @s.sync_type.should == :incremental
23
+ @s.partition_type.should == :user
24
+ @s.poll_interval.should == 300
25
+
26
+ @s1 = Source.load(@s.id,@s_params)
27
+ @s1.name.should == @s_fields[:name]
28
+ @s1.url.should == @s_fields[:url]
29
+ @s1.login.should == @s_fields[:login]
30
+ @s1.app.name.should == @a_fields[:name]
31
+ @s1.priority.should == 1
32
+ @s1.callback_url.should be_nil
33
+ @s1.poll_interval.should == 300
34
+ @s1.app_id.should == @s_params[:app_id]
35
+ @s1.user_id.should == @s_params[:user_id]
36
+ end
37
+
38
+ it "should create source with user" do
39
+ @s.user.login.should == @u_fields[:login]
40
+ end
41
+
42
+ it "should create source with app and document" do
43
+ @s.app.name.should == @a_fields[:name]
44
+ @s.docname(:md).should == "source:#{@s.app.id}:#{@u.id}:#{@s_fields[:name]}:md"
45
+ end
137
46
 
138
- it "should delete data from custom partition" do
139
- u1_fields = {:login => 'cus_user1'}
140
- u1 = User.create(u1_fields)
141
- data = {'1' => {'Name' => 'Value'}}
142
-
143
- s = Source.load('SampleAdapter', {:user_id => u1.login, :app_id => APP_NAME})
144
- s.user_by_partition.should == 'custom_partition'
145
- Source.define_valid_doctypes([:md_source])
146
- set_doc_state(s, {:md_source => data})
147
- Store.get_data("source:#{s.app.id}:custom_partition:SampleAdapter:md_source").should == data
148
- Store.get_data("source:#{s.app.id}:cus_user1:SampleAdapter:md_source").should == {}
149
- Store.put_data("source:#{s.app.id}:cus_user1:SampleAdapter:md_source", data)
150
-
151
- s.delete
152
- Store.get_data("source:#{s.app.id}:custom_partition:SampleAdapter:md_source").should == {}
153
- Store.get_data("source:#{s.app.id}:cus_user1:SampleAdapter:md_source").should == data
154
- Source.valid_doctypes.delete(:md_source)
47
+ it 'should return values that set by setter method' do
48
+ @s.login = "shurab"
49
+ @s.login.should == "shurab"
50
+ @s.poll_interval = 350
51
+ @s.poll_interval.should == 350
52
+ @s.poll_interval = nil
53
+ @s.poll_interval.should == nil
54
+ @s.url = nil
55
+ @s.url.should be_nil
56
+ end
57
+
58
+ it "should delete source" do
59
+ @s.delete
60
+ Source.is_exist?(@s_fields[:name]).should == false
61
+ @s = Source.create(@s_fields,@s_params)
62
+ end
63
+
64
+ it "should delete master and all documents associated with source" do
65
+ key = @s.docname('*')
66
+ Source.define_valid_doctypes([:md_source])
67
+ set_doc_state(@s, {:md_source => @data})
68
+ @s.delete
69
+ i = 0
70
+ while i < Store.num_stores do
71
+ Store.get_store(i).keys(key).should == []
72
+ i += 1
155
73
  end
74
+ Source.valid_doctypes.delete(:md_source)
75
+ @s = Source.create(@s_fields,@s_params)
76
+ end
77
+
78
+ it "should create source with default partition user" do
79
+ @s1 = Source.load(@s_fields[:name],{:app_id => @a.id,:user_id => '*'})
80
+ @s1.partition.should == :user
81
+ end
82
+
83
+ it "should create correct docname based on partition scheme" do
84
+ @s.partition = :app
85
+ @s.docname(:md).should == "source:#{@s.app.id}:__shared__:#{@s_fields[:name]}:md"
86
+ end
87
+
88
+ it "should create source with default read/write queue" do
89
+ @s.delete
90
+ @s_fields[:queue] = :default
91
+ @s_fields[:query_queue] = :query
92
+ @s_fields[:cud_queue] = :cud
93
+ @s = Source.create(@s_fields,@s_params)
94
+ s = Source.load(@s_fields[:name],@s_params)
95
+ s.queue.should == :default
96
+ s.query_queue.should == :query
97
+ s.cud_queue.should == :cud
98
+ end
99
+
100
+ it "should add associations based on belongs_to field for a source" do
101
+ @s2 = Source.create({:name => 'SimpleAdapter'}, @s_params)
102
+ @s2.belongs_to = [{'product_id' => 'SampleAdapter'}].to_json
103
+ sf = Source.load(@s1.name,{:app_id => @a.id,:user_id => '*'})
104
+ Source.update_associations([@s.name,@s1.name, @s2.name])
105
+ s = Source.load(@s.name,{:app_id => @a.id,:user_id => '*'})
106
+ s.has_many.should == "#{@s1.name},brand,#{@s2.name},product_id"
107
+ end
108
+
109
+ it "should log warning about incorrect belongs_to format for a source" do
110
+ @s2 = Source.create({:name => 'SimpleAdapter'}, @s_params)
111
+ @s2.belongs_to = {'product_id' => 'SampleAdapter'}.to_json
112
+ Source.should_receive(:log).once.with(
113
+ "WARNING: Incorrect belongs_to format for SimpleAdapter, belongs_to should be an array."
114
+ )
115
+ Source.update_associations([@s.name,@s1.name, @s2.name])
116
+ end
117
+
118
+ # check custom partitions
119
+ it "should return custom partition for users if defined in the model" do
120
+ u1_fields = {:login => 'cus_user1'}
121
+ u1 = User.create(u1_fields)
122
+ u2_fields = {:login => 'cus_user2'}
123
+ u2 = User.create(u2_fields)
124
+ u3_fields = {:login => 'other_user'}
125
+ u3 = User.create(u3_fields)
126
+
127
+ s = Source.load('SampleAdapter', {:user_id => u1.login, :app_id => APP_NAME})
128
+ s.user_by_partition.should == 'custom_partition'
129
+ s.docname(:md).should == "source:#{s.app.id}:custom_partition:SampleAdapter:md"
130
+ s = Source.load('FixedSchemaAdapter', {:user_id => u1.login, :app_id => APP_NAME})
131
+ s.user_by_partition.should == 'cus_user1'
132
+ s = Source.load('SampleAdapter', {:user_id => u2.login, :app_id => APP_NAME})
133
+ s.user_by_partition.should == 'custom_partition'
134
+ s = Source.load('SampleAdapter', {:user_id => u3.login, :app_id => APP_NAME})
135
+ s.user_by_partition.should == 'other_user'
136
+ end
137
+
138
+ it "should delete data from custom partition" do
139
+ u1_fields = {:login => 'cus_user1'}
140
+ u1 = User.create(u1_fields)
141
+ data = {'1' => {'Name' => 'Value'}}
142
+
143
+ s = Source.load('SampleAdapter', {:user_id => u1.login, :app_id => APP_NAME})
144
+ s.user_by_partition.should == 'custom_partition'
145
+ Source.define_valid_doctypes([:md_source])
146
+ set_doc_state(s, {:md_source => data})
147
+ Store.get_data("source:#{s.app.id}:custom_partition:SampleAdapter:md_source").should == data
148
+ Store.get_data("source:#{s.app.id}:cus_user1:SampleAdapter:md_source").should == {}
149
+ Store.put_data("source:#{s.app.id}:cus_user1:SampleAdapter:md_source", data)
150
+
151
+ s.delete
152
+ Store.get_data("source:#{s.app.id}:custom_partition:SampleAdapter:md_source").should == {}
153
+ Store.get_data("source:#{s.app.id}:cus_user1:SampleAdapter:md_source").should == data
154
+ Source.valid_doctypes.delete(:md_source)
156
155
  end
157
156
  end