This website works better with JavaScript.
Home
Explore
Help
Sign In
nekobus
/
mastodon_neko
forked from
closed-social/mastodon
Watch
1
Star
0
Fork
0
Code
Issues
0
Pull Requests
0
Projects
0
Releases
0
Wiki
Activity
Browse Source
Adding Turbolinks, adding status posting form on homepage
master
Eugen Rochko
8 years ago
parent
c28971c70c
commit
f14f462eaf
14 changed files
with
104 additions
and
2 deletions
Split View
Diff Options
Show Stats
Download Patch File
Download Diff File
+1
-0
Gemfile
+4
-0
Gemfile.lock
+1
-0
app/assets/javascripts/application.js
+3
-0
app/assets/javascripts/statuses.coffee
+9
-0
app/assets/stylesheets/dashboard.scss
+3
-0
app/assets/stylesheets/statuses.scss
+18
-0
app/controllers/statuses_controller.rb
+2
-0
app/helpers/statuses_helper.rb
+1
-0
app/models/status.rb
+4
-1
app/services/follow_remote_account_service.rb
+17
-0
app/views/home/index.html.haml
+2
-1
config/routes.rb
+24
-0
spec/controllers/statuses_controller_spec.rb
+15
-0
spec/helpers/statuses_helper_spec.rb
+ 1
- 0
Gemfile
View File
@ -36,6 +36,7 @@ gem 'onebox'
gem
'simple_form'
gem
'will_paginate'
,
'~> 3.0.6'
gem
'rack-attack'
gem
'turbolinks'
,
'~> 5.0.0.beta'
group
:development
,
:test
do
gem
'rspec-rails'
+ 4
- 0
Gemfile.lock
View File
@ -293,6 +293,9 @@ GEM
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.2)
turbolinks (5.0.0.beta2)
turbolinks-source
turbolinks-source (5.0.0.beta3)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
@ -362,6 +365,7 @@ DEPENDENCIES
simple_form
simplecov
therubyracer
turbolinks (~> 5.0.0.beta)
uglifier (>= 1.3.0)
web-console (~> 2.0)
webmock
+ 1
- 0
app/assets/javascripts/application.js
View File
@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
+ 3
- 0
app/assets/javascripts/statuses.coffee
View File
@ -0,0 +1,3 @@
#
Place
all
the
behaviors
and
hooks
related
to
the
matching
controller
here
.
#
All
this
logic
will
automatically
be
available
in
application
.
js
.
#
You
can
use
CoffeeScript
in
this
file:
http
:
/
/coffeescript.org/
+ 9
- 0
app/assets/stylesheets/dashboard.scss
View File
@ -200,6 +200,15 @@
box-shadow
:
0
0
15px
rgba
(
0
,
0
,
0
,
0
.
2
)
;
}
}
hr
{
clear
:
both
;
border
:
0
;
padding
:
0
;
width
:
100
%
;
height
:
0
;
margin
:
30px
0
;
}
}
.
dashboard__top-bar
{
+ 3
- 0
app/assets/stylesheets/statuses.scss
View File
@ -0,0 +1,3 @@
/
/
Place
all
the
styles
related
to
the
statuses
controller
here
.
/
/
They
will
automatically
be
included
in
application
.
css
.
/
/
You
can
use
Sass
(
SCSS
)
here
:
http
:
/
/
sass-lang
.
com
/
+ 18
- 0
app/controllers/statuses_controller.rb
View File
@ -0,0 +1,18 @@
class
StatusesController
<
ApplicationController
layout
'dashboard'
before_action
:authenticate_user!
def
create
status
=
PostStatusService
.
new
.
(
current_user
.
account
,
status_params
[
:text
]
)
redirect_to
root_path
rescue
ActiveRecord
::
RecordInvalid
redirect_to
root_path
end
private
def
status_params
params
.
require
(
:status
)
.
permit
(
:text
)
end
end
+ 2
- 0
app/helpers/statuses_helper.rb
View File
@ -0,0 +1,2 @@
module
StatusesHelper
end
+ 1
- 0
app/models/status.rb
View File
@ -13,6 +13,7 @@ class Status < ActiveRecord::Base
validates
:account
,
presence
:
true
validates
:uri
,
uniqueness
:
true
,
unless
:
'local?'
validates
:text
,
presence
:
true
,
if
:
Proc
.
new
{
|
s
|
s
.
local?
&&
!
s
.
reblog?
}
scope
:with_counters
,
-
>
{
select
(
'statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count'
)
}
scope
:with_includes
,
-
>
{
includes
(
:account
,
reblog
:
:account
,
thread
:
:account
)
}
+ 4
- 1
app/services/follow_remote_account_service.rb
View File
@ -7,7 +7,10 @@ class FollowRemoteAccountService < BaseService
# @return [Account]
def
call
(
uri
,
subscribe
=
true
)
username
,
domain
=
uri
.
split
(
'@'
)
account
=
Account
.
where
(
username
:
username
,
domain
:
domain
)
.
first
return
Account
.
find_local
(
username
)
if
domain
==
Rails
.
configuration
.
x
.
local_domain
account
=
Account
.
find_by
(
username
:
username
,
domain
:
domain
)
if
account
.
nil?
account
=
Account
.
new
(
username
:
username
,
domain
:
domain
)
+ 17
- 0
app/views/home/index.html.haml
View File
@ -1,3 +1,11 @@
= simple_form_for Status.new, url: statuses_path, method: :post do |f|
= f.input :text, required: true, autofocus: true, label: false, placeholder: 'What are you up to?'
.form-actions
= f.button :submit, 'Post update'
%hr/
%h3 OAuth2
%p All API methods require a valid access token.
@ -83,6 +91,15 @@
%samp /api/accounts/:id/unfollow
.description
Unfollows target account from the user's account. Returns the target account.
%li
.address
%samp.method GET
%samp /api/accounts/lookup
.options
Options:
%samp usernames
.description
Returns accounts for a comma-separated list of usernames
%h3 Follows
%ul.api-descriptions
+ 2
- 1
config/routes.rb
View File
@ -21,7 +21,8 @@ Rails.application.routes.draw do
end
end
resource
:settings
,
only
:
[
:show
,
:update
]
resource
:settings
,
only
:
[
:show
,
:update
]
resources
:statuses
,
only
:
[
:create
]
namespace
:api
do
# PubSubHubbub
+ 24
- 0
spec/controllers/statuses_controller_spec.rb
View File
@ -0,0 +1,24 @@
require
'rails_helper'
RSpec
.
describe
StatusesController
,
type
:
:controller
do
let
(
:user
)
{
Fabricate
(
:user
)
}
before
do
sign_in
:user
,
user
end
describe
'POST #create'
do
before
do
stub_request
(
:post
,
"
https://pubsubhubbub.superfeedr.com/
"
)
.
to_return
(
:status
=
>
200
,
:body
=
>
"
"
,
:headers
=
>
{
}
)
post
:create
,
status
:
{
text
:
'Hello world'
}
end
it
'redirects back to homepage'
do
expect
(
response
)
.
to
redirect_to
(
root_path
)
end
it
'creates a new status'
do
expect
(
user
.
account
.
statuses
.
count
)
.
to
eq
1
end
end
end
+ 15
- 0
spec/helpers/statuses_helper_spec.rb
View File
@ -0,0 +1,15 @@
require
'rails_helper'
# Specs in this file have access to a helper object that includes
# the StatusesHelper. For example:
#
# describe StatusesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec
.
describe
StatusesHelper
,
type
:
:helper
do
pending
"
add some examples to (or delete)
#{
__FILE__
}
"
end
Write
Preview
Loading…
Cancel
Save