Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from kwappa/record-edit-history
implement to record / show histories of editing user's resume
- Loading branch information
Showing
18 changed files
with
248 additions
and
13 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,10 @@ | ||
($ -> | ||
showResumeHistoryDiff = (e) -> | ||
e.preventDefault() | ||
history = $(this).closest('tr').find('.history_data').data('history') | ||
$('.edit_history_detail_container').html(history) | ||
|
||
$('.show_resume_history').each((idx, elem) -> | ||
$(elem).bind('click', showResumeHistoryDiff) | ||
) | ||
) |
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
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,18 @@ | ||
class UserResumeHistory < ActiveRecord::Base | ||
include Renderable | ||
|
||
belongs_to :user | ||
|
||
def self.record_diff(user_id, old_body, current_body) | ||
diff = Diffy::Diff.new(old_body + "\n", current_body + "\n", context: 3, include_diff_info: true).to_s | ||
create(user_id: user_id, diff: diff) | ||
end | ||
|
||
def quoted_diff | ||
<<-EOD | ||
```diff | ||
#{self.diff} | ||
``` | ||
EOD | ||
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,38 @@ | ||
= content_for :header do | ||
javascript_include_tag 'resume_histories' | ||
|
||
%div.content.pure-u-1.pure-u-md-3-4 | ||
%div | ||
%div.posts | ||
%h1.content-subhead | ||
%section.post | ||
%header.post-header | ||
%h2 | ||
%i.fa.fa-files-o.fa-lg | ||
Edit Histories | ||
%div.post-description | ||
%div.edit_histories | ||
%div.edit_history_list | ||
%table.pure-table.pure-table-bordered | ||
- @histories.each_with_index do |history, idx| | ||
%tbody | ||
%tr{ class: idx.odd? ? 'pure-table-odd' : '' } | ||
%td.history_data{ data: { history: history.render(:quoted_diff)} } | ||
= history.updated_at | ||
%td | ||
= link_to '#', class: 'show_resume_history' do | ||
%i.fa.fa-file-text-o.fa-lg | ||
%div.edit_history_detail | ||
%div.edit_history_detail_container | ||
= paginate @histories | ||
%div.posts | ||
%h1.content-subhead | ||
%section.post | ||
%header.post-header | ||
%h2 | ||
%i.fa.fa-file-text.fa-lg | ||
Resume | ||
%div.post-description | ||
%div.resume | ||
- if @user.resume.present? | ||
= @user.resume.render(:body).html_safe |
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,11 @@ | ||
class UserResumeHistories < ActiveRecord::Migration | ||
def change | ||
create_table :user_resume_histories do |t| | ||
t.integer :user_id, null: false | ||
t.text :diff, null: false, default: '' | ||
t.timestamp :updated_at, null: false | ||
end | ||
|
||
add_index :user_resume_histories, [:user_id, :updated_at] | ||
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,6 @@ | ||
FactoryGirl.define do | ||
factory :user_resume_history do | ||
|
||
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,17 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe UserResumeHistory, type: :model do | ||
let(:user) { create(:user) } | ||
|
||
describe '.record_diff' do | ||
subject(:record_diff) { described_class.record_diff(user.id, 'old_body', 'new_body') } | ||
specify { expect { record_diff }.to change { described_class.count }.from(0).to(1) } | ||
end | ||
|
||
describe '#quoted_diff' do | ||
let(:diff_body) { 'diff_body' } | ||
let(:quoted_diff_body) { "```diff\n#{diff_body}\n```\n" } | ||
let(:diff) { build(:user_resume_history, diff: diff_body) } | ||
specify { expect(diff.quoted_diff).to eq quoted_diff_body } | ||
end | ||
end |
Oops, something went wrong.