diff --git a/.gitignore b/.gitignore index 050c9d9..acd799b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ /log/* !/log/.keep /tmp + +# Ignore encrypted secrets key file. +config/secrets.yml.key diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..7f9e49d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,12 @@ +Rails: + Enabled: true +AllCops: + AutoCorrect: true + TargetRubyVersion: 2.4.0 + Include: + - '**/Gemfile' + - '**/Rakefile' + Exclude: + - 'bin/*' + - 'db/seeds.rb' + - 'db/schema.rb' diff --git a/Gemfile b/Gemfile index 841e0c9..4604d1c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,34 +1,26 @@ -source 'https://rubygems.org' +# frozen_string_literal: true +source 'https://rubygems.org' +ruby '2.4.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.6' +gem 'rails', '5.2.1' # Use sqlite3 as the database for Active Record gem 'sqlite3' -# Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' -# Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' -# Use CoffeeScript for .coffee assets and views -gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby -# Use jquery as the JavaScript library -gem 'jquery-rails' -# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks -gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc -gem 'acts-as-taggable-on', '~> 3.5.0' -gem 'acts_as_follower', '~> 0.2.1' -gem 'devise', '~> 4.2.0' +gem 'acts-as-taggable-on', git: 'https://github.com/mbleigh/acts-as-taggable-on' +gem 'acts_as_follower' +gem 'devise' gem 'jwt', '~> 1.5.4' -gem 'rack-cors', '~> 0.4.0' gem 'puma' +gem 'rack-cors', require: 'rack/cors' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -42,13 +34,12 @@ gem 'puma' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'listen' end group :development do - # Access an IRB console on exception pages or by using <%= console %> in views - gem 'web-console', '~> 2.0' - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'pry' + gem 'rubocop', require: false gem 'spring' end - diff --git a/Gemfile.lock b/Gemfile.lock index d8a673f..023198f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,187 +1,203 @@ +GIT + remote: https://github.com/mbleigh/acts-as-taggable-on + revision: 69322267029b54fe42be9a05e248df9de289a65b + specs: + acts-as-taggable-on (6.0.1) + activerecord (~> 5.0) + GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.6) - actionpack (= 4.2.6) - actionview (= 4.2.6) - activejob (= 4.2.6) + actioncable (5.2.1) + actionpack (= 5.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.6) - actionview (= 4.2.6) - activesupport (= 4.2.6) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.6) - activesupport (= 4.2.6) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.2.1) + actionview (= 5.2.1) + activesupport (= 5.2.1) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.6) - activesupport (= 4.2.6) - globalid (>= 0.3.0) - activemodel (4.2.6) - activesupport (= 4.2.6) + actionview (5.2.1) + activesupport (= 5.2.1) builder (~> 3.1) - activerecord (4.2.6) - activemodel (= 4.2.6) - activesupport (= 4.2.6) - arel (~> 6.0) - activesupport (4.2.6) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.1) + activesupport (= 5.2.1) + globalid (>= 0.3.6) + activemodel (5.2.1) + activesupport (= 5.2.1) + activerecord (5.2.1) + activemodel (= 5.2.1) + activesupport (= 5.2.1) + arel (>= 9.0) + activestorage (5.2.1) + actionpack (= 5.2.1) + activerecord (= 5.2.1) + marcel (~> 0.3.1) + activesupport (5.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - acts-as-taggable-on (3.5.0) - activerecord (>= 3.2, < 5) acts_as_follower (0.2.1) - arel (6.0.3) - bcrypt (3.1.11) - binding_of_caller (0.7.2) - debug_inspector (>= 0.0.1) - builder (3.2.2) - byebug (9.0.5) - coffee-rails (4.1.1) - coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.1.x) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.10.0) - concurrent-ruby (1.0.2) - debug_inspector (0.0.2) - devise (4.2.0) + arel (9.0.0) + ast (2.4.0) + bcrypt (3.1.12) + builder (3.2.3) + byebug (10.0.2) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + devise (4.5.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.1) + railties (>= 4.1.0, < 6.0) responders warden (~> 1.2.3) - erubis (2.7.0) - execjs (2.7.0) - globalid (0.3.6) - activesupport (>= 4.1.0) - i18n (0.7.0) - jbuilder (2.5.0) - activesupport (>= 3.0.0, < 5.1) - multi_json (~> 1.2) - jquery-rails (4.1.1) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - json (1.8.3) - jwt (1.5.4) - loofah (2.0.3) + erubi (1.7.1) + ffi (1.9.25) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (1.1.1) + concurrent-ruby (~> 1.0) + jaro_winkler (1.5.1) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + json (1.8.6) + jwt (1.5.6) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.2.2) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.9.0) - multi_json (1.12.1) - nokogiri (1.6.8) - mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.0) + mimemagic (0.3.2) + mini_mime (1.0.1) + mini_portile2 (2.3.0) + minitest (5.11.3) + multi_json (1.13.1) + nio4r (2.3.1) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) orm_adapter (0.5.0) - pkg-config (1.1.7) - puma (3.4.0) - rack (1.6.4) - rack-cors (0.4.0) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.6) - actionmailer (= 4.2.6) - actionpack (= 4.2.6) - actionview (= 4.2.6) - activejob (= 4.2.6) - activemodel (= 4.2.6) - activerecord (= 4.2.6) - activesupport (= 4.2.6) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.6) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (4.2.6) - actionpack (= 4.2.6) - activesupport (= 4.2.6) + parallel (1.12.1) + parser (2.5.1.2) + ast (~> 2.4.0) + powerpack (0.1.2) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + puma (3.12.0) + rack (2.0.5) + rack-cors (1.0.2) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.1) + actioncable (= 5.2.1) + actionmailer (= 5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + activemodel (= 5.2.1) + activerecord (= 5.2.1) + activestorage (= 5.2.1) + activesupport (= 5.2.1) + bundler (>= 1.3.0) + railties (= 5.2.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.2.1) + actionpack (= 5.2.1) + activesupport (= 5.2.1) + method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (11.2.2) - rdoc (4.2.2) - json (~> 1.4) - responders (2.2.0) - railties (>= 4.2.0, < 5.1) - sass (3.4.22) - sass-rails (5.0.5) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - sdoc (0.4.1) + thor (>= 0.19.0, < 2.0) + rainbow (3.0.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rdoc (4.3.0) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + rubocop (0.59.2) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5, != 2.5.1.1) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.10.0) + ruby_dep (1.5.0) + sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - spring (1.7.2) - sprockets (3.6.3) + spring (2.0.2) + activesupport (>= 4.2) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.1.1) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.11) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) - turbolinks (5.0.0) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) - tzinfo (1.2.2) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (3.0.0) - execjs (>= 0.3.0, < 3) - warden (1.2.6) + unicode-display_width (1.4.0) + warden (1.2.7) rack (>= 1.0) - web-console (2.3.0) - activemodel (>= 4.0) - binding_of_caller (>= 0.7.2) - railties (>= 4.0) - sprockets-rails (>= 2.0, < 4.0) + websocket-driver (0.7.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) PLATFORMS ruby DEPENDENCIES - acts-as-taggable-on (~> 3.5.0) - acts_as_follower (~> 0.2.1) + acts-as-taggable-on! + acts_as_follower byebug - coffee-rails (~> 4.1.0) - devise (~> 4.2.0) + devise jbuilder (~> 2.0) - jquery-rails jwt (~> 1.5.4) + listen + pry puma - rack-cors (~> 0.4.0) - rails (= 4.2.6) - sass-rails (~> 5.0) + rack-cors + rails (= 5.2.1) + rubocop sdoc (~> 0.4.0) spring sqlite3 - turbolinks - uglifier (>= 1.3.0) - web-console (~> 2.0) + +RUBY VERSION + ruby 2.4.1p111 BUNDLED WITH - 1.10.6 + 1.16.0 diff --git a/Rakefile b/Rakefile index ba6b733..da4efd5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/app/assets/images/.keep b/app/assets/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js deleted file mode 100644 index e07c5a8..0000000 --- a/app/assets/javascripts/application.js +++ /dev/null @@ -1,16 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// compiled file. -// -// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details -// about supported directives. -// -//= require jquery -//= require jquery_ujs -//= require turbolinks -//= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css deleted file mode 100644 index f9cd5b3..0000000 --- a/app/assets/stylesheets/application.css +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any styles - * defined in the other CSS/SCSS files in this directory. It is generally better to create a new - * file per style scope. - * - *= require_tree . - *= require_self - */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5e6b91b..d3cf437 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,11 +1,10 @@ -class ApplicationController < ActionController::Base - # Prevent CSRF attacks by raising an exception. - # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :null_session +# frozen_string_literal: true +class ApplicationController < ActionController::API respond_to :json - before_action :underscore_params! + include ActionController::HttpAuthentication::Token::ControllerMethods + before_action :configure_permitted_parameters, if: :devise_controller? before_action :authenticate_user @@ -16,20 +15,20 @@ def configure_permitted_parameters end def authenticate_user - if request.headers['Authorization'].present? - authenticate_or_request_with_http_token do |token| - begin - jwt_payload = JWT.decode(token, Rails.application.secrets.secret_key_base).first - - @current_user_id = jwt_payload['id'] - rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError - head :unauthorized - end + return if request.headers['Authorization'].blank? + + authenticate_or_request_with_http_token do |token| + begin + jwt_payload = JWT.decode(token, Rails.application.secrets.secret_key_base).first + + @current_user_id = jwt_payload['id'] + rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError + head :unauthorized end end end - def authenticate_user!(options = {}) + def authenticate_user!(_options = {}) head :unauthorized unless signed_in? end @@ -40,8 +39,4 @@ def current_user def signed_in? @current_user_id.present? end - - def underscore_params! - params.deep_transform_keys!(&:underscore) - end end diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 8c12015..2888939 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class ArticlesController < ApplicationController - before_action :authenticate_user!, except: [:index, :show] + before_action :authenticate_user!, except: %i[index show] def index @articles = Article.all.includes(:user) @@ -35,11 +37,11 @@ def create end def show - @article = Article.find_by_slug!(params[:slug]) + @article = Article.find_by!(slug: params[:slug]) end def update - @article = Article.find_by_slug!(params[:slug]) + @article = Article.find_by!(slug: params[:slug]) if @article.user_id == @current_user_id @article.update_attributes(article_params) @@ -51,7 +53,7 @@ def update end def destroy - @article = Article.find_by_slug!(params[:slug]) + @article = Article.find_by!(slug: params[:slug]) if @article.user_id == @current_user_id @article.destroy diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 2961226..b5b1e39 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CommentsController < ApplicationController before_action :authenticate_user!, except: [:index] before_action :find_article! @@ -31,6 +33,6 @@ def comment_params end def find_article! - @article = Article.find_by_slug!(params[:article_slug]) + @article = Article.find_by!(slug: params[:article_slug]) end end diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index c1cb2eb..28e38b1 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class FavoritesController < ApplicationController before_action :authenticate_user! before_action :find_article! @@ -17,6 +19,6 @@ def destroy private def find_article! - @article = Article.find_by_slug!(params[:article_slug]) + @article = Article.find_by!(slug: params[:article_slug]) end end diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index d1a62c2..fa6f674 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + class FollowsController < ApplicationController before_action :authenticate_user! def create - @user = User.find_by_username!(params[:profile_username]) + @user = User.find_by!(username: params[:profile_username]) current_user.follow(@user) if current_user.id != @user.id @@ -10,7 +12,7 @@ def create end def destroy - @user = User.find_by_username!(params[:profile_username]) + @user = User.find_by!(username: params[:profile_username]) current_user.stop_following(@user) if current_user.id != @user.id diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index a0b2bda..95898c8 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class ProfilesController < ApplicationController def show - @user = User.find_by_username(params[:username]) + @user = User.find_by(username: params[:username]) end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 8324f36..f2cdf07 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class SessionsController < Devise::SessionsController def create - user = User.find_by_email(sign_in_params[:email]) + user = User.find_by(email: sign_in_params[:email]) if user && user.valid_password?(sign_in_params[:password]) @current_user = user diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 07a90f1..ac376ad 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class TagsController < ApplicationController def index render json: { tags: Article.tag_counts.most_used.map(&:name) } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 05ce519..43e2eec 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + class UsersController < ApplicationController before_action :authenticate_user! - def show - end + def show; end def update if current_user.update_attributes(user_params) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..71fbba5 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/article.rb b/app/models/article.rb index fb97283..3ec81a2 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,10 +1,12 @@ -class Article < ActiveRecord::Base +# frozen_string_literal: true + +class Article < ApplicationRecord belongs_to :user has_many :favorites, dependent: :destroy has_many :comments, dependent: :destroy scope :authored_by, ->(username) { where(user: User.where(username: username)) } - scope :favorited_by, -> (username) { joins(:favorites).where(favorites: { user: User.where(username: username) }) } + scope :favorited_by, ->(username) { joins(:favorites).where(favorites: { user: User.where(username: username) }) } acts_as_taggable diff --git a/app/models/comment.rb b/app/models/comment.rb index 21b0ceb..d3627db 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,4 +1,6 @@ -class Comment < ActiveRecord::Base +# frozen_string_literal: true + +class Comment < ApplicationRecord belongs_to :user belongs_to :article diff --git a/app/models/favorite.rb b/app/models/favorite.rb index 249d476..3e5b435 100644 --- a/app/models/favorite.rb +++ b/app/models/favorite.rb @@ -1,4 +1,6 @@ -class Favorite < ActiveRecord::Base +# frozen_string_literal: true + +class Favorite < ApplicationRecord belongs_to :user belongs_to :article, counter_cache: true end diff --git a/app/models/follow.rb b/app/models/follow.rb index 125ec68..0746982 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -1,5 +1,6 @@ -class Follow < ActiveRecord::Base +# frozen_string_literal: true +class Follow < ApplicationRecord extend ActsAsFollower::FollowerLib extend ActsAsFollower::FollowScopes @@ -8,7 +9,6 @@ class Follow < ActiveRecord::Base belongs_to :follower, polymorphic: true def block! - self.update_attribute(:blocked, true) + update_attribute(:blocked, true) end - end diff --git a/app/models/user.rb b/app/models/user.rb index 39e9c0b..dfd056d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,6 @@ -class User < ActiveRecord::Base +# frozen_string_literal: true + +class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, @@ -11,7 +13,6 @@ class User < ActiveRecord::Base acts_as_follower acts_as_followable - validates :username, uniqueness: { case_sensitive: true }, format: { with: /\A[a-zA-Z0-9]+\z/ }, presence: true, diff --git a/app/views/articles/_article.json.jbuilder b/app/views/articles/_article.json.jbuilder index ff25e82..8bf1117 100644 --- a/app/views/articles/_article.json.jbuilder +++ b/app/views/articles/_article.json.jbuilder @@ -1,4 +1,6 @@ -json.(article, :title, :slug, :body, :created_at, :updated_at, :description, :tag_list) +# frozen_string_literal: true + +json.call(article, :title, :slug, :body, :created_at, :updated_at, :description, :tag_list) json.author article.user, partial: 'profiles/profile', as: :user json.favorited signed_in? ? current_user.favorited?(article) : false json.favorites_count article.favorites_count || 0 diff --git a/app/views/articles/index.json.jbuilder b/app/views/articles/index.json.jbuilder index 0273f37..974df02 100644 --- a/app/views/articles/index.json.jbuilder +++ b/app/views/articles/index.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.articles do |json| json.array! @articles, partial: 'articles/article', as: :article end diff --git a/app/views/articles/show.json.jbuilder b/app/views/articles/show.json.jbuilder index 57d5fbb..84ecc16 100644 --- a/app/views/articles/show.json.jbuilder +++ b/app/views/articles/show.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.article do |json| json.partial! 'articles/article', article: @article end diff --git a/app/views/comments/_comment.json.jbuilder b/app/views/comments/_comment.json.jbuilder index 24f463b..5f82280 100644 --- a/app/views/comments/_comment.json.jbuilder +++ b/app/views/comments/_comment.json.jbuilder @@ -1,2 +1,4 @@ -json.(comment, :id, :created_at, :updated_at, :body) +# frozen_string_literal: true + +json.call(comment, :id, :created_at, :updated_at, :body) json.author comment.user, partial: 'profiles/profile', as: :user diff --git a/app/views/comments/create.json.jbuilder b/app/views/comments/create.json.jbuilder index ccf728d..e9773ab 100644 --- a/app/views/comments/create.json.jbuilder +++ b/app/views/comments/create.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.comment do |json| json.partial! 'comments/comment', comment: @comment end diff --git a/app/views/comments/index.json.jbuilder b/app/views/comments/index.json.jbuilder index a79c11e..502bea2 100644 --- a/app/views/comments/index.json.jbuilder +++ b/app/views/comments/index.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.comments do |json| json.array! @comments, partial: 'comments/comment', as: :comment end diff --git a/app/views/devise/registrations/create.json.jbuilder b/app/views/devise/registrations/create.json.jbuilder index c5ec3e5..60f1da9 100644 --- a/app/views/devise/registrations/create.json.jbuilder +++ b/app/views/devise/registrations/create.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.user do |json| json.partial! 'users/user', user: current_user end diff --git a/app/views/devise/sessions/create.json.jbuilder b/app/views/devise/sessions/create.json.jbuilder index c5ec3e5..60f1da9 100644 --- a/app/views/devise/sessions/create.json.jbuilder +++ b/app/views/devise/sessions/create.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.user do |json| json.partial! 'users/user', user: current_user end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index 77d37b8..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - Conduit - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/app/views/profiles/_profile.json.jbuilder b/app/views/profiles/_profile.json.jbuilder index e5834e6..ded3482 100644 --- a/app/views/profiles/_profile.json.jbuilder +++ b/app/views/profiles/_profile.json.jbuilder @@ -1,3 +1,5 @@ -json.(user, :username, :bio) +# frozen_string_literal: true + +json.call(user, :username, :bio) json.image user.image || 'https://static.productionready.io/images/smiley-cyrus.jpg' json.following signed_in? ? current_user.following?(user) : false diff --git a/app/views/profiles/show.json.jbuilder b/app/views/profiles/show.json.jbuilder index 6aaeac2..887ba8e 100644 --- a/app/views/profiles/show.json.jbuilder +++ b/app/views/profiles/show.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.profile do |json| json.partial! 'profiles/profile', user: @user end diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index c361ada..a7ff346 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -1,2 +1,4 @@ -json.(user, :id, :email, :username, :bio, :image) +# frozen_string_literal: true + +json.call(user, :id, :email, :username, :bio, :image) json.token user.generate_jwt diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder index c5ec3e5..60f1da9 100644 --- a/app/views/users/show.json.jbuilder +++ b/app/views/users/show.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.user do |json| json.partial! 'users/user', user: current_user end diff --git a/bin/bundle b/bin/bundle index 7ee2081..66e9889 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,3 @@ -#!/usr/bin/env ruby2.2 +#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index efa17f8..0739660 100755 --- a/bin/rails +++ b/bin/rails @@ -1,9 +1,4 @@ -#!/usr/bin/env ruby2.2 -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end -APP_PATH = File.expand_path('../../config/application', __FILE__) +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 3d6d183..1724048 100755 --- a/bin/rake +++ b/bin/rake @@ -1,9 +1,4 @@ -#!/usr/bin/env ruby2.2 -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end +#!/usr/bin/env ruby require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index a242dbb..78c4e86 100755 --- a/bin/setup +++ b/bin/setup @@ -1,29 +1,38 @@ -#!/usr/bin/env ruby2.2 +#!/usr/bin/env ruby require 'pathname' +require 'fileutils' +include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) -Dir.chdir APP_ROOT do +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do # This script is a starting point to setup your application. - # Add necessary setup steps to this file: + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install" # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system "bin/rake db:setup" + system! 'bin/rails db:setup' puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" + system! 'bin/rails restart' end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000..a8e4462 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 0000000..c2bacef --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +VENDOR_PATH = File.expand_path('..', __dir__) +Dir.chdir(VENDOR_PATH) do + begin + exec "yarnpkg #{ARGV.join(" ")}" + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru index bd83b25..61c04e1 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) diff --git a/config/application.rb b/config/application.rb index 8951f9a..f7afc96 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,6 @@ -require File.expand_path('../boot', __FILE__) +# frozen_string_literal: true + +require_relative 'boot' require 'rails/all' @@ -8,19 +10,21 @@ module Conduit class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.1 + config.api_only = true + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. + config.middleware.insert_before 0, Rack::Cors, debug: true, logger: (-> { Rails.logger }) do + allow do + origins Rails.application.secrets[:client_root_url] - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true + resource '/api/*', + headers: :any, + methods: %i[get post delete put patch options head] + end + end end end diff --git a/config/boot.rb b/config/boot.rb index 6b750f0..30e594e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +# frozen_string_literal: true + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index ee8d90d..d5abe55 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require File.expand_path('../application', __FILE__) +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index b55e214..a07ca6d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -9,13 +11,28 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -27,15 +44,15 @@ # number of complex assets. config.assets.debug = true - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - - # Adds additional error checking when serving assets at runtime. - # Checks for improperly declared sprockets dependencies. - # Raises helpful error messages. - config.assets.raise_runtime_errors = true + # Suppress logger output for asset requests. + config.assets.quiet = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.debug_exception_response_format = :default end diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e..8a6a409 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -14,15 +16,14 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like - # NGINX, varnish or squid. - # config.action_dispatch.rack_cache = true + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -31,16 +32,20 @@ # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -49,16 +54,15 @@ config.log_level = :debug # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "conduit_#{Rails.env}" + config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. @@ -74,6 +78,16 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08..669350a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -12,9 +14,11 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" + } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -25,15 +29,13 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Randomize the order test cases are executed. - config.active_support.test_order = :random - # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..315ac48 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e6..a9b0d0f 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,11 +1,16 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' -# Add additional assets to the asset load path +# Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -# Rails.application.config.assets.precompile += %w( search.js ) +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cd..d0f0d3b 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 7f70458..ee8dff9 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,7 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 3030731..cf0a4b9 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf..aa7435f 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/jbuilder.rb b/config/initializers/jbuilder.rb index 418045d..b0accfe 100644 --- a/config/initializers/jbuilder.rb +++ b/config/initializers/jbuilder.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + Jbuilder.key_format camelize: :lower diff --git a/config/initializers/json_param_key_transform.rb b/config/initializers/json_param_key_transform.rb new file mode 100644 index 0000000..4224850 --- /dev/null +++ b/config/initializers/json_param_key_transform.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Transform JSON request param keys from JSON-conventional camelCase to +# Rails-conventional snake_case: +ActionDispatch::Request.parameter_parsers[:json] = ->(raw_post) { + # Modified from action_dispatch/http/parameters.rb + data = ActiveSupport::JSON.decode(raw_post) + data = { _json: data } unless data.is_a?(Hash) + + # Transform camelCase param keys to snake_case: + data.deep_transform_keys!(&:underscore) +} diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc18996..6e1d16f 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/new_framework_defaults_5_1.rb b/config/initializers/new_framework_defaults_5_1.rb new file mode 100644 index 0000000..b33ee80 --- /dev/null +++ b/config/initializers/new_framework_defaults_5_1.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make `form_with` generate non-remote forms. +Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Unknown asset fallback will return the path passed in when the given +# asset is not present in the asset pipeline. +# Rails.application.config.assets.unknown_asset_fallback = false diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index db7da2a..b788905 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_conduit_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 33725e9..2f3c0db 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which @@ -5,10 +7,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/config/locales/en.yml b/config/locales/en.yml index 0653957..decc5a8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,6 +16,16 @@ # # This would use the information in config/locales/es.yml. # +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# # To learn more, please read the Rails Internationalization guide # available at http://guides.rubyonrails.org/i18n.html. diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml new file mode 100644 index 0000000..c3e147a --- /dev/null +++ b/config/locales/responders.en.yml @@ -0,0 +1,12 @@ +en: + flash: + actions: + create: + notice: '%{resource_name} was successfully created.' + # alert: '%{resource_name} could not be created.' + update: + notice: '%{resource_name} was successfully updated.' + # alert: '%{resource_name} could not be updated.' + destroy: + notice: '%{resource_name} was successfully destroyed.' + alert: '%{resource_name} could not be destroyed.' diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..6ec461f --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch('PORT') { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch('RAILS_ENV') { 'development' } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# If you are preloading your application and using Active Record, it's +# recommended that you close any connections to the database before workers +# are forked to prevent connection leakage. +# +# before_fork do +# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) +# end + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted, this block will be run. If you are using the `preload_app!` +# option, you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, as Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end +# + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb index e57aab1..cb76a38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,18 +1,19 @@ +# frozen_string_literal: true + Rails.application.routes.draw do scope :api, defaults: { format: :json } do devise_for :users, controllers: { sessions: :sessions }, path_names: { sign_in: :login } - - resource :user, only: [:show, :update] + resource :user, only: %i[show update] resources :profiles, param: :username, only: [:show] do - resource :follow, only: [:create, :destroy] + resource :follow, only: %i[create destroy] end - resources :articles, param: :slug, except: [:edit, :new] do - resource :favorite, only: [:create, :destroy] - resources :comments, only: [:create, :index, :destroy] + resources :articles, param: :slug, except: %i[edit new] do + resource :favorite, only: %i[create destroy] + resources :comments, only: %i[create index destroy] get :feed, on: :collection end diff --git a/config/secrets.yml b/config/secrets.yml index 1a49280..565862c 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -5,18 +5,20 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. +# You can use `rails secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. +# Shared secrets are available across all environments. + +shared: + client_root_url: http://localhost:4100 + +# Environmental secrets are only available for that specific environment. + development: - secret_key_base: 1cedd34d1be5424c2646c82e267fcbb817dd118d47d52ea8835e7fd8ada93fcec1523148008c0ed647e5f852717692cb0236226929b02c97bfd032a275d5d87a + secret_key_base: b4ec4bebe065b6d81ff57acc4c81464d6ce8e8488a67391e0d51f2707ebc4ea474d86fa6c52d22adefd141f7236d6f99da046f4945c4773e6ff5f100eb4f29ed test: - secret_key_base: 7d4d2daa8c4b79efe9a9206d20b877a2cde9c90f46987c6ec24f811d06eddb9d554742fc6c25cd7ec73ce9e698424b152e78bb8bf61da8b669c53677f04ab0b8 - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> + secret_key_base: 25c0c6b3cfc81e9357d13657f5545d3401da7af97a2be88c37c0d5afff8913f49fa2ba5dd75c21fedc8a974e27a8bd486f318510944899eb535175a5359a7277 diff --git a/config/secrets.yml.enc b/config/secrets.yml.enc new file mode 100644 index 0000000..534adbb --- /dev/null +++ b/config/secrets.yml.enc @@ -0,0 +1 @@ +siBQfbvp2QIrFrw2Nb+S2ZJOKgQrXbV7tHsJWYafnxnruINEIo57G1+KVXIqfTFbvL95wh9R5dKoJj/7iJXk73KUv6VGg2AvmaWU9wEr9/nQsy2ojNAtg6F0T6ImsrzZchRDmycSPQkbQRBeqjDhuHqumSy8sqQOWeeIGM/4A99OxmCQIa2cAoQ09X38Og==--f7rABLaEoAVbrEWg--O15KZL5f10Z882jBsk4udA== \ No newline at end of file diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 0000000..c5933e4 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/db/migrate/20160712045707_devise_create_users.rb b/db/migrate/20160712045707_devise_create_users.rb index 9200e8b..78f4547 100644 --- a/db/migrate/20160712045707_devise_create_users.rb +++ b/db/migrate/20160712045707_devise_create_users.rb @@ -1,9 +1,11 @@ -class DeviseCreateUsers < ActiveRecord::Migration +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[4.2] def change create_table :users do |t| ## Database authenticatable - t.string :email, null: false, default: "" - t.string :encrypted_password, null: false, default: "" + t.string :email, null: false, default: '' + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token @@ -30,7 +32,6 @@ def change # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at - t.timestamps null: false end diff --git a/db/migrate/20160712045739_add_profile_fields_to_users.rb b/db/migrate/20160712045739_add_profile_fields_to_users.rb index 310bb17..4f02dc5 100644 --- a/db/migrate/20160712045739_add_profile_fields_to_users.rb +++ b/db/migrate/20160712045739_add_profile_fields_to_users.rb @@ -1,4 +1,6 @@ -class AddProfileFieldsToUsers < ActiveRecord::Migration +# frozen_string_literal: true + +class AddProfileFieldsToUsers < ActiveRecord::Migration[4.2] def change add_column :users, :username, :string add_index :users, :username, unique: true diff --git a/db/migrate/20160712052128_create_articles.rb b/db/migrate/20160712052128_create_articles.rb index afde63d..390e624 100644 --- a/db/migrate/20160712052128_create_articles.rb +++ b/db/migrate/20160712052128_create_articles.rb @@ -1,4 +1,6 @@ -class CreateArticles < ActiveRecord::Migration +# frozen_string_literal: true + +class CreateArticles < ActiveRecord::Migration[4.2] def change create_table :articles do |t| t.string :title diff --git a/db/migrate/20160712054809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20160712054809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb index 6bbd559..ec6c394 100644 --- a/db/migrate/20160712054809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +++ b/db/migrate/20160712054809_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # This migration comes from acts_as_taggable_on_engine (originally 1) -class ActsAsTaggableOnMigration < ActiveRecord::Migration +class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2] def self.up create_table :tags do |t| t.string :name @@ -21,7 +23,7 @@ def self.up end add_index :taggings, :tag_id - add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, %i[taggable_id taggable_type context] end def self.down diff --git a/db/migrate/20160712054810_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20160712054810_add_missing_unique_indices.acts_as_taggable_on_engine.rb index 4ca676f..34e5f54 100644 --- a/db/migrate/20160712054810_add_missing_unique_indices.acts_as_taggable_on_engine.rb +++ b/db/migrate/20160712054810_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + # This migration comes from acts_as_taggable_on_engine (originally 2) -class AddMissingUniqueIndices < ActiveRecord::Migration +class AddMissingUniqueIndices < ActiveRecord::Migration[4.2] def self.up add_index :tags, :name, unique: true remove_index :taggings, :tag_id - remove_index :taggings, [:taggable_id, :taggable_type, :context] + remove_index :taggings, %i[taggable_id taggable_type context] add_index :taggings, - [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], + %i[tag_id taggable_id taggable_type context tagger_id tagger_type], unique: true, name: 'taggings_idx' end @@ -15,6 +17,6 @@ def self.down remove_index :taggings, name: 'taggings_idx' add_index :taggings, :tag_id - add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, %i[taggable_id taggable_type context] end end diff --git a/db/migrate/20160712054811_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20160712054811_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb index 8edb508..e4bdc65 100644 --- a/db/migrate/20160712054811_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +++ b/db/migrate/20160712054811_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # This migration comes from acts_as_taggable_on_engine (originally 3) -class AddTaggingsCounterCacheToTags < ActiveRecord::Migration +class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2] def self.up add_column :tags, :taggings_count, :integer, default: 0 diff --git a/db/migrate/20160712054812_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20160712054812_add_missing_taggable_index.acts_as_taggable_on_engine.rb index 71f2d7f..c6cd136 100644 --- a/db/migrate/20160712054812_add_missing_taggable_index.acts_as_taggable_on_engine.rb +++ b/db/migrate/20160712054812_add_missing_taggable_index.acts_as_taggable_on_engine.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # This migration comes from acts_as_taggable_on_engine (originally 4) -class AddMissingTaggableIndex < ActiveRecord::Migration +class AddMissingTaggableIndex < ActiveRecord::Migration[4.2] def self.up - add_index :taggings, [:taggable_id, :taggable_type, :context] + add_index :taggings, %i[taggable_id taggable_type context] end def self.down - remove_index :taggings, [:taggable_id, :taggable_type, :context] + remove_index :taggings, %i[taggable_id taggable_type context] end end diff --git a/db/migrate/20160712054813_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20160712054813_change_collation_for_tag_names.acts_as_taggable_on_engine.rb index bfb06bc..d8eac54 100644 --- a/db/migrate/20160712054813_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +++ b/db/migrate/20160712054813_change_collation_for_tag_names.acts_as_taggable_on_engine.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # This migration comes from acts_as_taggable_on_engine (originally 5) # This migration is added to circumvent issue #623 and have special characters # work properly -class ChangeCollationForTagNames < ActiveRecord::Migration +class ChangeCollationForTagNames < ActiveRecord::Migration[4.2] def up if ActsAsTaggableOn::Utils.using_mysql? - execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") + execute('ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;') end end end diff --git a/db/migrate/20160712055201_create_favorites.rb b/db/migrate/20160712055201_create_favorites.rb index f754e99..39cc68f 100644 --- a/db/migrate/20160712055201_create_favorites.rb +++ b/db/migrate/20160712055201_create_favorites.rb @@ -1,4 +1,6 @@ -class CreateFavorites < ActiveRecord::Migration +# frozen_string_literal: true + +class CreateFavorites < ActiveRecord::Migration[4.2] def change create_table :favorites do |t| t.references :user, index: true, foreign_key: true diff --git a/db/migrate/20160712061113_create_comments.rb b/db/migrate/20160712061113_create_comments.rb index f015006..488d8c3 100644 --- a/db/migrate/20160712061113_create_comments.rb +++ b/db/migrate/20160712061113_create_comments.rb @@ -1,4 +1,6 @@ -class CreateComments < ActiveRecord::Migration +# frozen_string_literal: true + +class CreateComments < ActiveRecord::Migration[4.2] def change create_table :comments do |t| t.text :body diff --git a/db/migrate/20160712061614_acts_as_follower_migration.rb b/db/migrate/20160712061614_acts_as_follower_migration.rb index 0b39c01..9157184 100644 --- a/db/migrate/20160712061614_acts_as_follower_migration.rb +++ b/db/migrate/20160712061614_acts_as_follower_migration.rb @@ -1,4 +1,6 @@ -class ActsAsFollowerMigration < ActiveRecord::Migration +# frozen_string_literal: true + +class ActsAsFollowerMigration < ActiveRecord::Migration[4.2] def self.up create_table :follows, force: true do |t| t.references :followable, polymorphic: true, null: false @@ -7,8 +9,8 @@ def self.up t.timestamps end - add_index :follows, ["follower_id", "follower_type"], name: "fk_follows" - add_index :follows, ["followable_id", "followable_type"], name: "fk_followables" + add_index :follows, %w[follower_id follower_type], name: 'fk_follows' + add_index :follows, %w[followable_id followable_type], name: 'fk_followables' end def self.down diff --git a/db/migrate/20181015165120_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20181015165120_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..7416261 --- /dev/null +++ b/db/migrate/20181015165120_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,18 @@ +# This migration comes from acts_as_taggable_on_engine (originally 6) +class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2] + def change + add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id + add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id + add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type + add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id + add_index :taggings, :context unless index_exists? :taggings, :context + + unless index_exists? :taggings, [:tagger_id, :tagger_type] + add_index :taggings, [:tagger_id, :tagger_type] + end + + unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c65c025..29be70a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,96 +10,96 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160712061614) do +ActiveRecord::Schema.define(version: 20181015165120) do create_table "articles", force: :cascade do |t| - t.string "title" - t.string "slug" - t.text "body" - t.string "description" - t.integer "favorites_count" - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "title" + t.string "slug" + t.text "body" + t.string "description" + t.integer "favorites_count" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["slug"], name: "index_articles_on_slug", unique: true + t.index ["user_id"], name: "index_articles_on_user_id" end - add_index "articles", ["slug"], name: "index_articles_on_slug", unique: true - add_index "articles", ["user_id"], name: "index_articles_on_user_id" - create_table "comments", force: :cascade do |t| - t.text "body" - t.integer "user_id" - t.integer "article_id" + t.text "body" + t.integer "user_id" + t.integer "article_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["article_id"], name: "index_comments_on_article_id" + t.index ["user_id"], name: "index_comments_on_user_id" end - add_index "comments", ["article_id"], name: "index_comments_on_article_id" - add_index "comments", ["user_id"], name: "index_comments_on_user_id" - create_table "favorites", force: :cascade do |t| - t.integer "user_id" - t.integer "article_id" + t.integer "user_id" + t.integer "article_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["article_id"], name: "index_favorites_on_article_id" + t.index ["user_id"], name: "index_favorites_on_user_id" end - add_index "favorites", ["article_id"], name: "index_favorites_on_article_id" - add_index "favorites", ["user_id"], name: "index_favorites_on_user_id" - create_table "follows", force: :cascade do |t| - t.integer "followable_id", null: false - t.string "followable_type", null: false - t.integer "follower_id", null: false - t.string "follower_type", null: false - t.boolean "blocked", default: false, null: false + t.string "followable_type", null: false + t.integer "followable_id", null: false + t.string "follower_type", null: false + t.integer "follower_id", null: false + t.boolean "blocked", default: false, null: false t.datetime "created_at" t.datetime "updated_at" + t.index ["followable_id", "followable_type"], name: "fk_followables" + t.index ["follower_id", "follower_type"], name: "fk_follows" end - add_index "follows", ["followable_id", "followable_type"], name: "fk_followables" - add_index "follows", ["follower_id", "follower_type"], name: "fk_follows" - create_table "taggings", force: :cascade do |t| - t.integer "tag_id" - t.integer "taggable_id" - t.string "taggable_type" - t.integer "tagger_id" - t.string "tagger_type" - t.string "context", limit: 128 + t.integer "tag_id" + t.string "taggable_type" + t.integer "taggable_id" + t.string "tagger_type" + t.integer "tagger_id" + t.string "context", limit: 128 t.datetime "created_at" + t.index ["context"], name: "index_taggings_on_context" + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true + t.index ["tag_id"], name: "index_taggings_on_tag_id" + t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy" + t.index ["taggable_id"], name: "index_taggings_on_taggable_id" + t.index ["taggable_type"], name: "index_taggings_on_taggable_type" + t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type" + t.index ["tagger_id"], name: "index_taggings_on_tagger_id" end - add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true - add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" - create_table "tags", force: :cascade do |t| - t.string "name" + t.string "name" t.integer "taggings_count", default: 0 + t.index ["name"], name: "index_tags_on_name", unique: true end - add_index "tags", ["name"], name: "index_tags_on_name", unique: true - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "username" - t.string "image" - t.text "bio" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "username" + t.string "image" + t.text "bio" + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["username"], name: "index_users_on_username", unique: true end - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - add_index "users", ["username"], name: "index_users_on_username", unique: true - end diff --git a/test/controllers/articles_controller_test.rb b/test/controllers/articles_controller_test.rb new file mode 100644 index 0000000..d873d68 --- /dev/null +++ b/test/controllers/articles_controller_test.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ArticlesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/models/article_test.rb b/test/models/article_test.rb index 11c8abe..cfa5eba 100644 --- a/test/models/article_test.rb +++ b/test/models/article_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class ArticleTest < ActiveSupport::TestCase diff --git a/test/models/comment_test.rb b/test/models/comment_test.rb index b6d6131..7a6452f 100644 --- a/test/models/comment_test.rb +++ b/test/models/comment_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class CommentTest < ActiveSupport::TestCase diff --git a/test/models/favorite_test.rb b/test/models/favorite_test.rb index 1cc6656..84a2080 100644 --- a/test/models/favorite_test.rb +++ b/test/models/favorite_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class FavoriteTest < ActiveSupport::TestCase diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 82f61e0..5cc44ed 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class UserTest < ActiveSupport::TestCase diff --git a/test/test_helper.rb b/test/test_helper.rb index 92e39b2..c5369ca 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help'