diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..30da7e1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +# Trailing whitespace is significant in markdown files. +[*.md] +indent_size = 4 +trim_trailing_whitespace = false + diff --git a/.gitignore b/.gitignore index 95cd1b1..76c20db 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +# Ignore application configuration +/config/application.yml +coverage/ diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..e065c71 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,74 @@ +AllCops: + Exclude: + - db/schema.rb + - db/seeds.rb + - bin/**/* + - vendor/assets/**/* + +Layout/EmptyLines: + Exclude: + - config/initializers/sorcery.rb + +Layout/ExtraSpacing: + Exclude: + - db/migrate/**/* + +Layout/IndentationConsistency: + EnforcedStyle: rails + Exclude: + - config/routes.rb + +Layout/SpaceBeforeFirstArg: + Exclude: + - config/routes.rb + +Lint/Debugger: + AutoCorrect: False + +Style/AndOr: + Enabled: false + +Style/ClassAndModuleChildren: + Exclude: + - test/test_helper.rb + +Style/Documentation: + Enabled: false + +Style/MethodDefParentheses: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/StructInheritance: + Exclude: + - app/policies/**/* + +Metrics/AbcSize: + Exclude: + - db/migrate/**/* + Max: 20 + +Metrics/BlockLength: + Exclude: + - lib/tasks/auto_annotate_models.rake + - config/routes.rb + +Metrics/LineLength: + Max: 110 + Exclude: + - Rakefile + - Gemfile + - config/**/* + - lib/tasks/**/* + - test/test_helper.rb + +Metrics/MethodLength: + Exclude: + - db/migrate/* + ExcludedMethods: + - base_attributes + +Rails: + Enabled: true diff --git a/Gemfile b/Gemfile index ca96a13..f4f9e53 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,50 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.5.3' +gem 'figaro', '~> 1.1' gem 'rails', '~> 5.2.1' gem 'bcrypt', '~> 3.1.7' gem 'bootsnap', '>= 1.1.0', require: false gem 'jbuilder', '~> 2.5' +gem 'json', '~> 2.1' +gem 'jwt', '2.1.0' gem 'puma', '~> 3.11' +gem 'pundit', '~> 2.0' gem 'rack-cors' gem 'sqlite3' +gem 'validates_email_format_of' group :development, :test do - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'awesome_print' + gem 'binding_of_caller' + gem 'brakeman' + gem 'byebug', platforms: %i[mri mingw x64_mingw] + gem 'guard', github: 'guard/guard' + gem 'guard-brakeman' + gem 'guard-minitest' + gem 'guard-rubocop' + gem 'guard-shell' + gem 'guard-spring' gem 'listen', '>= 3.0.5', '< 3.2' + gem 'minitest-reporters', github: 'kern/minitest-reporters' + gem 'policy-assertions' + gem 'pry-byebug' + gem 'pry-rails' + gem 'rails-erd' + gem 'rubocop', '~> 0.59' + gem 'simplecov', github: 'colszowka/simplecov', require: false gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end +group :development do + gem 'annotate', require: false +end + # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 966636a..e75daa1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,36 @@ +GIT + remote: https://github.com/colszowka/simplecov.git + revision: 994dbff2780abe420f63036a7f674c296395b6c0 + specs: + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + +GIT + remote: https://github.com/guard/guard.git + revision: a47aed1d6654d4025c3192f90c99d6eba8a041a6 + specs: + guard (2.14.2) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + +GIT + remote: https://github.com/kern/minitest-reporters.git + revision: d04c7e9b0504542f6084dc5a2060c774dc6cdda4 + specs: + minitest-reporters (1.3.5) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + GEM remote: https://rubygems.org/ specs: @@ -42,19 +75,59 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + annotate (2.7.4) + activerecord (>= 3.2, < 6.0) + rake (>= 10.4, < 13.0) + ansi (1.5.0) arel (9.0.0) + ast (2.4.0) + awesome_print (1.8.0) + bcrypt (3.1.12) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) bootsnap (1.3.2) msgpack (~> 1.0) + brakeman (4.3.1) builder (3.2.3) byebug (10.0.2) + choice (0.2.0) + coderay (1.1.2) concurrent-ruby (1.1.3) crass (1.0.4) + debug_inspector (0.0.3) + docile (1.3.1) erubi (1.7.1) ffi (1.9.25) + figaro (1.1.1) + thor (~> 0.14) + formatador (0.2.5) globalid (0.4.1) activesupport (>= 4.2.0) + guard-brakeman (0.8.3) + brakeman (>= 2.1.1) + guard (>= 2.0.0) + guard-compat (1.2.1) + guard-minitest (2.4.6) + guard-compat (~> 1.2) + minitest (>= 3.0) + guard-rubocop (1.3.0) + guard (~> 2.0) + rubocop (~> 0.20) + guard-shell (0.7.1) + guard (>= 2.0.0) + guard-compat (~> 1.0) + guard-spring (1.1.1) + guard (~> 2.0) + guard-compat (~> 1.1) + spring i18n (1.1.1) concurrent-ruby (~> 1.0) + jaro_winkler (1.5.1) + jbuilder (2.8.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + json (2.1.0) + jwt (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -62,6 +135,7 @@ GEM loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) + lumberjack (1.0.13) mail (2.7.1) mini_mime (>= 0.1.1) marcel (0.3.3) @@ -72,11 +146,34 @@ GEM mini_portile2 (2.3.0) minitest (5.11.3) msgpack (1.2.4) + multi_json (1.13.1) + nenv (0.3.0) nio4r (2.3.1) nokogiri (1.8.5) mini_portile2 (~> 2.3.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + parallel (1.12.1) + parser (2.5.3.0) + ast (~> 2.4.0) + policy-assertions (0.2.0) + activesupport (>= 3.0.0) + pundit (>= 1.0.0) + powerpack (0.1.2) + pry (0.12.0) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-byebug (3.6.0) + byebug (~> 10.0) + pry (~> 0.10) + pry-rails (0.3.7) + pry (>= 0.10.4) puma (3.12.0) + pundit (2.0.0) + activesupport (>= 3.0.0) rack (2.0.6) + rack-cors (1.0.2) rack-test (1.1.0) rack (>= 1.0, < 3) rails (5.2.1) @@ -95,6 +192,11 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) + rails-erd (1.5.2) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) railties (5.2.1) @@ -103,11 +205,24 @@ GEM method_source rake (>= 0.8.7) 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) + rubocop (0.60.0) + 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.4.0) + ruby-graphviz (1.2.3) + ruby-progressbar (1.10.0) ruby_dep (1.5.0) + shellany (0.0.1) + simplecov-html (0.10.2) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -121,10 +236,13 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - thor (0.20.2) + thor (0.20.3) thread_safe (0.3.6) tzinfo (1.2.5) thread_safe (~> 0.1) + unicode-display_width (1.4.0) + validates_email_format_of (1.6.3) + i18n websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) @@ -133,15 +251,40 @@ PLATFORMS ruby DEPENDENCIES + annotate + awesome_print + bcrypt (~> 3.1.7) + binding_of_caller bootsnap (>= 1.1.0) + brakeman byebug + figaro (~> 1.1) + guard! + guard-brakeman + guard-minitest + guard-rubocop + guard-shell + guard-spring + jbuilder (~> 2.5) + json (~> 2.1) + jwt (= 2.1.0) listen (>= 3.0.5, < 3.2) + minitest-reporters! + policy-assertions + pry-byebug + pry-rails puma (~> 3.11) + pundit (~> 2.0) + rack-cors rails (~> 5.2.1) + rails-erd + rubocop (~> 0.59) + simplecov! spring spring-watcher-listen (~> 2.0.0) sqlite3 tzinfo-data + validates_email_format_of RUBY VERSION ruby 2.5.3p105 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..f65f89c --- /dev/null +++ b/Guardfile @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +guard :minitest, spring: "bin/rails test", all_after_pass: true do + watch(%r{^app/(.+)\.rb$}) { |m| ["test/#{m[1]}", "test/#{m[1]}_test.rb"] } + watch(%r{^app/controllers/(admin|application)_controller\.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/test_helper\.rb$}) { 'test' } + watch(%r{^test/.+_test\.rb$}) + + # run controller/integration test when touching the router, jbuilder, or erb files + watch(%r{^app/views/((?!_mailer).)*([^/]+)\.erb$}) { ["test/controllers", "test/integration"] } + watch(%r{^app/views/((?!_mailer).)*([^/]+)\.jbuilder$}) { ["test/controllers", "test/integration"] } + watch(%r{^config/routes.rb}) { ["test/controllers", "test/integration"] } + + # run mailers/integration test when touching mailer erb files + watch(%r{^app/views/(.*_mailer/)?([^/]+)\.erb$}) { ["test/mailers", "test/integration"] } +end + +guard :rubocop, cli: %w[-D -S -a] do + watch(/.rubocop.yml/) + watch(/.+\.rb$/) + watch(/Rakefile/) + watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } +end + +guard 'brakeman', run_on_start: true, quiet: true do + ## Lets not watch files for brakeman, just scan on guard start, and full runs. + # + # watch(%r{^app/.+\.(erb|haml|rhtml|rb)$}) + # watch(%r{^config/.+\.rb$}) + # watch(%r{^lib/.+\.rb$}) + # watch('Gemfile') +end + +guard 'spring', bundler: true do + watch('Gemfile.lock') + watch(%r{^config/}) + watch(%r{^spec/(support|factories)/}) + watch(%r{^spec/factory.rb}) +end diff --git a/README.md b/README.md index d7b37dc..59da9bc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,50 @@ # MicroBlogger +This is a Rails 5.2.n API stack. +## Local dev setup + +Be sure to have ruby (2.5.n) installed. RVM is +recommended to manage ruby. This dev stack uses `guard` for +rapid style and test feedback. It is strongly recommended to +have it running for every dev change/session. + +### Initial setup + +* rvm install ruby-2.5.1 +* bundle install +* set up application.yml + * copy `config/application.yml.sample` to `config/application.yml` + * edit values as needed +* rake db:create +* rake db:migrate +* rake db:fixtures:load + +There is a shell script in the root that will rebuild both +the local dev and test databases which executes the last +three setup steps: +`./rebuild-dev-db.sh` + +Currently fixture files are used to seed local and test dev +instead of the `rake db:seed` pattern. + +### dev session + +* `bundle exec guard` +* do work until tests pass. +* `quit` to exit guard + +The guard config file is `/Guardfile`. + +With (almost) every file save, associated tests to that file +are ran, if successful the whole suite is then executed. + +After the test suite `rubocop` kicks off with +auto-correction flags. + +Finally simple cover reports are updated. + +## other notes +* minitest is the testing framework +* editorconfig: https://editorconfig.org/ +* rails-erd: https://github.com/voormedia/rails-erd diff --git a/Rakefile b/Rakefile index e85f913..488c551 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/controllers/concerns/.keep b/app/commands/.keep similarity index 100% rename from app/controllers/concerns/.keep rename to app/commands/.keep diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4ac8823..13c271f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::API end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace..d92ffdd 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..71fbba5 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/concerns/.keep b/app/policies/.keep similarity index 100% rename from app/models/concerns/.keep rename to app/policies/.keep diff --git a/app/validators/.keep b/app/validators/.keep new file mode 100644 index 0000000..e69de29 diff --git a/config.ru b/config.ru index f7ba0b5..842bccc 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_relative 'config/environment' diff --git a/config/application.rb b/config/application.rb index f7736d0..d11e3c3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'boot' require "rails" diff --git a/config/application.yml.sample b/config/application.yml.sample new file mode 100644 index 0000000..f99503a --- /dev/null +++ b/config/application.yml.sample @@ -0,0 +1,14 @@ +# Add configuration values here, as shown below. +# +# pusher_app_id: "2954" +# pusher_key: 7381a978f7dd7f9a1117 +# pusher_secret: abdc3b896a0ffb85d373 +# stripe_api_key: sk_test_2J0l093xOyW72XUYJHE4Dv2r +# stripe_publishable_key: pk_test_ro9jV5SNwGb1yYlQfzG17LHK +# +# production: +# stripe_api_key: sk_live_EeHnL644i6zo4Iyq4v1KdV9H +# stripe_publishable_key: pk_live_9lcthxpSIHbGwmdO941O1XVU + +aws_key: this-is-the-key +aws_secret: this-is-the-secret diff --git a/config/boot.rb b/config/boot.rb index b9e460c..c04863f 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# 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 426333b..d5abe55 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 8f7b485..602fd40 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. @@ -41,7 +43,6 @@ Rails.application.configure do # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 0be3e87..13175d2 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. @@ -37,7 +39,7 @@ Rails.application.configure do config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store diff --git a/config/environments/test.rb b/config/environments/test.rb index b08fc84..5f7b92e 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. diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 89d2efa..6d56e43 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cd..4b63f28 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# 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/cors.rb b/config/initializers/cors.rb index 3b1c1b5..82eafe5 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Avoid CORS issues when API is called from the frontend app. 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..dc84742 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# 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/mime_types.rb b/config/initializers/mime_types.rb index dc18996..be6fedc 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# 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/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc396..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 diff --git a/config/puma.rb b/config/puma.rb index a5eccf8..dd9e863 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,3 +1,5 @@ +# 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 diff --git a/config/routes.rb b/config/routes.rb index 787824f..47cc16e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/config/spring.rb b/config/spring.rb index 9fa7863..c5933e4 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + %w[ .ruby-version .rbenv-vars diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..52ab025 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,15 @@ +# 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. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + +end diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 0000000..53f2c72 --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +if Rails.env.development? + require 'annotate' + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + 'routes' => 'false', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'show_foreign_keys' => 'true', + 'show_complete_foreign_keys' => 'true', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'true', + 'exclude_fixtures' => 'false', + 'exclude_factories' => 'false', + 'exclude_serializers' => 'true', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'exclude_sti_subclasses' => 'false', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, # '^(updated_at|created_at)', + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => 'integer,boolean', + 'hide_default_column_types' => 'json,jsonb,hstore', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'classified_sort' => 'true', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil, + 'with_comment' => true + ) + end + + Annotate.load_tasks +end diff --git a/rebuild-dev-db.sh b/rebuild-dev-db.sh new file mode 100755 index 0000000..2a510b7 --- /dev/null +++ b/rebuild-dev-db.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +RAILS_ENV=development \ +bundle exec rake \ + db:drop \ + db:create \ + db:migrate \ + db:fixtures:load \ + +RAILS_ENV=test \ +bundle exec rake \ + db:migrate \ + db:fixtures:load + diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ab84e3..2a30587 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,10 +1,32 @@ +# frozen_string_literal: true + ENV['RAILS_ENV'] ||= 'test' + +# https://github.com/colszowka/simplecov +require 'simplecov' +SimpleCov.start 'rails' do + add_group 'Models', %w[app/models app/validators] + add_group 'Commands & Libs', %w[app/workers app/services app/libs app/commands] + add_group "Jobs", 'app/jobs' + add_group "Policies", 'app/policies' +end +Rails.application.eager_load! + require_relative '../config/environment' require 'rails/test_help' +require 'minitest/reporters' +require 'policy_assertions' +Dir[Rails.root.join("test", "test_helpers", "**", "*.rb")].each { |f| require f } + +Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] class ActiveSupport::TestCase + ActiveRecord::Migration.maintain_test_schema! + ActiveRecord::Migration.check_pending! + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all # Add more helper methods to be used by all tests here... + include AuthTestHelper end diff --git a/test/test_helpers/auth_test_helper.rb b/test/test_helpers/auth_test_helper.rb new file mode 100644 index 0000000..dc3e39e --- /dev/null +++ b/test/test_helpers/auth_test_helper.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module AuthTestHelper + def user_token user + AuthenticateUser.new(email: user.email, password: 'password').perform + end + + def auth_headers user, headers = {} + headers["HTTP_AUTHORIZATION"] = user_token(user) + headers + end +end diff --git a/user_stories.md b/user_stories.md new file mode 100644 index 0000000..c0640aa --- /dev/null +++ b/user_stories.md @@ -0,0 +1,37 @@ +# MicroBlogger + +An API for a micro blogging platform + +Guests can only view published content and author list +Standard can edit their profile & blogs +Admins can view list of users and edit any blog + +users: + display_name + email + password_digest + roles: guest, standard, admin + +blogs: + title + article + published_date + author_id + + + +## Tasks + +### User Bios + +As a user, I want to be able to author a bio that is +displayed with each of my postings. + +### Moderation + +As an admin, I want to be able to put a blog it in a state +of moderation. + +Once a blog post has this state, the author must edit and +submit for another review before an admin will republish. +