File tree 6 files changed +20
-20
lines changed
6 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def kata
15
15
16
16
def show
17
17
@doc = Document . new ( params [ :id ] )
18
- redirect_to root_url unless @doc . exists ?
18
+ redirect_to root_url unless @doc . exist ?
19
19
20
20
if @doc . content . include? "NUM_OF_"
21
21
@doc . content . gsub! "{{ NUM_OF_JAPAN_DOJOS }}" , Dojo . active_dojos_count . to_s
Original file line number Diff line number Diff line change @@ -55,21 +55,21 @@ def url
55
55
"#{ URL_PATH } /#{ self . filename } "
56
56
end
57
57
58
- def exists ?
58
+ def exist ?
59
59
return false if path . include? "\u0000 "
60
60
Document . all . map ( &:filename ) . include? ( filename )
61
61
end
62
62
63
63
def title
64
- return '' unless self . exists ?
64
+ return '' unless self . exist ?
65
65
@title ||=
66
66
ActionController ::Base . helpers . strip_tags (
67
67
Kramdown ::Document . new ( self . get_first_paragraph , input : 'GFM' ) . to_html
68
68
) . strip
69
69
end
70
70
71
71
def description
72
- return '' unless self . exists ?
72
+ return '' unless self . exist ?
73
73
@desc ||=
74
74
ActionController ::Base . helpers . strip_tags (
75
75
Kramdown ::Document . new ( self . get_second_paragraph , input : 'GFM' ) . to_html
@@ -80,7 +80,7 @@ def description=(text)
80
80
end
81
81
82
82
def content
83
- @content ||= self . exists ? ? File . read ( self . path ) : ''
83
+ @content ||= self . exist ? ? File . read ( self . path ) : ''
84
84
end
85
85
86
86
private
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def path
18
18
"#{ DIR_PATH } /#{ id } .md"
19
19
end
20
20
21
- def exists ?( offset : 0 )
21
+ def exist ?( offset : 0 )
22
22
return false if self . path . include? ( "\u0000 " )
23
23
return false if ( self . id + offset ) . zero?
24
24
File . exist? ( "#{ DIR_PATH } /#{ id + offset } .md" )
@@ -30,6 +30,6 @@ def cover
30
30
end
31
31
32
32
def content
33
- exists ? ? File . read ( path ) : ''
33
+ exist ? ? File . read ( path ) : ''
34
34
end
35
35
end
Original file line number Diff line number Diff line change 1
1
< div style ="display: table; font-weight: bolder; width: 100%; padding: 10px 10px; background-color:#3870c4; ">
2
2
< p class ="nav prev ">
3
- <% if @episode . exists ?( offset : -1 ) %>
3
+ <% if @episode . exist ?( offset : -1 ) %>
4
4
<%= link_to podcast_path ( @episode . id - 1 ) , title : '前のエピソードを見る' do %>
5
5
« prev
6
6
<% end %>
12
12
<%= link_to '目次に戻る' . html_safe , podcasts_path %>
13
13
</ p >
14
14
< p class ="nav next ">
15
- <% if @episode . exists ?( offset : +1 ) %>
15
+ <% if @episode . exist ?( offset : +1 ) %>
16
16
<%= link_to podcast_path ( @episode . id + 1 ) , title : '次のエピソードを見る' do %>
17
17
next »
18
18
<% end %>
Original file line number Diff line number Diff line change 9
9
10
10
scenario 'Charter should be exist' do
11
11
@podcast = create ( :podcast )
12
- allow ( @podcast ) . to receive ( :exists ? ) { true }
13
- allow ( @podcast ) . to receive ( :exists ? ) . with ( offset : -1 ) { false }
12
+ allow ( @podcast ) . to receive ( :exist ? ) { true }
13
+ allow ( @podcast ) . to receive ( :exist ? ) . with ( offset : -1 ) { false }
14
14
allow ( @podcast ) . to receive ( :content ) { "title\n 収録日: 2019/05/10\n ..." }
15
15
allow ( Podcast ) . to receive ( :find_by ) . with ( id : @podcast . id . to_s ) { @podcast }
16
16
25
25
26
26
scenario 'Load doc file with absolute path' do
27
27
@podcast = create ( :podcast )
28
- allow ( @podcast ) . to receive ( :exists ? ) { true }
28
+ allow ( @podcast ) . to receive ( :exist ? ) { true }
29
29
allow ( @podcast ) . to receive ( :content ) { "title\n 収録日: 2019/05/10\n ..." }
30
30
allow ( Podcast ) . to receive ( :find_by ) . with ( id : @podcast . id . to_s ) { @podcast }
31
31
Original file line number Diff line number Diff line change 10
10
expect ( @podcast . path ) . to eq ( "public/podcasts/#{ @podcast . id } .md" )
11
11
end
12
12
13
- describe 'exists ?(offset: 0)' do
13
+ describe 'exist ?(offset: 0)' do
14
14
it '\u0000 を含む ⇒ false' do
15
15
allow ( @podcast ) . to receive ( :path ) { "public/podcasts/\u0000 " }
16
16
17
- expect ( @podcast . exists ?) . to eq ( false )
17
+ expect ( @podcast . exist ?) . to eq ( false )
18
18
end
19
19
20
20
context 'offset 省略' do
25
25
it 'ファイルあり ⇒ true' do
26
26
allow ( File ) . to receive ( :exist? ) . with ( "public/podcasts/#{ @podcast . id } .md" ) { true }
27
27
28
- expect ( @podcast . exists ?) . to eq ( true )
28
+ expect ( @podcast . exist ?) . to eq ( true )
29
29
end
30
30
31
31
it 'ファイルなし ⇒ false' do
32
- expect ( @podcast . exists ?) . to eq ( false )
32
+ expect ( @podcast . exist ?) . to eq ( false )
33
33
end
34
34
end
35
35
41
41
it 'ファイルあり ⇒ true' do
42
42
allow ( File ) . to receive ( :exist? ) . with ( "public/podcasts/#{ @podcast . id + 1 } .md" ) { true }
43
43
44
- expect ( @podcast . exists ?( offset : 1 ) ) . to eq ( true )
44
+ expect ( @podcast . exist ?( offset : 1 ) ) . to eq ( true )
45
45
end
46
46
47
47
it 'ファイルなし ⇒ false' do
48
- expect ( @podcast . exists ?( offset : 1 ) ) . to eq ( false )
48
+ expect ( @podcast . exist ?( offset : 1 ) ) . to eq ( false )
49
49
end
50
50
end
51
51
end
57
57
end
58
58
59
59
it 'ファイル存在 ⇒ ファイルから読み込み' do
60
- allow ( @podcast ) . to receive ( :exists ? ) { true }
60
+ allow ( @podcast ) . to receive ( :exist ? ) { true }
61
61
62
62
expect ( @podcast . content ) . to eq ( @content_body )
63
63
end
64
64
65
65
it 'ファイルなし ⇒ 空文字列' do
66
- allow ( @podcast ) . to receive ( :exists ? ) { false }
66
+ allow ( @podcast ) . to receive ( :exist ? ) { false }
67
67
68
68
expect ( @podcast . content ) . to eq ( '' )
69
69
end
You can’t perform that action at this time.
0 commit comments