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
@@ -7,9 +7,9 @@ module Rhoconnect
7
7
  base.extend Rhoconnect::Model::Helpers::FindDuplicatesOnUpdate::ClassMethods
8
8
  end
9
9
 
10
- def find_duplicates_on_update(options, invalid_meta, operation, operation_data, client_ids)
10
+ def find_duplicates_on_update(options, invalid_meta, operation, operation_data, client_ids)
11
11
  invalid_meta ||= {}
12
- processed_ids = {}
12
+ # processed_ids = {}
13
13
  processed_objs = {}
14
14
  operation_data.each_with_index do |client_operation_data,index|
15
15
  client_id = client_ids[index]
@@ -27,29 +27,29 @@ module Rhoconnect
27
27
  processed_records = processed_source_objs[key]
28
28
  processed_records.each do |processed_record|
29
29
  master_obj = processed_record[:value]
30
- master_client_id = processed_record[:client_id]
30
+ # master_client_id = processed_record[:client_id]
31
31
  master_queue_index = processed_record[:queue_index].to_i
32
32
  master_obj_index = processed_record[:index].to_i
33
33
 
34
34
  if master_obj == objvalue
35
35
  obj_not_a_duplicate = false
36
- if options[:raise_error]
36
+ if options[:raise_error]
37
37
  invalid_meta[index] ||= {}
38
38
  invalid_meta[index][source_id] ||= {}
39
39
  invalid_meta[index][source_id][objindex] ||= {}
40
40
  invalid_meta[index][source_id][objindex][:error] = "Error during #{operation}: object confict detected"
41
- else
41
+ else
42
42
  invalid_meta[index] ||= {}
43
43
  invalid_meta[index][source_id] ||= {}
44
44
  invalid_meta[index][source_id][objindex] ||= {}
45
45
  invalid_meta[index][source_id][objindex][:duplicate_of] = true
46
-
46
+
47
47
  invalid_meta[master_queue_index] ||= {}
48
48
  invalid_meta[master_queue_index][source_id] ||= {}
49
49
  invalid_meta[master_queue_index][source_id][master_obj_index] ||= {}
50
50
  invalid_meta[master_queue_index][source_id][master_obj_index][:duplicates] ||= []
51
- invalid_meta[master_queue_index][source_id][master_obj_index][:duplicates] << {:client_id => client_id, :key => key, :value => objvalue}
52
- end
51
+ invalid_meta[master_queue_index][source_id][master_obj_index][:duplicates] << {:client_id => client_id, :key => key, :value => objvalue}
52
+ end
53
53
  break
54
54
  end
55
55
  end
@@ -62,15 +62,15 @@ module Rhoconnect
62
62
  end
63
63
  end
64
64
  end
65
- if options[:handler] and invalid_meta.size > 0
65
+ if options[:handler] and invalid_meta.size > 0
66
66
  proc = bind_handler :find_duplicates_on_update, options[:handler]
67
67
  invalid_meta = proc.call options, invalid_meta, operation, operation_data, client_ids
68
68
  end
69
- invalid_meta
70
- end
69
+ invalid_meta
70
+ end
71
71
 
72
72
  # methods that needs to be 'extended', not 'included'
73
- module ClassMethods
73
+ module ClassMethods
74
74
  def install_find_duplicates_on_update(options)
75
75
  options ||= {}
76
76
  options[:update] = true
@@ -78,7 +78,7 @@ module Rhoconnect
78
78
  @validators[:find_duplicates_on_update] = options
79
79
  options
80
80
  end
81
- end
81
+ end
82
82
  end
83
83
  end
84
84
  end
@@ -9,10 +9,10 @@ module Rhoconnect
9
9
  passphrase = settings[:iphonepassphrase]
10
10
  host = settings[:iphoneserver]
11
11
  port = settings[:iphoneport]
12
- if(cert and host and port)
12
+ if(cert and host and port)
13
13
  begin
14
14
  ssl_ctx = OpenSSL::SSL::SSLContext.new
15
- ssl_ctx.key = OpenSSL::PKey::RSA.new(cert, passphrase)
15
+ ssl_ctx.key = OpenSSL::PKey::RSA.new(cert, passphrase.to_s)
16
16
  ssl_ctx.cert = OpenSSL::X509::Certificate.new(cert)
17
17
 
18
18
  socket = TCPSocket.new(host, port)
@@ -23,10 +23,10 @@ module Rhoconnect
23
23
  res = ssl_socket.write(apn_message(params))
