Coder Social home page Coder Social logo

mooreniemi / transbucket_rails Goto Github PK

View Code? Open in Web Editor NEW
10.0 6.0 4.0 113.25 MB

:hospital: → :camera: → :thumbsup:

Home Page: http://www.transbucket.com

Ruby 59.01% CoffeeScript 0.24% JavaScript 3.26% CSS 0.15% Shell 0.18% HTML 36.32% SCSS 0.49% Dockerfile 0.34% Procfile 0.01%
ruby postgres transgender open-source community photos photo-sharing elasticsearch rails rails4 heroku

transbucket_rails's Introduction

          _______
      _.-()______)-._
    .'               '.
   /                   \
  :      _________      :
  |.--'''         '''--.|
  (                     )
  :'--..._________...--':
  :                     :
   :                   :
   :         ⚧️         :
    :                 :
    :                 :
     :               :
     :               :
      :             :
jrei  :_           _:
        '''-----'''

Transbucket.com (Transbucket_Rails)

The TL;DR of technical specs is: Rails 4.2.8 (in Ruby 2.6.6), using bower_rails to manage Javascript dependencies, on Postgres database for storage, and with Elasticsearch for search.

Table of Contents

setup

docker-compose

Once you have docker-compose installed, you can spin up a containerized local dev environment by running:

docker-compose up --build

This will bring up the app at http://localhost:3000 alongside Elasticsearch, Kibana, and Postgres. You can then complete the initial setup by running:

docker-compose exec web bundle exec rake db:setup
docker-compose exec web \
    bundle exec rake environment elasticsearch:import:model CLASS=Pin INDEX=development_pins FORCE=y

To stop the environment, run:

docker-compose down

Alternatively, you can set up all the services directly on your machine as described in the rest of this section.

database setup

For set up, you'll need to make sure you have Elasticsearch installed for search functionality and Postgres installed for the actual database. The database is currently set up to have the user "Alex".

elasticsearch

brew install elasticsearch
brew install kibana

# to make sure ES is up
curl localhost:9200

Then you can access the Kibana UI.

postgres

Heroku manages our database.yml in production (and staging), so all these instructions are just for local environment.

For Postgres on Mac, you can use postgresapp. On Linux check your distribution details.

Use createuser "Alex" -s in the shell to create the user. (On Linux,createuser is its own executable, so log onto psql first.) If permissions seem wrong, run psql and enter ALTER ROLE "ALEX" CREATEDB; to give it the right permissions.

Now you should be able to run rake db:setup. Make sure to redo this command and for subsequent commands rerun for RAILS_ENV=test, then you can run bundle to install gems, and rspec to run tests.

Some seed data is necessary for the site to work. It is all handled via rake db:seed which is included during rake db:setup. The process in general is a backup and dump of the prod database is made, then a seed_dump from it.

For your ease, rake db:seed will also create a user and an admin. Both will have the password "password". The usernames should output to console.

On Ubuntu, you will likely need to follow these instructions after you've installed headers.

run environments

Staging and production both deploy and depend on Heroku. You should grab their cli. These instructions assume you've set it up.

Environment variables are kept in an untracked file (config/application.yml) managed by Figaro. Running heroku config --app transbucket will give you the production env, and heroku config --app transbucket-staging staging's env. When you want to push local changes to Heroku (be VERY careful with this), you use figaro heroku:set -e production.

To run locally, I use rails s -p 3003 (because I am often running servers on other ports). Then navigate to localhost:3003 to browse. You can also just run it without specifiying the port.

If you need to test against an actual S3 instance, you can uncomment the config block in config/environments/development.rb and set the required environment varialbles. (You can grab those with heroku config --app transbucket-staging. Otherwise you'll just store on your local file system.

Currently using CircleCI, which runs the app on Ubuntu 12. If you need to change a setting, try changing it via the UI first, then edit the circle.yml file.

For master branch: CircleCI

Staging is meant to run in the production environment, as close to actual production as possible. Every successful build on CI (based on every git push you do) will trigger a deployment on staging automatically.

If you need to deploying a branch to staging manually:

git push staging your_branch:master

Connecting to staging to debug or run tasks:

heroku run rails console --app transbucket-staging

For staging and production, assets need to be recompiled. It's wise to clean them first:

  rake assets:clean
  RAILS_ENV=production bundle exec rake assets:precompile

While we remain on Heroku, it will infer this step for us. (You won't need to do it.)

tests

On the Ruby side, rspec, but you also need chromium-chromedriver in order to run UI integ tests, via Selenium. For example, on Ubuntu you can run: sudo apt-get install chromium-chromedriver. If you want to spy on what's happening during a Selenium run, you can edit spec/support/capybara_config.rb to switch off _headless.

Spring is installed to speed up Rails loading times; you should see much shorter load times after the first run.

If you need to see some performance stats, use rspec --profile.

parallel tests

To set up (one time only):

rake parallel:setup

Then, run tests with:

rake parallel:spec

Or, to run with Spring for faster load times:

export DISABLE_SPRING=0 # needed to force activate spring
spring rake parallel:spec

performance testing

Best if you run unicorn rather than usual development server thin:

unicorn -c config/unicorn.rb # this will spawn 3 processes

Then after installing apache_bench (you should be able to do brew install ab) run:

ab -n 100 -c 10 http://0.0.0.0:8080/

static analysis

rubocop and brakeman are available.

profiling

In dev mode, rack-mini-profiler, stackprof and ruby-prof are available.

ruby-prof example

  require 'ruby-prof'
  RubyProf.start

  # some ruby code you want to profile

  result = RubyProf.stop
  printer = RubyProf::FlatPrinter.new(result)
  printer.print(STDOUT)

  # if you need the call stack, try
  #printer = RubyProf::CallStackPrinter.new(result)
  #printer.print(File.open('tmp/ruby_prof.html', "w"))

stackprof example

  # i add this to the top of a test file
  # say, spec/presenters/pin_presenter_spec.rb

  RSpec.configure do |config|
    config.around(:each) do |example|
      path = Rails.root.join("tmp/stackprof-cpu-test-#{example.full_description.parameterize}.dump")
      StackProf.run(mode: :cpu, out: path.to_s) do
        example.run
      end
    end
  end

Then you can use something like: bundle exec stackprof tmp/stackprof-cpu-test-pinpresenter-filtering-results-returns-pins-scoped-by-procedure.dump to view the dump.

If you need to find a corresponding call, you can use git grep suspicious_call -- '*.rb'.

caching

Fragment, page, and low-level caching are being used despite Heroku's ephemeral file store. Given the site runs on one dyno, and that deploys are infrequent, filestore caching still has some benefit.

Page caching is only used for public areas of the site. For the majority of the site, fragment caching and low-level calls of the form Rails.cache.fetch are being used.

search

The Pin model has a callback that will update Elasticsearch. But when you are initially filling the index, you want to run the below command after you have seeded the database. Essentially Elasticsearch is a secondary view of our database data. It is safe to delete it and reindex it.

rake environment elasticsearch:import:model CLASS='Pin' INCLUDE='PinImage,Surgeon,Procedure' FORCE=true

# should show you the index you created, labeled by env
curl localhost:9200/_cat/indices

running scheduled jobs / async execution

Via Heroku add-ons we have scheduler. The process is basically add a rake task, and use heroku addons:open scheduler to open the scheduler.

The other option is delayed_job. During deploy, a separate dyno is used to run rake jobs:work which starts the delayed_job process that manages execution of the queue.

I've been using the scheduler to run things like periodic jobs, whereas I use delayed_jobs for stuff like sending an email async. (For an example see app/helpers/notifications_helper.rb.)

more help

  • Is there a rake task? Use rake -T to check.
  • Locked yourself out? User.where(email: 'user_email_address').take.reset_password('new_password','new_password').confirm
  • Having trouble getting to where an error is raised or want a quick feedback loop? Try pry-rescue by doing bundle exec rescue rspec or bundle exec rescue rails s.
  • Not seeing a change you expect? Some fragment caching is being used. If you need to manually clear it, hop into rails c and then run Rails.cache.clear. (You can also just rm -rf tmp.)

contact

email alex

transbucket_rails's People

Contributors

asherkory avatar corajr avatar dependabot[bot] avatar mooreniemi avatar saltavenger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

transbucket_rails's Issues

admin: remove flag button not working

Jun 15 15:09:54 transbucket app/web.1:  Started DELETE "/comments/4914/flags/remove_flag" for 73.38.57.191 at 2016-06-15 22:09:53 +0000 
Jun 15 15:09:54 transbucket app/web.1:  ActionController::RoutingError (No route matches [DELETE] "/comments/4914/flags/remove_flag"):

complications

add complications option to pins
should be related to procedure too, as some complications are particular to a procedure

Long caption causes 500 error

Captions are limited in the database to 555 chars. If someone tries to enter a longer comment, they get a 500 error rather than a validation error.

Fixes: add length validation, or change field to text.

Feature tests around sign-up and confirmation

Urgently needed to ensure that people can actually sign up.

Tests:

  • The sign-up process
    • keeps the user's info (esp. gender; see issue #20)
    • displays any errors in the form
    • redirects to /users/sign_in (with mention of the confirmation email) when successful

Add pronouns field

Add a pronouns field, possibly with the option for users to add their own.

surgeon listing

now that individual profile pages exist from #2, would be nice to have a surgeons tab like procedures tab

unsure what is most useful for people to see displayed

map? sortable list with numbers on satisfaction?

"Confirmation token is invalid" on staging

Might be related to heartcombo/devise#2615 (comment)

I had the following in an after_create callback:

if account.nil?
  self.account = Account.new
  self.save
end

That self.save was updating the confirmation_token, because it was happening mid transaction. If I move it into an after_commit callback, or change it to self.account = Account.create, it works fine.

We have "after_create :set_preference" which updates the user's preference has_one relation.

procedure improvements

can we remodel procedures to be more granular? ie., phalloplasty > forearm phalloplasty?

procedure profile pages

ie /procedure/:id or /procedure/procedure-slug

display recent pins, avg sensation and avg satisfaction ratings

some editable wiki / comments?

Change UI to show that password is required to make changes

There were at least two possibilities regarding the user profile update:

  1. change the UI to indicate that the password is required to update any field
  2. separate the form out into a sensitive (password, email) and non-sensitive section by:
    • creating a new controller to manage user profile
    • overriding RegistrationsController#update to check if any sensitive attributes are changed (use update_with_password if so or update_without_password otherwise

Option 1 is more readily achievable and doesn't require a bunch of new tests, but option 2 is still possible.

get off heroku?

heroku is like $40 and we don't even have a worker or memcached running. cheaper options?

would also like to explore: dockerize a vps solution

Missing surgeon causes front page to 500

https://papertrailapp.com/systems/transbucket/events?r=679928993176379394-679930218299023386

Jun 15 19:44:52 transbucket app/web.1:  Started GET "/" for 73.38.57.191 at 2016-06-16 02:44:52 +0000 
Jun 15 19:44:52 transbucket app/web.1:  ActionView::Template::Error (undefined method `id' for nil:NilClass): 
Jun 15 19:44:52 transbucket app/web.1:      28:           <%= link_to (image_tag pin.cover_image(@presenter.safe_mode)), pin %></div> 
Jun 15 19:44:52 transbucket app/web.1:      29:  
Jun 15 19:44:52 transbucket app/web.1:      30:             <p class="description"> 
Jun 15 19:44:52 transbucket app/web.1:      31:             <%= pin.procedure.name unless pin.procedure.nil? %> by <strong><%= pin.surgeon.id == 911 ? 'unknown' : 'Dr. ' + pin.surgeon.to_s %></strong> 
Jun 15 19:44:52 transbucket app/web.1:      32:           </p> 
Jun 15 19:44:52 transbucket app/web.1:      33:         </div> 
Jun 15 19:44:52 transbucket app/web.1:      34:       <% end %> 
Jun 15 19:44:52 transbucket app/web.1:    app/views/pins/_pin.html.erb:31:in `_app_views_pins__pin_html_erb__241991805469676778_55951280' 
Jun 15 19:44:52 transbucket app/web.1:    app/views/pins/index.html.erb:25:in `_app_views_pins_index_html_erb___310917248500694328_55195940' 
Jun 15 19:44:52 transbucket app/web.1:    app/controllers/pins_controller.rb:21:in `index' 
Jun 15 19:44:52 transbucket heroku/router:  at=info method=GET path="/" host=www.transbucket.com request_id=5da3b0d7-b3fb-40e0-aa83-d7f3d2fce81a fwd="73.38.57.191" dyno=web.1 connect=0ms service=175ms status=500 bytes=4998 

User settings tests

  • Turning off notifications
    • prevent emails from being sent
  • Clicking submit on user settings
    • updates them on the backend
    • doesn't delete user (re: issue #23)
  • Cancellation
    • confirms before deleting, if JS
    • deletes immediately without JS

Mobile UX

Make use of Bootstrap's responsive features.

body type

unsure whether to put on user and have many (as a body changes over time potentially) or have one attached to a procedure

would want to track weight, height, possibly pre and post chest measurements

surgeon profile pages

ie /surgeons/:id or /surgeons/last-name-first-name-slug

display recent pins, avg sensation and avg satisfaction ratings, and procedure types offered

open source the code

there's definitely some stuff in the git tree that shouldn't be there, and would be a privacy/security risk if we removed private right now. need to audit the code for any of those risks, move them out to env vars, and then can make this repo open.

Comment UX

A few concerns:

  • Replies currently appear above the comment they're responding to, which feels confusing.
  • Flagging also seems to be a point of confusion, in part due to issue #28.
  • Display in chronological (rather than reverse chronological) order
  • Enable threading
  • Put "Report" next to flag and add an explanatory pop-over, as on the pins page
    • visual feedback that the flag has been added
    • maybe the text should be "Hide"
  • Move add comment box to the bottom (and wrap in nicer bootstrap classes)

make comments clickable

screenshot 2016-06-14 21 20 09

the top element here of a _pin view is not clickable, and it'd be nice to have it clickable through to the pin then an anchor link to the specific comment on the pin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.