Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def edit
# POST /documents or /documents.json
def create
@document = current_user.documents.build(document_params)
@document.update(description: Document.add_unique_action_item_marker(@document[:description]))

if @document.save #XXX: save! => save
flash[:success] = "文書を追加しました"
Expand All @@ -44,6 +45,9 @@ def create

# PATCH/PUT /documents/1 or /documents/1.json
def update

@document.update(description: Document.add_unique_action_item_marker(@document[:description]))

if @document.update(document_params)
flash[:success] = "文書を更新しました"
redirect_to documents_path
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/action_items_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ActionItemsHelper
end
13 changes: 13 additions & 0 deletions app/models/action_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ActionItem < ApplicationRecord
after_create :set_uid

def uid
"%04d" % self.id
end

private

def set_uid
self.update(uid: uid)
end
end
36 changes: 36 additions & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,40 @@ class Document < ApplicationRecord
validates :end_at, presence: true
validates :location, presence: true
#validates :project, presence: true
# Replace action-item number into corresponding GitHub issue number.
# Example:
# "-->(name !:0001)" becomes "-->(name nomlab/jay/#10)"
def self.cooked_content(description)
new_description = ""
description.split("\n").map do |line|
line.gsub(/-->\((.+?)!:([0-9]{4})\)/) do |match|
assignee, action = $1.strip, $2
issue = ActionItem.find_by_id(action.to_i).try(:github_issue)
issue ? "-->(#{assignee} #{issue}{:data-action-item=\"#{action}\"})" :
"-->(#{assignee} !:#{action})"
line = line.gsub(/-->\((.+?)(?:!:([0-9]{4}))?\)/, "-->(#{assignee} !:#{issue}{:data-action-item=\"#{action}\"})")
end
new_description += line
new_description += "\n"
end
return new_description
end

# Add action-item number with prefix "!:".
# Example:
# "-->(name)" becomes "-->(name !:0001)"
def self.add_unique_action_item_marker(content)
new_description = ""
description = content.split("\n").map do |line|
line.gsub(/-->\((.+?)(?:!:([0-9]{4}))?\)/) do |match|
assignee, action = $1.strip, $2
action = ActionItem.create.uid unless action
"-->(#{assignee} !:#{action})"
line = line.gsub(/-->\((.+?)(?:!:([0-9]{4}))?\)/, "-->(#{assignee} !:#{action})")
end
new_description += line
new_description += "\n"
end
return new_description
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do

resources :tags
resources :action_items
resources :api_tokens
resources :projects
resources :tasks
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20211119024205_create_action_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateActionItems < ActiveRecord::Migration[6.1]
def change
create_table :action_items do |t|
t.string :summary
t.string :uid
t.string :url

t.timestamps null: false
end
add_index :action_items, :url, unique: true
end
end
11 changes: 10 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions test/controllers/action_items_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class ActionItemsControllerTest < ActionDispatch::IntegrationTest
setup do
@action_item = action_items(:one)
end

test "should get index" do
get action_items_url
assert_response :success
end

test "should get new" do
get new_action_item_url
assert_response :success
end

test "should create action_item" do
assert_difference('ActionItem.count') do
post action_items_url, params: { action_item: { summary: @action_item.summary, uid: @action_item.uid, url: @action_item.url } }
end

assert_redirected_to action_item_url(ActionItem.last)
end

test "should show action_item" do
get action_item_url(@action_item)
assert_response :success
end

test "should get edit" do
get edit_action_item_url(@action_item)
assert_response :success
end

test "should update action_item" do
patch action_item_url(@action_item), params: { action_item: { summary: @action_item.summary, uid: @action_item.uid, url: @action_item.url } }
assert_redirected_to action_item_url(@action_item)
end

test "should destroy action_item" do
assert_difference('ActionItem.count', -1) do
delete action_item_url(@action_item)
end

assert_redirected_to action_items_url
end
end
11 changes: 11 additions & 0 deletions test/fixtures/action_items.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
summary: MyString
uid: MyString
url: MyString

two:
summary: MyString
uid: MyString
url: MyString
7 changes: 7 additions & 0 deletions test/models/action_item_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class ActionItemTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
47 changes: 47 additions & 0 deletions test/system/action_items_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require "application_system_test_case"

class ActionItemsTest < ApplicationSystemTestCase
setup do
@action_item = action_items(:one)
end

test "visiting the index" do
visit action_items_url
assert_selector "h1", text: "Action Items"
end

test "creating a Action item" do
visit action_items_url
click_on "New Action Item"

fill_in "Summary", with: @action_item.summary
fill_in "Uid", with: @action_item.uid
fill_in "Url", with: @action_item.url
click_on "Create Action item"

assert_text "Action item was successfully created"
click_on "Back"
end

test "updating a Action item" do
visit action_items_url
click_on "Edit", match: :first

fill_in "Summary", with: @action_item.summary
fill_in "Uid", with: @action_item.uid
fill_in "Url", with: @action_item.url
click_on "Update Action item"

assert_text "Action item was successfully updated"
click_on "Back"
end

test "destroying a Action item" do
visit action_items_url
page.accept_confirm do
click_on "Destroy", match: :first
end

assert_text "Action item was successfully destroyed"
end
end