24
24
  ssl_socket.close
25
25
  socket.close
26
- rescue SocketError => error
26
+ rescue SocketError => error
27
27
  log "Error while sending ping: #{error}"
28
28
  raise error
29
- end
29
+ end
30
30
  else
31
31
  log "Invalid APNS settings: ping is ignored."
32
32
  log "cert_file: #{cert_file}, host: #{host}, port: #{port}"
@@ -151,7 +151,7 @@ module Rhoconnect
151
151
  return false if @dispatch_framework_initialized
152
152
 
153
153
  @dispatch_framework_initialized ||=true
154
- if RUBY_VERSION =~ /1.9/ and not defined?(JRUBY_VERSION)
154
+ if (RUBY_VERSION =~ /^1\.9\.\d/ || RUBY_VERSION =~ /^2\.\d+\.\d+/) and not defined?(JRUBY_VERSION)
155
155
  begin
156
156
  require 'rhoconnect/async'
157
157
  register Rhoconnect::Synchrony
@@ -231,7 +231,7 @@ _INSTALL_ASYNC_GEMS
231
231
  if rc_handler
232
232
  rc_handler_method = "execute_#{rc_handler}_handler"
233
233
  invoke_hook(:handler_installed, self, rc_handler, verb, route_url, options)
234
- end
234
+ end
235
235
  unless deprecated_route.nil?
236
236
  deprecated_urls = deprecated_route[:url].is_a?(String) ? [deprecated_route[:url]] : deprecated_route[:url]
237
237
  deprecated_urls.each do |deprecated_url|
@@ -365,11 +365,11 @@ module Rhoconnect
365
365
  return self.user_id if self.user_id == '*'
366
366
  # default is user_id
367
367
  pname = self.user_id
368
- begin
368
+ begin
369
369
  model_klass = Rhoconnect::Model::Base.load_source_model(self)
370
370
  pname = model_klass ? model_klass.partition_name(self.user_id) : self.user_id
371
371
  # eat the exception here
372
- rescue Exception => e
372
+ rescue Exception #=> e
373
373
  end
374
374
  pname
375
375
  end
@@ -361,7 +361,7 @@ module Rhoconnect
361
361
 
362
362
  collected_adds = {}
363
363
  collected_rems = {}
364
- my_bucket = nil
364
+ # my_bucket = nil
365
365
  @db.pipelined do
366
366
  data.each do |key,obj|
367
367
  is_create = objs[key].nil?
@@ -688,7 +688,7 @@ module Rhoconnect
688
688
  # ensure lock wasn't released between the setnx and get calls
689
689
  if current_lock
690
690
  current_lock_timeout = current_lock.to_i
691
- if raise_on_expire or Rhoconnect.raise_on_expired_lock
691
+ if raise_on_expire or Rhoconnect.raise_on_expired_lock
692
692
  if current_lock_timeout <= current_time
693
693
  # lock expired before operation which set it up completed
694
694
  # this process cannot continue without corrupting locked data
@@ -700,11 +700,11 @@ module Rhoconnect
700
700
  # previous lock expired and we replaced it with our own
701
701
  break
702
702
  end
703
- end
703
+ end
704
704
  # lock was released between setnx and get - try to acquire it again
705
705
  elsif @db.setnx(lock_key,ts)
706
706
  break
707
- end
707
+ end
708
708
  sleep(1)
709
709
  current_time = Time.now.to_i
710
710
  else
@@ -885,8 +885,14 @@ module Rhoconnect
885
885
  ConnectionPool::Wrapper.new(:size => Rhoconnect.connection_pool_size,
886
886
  :timeout => Rhoconnect.connection_pool_timeout) do
887
887
  host = '127.0.0.1' if host == 'localhost'
888
- Redis.connect(:thread_safe => true, :host => host,
889
- :port => port, :db => db, :password => password, :timeout => Rhoconnect.redis_timeout)
888
+ Redis.connect(
889
+ :thread_safe => true,
890
+ :host => host,
891
+ :port => port,
892
+ :db => db,
893
+ :password => password,
894
+ :timeout => Rhoconnect.redis_timeout
895
+ )
890
896
  end
891
897
  elsif server and (server.is_a?(Redis) or server.is_a?(ConnectionPool::Wrapper))
892
898
  server
@@ -73,8 +73,8 @@ module Utilities
73
73
  ENV['REDIS_HOME'] || File.join($redis_dest,$redis_ver)
74
74
  end
