yaw 0.0.1 → 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 +4 -4
- data/app/decorators/yaw/wiki_page_decorator.rb +19 -0
- data/app/models/yaw/wiki_page.rb +44 -0
- data/app/models/yaw/wiki_page_revision.rb +9 -0
- data/app/models/yaw/wiki_space.rb +11 -0
- data/lib/yaw/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +2190 -0
- data/spec/factories/wiki.rb +2 -2
- data/spec/yaw/wiki_page_decorator_spec.rb +13 -11
- data/spec/yaw/wiki_page_model_spec.rb +47 -45
- metadata +48 -6
- data/app/decorators/wiki_page_decorator.rb +0 -17
- data/app/models/wiki_page.rb +0 -41
- data/app/models/wiki_page_revision.rb +0 -6
- data/app/models/wiki_space.rb +0 -8
data/spec/factories/wiki.rb
CHANGED
@@ -13,7 +13,7 @@ FactoryBot.define do
|
|
13
13
|
name 'tom'
|
14
14
|
end
|
15
15
|
|
16
|
-
factory :wiki_page do
|
16
|
+
factory :wiki_page, class: 'Yaw::WikiPage' do
|
17
17
|
wiki_space
|
18
18
|
path
|
19
19
|
user
|
@@ -21,7 +21,7 @@ FactoryBot.define do
|
|
21
21
|
body 'is a page'
|
22
22
|
end
|
23
23
|
|
24
|
-
factory :wiki_space do
|
24
|
+
factory :wiki_space, class: 'Yaw::WikiSpace' do
|
25
25
|
title
|
26
26
|
end
|
27
27
|
end
|
@@ -2,19 +2,21 @@
|
|
2
2
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Yaw
|
6
|
+
describe WikiPageDecorator, type: :decorator do
|
7
|
+
subject { create(:wiki_page).decorate }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
context 'the page with a link' do
|
10
|
+
before { subject.body = '[[something here]]' }
|
11
|
+
its(:render_body) { should have_link('something here') }
|
12
|
+
its(:render_body) { should have_link(href: h.yaw.wiki_space_wiki_page_path(subject.wiki_space, 'something here')) }
|
13
|
+
its(:render_body) { should have_link(class: 'absent') }
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
context 'when the linked page exists' do
|
16
|
+
before { create :wiki_page, path: 'something here', wiki_space: subject.wiki_space }
|
17
|
+
its(:render_body) { should_not have_link(class: 'absent') }
|
18
|
+
its(:render_body) { should have_link(class: 'internal') }
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -2,53 +2,55 @@
|
|
2
2
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
describe 'an existing page' do
|
27
|
-
subject! { create :wiki_page }
|
28
|
-
describe 'assignemnt' do
|
29
|
-
before { subject.title = 'title' }
|
30
|
-
before { subject.body = 'body' }
|
31
|
-
before { subject.user = user }
|
32
|
-
its(:title) { should eq 'title' }
|
33
|
-
its(:body) { should eq 'body' }
|
34
|
-
it { expect(subject.current_revision.user).to eq user }
|
35
|
-
end
|
36
|
-
it { expect { subject.update(body: 'new title') }.to change { WikiPageRevision.where(wiki_page: subject).count }.to 2 }
|
37
|
-
its(:render_body) { should be_html_safe }
|
38
|
-
|
39
|
-
context 'creating a page with same path in another space' do
|
40
|
-
let(:new_page) { build :wiki_page, path: subject.path }
|
41
|
-
it { expect(new_page).to be_valid }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'creating a page with same path in the same space' do
|
45
|
-
let(:new_page) { build :wiki_page, path: subject.path, wiki_space: subject.wiki_space }
|
46
|
-
it { expect(new_page).to be_invalid }
|
5
|
+
module Yaw
|
6
|
+
RSpec.describe WikiPage, type: :model do
|
7
|
+
let(:user) { create :user }
|
8
|
+
|
9
|
+
describe 'a new page' do
|
10
|
+
subject { WikiPage.new path: 'path/to/page' }
|
11
|
+
|
12
|
+
its(:title) { should eq 'page' }
|
13
|
+
its(:body) { should be_nil }
|
14
|
+
|
15
|
+
context 'when assigning title & body' do
|
16
|
+
before { subject.wiki_space = create(:wiki_space) }
|
17
|
+
before { subject.title = 'title' }
|
18
|
+
before { subject.body = 'body' }
|
19
|
+
before { subject.user = user }
|
20
|
+
its(:title) { should eq 'title' }
|
21
|
+
its(:body) { should eq 'body' }
|
22
|
+
it { expect(subject.current_revision.user).to eq user }
|
23
|
+
it { expect { subject.save! }.to change(WikiPageRevision, :count).by 1 }
|
24
|
+
end
|
47
25
|
end
|
48
26
|
|
49
|
-
|
50
|
-
|
51
|
-
|
27
|
+
describe 'an existing page' do
|
28
|
+
subject! { create :wiki_page }
|
29
|
+
describe 'assignemnt' do
|
30
|
+
before { subject.title = 'title' }
|
31
|
+
before { subject.body = 'body' }
|
32
|
+
before { subject.user = user }
|
33
|
+
its(:title) { should eq 'title' }
|
34
|
+
its(:body) { should eq 'body' }
|
35
|
+
it { expect(subject.current_revision.user).to eq user }
|
36
|
+
end
|
37
|
+
it { expect { subject.update(body: 'new title') }.to change { WikiPageRevision.where(wiki_page: subject).count }.to 2 }
|
38
|
+
its(:render_body) { should be_html_safe }
|
39
|
+
|
40
|
+
context 'creating a page with same path in another space' do
|
41
|
+
let(:new_page) { build :wiki_page, path: subject.path }
|
42
|
+
it { expect(new_page).to be_valid }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'creating a page with same path in the same space' do
|
46
|
+
let(:new_page) { build :wiki_page, path: subject.path, wiki_space: subject.wiki_space }
|
47
|
+
it { expect(new_page).to be_invalid }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'find sibling wont find in other space' do
|
51
|
+
let(:new_page) { create :wiki_page }
|
52
|
+
it { expect(subject.find_sibling(new_page.path)).to be_nil }
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- less team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ckeditor
|
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: draper
|
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'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: kramdown
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +52,20 @@ dependencies:
|
|
24
52
|
- - ">="
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simple_form
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: capybara
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,10 +209,10 @@ files:
|
|
167
209
|
- app/assets/stylesheets/yaw/wiki.sass
|
168
210
|
- app/controllers/yaw/application_controller.rb
|
169
211
|
- app/controllers/yaw/wiki_page_controller.rb
|
170
|
-
- app/decorators/wiki_page_decorator.rb
|
171
|
-
- app/models/wiki_page.rb
|
172
|
-
- app/models/wiki_page_revision.rb
|
173
|
-
- app/models/wiki_space.rb
|
212
|
+
- app/decorators/yaw/wiki_page_decorator.rb
|
213
|
+
- app/models/yaw/wiki_page.rb
|
214
|
+
- app/models/yaw/wiki_page_revision.rb
|
215
|
+
- app/models/yaw/wiki_space.rb
|
174
216
|
- app/views/layouts/wiki.haml
|
175
217
|
- app/views/yaw/wiki_page/_form.html.haml
|
176
218
|
- app/views/yaw/wiki_page/edit.html.haml
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class WikiPageDecorator < Draper::Decorator
|
4
|
-
delegate_all
|
5
|
-
|
6
|
-
def render_body
|
7
|
-
# rubocop:disable all
|
8
|
-
link_reg = /\[\[([^\]]+)\]\]/
|
9
|
-
body.gsub(link_reg) do |match|
|
10
|
-
matched = match[link_reg, 1]
|
11
|
-
options = { class: 'internal' }
|
12
|
-
options[:class] = 'absent' if find_sibling(matched).blank?
|
13
|
-
h.link_to matched, h.yaw.wiki_space_wiki_page_path(wiki_space, matched), options
|
14
|
-
end.html_safe
|
15
|
-
# rubocop:enable all
|
16
|
-
end
|
17
|
-
end
|
data/app/models/wiki_page.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class WikiPage < ApplicationRecord
|
4
|
-
delegate :title=, :body=, :user=, to: :dirty_revision
|
5
|
-
after_save :reset_dirty_revision
|
6
|
-
belongs_to :wiki_space, required: true, inverse_of: :wiki_pages
|
7
|
-
validates :path, uniqueness: { scope: :wiki_space_id }
|
8
|
-
has_many :wiki_page_revisions,
|
9
|
-
-> { order id: :desc },
|
10
|
-
autosave: true,
|
11
|
-
inverse_of: :wiki_page
|
12
|
-
|
13
|
-
def current_revision
|
14
|
-
@dirty_revision || wiki_page_revisions.first
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_param
|
18
|
-
path
|
19
|
-
end
|
20
|
-
|
21
|
-
delegate :body, to: :current_revision, allow_nil: true
|
22
|
-
def title
|
23
|
-
current_revision&.title || path&.split('/')&.last
|
24
|
-
end
|
25
|
-
|
26
|
-
delegate :render_body, to: :decorate
|
27
|
-
|
28
|
-
def find_sibling(path)
|
29
|
-
wiki_space.wiki_pages.find_by(path: path)
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def dirty_revision
|
35
|
-
@dirty_revision ||= wiki_page_revisions.build
|
36
|
-
end
|
37
|
-
|
38
|
-
def reset_dirty_revision
|
39
|
-
@dirty_revision = nil
|
40
|
-
end
|
41
|
-
end
|