integration_pal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +81 -0
- data/Rakefile +36 -0
- data/app/assets/config/integration_pal_manifest.js +2 -0
- data/app/assets/javascripts/integration_pal/application.js +13 -0
- data/app/assets/stylesheets/integration_pal/application.css +27 -0
- data/app/controllers/integration_pal/api/v1/jobs_controller.rb +29 -0
- data/app/controllers/integration_pal/api_controller.rb +16 -0
- data/app/controllers/integration_pal/application_controller.rb +8 -0
- data/app/controllers/integration_pal/jobs_controller.rb +62 -0
- data/app/controllers/integration_pal/workers_controller.rb +62 -0
- data/app/helpers/integration_pal/application_helper.rb +4 -0
- data/app/jobs/integration_pal/application_job.rb +4 -0
- data/app/mailers/integration_pal/application_mailer.rb +6 -0
- data/app/models/integration_pal/application_record.rb +5 -0
- data/app/models/integration_pal/job.rb +22 -0
- data/app/models/integration_pal/worker.rb +29 -0
- data/app/views/integration_pal/jobs/_form.html.erb +32 -0
- data/app/views/integration_pal/jobs/edit.html.erb +6 -0
- data/app/views/integration_pal/jobs/index.html.erb +25 -0
- data/app/views/integration_pal/jobs/new.html.erb +5 -0
- data/app/views/integration_pal/jobs/show.html.erb +19 -0
- data/app/views/integration_pal/workers/_form.html.erb +48 -0
- data/app/views/integration_pal/workers/edit.html.erb +6 -0
- data/app/views/integration_pal/workers/index.html.erb +32 -0
- data/app/views/integration_pal/workers/new.html.erb +5 -0
- data/app/views/integration_pal/workers/show.html.erb +14 -0
- data/app/views/layouts/_navbar.html.erb +24 -0
- data/app/views/layouts/integration_pal/application.html.erb +15 -0
- data/config/initializers/encryption.rb +2 -0
- data/config/initializers/jobs.rb +4 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20170524203831_create_integration_pal_workers.rb +14 -0
- data/db/migrate/20170525153603_create_integration_pal_jobs.rb +14 -0
- data/lib/integration_pal/engine.rb +25 -0
- data/lib/integration_pal/version.rb +3 -0
- data/lib/integration_pal.rb +5 -0
- data/lib/tasks/integration_pal_tasks.rake +4 -0
- data/spec/controllers/integration_pal/api/v1/jobs_controller_spec.rb +74 -0
- data/spec/controllers/integration_pal/jobs_controller_spec.rb +107 -0
- data/spec/controllers/integration_pal/workers_controller_spec.rb +107 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/jobs/test_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +38 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +18 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +18 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +91 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +14 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +56 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +32 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/schema.rb +40 -0
- data/spec/dummy/log/development.log +38 -0
- data/spec/dummy/log/test.log +7232 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/integration_pal_jobs.rb +8 -0
- data/spec/factories/integration_pal_workers.rb +9 -0
- data/spec/models/integration_pal/job_spec.rb +21 -0
- data/spec/models/integration_pal/worker_spec.rb +29 -0
- data/spec/rails_helper.rb +61 -0
- data/spec/spec_helper.rb +100 -0
- metadata +349 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require_dependency "integration_pal/application_controller"
|
2
|
+
|
3
|
+
module IntegrationPal
|
4
|
+
class WorkersController < ApplicationController
|
5
|
+
before_action :set_worker, only: [:show, :edit, :update, :destroy]
|
6
|
+
|
7
|
+
# GET /workers
|
8
|
+
def index
|
9
|
+
@workers = Worker.all
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /workers/1
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /workers/new
|
17
|
+
def new
|
18
|
+
@worker = Worker.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /workers/1/edit
|
22
|
+
def edit
|
23
|
+
end
|
24
|
+
|
25
|
+
# POST /workers
|
26
|
+
def create
|
27
|
+
@worker = Worker.new(worker_params)
|
28
|
+
|
29
|
+
if @worker.save
|
30
|
+
redirect_to @worker, notice: 'Worker was successfully created.'
|
31
|
+
else
|
32
|
+
render :new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# PATCH/PUT /workers/1
|
37
|
+
def update
|
38
|
+
if @worker.update(worker_params)
|
39
|
+
redirect_to @worker, notice: 'Worker was successfully updated.'
|
40
|
+
else
|
41
|
+
render :edit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# DELETE /workers/1
|
46
|
+
def destroy
|
47
|
+
@worker.destroy
|
48
|
+
redirect_to workers_url, notice: 'Worker was successfully destroyed.'
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
# Use callbacks to share common setup or constraints between actions.
|
53
|
+
def set_worker
|
54
|
+
@worker = Worker.find(params[:id])
|
55
|
+
end
|
56
|
+
|
57
|
+
# Only allow a trusted parameter "white list" through.
|
58
|
+
def worker_params
|
59
|
+
params.require(:worker).permit(:name, :access_id, :secret_key, :settings, :job_type)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module IntegrationPal
|
2
|
+
class Job < ApplicationRecord
|
3
|
+
PENDING_STATUS = 'pending'.freeze
|
4
|
+
COMPLETED_STATUS = 'completed'.freeze
|
5
|
+
IN_PROGRESS_STATUS = 'in_progress'.freeze
|
6
|
+
FAILED_STATUS = 'failed'.freeze
|
7
|
+
STATUSES = [PENDING_STATUS, COMPLETED_STATUS, IN_PROGRESS_STATUS, FAILED_STATUS].freeze
|
8
|
+
|
9
|
+
store :job_params, coder: Hash
|
10
|
+
|
11
|
+
belongs_to :worker
|
12
|
+
|
13
|
+
validates :worker, presence: true
|
14
|
+
validates :status, presence: true, inclusion: { in: STATUSES }
|
15
|
+
|
16
|
+
before_validation :set_status
|
17
|
+
def set_status
|
18
|
+
self.status ||= PENDING_STATUS
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module IntegrationPal
|
2
|
+
class Worker < ApplicationRecord
|
3
|
+
include ActiveModel
|
4
|
+
store :settings, coder: Hash
|
5
|
+
attr_encrypted :settings, key: ENV['ENCRYPTION_KEY'], salt: ENV['SALT_KEY'], marshal: true
|
6
|
+
|
7
|
+
validates :name, presence: true
|
8
|
+
validates :access_id, presence: true
|
9
|
+
validates :secret_key, presence: true
|
10
|
+
validates :job_type, presence: true
|
11
|
+
|
12
|
+
has_many :jobs
|
13
|
+
|
14
|
+
before_create :generate_api_key
|
15
|
+
def generate_api_key
|
16
|
+
ApiAuth.generate_secret_key
|
17
|
+
end
|
18
|
+
|
19
|
+
after_initialize do |user|
|
20
|
+
self.settings ||= {}
|
21
|
+
self.secret_key ||= ApiAuth.generate_secret_key
|
22
|
+
end
|
23
|
+
|
24
|
+
def job_class
|
25
|
+
self.job_type.constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%= form_with(model: job, local: true) do |form| %>
|
2
|
+
<% if job.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(job.errors.count, "error") %> prohibited this job from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% job.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= form.label :status %>
|
16
|
+
<%= form.text_field :status, id: :job_status %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="field">
|
20
|
+
<%= form.label :progress %>
|
21
|
+
<%= form.text_field :progress, id: :job_progress %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="field">
|
25
|
+
<%= form.label :worker_id %>
|
26
|
+
<%= form.number_field :worker_id, id: :job_worker_id %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="actions">
|
30
|
+
<%= form.submit %>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1>Jobs</h1>
|
4
|
+
|
5
|
+
<table class='table'>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>ID</th>
|
9
|
+
<th>Worker</th>
|
10
|
+
<th>Status</th>
|
11
|
+
<th>Progress</th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
<% @jobs.each do |job| %>
|
17
|
+
<tr>
|
18
|
+
<td><%= job.id %></td>
|
19
|
+
<td><%= job.worker.name %></td>
|
20
|
+
<td><%= job.status %></td>
|
21
|
+
<td><%= job.progress %></td>
|
22
|
+
</tr>
|
23
|
+
<% end %>
|
24
|
+
</tbody>
|
25
|
+
</table>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Status:</strong>
|
5
|
+
<%= @job.status %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Progress:</strong>
|
10
|
+
<%= @job.progress %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<strong>Worker:</strong>
|
15
|
+
<%= @job.worker_id %>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<%= link_to 'Edit', edit_job_path(@job) %> |
|
19
|
+
<%= link_to 'Back', jobs_path %>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%= form_with(model: worker, local: true) do |form| %>
|
2
|
+
<% if worker.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(worker.errors.count, "error") %> prohibited this worker from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% worker.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= form.label :name %>
|
16
|
+
<%= form.text_field :name, class: 'form-control' %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="form-group">
|
20
|
+
<%= form.label :access_id, 'Access ID' %>
|
21
|
+
<%= form.text_field :access_id, class: 'form-control' %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="form-group">
|
25
|
+
<%= form.label :secret_key %>
|
26
|
+
<%= form.text_field :secret_key, class: 'form-control' %>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="form-group">
|
30
|
+
<%= form.label :job_type %>
|
31
|
+
<%= form.select :job_type, JOB_TYPES, {}, class: 'form-control' %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<% if worker.settings.present? %>
|
35
|
+
<strong>Settings</strong>
|
36
|
+
<hr />
|
37
|
+
<div class="form-group">
|
38
|
+
<% worker.settings.each do |key, value| %>
|
39
|
+
<%= form.label key %>
|
40
|
+
<input name="worker[settings][<%= key %>]" type="text" value="<%= value %>" />
|
41
|
+
<% end %>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
<div class="actions">
|
46
|
+
<%= form.submit 'Update Worker', class: 'btn btn-primary' %>
|
47
|
+
</div>
|
48
|
+
<% end %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1>Workers</h1>
|
4
|
+
|
5
|
+
<table class='table'>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>ID</th>
|
9
|
+
<th>Name</th>
|
10
|
+
<th>Access ID</th>
|
11
|
+
<th>Job Type</th>
|
12
|
+
<th colspan="2"></th>
|
13
|
+
</tr>
|
14
|
+
</thead>
|
15
|
+
|
16
|
+
<tbody>
|
17
|
+
<% @workers.each do |worker| %>
|
18
|
+
<tr>
|
19
|
+
<td><%= worker.id %></td>
|
20
|
+
<td><%= worker.name %></td>
|
21
|
+
<td><%= worker.access_id %></td>
|
22
|
+
<td><%= worker.job_type %></td>
|
23
|
+
<td><%= link_to 'Edit', edit_worker_path(worker) %></td>
|
24
|
+
<td><%= link_to 'Destroy', worker, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
25
|
+
</tr>
|
26
|
+
<% end %>
|
27
|
+
</tbody>
|
28
|
+
</table>
|
29
|
+
|
30
|
+
<br>
|
31
|
+
|
32
|
+
<%= link_to 'New Worker', new_worker_path, class: 'btn btn-primary' %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Name:</strong>
|
5
|
+
<%= @worker.name %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Access ID:</strong>
|
10
|
+
<%= @worker.access_id %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<%= link_to 'Edit', edit_worker_path(@worker) %> |
|
14
|
+
<%= link_to 'Back', workers_path %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<nav class="navbar navbar-default">
|
2
|
+
<div class="container-fluid">
|
3
|
+
<div class="navbar-header">
|
4
|
+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
|
5
|
+
<span class="sr-only">Toggle navigation</span>
|
6
|
+
<span class="icon-bar"></span>
|
7
|
+
<span class="icon-bar"></span>
|
8
|
+
<span class="icon-bar"></span>
|
9
|
+
</button>
|
10
|
+
<%= link_to Rails.application.class.parent_name.underscore.humanize, root_path, class: "navbar-brand" %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
14
|
+
<ul class="nav navbar-nav">
|
15
|
+
<li><%= link_to 'Workers', workers_path %></li>
|
16
|
+
<li><%= link_to 'Jobs', jobs_path %></li>
|
17
|
+
</ul>
|
18
|
+
|
19
|
+
<ul class="nav navbar-nav navbar-right">
|
20
|
+
<li><%= link_to 'Logout', logout_url if logout_url.present? %></li>
|
21
|
+
</ul>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</nav>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Integration pal</title>
|
5
|
+
<%= stylesheet_link_tag "integration_pal/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "integration_pal/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div class='container'>
|
11
|
+
<%= render 'layouts/navbar' %>
|
12
|
+
<%= yield %>
|
13
|
+
</div>
|
14
|
+
</body>
|
15
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateIntegrationPalWorkers < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :integration_pal_workers do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :access_id
|
6
|
+
t.string :secret_key
|
7
|
+
t.string :job_type
|
8
|
+
t.text :encrypted_settings
|
9
|
+
t.string :encrypted_settings_iv
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateIntegrationPalJobs < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :integration_pal_jobs do |t|
|
4
|
+
t.text :job_params
|
5
|
+
t.string :status
|
6
|
+
t.datetime :started_at
|
7
|
+
t.datetime :finished_at
|
8
|
+
t.string :progress
|
9
|
+
t.integer :worker_id
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module IntegrationPal
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
require 'api-auth'
|
4
|
+
require 'rack-cas-rails'
|
5
|
+
require 'attr_encrypted'
|
6
|
+
|
7
|
+
config.autoload_once_paths += Dir["#{config.root}/lib/**/"]
|
8
|
+
|
9
|
+
isolate_namespace IntegrationPal
|
10
|
+
|
11
|
+
config.generators do |g|
|
12
|
+
g.test_framework :rspec
|
13
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer :append_migrations do |app|
|
17
|
+
unless app.root.to_s.match root.to_s
|
18
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
19
|
+
app.config.paths["db/migrate"] << expanded_path
|
20
|
+
end
|
21
|
+
ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module IntegrationPal
|
4
|
+
describe Api::V1::JobsController, :type => :controller do
|
5
|
+
routes { IntegrationPal::Engine.routes }
|
6
|
+
|
7
|
+
context 'unauthorized' do
|
8
|
+
describe '#index' do
|
9
|
+
let(:job) { create(:integration_pal_job) }
|
10
|
+
|
11
|
+
it 'restricts access to authorized users' do
|
12
|
+
get :show, params: {id: job.to_param}
|
13
|
+
expect(response.status).to eq(401)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'authorized' do
|
19
|
+
let!(:worker) { create(:integration_pal_worker) }
|
20
|
+
|
21
|
+
describe '#show' do
|
22
|
+
let(:job) { create(:integration_pal_job) }
|
23
|
+
let(:controller_path) { "/api/v1/jobs/#{job.id}"}
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
allow_any_instance_of(ActionDispatch::TestRequest).to receive(:fullpath).and_return(controller_path)
|
27
|
+
request.env["HTTP_ACCEPT"] = "application/json"
|
28
|
+
ApiAuth.sign!(request, worker.access_id, worker.secret_key)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns workers as @workers' do
|
32
|
+
get :show, params: {id: job.to_param}
|
33
|
+
expect(response.body).to eq job.to_json
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "POST #create" do
|
38
|
+
before(:each) do
|
39
|
+
controller.class.skip_before_action :authenticate_api rescue nil
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with valid params" do
|
43
|
+
let(:valid_attributes) {
|
44
|
+
build(:integration_pal_job).attributes
|
45
|
+
}
|
46
|
+
|
47
|
+
it "creates a new Job" do
|
48
|
+
expect {
|
49
|
+
post :create, params: {job: valid_attributes}
|
50
|
+
}.to change(Job, :count).by(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "assigns a newly created job as @job" do
|
54
|
+
post :create, params: {job: valid_attributes}
|
55
|
+
expect(assigns(:job)).to be_a(Job)
|
56
|
+
expect(assigns(:job)).to be_persisted
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with invalid params" do
|
61
|
+
let(:invalid_attributes) {
|
62
|
+
build(:integration_pal_job, worker_id: nil).attributes
|
63
|
+
}
|
64
|
+
|
65
|
+
it "doesn't create the job" do
|
66
|
+
expect {
|
67
|
+
post :create, params: {job: invalid_attributes}
|
68
|
+
}.to change(Job, :count).by(0)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module IntegrationPal
|
4
|
+
describe JobsController, :type => :controller do
|
5
|
+
routes { IntegrationPal::Engine.routes }
|
6
|
+
|
7
|
+
context 'unauthorized' do
|
8
|
+
describe '#index' do
|
9
|
+
let!(:job) { create(:integration_pal_job) }
|
10
|
+
|
11
|
+
it 'restricts access to authorized users' do
|
12
|
+
get :index
|
13
|
+
expect(response.status).to eq(401)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'authorized' do
|
19
|
+
before(:each) do
|
20
|
+
controller.class.skip_before_action :authenticate! rescue nil
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#index' do
|
24
|
+
let!(:job) { create(:integration_pal_job) }
|
25
|
+
|
26
|
+
it 'returns jobs as @jobs' do
|
27
|
+
get :index
|
28
|
+
expect(assigns(:jobs)).to match_array([job])
|
29
|
+
expect(response).to render_template(:index)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "POST #create" do
|
34
|
+
context "with valid params" do
|
35
|
+
let(:valid_attributes) {
|
36
|
+
build(:integration_pal_job).attributes
|
37
|
+
}
|
38
|
+
|
39
|
+
it "creates a new Job" do
|
40
|
+
expect {
|
41
|
+
post :create, params: {job: valid_attributes}
|
42
|
+
}.to change(Job, :count).by(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "assigns a newly created job as @job" do
|
46
|
+
post :create, params: {job: valid_attributes}
|
47
|
+
expect(assigns(:job)).to be_a(Job)
|
48
|
+
expect(assigns(:job)).to be_persisted
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with invalid params" do
|
53
|
+
let(:invalid_attributes) {
|
54
|
+
build(:integration_pal_job, worker_id: nil).attributes
|
55
|
+
}
|
56
|
+
|
57
|
+
it "doesn't create the job" do
|
58
|
+
expect {
|
59
|
+
post :create, params: {job: invalid_attributes}
|
60
|
+
}.to change(Job, :count).by(0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "PUT #update" do
|
66
|
+
let(:job) { create(:integration_pal_job) }
|
67
|
+
|
68
|
+
context "with valid params" do
|
69
|
+
let(:new_attributes) {
|
70
|
+
{name: 'New Name'}
|
71
|
+
}
|
72
|
+
|
73
|
+
it "updates the requested job" do
|
74
|
+
put :update, params: {id: job.to_param, job: new_attributes}
|
75
|
+
job.reload
|
76
|
+
skip("Add assertions for updated state")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "assigns the requested job as @job" do
|
80
|
+
put :update, params: {id: job.to_param, job: new_attributes}
|
81
|
+
expect(assigns(:job)).to eq(job)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "redirects to the job" do
|
85
|
+
put :update, params: {id: job.to_param, job: new_attributes}
|
86
|
+
expect(response).to redirect_to(job)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with invalid params" do
|
91
|
+
let(:invalid_attributes) {
|
92
|
+
{worker_id: ''}
|
93
|
+
}
|
94
|
+
it "assigns the job as @job" do
|
95
|
+
put :update, params: {id: job.to_param, job: invalid_attributes}
|
96
|
+
expect(assigns(:job)).to eq(job)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "re-renders the 'edit' template" do
|
100
|
+
put :update, params: {id: job.to_param, job: invalid_attributes}
|
101
|
+
expect(response).to render_template("edit")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|