75
75
 
76
- def ruby19?
77
- RUBY_VERSION =~ /1.9/
76
+ def supported_mri_ruby?
77
+ RUBY_VERSION =~ /^1\.9\.\d/ || RUBY_VERSION =~ /^2\.\d+\.\d+/
78
78
  end
79
79
 
80
80
  def jruby?
@@ -1,3 +1,3 @@
1
1
  module Rhoconnect
2
- VERSION = '4.0.4'
2
+ VERSION = '5.1.1'
3
3
  end
data/lib/rhoconnect.rb CHANGED
@@ -3,7 +3,7 @@ require 'cgi'
3
3
  require 'json'
4
4
  require 'base64'
5
5
  require 'securerandom'
6
- require 'zip/zip'
6
+ require 'zip'
7
7
  require 'yaml'
8
8
  require 'rhoconnect/license'
9
9
  require 'rhoconnect/version'
@@ -56,7 +56,8 @@ module Rhoconnect
56
56
  :log_disabled, :license, :bulk_sync_poll_interval, :stats, :appserver, :api_token,
57
57
  :raise_on_expired_lock, :lock_duration, :cookie_expire, :predefined_sources,
58
58
  :connection_pool_size, :connection_pool_timeout, :redis_timeout, :store_key_ttl,
59
- :disable_resque_console, :disable_rc_console, :use_node, :restart_node_on_error, :redis_url
59
+ :disable_resque_console, :disable_rc_console, :use_node, :restart_node_on_error, :redis_url,
60
+ :node_channel_timeout
60
61
  end
61
62
 
62
63
  # this mixin adds the controller into the Application's URL Map
@@ -123,6 +124,7 @@ module Rhoconnect
123
124
  Rhoconnect.disable_resque_console ||= false
124
125
  Rhoconnect.use_node = Rhoconnect.use_node.nil? ? true : Rhoconnect.use_node
125
126
  Rhoconnect.restart_node_on_error ||= true if Rhoconnect.use_node
127
+ Rhoconnect.node_channel_timeout = get_setting(config, environment, :node_channel_timeout, 30)
126
128
  if File.directory?(File.join(Rhoconnect.app_directory,'sources'))
127
129
  check_and_add(File.join(Rhoconnect.app_directory,'sources'))
128
130
  # post deprecation warning !!!
@@ -193,7 +195,7 @@ _MIGRATE_TO_NEW_RHOCONNECT
193
195
 
194
196
  def start_nodejs_channels(opts = {})
195
197
  Node.shell_node(opts)
196
- NodeChannel.bootstrap if Node.started
198
+ NodeChannel.bootstrap(Rhoconnect.node_channel_timeout) if Node.started
197
199
  end
198
200
 
199
201
  # Generate admin user on first load
@@ -332,7 +334,7 @@ _MIGRATE_TO_NEW_RHOCONNECT
332
334
  File.open(uploaded_file, 'wb') do |file|
333
335
  file.write(params[:tempfile].read)
334
336
  end
335
- Zip::ZipFile.open(uploaded_file) do |zip_file|
337
+ Zip::File.open(uploaded_file) do |zip_file|
336
338
  zip_file.each do |f|
337
339
  f_path = File.join(file_dir,f.name)
338
340
  FileUtils.mkdir_p(File.dirname(f_path))
data/rhoconnect.gemspec CHANGED
@@ -41,14 +41,13 @@ Gem::Specification.new do |s|
41
41
 
42
42
  s.add_dependency('bundler', '~> 1.0')
43
43
  s.add_dependency('rack', '~> 1.5.2')
44
- s.add_dependency('sinatra', '~> 1.3')
45
- s.add_dependency('rake', '~> 10.0.0')
46
- s.add_dependency('json', '~> 1.7.7')
47
- s.add_dependency('rubyzip', '~> 0.9.4')
48
- s.add_dependency('connection_pool', '~> 1.0.0')
44
+ s.add_dependency('sinatra', '~> 1.4')
45
+ s.add_dependency('rake', '~> 10.4.0')
46
+ s.add_dependency('json', '~> 1.8')
47
+ s.add_dependency('rubyzip', '~> 1.1')
48
+ s.add_dependency('connection_pool', '~> 1.2.0')
49
49
  s.add_dependency('redis', '>= 3.0.1')
50
50
  s.add_dependency('resque', '>= 1.22.0')
51
51
  s.add_dependency('rest-client', '~> 1.6.1')
52
- s.add_dependency('templater', '~> 1.0.0')
53
52
  s.add_dependency('thor', '~> 0.18.0')
54
53
  end
@@ -9,7 +9,7 @@ def compress(path)
9
9
  path.sub!(%r[/$],'')
10
10
  archive = File.join(path,File.basename(path))+'.zip'
11
11
  FileUtils.rm archive, :force=>true
12
- Zip::ZipFile.open(archive, 'w') do |zipfile|
12
+ Zip::File.open(archive, 'w') do |zipfile|
13
13
  Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file|
14
14
  zipfile.add(file.sub(path+'/',''),file)
15
15
  end
@@ -1,27 +1,27 @@
1
1
  require File.join(File.dirname(__FILE__),'..','api_helper')
2
2
 
3
3
  describe "RhoconnectApiFastDelete" do
4
- it_should_behave_like "ApiHelper" do
5
- it "should delete an object from rhoconnect's :md" do
6
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
7
- @s = Source.load(@s_fields[:name],@s_params)
8
- set_doc_state(@s, {:md => data, :md_size => '3'})
9
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_delete",
10
- {:user_id => @u.id, :data => {'3' => @product3}}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
11
- last_response.should be_ok
12
- data.delete('3')
13
- verify_doc_result(@s, {:md => data, :md_size =>'2'})
14
- end
4
+ include_examples "ApiHelper"
15
5
 
