Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rendezvous
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VeNtura
rendezvous
Commits
afe9a937
Commit
afe9a937
authored
Mar 19, 2014
by
tady
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下書き機能 test通過
parent
b930d512
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
14 deletions
+41
-14
app/decorators/user_decorator.rb
+4
-0
app/models/post.rb
+17
-7
app/views/partials/_app_header.html.slim
+5
-2
spec/models/post_spec.rb
+8
-2
spec/models/tag_spec.rb
+3
-3
spec/models/user_spec.rb
+4
-0
No files found.
app/decorators/user_decorator.rb
View file @
afe9a937
class
UserDecorator
<
Draper
::
Decorator
delegate_all
def
draft_count
model
.
posts
.
where
(
is_draft:
true
).
count
end
end
app/models/post.rb
View file @
afe9a937
...
...
@@ -6,28 +6,38 @@ class Post < ActiveRecord::Base
# default_scope { where(is_draft: false).order(:updated_at => :desc) }
######################################################################
# validations
######################################################################
validates
:title
,
presence:
true
validates
:body
,
presence:
true
######################################################################
# Named scope
######################################################################
scope
:search
,
(
lambda
do
|
query
|
_where_list
=
includes
(
:author
,
:tags
)
# Convert spaces to one space.
query_list
=
query
.
gsub
(
/[\s ]+/
,
' '
).
split
(
' '
)
query_list
=
query
.
split
(
/[\s ]+/
)
query_list
.
each
do
|
_query
|
case
_query
when
/
^
id:(.+)/
when
/
\A
id:(.+)/
_where_list
=
_where_list
.
where
(
id:
Regexp
.
last_match
[
1
])
when
/
^
title:(.+)/
when
/
\A
title:(.+)/
_where_list
=
_where_list
.
where
(
'title LIKE ?'
,
"%
#{
Regexp
.
last_match
[
1
]
}
%"
)
when
/
^
body:(.+)/
when
/
\A
body:(.+)/
_where_list
=
_where_list
.
where
(
'body LIKE ?'
,
"%
#{
Regexp
.
last_match
[
1
]
}
%"
)
when
/
^
@(.+)/
when
/
\A
@(.+)/
_where_list
=
_where_list
.
where
(
users:
{
name:
Regexp
.
last_match
[
1
]
})
when
/
^
#(.+)/
when
/
\A
#(.+)/
_where_list
=
_where_list
.
where
(
tags:
{
name:
Regexp
.
last_match
[
1
]
})
when
/
^
date:(\d+)-(\d+)-(\d+)/
when
/
\A
date:(\d+)-(\d+)-(\d+)/
_date
=
Time
.
new
(
Regexp
.
last_match
[
1
],
Regexp
.
last_match
[
2
],
Regexp
.
last_match
[
3
])
_where_list
=
_where_list
.
where
(
'updated_at > ? AND updated_at < ?'
,
_date
,
_date
+
1
.
day
)
when
/\Adraft:1/
_where_list
=
_where_list
.
where
(
is_draft:
true
)
else
_where_list
=
_where_list
.
where
(
'title LIKE ? OR body LIKE ?'
,
"%
#{
_query
}
%"
,
"%
#{
_query
}
%"
)
end
...
...
app/views/partials/_app_header.html.slim
View file @
afe9a937
nav
.navbar.navbar-default.navbar-fixed-top
role
=
"navigation"
.container
.navbar-header
a
.navbar-brand
href
=
root_path
Rendezvous
...
...
@@ -18,7 +19,6 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
a
href
=
flow_path
title
=
"Frow"
|
Flow
ul
.nav.navbar-nav.navbar-right
li
form
...
...
@@ -29,10 +29,13 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
a
.dropdown-toggle
data-toggle
=
"dropdown"
=
current_user
.
name
img
src
=
current_user
.image_url
width
=
"20"
height
=
"20"
/
span
.badge
=
current_user
.
decorate
.
draft_count
b
.caret
ul
.dropdown-menu
li
a
Account
(todo)
a
href
=
search_path
(
q:
"@
#{
current_user
.
name
}
draft:1"
)
|
下書き
span
.badge.pull-right
=
current_user
.
decorate
.
draft_count
li
a
Settings
(todo)
li
.divider
...
...
spec/models/post_spec.rb
View file @
afe9a937
...
...
@@ -45,6 +45,7 @@ describe Post do
@post1
=
Post
.
create
id:
1001
,
title:
'ruby rspec'
,
body:
'This is first espec test: ruby'
@post2
=
Post
.
create
id:
1002
,
title:
'php test'
,
body:
'PHP is very easy'
,
author_id:
@alice
.
id
@post3
=
Post
.
create
id:
1003
,
title:
'java java...'
,
body:
'Java is not ruby...'
,
updated_at:
Time
.
new
(
1989
,
2
,
25
,
5
,
30
,
0
)
@post4
=
Post
.
create
id:
1004
,
title:
'about ruby TDD'
,
body:
'test is the best ....'
,
is_draft:
true
@tag_java
=
Tag
.
create
(
name:
'java'
)
@post3
.
tags
<<
@tag_java
end
...
...
@@ -55,7 +56,7 @@ describe Post do
end
it
'by title'
do
expect
(
Post
.
search
(
'title:ruby'
)).
to
have
(
1
).
items
expect
(
Post
.
search
(
'title:ruby'
)).
to
have
(
2
).
items
expect
(
Post
.
search
(
'title:ruby'
)).
to
include
(
@post1
)
end
...
...
@@ -79,8 +80,13 @@ describe Post do
expect
(
Post
.
search
(
'date:1989-2-25'
)).
to
include
(
@post3
)
end
it
'by draft'
do
expect
(
Post
.
search
(
'ruby'
)).
to
have
(
3
).
items
expect
(
Post
.
search
(
'ruby draft:1'
)).
to
have
(
1
).
items
end
it
'by else'
do
expect
(
Post
.
search
(
'ruby'
)).
to
have
(
2
).
items
expect
(
Post
.
search
(
'ruby'
)).
to
have
(
3
).
items
expect
(
Post
.
search
(
'ruby'
)).
to
include
(
@post1
)
expect
(
Post
.
search
(
'ruby'
)).
to
include
(
@post3
)
end
...
...
spec/models/tag_spec.rb
View file @
afe9a937
...
...
@@ -5,9 +5,9 @@ describe Tag do
before
:each
do
@tag_ruby
=
Tag
.
create
(
name:
'ruby'
)
@tag_java
=
Tag
.
create
(
name:
'java'
)
@post1
=
Post
.
create
id:
1001
,
title:
'ruby rspec'
,
tags:
[
@tag_ruby
]
@post2
=
Post
.
create
id:
1002
,
title:
'ruby is better than java'
,
tags:
[
@tag_ruby
,
@tag_java
]
@post3
=
Post
.
create
id:
1003
,
title:
'java java...'
,
tags:
[
@tag_java
]
@post1
=
Post
.
create
id:
1001
,
title:
'ruby rspec'
,
body:
'hoge'
,
tags:
[
@tag_ruby
]
@post2
=
Post
.
create
id:
1002
,
title:
'ruby is better than java'
,
body:
'hoge'
,
tags:
[
@tag_ruby
,
@tag_java
]
@post3
=
Post
.
create
id:
1003
,
title:
'java java...'
,
body:
'hoge'
,
tags:
[
@tag_java
]
end
it
'successfully moved'
do
...
...
spec/models/user_spec.rb
View file @
afe9a937
...
...
@@ -118,4 +118,8 @@ describe User do
end
end
describe
'draft'
do
pending
'draft'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment