-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b4bb4d
commit c6130ed
Showing
18 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Kuroko2::ScriptRevisionsController < Kuroko2::ApplicationController | ||
def index | ||
@definition = Kuroko2::JobDefinition.find(params[:job_definition_id]) | ||
|
||
@revisions = @definition.revisions.includes(:user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Kuroko2::ScriptRevision < Kuroko2::ApplicationRecord | ||
include Kuroko2::TableNameCustomizable | ||
|
||
belongs_to :job_definition | ||
belongs_to :user, optional: true | ||
|
||
def html_diff(previous) | ||
Diffy::Diff.new(previous.try(:script), self.script, context: 3).to_s(:html).html_safe | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
- content_for :title, "##{@definition.id} #{@definition.name} « Script Revisions" | ||
- content_for :content_title, "Script Revisions" | ||
|
||
- content_for :breadcrumb do | ||
ol.breadcrumb | ||
li= link_to raw('<i class="fa fa-database"></i> Job Definitions'), job_definitions_path | ||
li= link_to "Details", @definition | ||
li.active Revisions | ||
|
||
style= Diffy::CSS | ||
|
||
- @revisions.each.with_index(1) do |revision, nextIndex| | ||
.box id="revision-#{revision.id}" | ||
.box-header | ||
.row | ||
.col-md-9 | ||
- if revision.user | ||
h2.box-title= revision.user.name | ||
- else | ||
h2.box-title Unknown User | ||
.col-md-3.right-button.text-right | ||
= link_to revision.changed_at, anchor: "revision-#{revision.id}" | ||
.box-body= revision.html_diff(@revisions[nextIndex]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class CreateScriptRevisions < ActiveRecord::Migration[5.1] | ||
def up | ||
create_table :script_revisions do |t| | ||
t.belongs_to :job_definition, foreign_key: true, null: false | ||
t.text :script, null: false | ||
t.belongs_to :user, foreign_key: true, null: true | ||
t.datetime :changed_at, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
Kuroko2::JobDefinition.all.each do |definition| | ||
Kuroko2::ScriptRevision.create(job_definition: definition, script: definition.script, changed_at: definition.updated_at) | ||
end | ||
end | ||
|
||
def down | ||
drop_table :script_revisions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'rails_helper' | ||
|
||
describe Kuroko2::ScriptRevisionsController do | ||
routes { Kuroko2::Engine.routes } | ||
|
||
before { sign_in } | ||
|
||
let!(:definition) { create(:job_definition, script: "noop:\n") } | ||
before do | ||
1.upto(3) { |i| definition.update_and_record_revision(script: "noop:\n" * i) } | ||
end | ||
|
||
describe '#index' do | ||
subject! { get :index, params: { job_definition_id: definition.id } } | ||
|
||
it do | ||
expect(response).to have_http_status(:ok) | ||
expect(response).to render_template('index') | ||
|
||
expect(assigns(:definition)).to eq definition | ||
expect(assigns(:revisions).size).to eq 3 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FactoryBot.define do | ||
factory :script_revision, class: Kuroko2::ScriptRevision do | ||
job_definition { create(:job_definition) } | ||
user { create(:user) } | ||
sequence(:script) { |n| "noop:\n" * n } | ||
changed_at { Time.current } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rails_helper' | ||
|
||
describe 'Shows job definition revisions', type: :feature do | ||
before { sign_in } | ||
|
||
let!(:definition) { create(:job_definition, script: "noop:\n") } | ||
before do | ||
1.upto(3) { |i| definition.update_and_record_revision(script: "noop:\n" * i) } | ||
end | ||
|
||
it do | ||
visit kuroko2.job_definition_path definition | ||
expect(page).to have_content('Job Definition Details') | ||
|
||
click_on 'Show script revisions' | ||
|
||
expect(page).to have_content('Script Revisions') | ||
expect(page).to have_selector('.diff', count: 3) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'rails_helper' | ||
|
||
describe Kuroko2::ScriptRevision do | ||
end |