16
- it "should not properly delete the object if fast_delete is called without all the attributes (because fast_delete doesn't ensure any data integrity)" do
17
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
18
- delete_data = {'3' => {'price' => '1.99'}}
19
- @s = Source.load(@s_fields[:name],@s_params)
20
- set_doc_state(@s, {:md => data, :md_size => '3'})
21
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_delete",
22
- {:user_id => @u.id, :data => delete_data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
23
- last_response.should be_ok
24
- verify_doc_result(@s, {:md => data, :md_size=>'2'})
25
- end
26
- end
6
+ it "should delete an object from rhoconnect's :md" do
7
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
8
+ @s = Source.load(@s_fields[:name],@s_params)
9
+ set_doc_state(@s, {:md => data, :md_size => '3'})
10
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_delete",
11
+ {:user_id => @u.id, :data => {'3' => @product3}}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
12
+ last_response.should be_ok
13
+ data.delete('3')
14
+ verify_doc_result(@s, {:md => data, :md_size =>'2'})
15
+ end
16
+
17
+ it "should not properly delete the object if fast_delete is called without all the attributes (because fast_delete doesn't ensure any data integrity)" do
18
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
19
+ delete_data = {'3' => {'price' => '1.99'}}
20
+ @s = Source.load(@s_fields[:name],@s_params)
21
+ set_doc_state(@s, {:md => data, :md_size => '3'})
22
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_delete",
23
+ {:user_id => @u.id, :data => delete_data}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
24
+ last_response.should be_ok
25
+ verify_doc_result(@s, {:md => data, :md_size=>'2'})
26
+ end
27
27
  end
@@ -1,28 +1,28 @@
1
1
  require File.join(File.dirname(__FILE__),'..','api_helper')
2
2
 
3
3
  describe "RhoconnectApiFastInsert" do
4
- it_should_behave_like "ApiHelper" do
5
- it "should append new objects to rhoconnect's :md" do
6
- data = {'1' => @product1, '2' => @product2}
7
- @s = Source.load(@s_fields[:name],@s_params)
8
- set_doc_state(@s, {:md => data, :md_size => '2'})
9
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_insert",
10
- {:user_id => @u.id, :data => {'3' => @product3}}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
11
- last_response.should be_ok
12
- data.merge!({'3' => @product3})
13
- verify_doc_result(@s, {:md => data, :md_size=>'3'})
14
- end
4
+ include_examples "ApiHelper"
15
5
 
16
- it "should incorrectly append data to existing object (because fast_insert doesn't ensure any data integrity)" do
17
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
18
- incorrect_insert = {'3' => {'price' => '1.99', 'new_field' => 'value'}}
19
- @s = Source.load(@s_fields[:name],@s_params)
20
- set_doc_state(@s, {:md => data, :md_size => '3'})
21
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_insert",
22
- {:user_id => @u.id, :data => incorrect_insert}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
23
- last_response.should be_ok
24
- data['3'].merge!(incorrect_insert['3'])
25
- verify_doc_result(@s, :md_size=>'4')
26
- end
27
- end
6
+ it "should append new objects to rhoconnect's :md" do
7
+ data = {'1' => @product1, '2' => @product2}
8
+ @s = Source.load(@s_fields[:name],@s_params)
9
+ set_doc_state(@s, {:md => data, :md_size => '2'})
10
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_insert",
11
+ {:user_id => @u.id, :data => {'3' => @product3}}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
12
+ last_response.should be_ok
13
+ data.merge!({'3' => @product3})
14
+ verify_doc_result(@s, {:md => data, :md_size=>'3'})
15
+ end
16
+
17
+ it "should incorrectly append data to existing object (because fast_insert doesn't ensure any data integrity)" do
18
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
19
+ incorrect_insert = {'3' => {'price' => '1.99', 'new_field' => 'value'}}
20
+ @s = Source.load(@s_fields[:name],@s_params)
21
+ set_doc_state(@s, {:md => data, :md_size => '3'})
22
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_insert",
23
+ {:user_id => @u.id, :data => incorrect_insert}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
24
+ last_response.should be_ok
25
+ data['3'].merge!(incorrect_insert['3'])
26
+ verify_doc_result(@s, :md_size=>'4')
27
+ end
28
28
  end
@@ -1,67 +1,67 @@
1
1
  require File.join(File.dirname(__FILE__),'..','api_helper')
2
2
 
3
3
  describe "RhoconnectApiFastUpdate" do
4
- it_should_behave_like "ApiHelper" do
5
- it "should update an attribute and add new one for an object in rhoconnect's :md" do
6
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
7
- @s = Source.load(@s_fields[:name],@s_params)
8
- set_doc_state(@s, {:md => data, :md_size => '3'})
9
-
10
- orig_obj_attrs = {'3' => {'price' => @product3['price']}}
11
- new_obj_attrs = {'3' => {'price' => '0.99', 'new_attr' => 'new_value'}}
12
-
13
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_update",
14
- {:user_id => @u.id, :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
15
- last_response.should be_ok
16
- data['3'].merge!(new_obj_attrs['3'])
17
- verify_doc_result(@s, {:md => data, :md_size=>'3'})
18
- end
19
-
20
- it "should update an attribute and add new one for an object in rhoconnect's :md using old route with deprecation warning" do
21
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
22
- @s = Source.load(@s_fields[:name],@s_params)
23
- set_doc_state(@s, {:md => data, :md_size => '3'})
24
-
25
- orig_obj_attrs = {'3' => {'price' => @product3['price']}}
26
- new_obj_attrs = {'3' => {'price' => '0.99', 'new_attr' => 'new_value'}}
27
-
28
- post "/api/source/fast_update",
29
- {:user_id => @u.id, :source_id => @s_fields[:name], :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
30
- last_response.should be_ok
31
- last_response.headers["Warning"].index('deprecated').should_not == nil
32
- data['3'].merge!(new_obj_attrs['3'])
33
- verify_doc_result(@s, {:md => data, :md_size=>'3'})
34
- end
35
-
36
- it "should update one attr, add one attr, and remove one attr for an object in rhoconnect's :md" do
37
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
38
- @s = Source.load(@s_fields[:name],@s_params)
39
- set_doc_state(@s, {:md => data, :md_size => '3'})
40
-
41
- orig_obj_attrs = {'3' => {'name' => @product3['name'], 'price' => @product3['price']}}
42
- new_obj_attrs = {'3' => {'price' => '0.99', 'new_attr' => 'new_value'}}
43
-
44
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_update",
45
- {:user_id => @u.id, :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
46
- last_response.should be_ok
47
- data['3'].delete('name')
48
- data['3'].merge!(new_obj_attrs['3'])
49
- verify_doc_result(@s, {:md => data, :md_size=>'3'})
50
- end
51
-
52
- it "should remove all attributes , and properly adjust md_size" do
53
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
54
- @s = Source.load(@s_fields[:name],@s_params)
55
- set_doc_state(@s, {:md => data, :md_size => '3'})
56
-
57
- orig_obj_attrs = {'3' => @product3}
58
- new_obj_attrs = {}
59
-
60
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_update",
61
- {:user_id => @u.id, :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
62
- last_response.should be_ok
63
- data.delete('3')
64
- verify_doc_result(@s, {:md => data, :md_size=>'2'})
65
- end
66
- end
4
+ include_examples "ApiHelper"
5
+
6
+ it "should update an attribute and add new one for an object in rhoconnect's :md" do
7
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
8
+ @s = Source.load(@s_fields[:name],@s_params)
9
+ set_doc_state(@s, {:md => data, :md_size => '3'})
10
+
11
+ orig_obj_attrs = {'3' => {'price' => @product3['price']}}
12
+ new_obj_attrs = {'3' => {'price' => '0.99', 'new_attr' => 'new_value'}}
13
+
14
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_update",
15
+ {:user_id => @u.id, :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
16
+ last_response.should be_ok
17
+ data['3'].merge!(new_obj_attrs['3'])
18
+ verify_doc_result(@s, {:md => data, :md_size=>'3'})
19
+ end
20
+
21
+ it "should update an attribute and add new one for an object in rhoconnect's :md using old route with deprecation warning" do
22
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
23
+ @s = Source.load(@s_fields[:name],@s_params)
24
+ set_doc_state(@s, {:md => data, :md_size => '3'})
25
+
26
+ orig_obj_attrs = {'3' => {'price' => @product3['price']}}
27
+ new_obj_attrs = {'3' => {'price' => '0.99', 'new_attr' => 'new_value'}}
28
+
29
+ post "/api/source/fast_update",
30
+ {:user_id => @u.id, :source_id => @s_fields[:name], :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
31
+ last_response.should be_ok
32
+ last_response.headers["Warning"].index('deprecated').should_not == nil
33
+ data['3'].merge!(new_obj_attrs['3'])
34
+ verify_doc_result(@s, {:md => data, :md_size=>'3'})
35
+ end
36
+
37
+ it "should update one attr, add one attr, and remove one attr for an object in rhoconnect's :md" do
38
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
39
+ @s = Source.load(@s_fields[:name],@s_params)
40
+ set_doc_state(@s, {:md => data, :md_size => '3'})
41
+
42
+ orig_obj_attrs = {'3' => {'name' => @product3['name'], 'price' => @product3['price']}}
43
+ new_obj_attrs = {'3' => {'price' => '0.99', 'new_attr' => 'new_value'}}
44
+
45
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_update",
46
+ {:user_id => @u.id, :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
47
+ last_response.should be_ok
48
+ data['3'].delete('name')
49
+ data['3'].merge!(new_obj_attrs['3'])
50
+ verify_doc_result(@s, {:md => data, :md_size=>'3'})
51
+ end
52
+
53
+ it "should remove all attributes , and properly adjust md_size" do
54
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
55
+ @s = Source.load(@s_fields[:name],@s_params)
56
+ set_doc_state(@s, {:md => data, :md_size => '3'})
57
+
58
+ orig_obj_attrs = {'3' => @product3}
59
+ new_obj_attrs = {}
60
+
61
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/fast_update",
62
+ {:user_id => @u.id, :delete_data => orig_obj_attrs, :data => new_obj_attrs}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
63
+ last_response.should be_ok
64
+ data.delete('3')
65
+ verify_doc_result(@s, {:md => data, :md_size=>'2'})
66
+ end
67
67
  end
@@ -1,18 +1,16 @@
1
1
  require File.join(File.dirname(__FILE__),'..','api_helper')
2
2
 
3
3
  describe "RhoconnectApiPushDeletes" do
4
- it_should_behave_like "ApiHelper" do
5
-
6
- it "should delete object from :md" do
7
- data = {'1' => @product1, '2' => @product2, '3' => @product3}
8
- @s = Source.load(@s_fields[:name],@s_params)
9
- set_doc_state(@s, {:md => data, :md_size => '3'})
10
- data.delete('2')
11
- post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/push_deletes",
12
- {:user_id => @u.id, :objects => ['2']}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
13
- last_response.should be_ok
14
- verify_doc_result(@s, {:md => data, :md_size=>'2'})
15
- end
16
-
4
+ include_examples "ApiHelper"
5
+
6
+ it "should delete object from :md" do
7
+ data = {'1' => @product1, '2' => @product2, '3' => @product3}
8
+ @s = Source.load(@s_fields[:name],@s_params)
9
+ set_doc_state(@s, {:md => data, :md_size => '3'})
10
+ data.delete('2')
11
+ post "/app/#{Rhoconnect::API_VERSION}/#{@s_fields[:name]}/push_deletes",
12
+ {:user_id => @u.id, :objects => ['2']}, {Rhoconnect::API_TOKEN_HEADER => @api_token}
13
+ last_response.should be_ok
14
+ verify_doc_result(@s, {:md => data, :md_size=>'2'})
17
15
  end
18
16
  end