lib/submodules/ably-ruby/spec/support/test_app.rb in ably-rest-0.7.5 vs lib/submodules/ably-ruby/spec/support/test_app.rb in ably-rest-0.8.1
- old
+ new
@@ -1,31 +1,18 @@
require 'singleton'
class TestApp
- APP_SPEC = {
- 'keys' => [
- {},
- {
- 'capability' => '{ "cansubscribe:*":["subscribe"], "canpublish:*":["publish"], "canpublish:andpresence":["presence","publish"] }'
- }
- ],
- 'namespaces' => [
- { 'id' => 'persisted', 'persisted' => true }
- ],
- 'channels' => [
- {
- 'name' => 'persisted:presence_fixtures',
- 'presence' => [
- { 'clientId' => 'client_bool', 'data' => 'true' },
- { 'clientId' => 'client_int', 'data' => '24' },
- { 'clientId' => 'client_string', 'data' => 'This is a string clientData payload' },
- { 'clientId' => 'client_json', 'data' => '{ "test" => \'This is a JSONObject clientData payload\'}' }
- ]
- }
- ]
- }
+ TEST_RESOURCES_PATH = File.expand_path('../../../lib/submodules/ably-common/test-resources', __FILE__)
+ # App configuration for test app
+ # See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
+ APP_SPEC = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['post_apps']
+
+ # Cipher details used for client_encoded presence data in test app
+ # See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
+ APP_SPEC_CIPHER = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['cipher']
+
# If an app has already been created and we need a new app, create a new test app
# This is sometimes needed when a test needs to be isolated from any other tests
def self.reload
if instance_variable_get('@singleton__instance__')
instance.delete
@@ -38,35 +25,35 @@
def initialize
create_test_app
end
def app_id
- @attributes["appId"]
+ @attributes.fetch('appId')
end
def key
- @attributes["keys"].first
+ @attributes.fetch('keys').first
end
def restricted_key
- @attributes["keys"][1]
+ @attributes.fetch('keys')[1]
end
- def key_id
- "#{app_id}.#{key['id']}"
+ def key_name
+ key.fetch('keyName')
end
- def key_value
- key['value']
+ def key_secret
+ key.fetch('keySecret')
end
def api_key
- "#{key_id}:#{key_value}"
+ key.fetch('keyStr')
end
def restricted_api_key
- "#{app_id}.#{restricted_key['id']}:#{restricted_key['value']}"
+ restricted_key.fetch('keyStr')
end
def delete
return unless TestApp.instance_variable_get('@singleton__instance__')
@@ -105,15 +92,15 @@
def realtime_host
host.gsub(/rest/, 'realtime')
end
def create_test_stats(stats)
- client = Ably::Rest::Client.new(api_key: api_key, environment: environment)
+ client = Ably::Rest::Client.new(key: api_key, environment: environment)
response = client.post('/stats', stats)
raise "Could not create stats fixtures. Ably responded with status #{response.status}\n#{response.body}" unless (200..299).include?(response.status)
end
private
def sandbox_client
- @sandbox_client ||= Ably::Rest::Client.new(api_key: 'app.key:secret', tls: true, environment: environment)
+ @sandbox_client ||= Ably::Rest::Client.new(key: 'app.key:secret', tls: true, environment: environment)
end
end