umts-microservices-engine 0.0.2
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/Rakefile +23 -0
- data/app/controllers/microservices_engine/application_controller.rb +5 -0
- data/app/controllers/microservices_engine/v1/data_controller.rb +77 -0
- data/app/models/microservices_engine/connection.rb +28 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20160914202818_create_microservices_engine_connections.rb +12 -0
- data/lib/generators/install/USAGE +8 -0
- data/lib/generators/install/install_generator.rb +10 -0
- data/lib/generators/install/templates/microservices_engine.rb +29 -0
- data/lib/generators/install/templates/mse_router_info.yml +23 -0
- data/lib/microservices_engine.rb +74 -0
- data/lib/microservices_engine/engine.rb +10 -0
- data/lib/microservices_engine/version.rb +4 -0
- data/lib/tasks/microservices_engine_tasks.rake +5 -0
- data/spec/controllers/data_controller_spec.rb +183 -0
- data/spec/microservices_engine/install_generator_spec.rb.old +17 -0
- data/spec/microservices_engine_spec.rb +8 -0
- data/spec/models/connection_spec.rb +28 -0
- data/spec/rails_helper.rb +59 -0
- data/spec/spec_helper.rb +91 -0
- metadata +211 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75e14e03e11207896af79f0e5a102ff8a139e7cd
|
4
|
+
data.tar.gz: 37a40ed242523be25d32c9cb1369c57f1a73c546
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d6eb44c86793bf4345185fe4919dc11b6c99dfd7c601d3b6ccae09f112e56242e318b186e8b22928d20cd6b10f4cebbfdecaae7c80c9cca5eade528705a9cf8
|
7
|
+
data.tar.gz: 227bb25ff5044144774e1211f177963f15b8006032fa48b4f6497d8ee3411991c0e9ec207367a7ab489448a2bb36f09247a8b8ff21841529b70deee493b15133
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 UMass Transportation Services
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
|
9
|
+
load 'rails/tasks/engine.rake'
|
10
|
+
load 'rails/tasks/statistics.rake'
|
11
|
+
|
12
|
+
Bundler::GemHelper.install_tasks
|
13
|
+
|
14
|
+
require 'rake/testtask'
|
15
|
+
|
16
|
+
Rake::TestTask.new(:test) do |t|
|
17
|
+
t.libs << 'lib'
|
18
|
+
t.libs << 'test'
|
19
|
+
t.pattern = 'test/**/*_test.rb'
|
20
|
+
t.verbose = false
|
21
|
+
end
|
22
|
+
|
23
|
+
task default: :test
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_dependency 'microservices_engine/application_controller'
|
3
|
+
|
4
|
+
module MicroservicesEngine
|
5
|
+
module V1
|
6
|
+
class DataController < ApplicationController
|
7
|
+
def register
|
8
|
+
# TO-DO
|
9
|
+
# . . .
|
10
|
+
|
11
|
+
# Current assumption of example request format
|
12
|
+
#
|
13
|
+
# {
|
14
|
+
# 'build': 1.0.0,
|
15
|
+
# 'token': 'a72!j*^bQ34dE%SS$#haBd%67#cD',
|
16
|
+
# 'content': {
|
17
|
+
# {
|
18
|
+
# 'name': 'Endpoint 1'
|
19
|
+
# 'object': 'FieldTrip'
|
20
|
+
# 'url': 'http://example.com/microservices_engine/v1/data'
|
21
|
+
# },
|
22
|
+
# {
|
23
|
+
# 'name': 'Endpoint 2'
|
24
|
+
# 'object': 'Survey'
|
25
|
+
# 'url': 'http://potatoes.com/microservices_engine/v1/data'
|
26
|
+
# }
|
27
|
+
# }
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
|
31
|
+
data = params['content']
|
32
|
+
data_objects = data.map { |d| d['object'] }
|
33
|
+
|
34
|
+
verify_token(params['token'])
|
35
|
+
verify_build(params['build'])
|
36
|
+
|
37
|
+
existing = Connection.all
|
38
|
+
in_request = existing.dup.to_a.keep_if { |c| data_objects.include? c.object }
|
39
|
+
not_in_request = existing - in_request
|
40
|
+
|
41
|
+
# Remove all objects not included in the request
|
42
|
+
not_in_request.each do |unwanted|
|
43
|
+
Connection.destroy(unwanted.id)
|
44
|
+
end
|
45
|
+
|
46
|
+
# 'Find and update' or 'Create' all remaining models
|
47
|
+
data.each do |endpoint|
|
48
|
+
desired = Connection.find_by object: endpoint['object']
|
49
|
+
if desired.present?
|
50
|
+
desired.update_attributes(
|
51
|
+
name: endpoint.require(:name),
|
52
|
+
url: endpoint.require(:url)
|
53
|
+
)
|
54
|
+
else
|
55
|
+
Connection.create(
|
56
|
+
name: endpoint.require(:name),
|
57
|
+
url: endpoint.require(:url),
|
58
|
+
object: endpoint.require(:object)
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
render json: { 'response': 200 }, status: :ok
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def verify_token(token)
|
68
|
+
raise SecurityError, '(Stub) Invalid Token' unless MicroservicesEngine.valid_token?(token)
|
69
|
+
end
|
70
|
+
|
71
|
+
def verify_build(build)
|
72
|
+
# The build= method already has verification built-in
|
73
|
+
MicroservicesEngine.build = build
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module MicroservicesEngine
|
5
|
+
class Connection < ActiveRecord::Base
|
6
|
+
validates :name, :url, :object, presence: true
|
7
|
+
|
8
|
+
def self.get(resource, path, params = {})
|
9
|
+
conn = Connection.find_by(object: resource.to_s) # Does :abc match "abc"?
|
10
|
+
conn.get(path, params) if conn.present?
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, params = {})
|
14
|
+
# Example use:
|
15
|
+
# (connection object for FieldTrip).get([123223, public_trip_stops], {active_only: true})
|
16
|
+
# => queries endpoint: uri/123223/public_trip_stops
|
17
|
+
# => endpoint finds all FieldTrip objects that are active (param flag)
|
18
|
+
# => returns the response if the request was a success
|
19
|
+
|
20
|
+
# Assumption: url is followed by a `/`
|
21
|
+
uri = URI.parse(url + path.join('/'))
|
22
|
+
uri.query = URI.encode_www_form(params)
|
23
|
+
|
24
|
+
res = Net::HTTP.get_response(uri)
|
25
|
+
return res.body if res.is_a?(Net::HTTPSuccess)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class CreateMicroservicesEngineConnections < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :microservices_engine_connections do |t|
|
5
|
+
t.string :name
|
6
|
+
t.string :object
|
7
|
+
t.string :url
|
8
|
+
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def setup_initializer
|
6
|
+
template 'mse_router_info.yml', 'config/mse_router_info.yml'
|
7
|
+
copy_file 'microservices_engine.rb',
|
8
|
+
'config/initializers/microservices_engine.rb'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'net/http'
|
3
|
+
config_file = 'config/mse_router_info.yml'
|
4
|
+
|
5
|
+
unless File.file?(config_file)
|
6
|
+
raise IOError, '[MSE] > No router configuration YAML file found'
|
7
|
+
end
|
8
|
+
|
9
|
+
config_data = YAML.load_file(config_file)
|
10
|
+
|
11
|
+
if [config_data['name'], config_data['uri'], config_data['security_token']].any?(&:blank?)
|
12
|
+
raise '[MSE] > Please fill out config/mse_router_info.yml'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Make sure the URI ends with a / character
|
16
|
+
router_uri = config['router_uri']
|
17
|
+
|
18
|
+
uri = config_data['uri']
|
19
|
+
uri += '/' if uri[-1] != '/'
|
20
|
+
|
21
|
+
res = Net::HTTP.post_form(
|
22
|
+
URI(router_uri),
|
23
|
+
'name': config_data['name'],
|
24
|
+
'url': uri,
|
25
|
+
'models': config_data['accessible_models'],
|
26
|
+
'security_token': config_data['security_token']
|
27
|
+
)
|
28
|
+
|
29
|
+
raise '[MSE] > The router API response was invalid' if res.code != '200'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# UMass Transit Microservices Engine
|
2
|
+
# Router API Data Endpoint Configuration
|
3
|
+
|
4
|
+
# REQUIRED field
|
5
|
+
# The name of the microservice
|
6
|
+
name: ''
|
7
|
+
|
8
|
+
# REQUIRED field
|
9
|
+
# The URI for the site hosting the microservice
|
10
|
+
# NOTE: Do not attach the /v1/data to this.
|
11
|
+
uri: ''
|
12
|
+
|
13
|
+
# REQUIRED field
|
14
|
+
# Verification token
|
15
|
+
security_token: ''
|
16
|
+
|
17
|
+
# REQUIRED Field
|
18
|
+
# Endpoint of Microservices router
|
19
|
+
router_uri: ''
|
20
|
+
|
21
|
+
# OPTIONAL field (leave blank if not applicable)
|
22
|
+
# The models that the service can give info on
|
23
|
+
accessible_models: []
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'microservices_engine/engine' if defined? Rails
|
5
|
+
|
6
|
+
module MicroservicesEngine
|
7
|
+
class << self
|
8
|
+
# Setter method for the `build` portion of the engine, includes various validations
|
9
|
+
def build=(b)
|
10
|
+
@build = b if Rails.env.test? && b == '1.1.1'
|
11
|
+
|
12
|
+
# ---------------- Semantic Versioning ---------------- #
|
13
|
+
# 1. All version INCREASES are VALID #
|
14
|
+
# 2. Version DECREASES are INVALID IF AND ONLY IF none #
|
15
|
+
# of the more importantversion numbers increase. #
|
16
|
+
# 3. That is to say... #
|
17
|
+
# a. A major decrease is never valid #
|
18
|
+
# b. A minor decrease is only valid when the major #
|
19
|
+
# version increases. #
|
20
|
+
# c. A revision decrease is only valid when either #
|
21
|
+
# the major or minor version increases. #
|
22
|
+
# ----------------------------------------------------- #
|
23
|
+
|
24
|
+
major, minor, rev = b.split('.').map(&:to_i)
|
25
|
+
cmajor, cminor, crev = build.split('.').map(&:to_i)
|
26
|
+
|
27
|
+
# ---------------------- Examples ---------------------- #
|
28
|
+
# 2.3.2 -> 1.3.2 1.2.3 -> 1.1.3 1.2.3 -> 0.2.3 #
|
29
|
+
# 1.2.3 -> 1.2.2 1.2.3 -> 1.1.2 1.2.3 -> 0.2.3 #
|
30
|
+
# ------------------------------------------------------ #
|
31
|
+
invalid_changes = [
|
32
|
+
cmajor > major,
|
33
|
+
cminor > minor && cmajor <= major,
|
34
|
+
crev > rev && cminor <= minor && cmajor <= major
|
35
|
+
]
|
36
|
+
|
37
|
+
if invalid_changes.any?
|
38
|
+
raise 'Received version is older than existing. Now: #{build}. Given: #{b}'
|
39
|
+
end
|
40
|
+
|
41
|
+
@build = b
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the engine's current build
|
45
|
+
def build
|
46
|
+
@build ||= '0.0.0'
|
47
|
+
end
|
48
|
+
|
49
|
+
# Reloads and returns the engine's current YML configuration
|
50
|
+
def reload_config
|
51
|
+
@config = YAML.load_file('config/mse_router_info.yml')
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the engine's YML configuration, alias for `reload_config`
|
55
|
+
alias config reload_config
|
56
|
+
|
57
|
+
# Takes in a token and verifies against the engine's YML configuration files
|
58
|
+
# Params:
|
59
|
+
# +token+:: The token to test validity of
|
60
|
+
def valid_token?(token)
|
61
|
+
return token == 'TEST_ENV_VALID_TOKEN' if Rails.env.test?
|
62
|
+
|
63
|
+
valid_token = config['security_token']
|
64
|
+
raise 'Security token is not set! Please set it as soon as possible!' if valid_token.blank?
|
65
|
+
|
66
|
+
token == valid_token
|
67
|
+
end
|
68
|
+
|
69
|
+
# Redirects an engine `get` call to the appropriate resource
|
70
|
+
def get(resource, path, params = {})
|
71
|
+
MicroservicesEngine::Connection.get(resource, path, params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails_helper'
|
3
|
+
|
4
|
+
# PLANNED FOR MOVE TO OTHER FILE
|
5
|
+
def change_build(v, b)
|
6
|
+
b['build'] = v
|
7
|
+
end
|
8
|
+
|
9
|
+
def relative_build(ma, mi, r)
|
10
|
+
[ma, mi, r].map { |ver| 1 + ver }.join('.')
|
11
|
+
end
|
12
|
+
# PLANNED FOR MOVE TO OTHER FILE
|
13
|
+
|
14
|
+
describe MicroservicesEngine::V1::DataController, type: :controller do
|
15
|
+
routes { MicroservicesEngine::Engine.routes }
|
16
|
+
def setup
|
17
|
+
@routes = MicroservicesEngine::Engine.routes
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
MicroservicesEngine.build = '1.1.1'
|
22
|
+
@data = {
|
23
|
+
'build': '1.1.2',
|
24
|
+
'token': 'TEST_ENV_VALID_TOKEN',
|
25
|
+
'content': [
|
26
|
+
{
|
27
|
+
'name': 'Endpoint 1',
|
28
|
+
'object': 'FieldTrip',
|
29
|
+
'url': 'http://example.com/microservices_engine/v1/data'
|
30
|
+
},
|
31
|
+
{
|
32
|
+
'name': 'Endpoint 2',
|
33
|
+
'object': 'Survey',
|
34
|
+
'url': 'http://potatoes.com/microservices_engine/v1/data'
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
@changed_data = @data.deep_dup # A version of data that is changed for tests
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'POST #register' do
|
42
|
+
it 'responds' do
|
43
|
+
post :register, @data
|
44
|
+
expect(response.status).to be(200)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Validating tokens
|
48
|
+
describe 'validating token' do
|
49
|
+
it 'accepts valid token' do
|
50
|
+
# 1. Expect submitting the data to not cause any issues
|
51
|
+
|
52
|
+
expect { post :register, @data }.not_to raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'denies invalid token' do
|
56
|
+
# 1. Change base data to be an invalid token
|
57
|
+
# 2. Expect the request to cause an error.
|
58
|
+
|
59
|
+
@changed_data['token'] = 'mayonnaise_is_not_an_instrument_patrick'
|
60
|
+
expect { post :register, @changed_data }.to raise_error(SecurityError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# The request updates the build version properly
|
65
|
+
describe 'updating MicroservicesEngine.build' do
|
66
|
+
context 'failing builds' do
|
67
|
+
failing_builds = [0, -1].repeated_permutation(3).to_a.map { |bld| relative_build(*bld) }
|
68
|
+
failing_builds -= ['1.1.1'] # this is a result of above but is a valid build
|
69
|
+
|
70
|
+
failing_builds.each do |failing_build|
|
71
|
+
it 'fails with older version #{failing_build}' do
|
72
|
+
change_build(failing_build, @changed_data)
|
73
|
+
expect { post :register, @changed_data }.to raise_error(RuntimeError)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'passing builds' do
|
79
|
+
passing_builds = [0, 1].repeated_permutation(3).to_a.map { |bld| relative_build(*bld) }
|
80
|
+
|
81
|
+
passing_builds.each do |passing_build|
|
82
|
+
it 'passes with newer version #{passing_build}' do
|
83
|
+
change_build(passing_build, @changed_data)
|
84
|
+
expect(MicroservicesEngine.build).to eq('1.1.1')
|
85
|
+
post :register, @changed_data
|
86
|
+
expect(MicroservicesEngine.build).to eq(passing_build)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# The request generates, modifies, and removes Connection
|
93
|
+
# objects as expected
|
94
|
+
describe 'resulting Connection models' do
|
95
|
+
before(:each) do
|
96
|
+
@extract = ->(d, key) { d[:content].collect { |c| c[key.to_sym] } }
|
97
|
+
@connection = MicroservicesEngine::Connection
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'before the request' do
|
101
|
+
it 'has no objects' do
|
102
|
+
expect(@connection.count).to be(0)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'new' do
|
107
|
+
before(:each) do
|
108
|
+
post :register, @data
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'generates the models' do
|
112
|
+
expect(@connection.count).to be(2)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'generated the names' do
|
116
|
+
expect(@connection.all.map(&:name)).to eq(@extract.call(@data, :name))
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'generated the urls' do
|
120
|
+
expect(@connection.all.map(&:url)).to eq(@extract.call(@data, :url))
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'generated the objects' do
|
124
|
+
expect(@connection.all.map(&:object)).to eq(@extract.call(@data, :object))
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'adds model when new data appears' do
|
128
|
+
new_data = {
|
129
|
+
'name': 'Endpoint 2',
|
130
|
+
'object': 'Potatoes',
|
131
|
+
'url': 'pota://toe.sareawes.ome'
|
132
|
+
}
|
133
|
+
@changed_data[:content].append(new_data)
|
134
|
+
|
135
|
+
expect { post :register, @changed_data }
|
136
|
+
.to change { @connection.count }
|
137
|
+
.by(1)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'editing' do
|
142
|
+
before(:each) do
|
143
|
+
post :register, @data
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'updates the name' do
|
147
|
+
@changed_data[:content][0][:name] = 'Potatoes'
|
148
|
+
expect { post :register, @changed_data }
|
149
|
+
.to change { @connection.all.map(&:name) }
|
150
|
+
.from(@extract.call(@data, :name))
|
151
|
+
.to(@extract.call(@changed_data, :name))
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'updates the url' do
|
155
|
+
@changed_data[:content][0][:url] = 'pota://toe.s/'
|
156
|
+
expect { post :register, @changed_data }
|
157
|
+
.to change { @connection.all.map(&:url) }
|
158
|
+
.from(@extract.call(@data, :url))
|
159
|
+
.to(@extract.call(@changed_data, :url))
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'swaps information to other model' do
|
163
|
+
@changed_data[:content][0][:object] = 'SomeOtherObject'
|
164
|
+
expect { post :register, @changed_data }
|
165
|
+
.not_to change { @connection.count }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'removing' do
|
170
|
+
before(:each) do
|
171
|
+
post :register, @data
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'removes the model' do
|
175
|
+
@changed_data[:content].delete_at(0)
|
176
|
+
expect { post :register, @changed_data }
|
177
|
+
.to change { @connection.count }
|
178
|
+
.by(-1)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'generators/install/install_generator'
|
4
|
+
|
5
|
+
module MicroservicesEngine
|
6
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
7
|
+
tests InstallGenerator
|
8
|
+
destination Rails.root.join('tmp/generators')
|
9
|
+
setup :prepare_destination
|
10
|
+
|
11
|
+
# test "generator runs without errors" do
|
12
|
+
# assert_nothing_raised do
|
13
|
+
# run_generator ["arguments"]
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails_helper'
|
3
|
+
|
4
|
+
describe MicroservicesEngine::Connection do
|
5
|
+
before(:each) do
|
6
|
+
@conn = MicroservicesEngine::Connection.create(
|
7
|
+
name: 'Connection 1',
|
8
|
+
url: 'http://example.com/',
|
9
|
+
object: 'ExampleModel'
|
10
|
+
)
|
11
|
+
@path = %w(test tset)
|
12
|
+
stub_request(:get, @conn.url + @path.join('/'))
|
13
|
+
.with(headers: {
|
14
|
+
'Accept' => '*/*',
|
15
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
16
|
+
'Host' => 'example.com',
|
17
|
+
'User-Agent' => 'Ruby'
|
18
|
+
})
|
19
|
+
.to_return(status: 200, body: '', headers: {})
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'self.get' do
|
23
|
+
# it 'implies params' do
|
24
|
+
# expect(@conn).to receive(:get).with(@path, {})
|
25
|
+
# resp = MicroservicesEngine::Connection.get('ExampleModel', @path)
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
3
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
|
+
require File.expand_path('../../test/dummy/config/environment', __FILE__)
|
5
|
+
# Prevent database truncation if the environment is production
|
6
|
+
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
7
|
+
require 'spec_helper'
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'webmock/rspec'
|
10
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
11
|
+
|
12
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
13
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
14
|
+
# run as spec files by default. This means that files in spec/support that end
|
15
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
16
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
17
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
18
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
19
|
+
#
|
20
|
+
# The following line is provided for convenience purposes. It has the downside
|
21
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
22
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
23
|
+
# require only the support files necessary.
|
24
|
+
#
|
25
|
+
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
26
|
+
|
27
|
+
# Checks for pending migration and applies them before tests are run.
|
28
|
+
# If you are not using ActiveRecord, you can remove this line.
|
29
|
+
ActiveRecord::Migration.maintain_test_schema!
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
33
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
34
|
+
|
35
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
36
|
+
# examples within a transaction, remove the following line or assign false
|
37
|
+
# instead of true.
|
38
|
+
config.use_transactional_fixtures = true
|
39
|
+
|
40
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
41
|
+
# based on their file location, for example enabling you to call `get` and
|
42
|
+
# `post` in specs under `spec/controllers`.
|
43
|
+
#
|
44
|
+
# You can disable this behaviour by removing the line below, and instead
|
45
|
+
# explicitly tag your specs with their type, e.g.:
|
46
|
+
#
|
47
|
+
# RSpec.describe UsersController, :type => :controller do
|
48
|
+
# # ...
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# The different available types are documented in the features, such as in
|
52
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
53
|
+
config.infer_spec_type_from_file_location!
|
54
|
+
|
55
|
+
# Filter lines from Rails gems in backtraces.
|
56
|
+
config.filter_rails_from_backtrace!
|
57
|
+
# arbitrary gems may also be filtered via:
|
58
|
+
# config.filter_gems_from_backtrace("gem name")
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
5
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
6
|
+
# files.
|
7
|
+
#
|
8
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
9
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
10
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
11
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
12
|
+
# a separate helper file that requires the additional dependencies and performs
|
13
|
+
# the additional setup, and require it from the spec files that actually need
|
14
|
+
# it.
|
15
|
+
#
|
16
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
17
|
+
# users commonly want.
|
18
|
+
#
|
19
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# rspec-expectations config goes here. You can use an alternate
|
22
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
23
|
+
# assertions if you prefer.
|
24
|
+
config.expect_with :rspec do |expectations|
|
25
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
26
|
+
# and `failure_message` of custom matchers include text for helper methods
|
27
|
+
# defined using `chain`, e.g.:
|
28
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
29
|
+
# # => "be bigger than 2 and smaller than 4"
|
30
|
+
# ...rather than:
|
31
|
+
# # => "be bigger than 2"
|
32
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
36
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
37
|
+
config.mock_with :rspec do |mocks|
|
38
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
39
|
+
# a real object. This is generally recommended, and will default to
|
40
|
+
# `true` in RSpec 4.
|
41
|
+
mocks.verify_partial_doubles = true
|
42
|
+
end
|
43
|
+
|
44
|
+
# The settings below are suggested to provide a good initial experience
|
45
|
+
# with RSpec, but feel free to customize to your heart's content.
|
46
|
+
# # These two settings work together to allow you to limit a spec run
|
47
|
+
# # to individual examples or groups you care about by tagging them with
|
48
|
+
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# # get run.
|
50
|
+
# config.filter_run :focus
|
51
|
+
# config.run_all_when_everything_filtered = true
|
52
|
+
#
|
53
|
+
# # Allows RSpec to persist some state between runs in order to support
|
54
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# # you configure your source control system to ignore this file.
|
56
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
57
|
+
#
|
58
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# # recommended. For more details, see:
|
60
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
61
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
63
|
+
# config.disable_monkey_patching!
|
64
|
+
#
|
65
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
66
|
+
# # file, and it's useful to allow more verbose output when running an
|
67
|
+
# # individual spec file.
|
68
|
+
# if config.files_to_run.one?
|
69
|
+
# # Use the documentation formatter for detailed output,
|
70
|
+
# # unless a formatter has already been configured
|
71
|
+
# # (e.g. via a command-line flag).
|
72
|
+
# config.default_formatter = 'doc'
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# # Print the 10 slowest examples and example groups at the
|
76
|
+
# # end of the spec run, to help surface which specs are running
|
77
|
+
# # particularly slow.
|
78
|
+
# config.profile_examples = 10
|
79
|
+
#
|
80
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
81
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
82
|
+
# # the seed, which is printed after each run.
|
83
|
+
# # --seed 1234
|
84
|
+
# config.order = :random
|
85
|
+
#
|
86
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
87
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
88
|
+
# # test failures related to randomization by passing the same `--seed` value
|
89
|
+
# # as the one that triggered the failure.
|
90
|
+
# Kernel.srand config.seed
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: umts-microservices-engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- UMass Transportation Services
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.2.7.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.2.7.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Simple UMTS inter-service communication network
|
154
|
+
email:
|
155
|
+
- transit-it@admin.umass.edu
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- LICENSE
|
161
|
+
- Rakefile
|
162
|
+
- app/controllers/microservices_engine/application_controller.rb
|
163
|
+
- app/controllers/microservices_engine/v1/data_controller.rb
|
164
|
+
- app/models/microservices_engine/connection.rb
|
165
|
+
- config/routes.rb
|
166
|
+
- db/migrate/20160914202818_create_microservices_engine_connections.rb
|
167
|
+
- lib/generators/install/USAGE
|
168
|
+
- lib/generators/install/install_generator.rb
|
169
|
+
- lib/generators/install/templates/microservices_engine.rb
|
170
|
+
- lib/generators/install/templates/mse_router_info.yml
|
171
|
+
- lib/microservices_engine.rb
|
172
|
+
- lib/microservices_engine/engine.rb
|
173
|
+
- lib/microservices_engine/version.rb
|
174
|
+
- lib/tasks/microservices_engine_tasks.rake
|
175
|
+
- spec/controllers/data_controller_spec.rb
|
176
|
+
- spec/microservices_engine/install_generator_spec.rb.old
|
177
|
+
- spec/microservices_engine_spec.rb
|
178
|
+
- spec/models/connection_spec.rb
|
179
|
+
- spec/rails_helper.rb
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
homepage: https://github.com/umts/microservices-engine
|
182
|
+
licenses:
|
183
|
+
- MIT
|
184
|
+
metadata: {}
|
185
|
+
post_install_message:
|
186
|
+
rdoc_options: []
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
requirements: []
|
200
|
+
rubyforge_project:
|
201
|
+
rubygems_version: 2.5.1
|
202
|
+
signing_key:
|
203
|
+
specification_version: 4
|
204
|
+
summary: Simple UMTS inter-service communication network
|
205
|
+
test_files:
|
206
|
+
- spec/controllers/data_controller_spec.rb
|
207
|
+
- spec/microservices_engine/install_generator_spec.rb.old
|
208
|
+
- spec/microservices_engine_spec.rb
|
209
|
+
- spec/models/connection_spec.rb
|
210
|
+
- spec/rails_helper.rb
|
211
|
+
- spec/spec_helper.rb
|