Adding Turbolinks, adding status posting form on homepage

master
Eugen Rochko 9 years ago
parent c28971c70c
commit f14f462eaf
  1. 1
      Gemfile
  2. 4
      Gemfile.lock
  3. 1
      app/assets/javascripts/application.js
  4. 3
      app/assets/javascripts/statuses.coffee
  5. 9
      app/assets/stylesheets/dashboard.scss
  6. 3
      app/assets/stylesheets/statuses.scss
  7. 18
      app/controllers/statuses_controller.rb
  8. 2
      app/helpers/statuses_helper.rb
  9. 1
      app/models/status.rb
  10. 5
      app/services/follow_remote_account_service.rb
  11. 17
      app/views/home/index.html.haml
  12. 1
      config/routes.rb
  13. 24
      spec/controllers/statuses_controller_spec.rb
  14. 15
      spec/helpers/statuses_helper_spec.rb

@ -36,6 +36,7 @@ gem 'onebox'
gem 'simple_form' gem 'simple_form'
gem 'will_paginate', '~> 3.0.6' gem 'will_paginate', '~> 3.0.6'
gem 'rack-attack' gem 'rack-attack'
gem 'turbolinks', '~> 5.0.0.beta'
group :development, :test do group :development, :test do
gem 'rspec-rails' gem 'rspec-rails'

@ -293,6 +293,9 @@ GEM
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.2) tilt (2.0.2)
turbolinks (5.0.0.beta2)
turbolinks-source
turbolinks-source (5.0.0.beta3)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.7.2) uglifier (2.7.2)
@ -362,6 +365,7 @@ DEPENDENCIES
simple_form simple_form
simplecov simplecov
therubyracer therubyracer
turbolinks (~> 5.0.0.beta)
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (~> 2.0) web-console (~> 2.0)
webmock webmock

@ -12,4 +12,5 @@
// //
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks
//= require_tree . //= require_tree .

@ -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/

@ -200,6 +200,15 @@
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2); 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 { .dashboard__top-bar {

@ -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/

@ -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

@ -0,0 +1,2 @@
module StatusesHelper
end

@ -13,6 +13,7 @@ class Status < ActiveRecord::Base
validates :account, presence: true validates :account, presence: true
validates :uri, uniqueness: true, unless: 'local?' 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_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) } scope :with_includes, -> { includes(:account, reblog: :account, thread: :account) }

@ -7,7 +7,10 @@ class FollowRemoteAccountService < BaseService
# @return [Account] # @return [Account]
def call(uri, subscribe = true) def call(uri, subscribe = true)
username, domain = uri.split('@') 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? if account.nil?
account = Account.new(username: username, domain: domain) account = Account.new(username: username, domain: domain)

@ -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 %h3 OAuth2
%p All API methods require a valid access token. %p All API methods require a valid access token.
@ -83,6 +91,15 @@
%samp /api/accounts/:id/unfollow %samp /api/accounts/:id/unfollow
.description .description
Unfollows target account from the user's account. Returns the target account. 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 %h3 Follows
%ul.api-descriptions %ul.api-descriptions

@ -22,6 +22,7 @@ Rails.application.routes.draw do
end end
resource :settings, only: [:show, :update] resource :settings, only: [:show, :update]
resources :statuses, only: [:create]
namespace :api do namespace :api do
# PubSubHubbub # PubSubHubbub

@ -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

@ -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
Loading…
Cancel
Save