| .vscode | ||
| app | ||
| bin | ||
| config | ||
| db | ||
| docs | ||
| lib | ||
| log | ||
| public | ||
| spec | ||
| vendor/assets | ||
| .babelrc | ||
| .eslintrc.js | ||
| .gitignore | ||
| .postcssrc.yml | ||
| .rspec | ||
| .rubocop.yml | ||
| .ruby-version | ||
| .simplecov | ||
| config.ru | ||
| empty-module.js | ||
| Gemfile | ||
| Gemfile.lock | ||
| Guardfile | ||
| ISSUE_TEMPLATE.md | ||
| jest.config.js | ||
| package-lock.json | ||
| package.json | ||
| Procfile | ||
| Procfile.dev | ||
| Procfile.dev-hot | ||
| Rakefile | ||
| README.md | ||
| yarn.lock | ||
The DEV Community 👩💻👨💻
Where programmers share ideas and help each other grow
Introduction and Contribution Guideline
Welcome to the dev.to codebase. We are so excited to have you. Most importantly, all contributors must abide by the code of conduct.
With your help, we can build out the DEV Community platform to be more stable and better serve the users. The platform is built on Ruby on Rails. When in doubt, try to do things "The Rails Way", but it is an evolving codebase and we will learn from all new contributions in order to evolve.
Before we can make the codebase fully open source, we must ensure we discover any possible vulnerabilities that could be exposed by eyes on the code, but in the long run we think that openness can do nothing but help in this way.
How to contribute
When in doubt, ask! We are doing this for the first time and we may not be clear about everything. Creating an issue to ask about how to do something in the open is a great decision. We will try to create clear issues, but communication is the most important thing and it's hard! You may communicate through a pull request. It's a fine approach, but it could result in going down the wrong path. The earlier we talk about something the better.
Refactoring code, e.g. improving the code without modifying the behavior is an area that can probably be done based on intuition and may not require much communication to be merged.
Fixing bugs may also not require a lot of communication, but the more the better. Please surround bug fixes with ample tests. Bugs are magnets for other bugs. Write tests near bugs!
Building features is the area which will require the most communication and/or negotiation. Every feature is subjective and open for debate. Let's talk about the features!
Clean code with tests
Even though some of the existing code is poorly written or not tested as well as it could be, we have much more scrutiny for these things going forward, as the transition from team-only development to open development makes clean code more important than ever in order to avoid communication breakdown. Good luck writing the best code of your life!
Non-code contributions
Improving documentation and wikis is very valuable, as is participating in any discussions about approaches or features.
The bottom line
If a process could be improved, don't hesitate to bring it up, but there are always tradeoffs and we are humans. Mistakes happen and opinions may not always line up. Shaming anyone trying to contribute is not allowed.
Getting Started
Prerequisite
- Ruby: we recommend using rbenv to install the Ruby version listed on the badge.
- Bundler:
gem install bundler - Foreman:
gem install foreman - Yarn: use
brew install yarnto install yarn. It will also install node if you don't already have it. - PostgresSQL: the easiest way to get started with this is to use Postgres.app.
Installation steps
git clone git@github.com:benhalpern/practicaldeveloper.gitbundle installbin/yarnbin/setup- Set up your environment variables/secrets with the either of the following two methods:
- A. create a
config/application.ymlfile and paste secret keys in it. - B. Use Torus to wrap around the whole app. Refer to the wiki if you are interested. Please bear in mind that usage of Torus is experimental.
- If you are missing
ENVvariables on bootup,_env_checker.rbwill let you know. If you add or removeENVvars to the project, you must also modify this file before they can be merged.
- A. create a
Starting the application
We're mostly a Rails app, with a bit of Webpack sprinkled in. For most cases, simply running bin/rails server will do. If you're working with Webpack though, you'll need to run the following:
- Run
bin/startupto start the server, Webpack, and our job runnerdelayed_job.bin/startuprunsforeman start -f Procfile.devunder the hood. alias start="bin/startup"makes this even faster. 😊- If you're using
pryfor debugging in Rails, note that usingforemanandprytogether works, but it's not as clean asbin/rails server.
Here are some singleton commands you may need, usually in a separate instance/tab of your Terminal.
- Running the job server -- this is for mostly for notifications and emails:
bin/rails jobs:work - Clearing jobs (in case you don't want to wait for the backlog of jobs):
bin/rails jobs:clear
Current gotchas: potential environment issues with external services need to be worked out.
🔑 Key App tech/services
- We use Puma for the server
- We rely heavily on edge caching with Fastly
- We use Cloudinary for image manipulation/serving
- We use Keen for event storage
- We use Airbrake for error monitoring
- We use Timber for logging
- We use Delayed Job for background workers
- We use Algolia for search
- We use Redcarpet/Rouge for Markdown
- We use Carrierwave/Fog/AWS S3 for image upload/storage
- We use a modified version of InstantClick instead of Turbolinks
- We are hosted on Heroku
- We use Heroku scheduler for scheduled jobs (default)
- We use Sendgrid for API-triggered mailing
- We use Mailchimp for marketing/outreach emails
- We use Figaro for app configuration.
- We use CounterCulture to keep track of association counts (counter caches)
- We use Rolify for role management.
- We use Pundit for authorization.
There's more, but that's a decent overview of the key need-to-knows.
Workflow Suggestion
We use Spring and it is already included in the project.
- Use the provided bin stubs to automatically start Spring, i.e.
bin/rails server,bin/rspec spec/models/,bin/rake db:migrate. - If Spring isn't picking up on new changes, use
spring stop. For example, Spring should always be restarted if there's a change in environment key. - Check Spring's status whenever with
spring status.
Caveat: bin/rspec is not equipped with Spring because it affect Simplecov's result. Instead use bin/spring rspec.
Style Guide
This project follows Bbatsov's Ruby Style Guide, using Rubocop along with Rubocop-Rspec as the code analyzer. If you have Rubocop installed with your text editor of choice, you should be up and running. Settings can be edited in .rubocop.yml.
For Javascript, we follow Airbnb's JS Style Guide, using ESLint. If you have ESLint installed with your text editor of choice, you should be up and running.
Testing
The following technologies are used for testing:
- Rspec
- Capybara with selenium-webdriver
- chromedriver-helper for standard JS testing.
- Capybara-webkit for headless JS testing.(not in use)
rack_session_access- Warden
- guard-rspec for automated testing
Installing Capybara-webkit
This is currently commented out in the Gemfile, but if you want to experiment with it Follow the instruction of installing Qt here then bundle install normally.
When should I use login_via_session_as(:user) vs login_as(:user)?
login_as(:user)uses Warden's stubbing actions to make the application think that a user is signed in but without all of the overhead of actually signing them in. Recommended for view test.login_via_session_as(:user)usesrack_session_accessto modify application's session. It is integrated with Devise so current_user won't be nil. Recommended for feature test.
Environment Variables
You need to keep your personal config/application.yml up-to-date in order to properly set up your environment variables. We have some "shared" environment variables, but you may need "personal" environment variables for one reason or another (such as a private Algolia instance, possibly). It is important to keep people up-to-date on changes to this protocol, as it is not checked into git. It is also important to use secure ways of passing these keys around. We currently use LastPass to store this.
Previewing emails in development
You can modify the test in /test/mailers/previews
You can view the previews at (for example) http://localhost:3000/rails/mailers/notify_mailer/new_reply_email
How to contribute (Internal)
- Clone the project locally.
- Create a branch for each separate piece of work.
- Do the work and write good commit messages.
- If your work includes adding a new environment variable, make sure you update
_env_checker.rb.
- Push your branch up to this repository.
- Create a new pull-reqest.
- After the pull-request is approved and merged, delete your branch on github.
Avoid pushing spike(test) branches up to the main repository. If you must, push the spike branches up to a forked repository.
Branch Policies
Branch naming convention
Name the branch in the following manner.
<your-name>/<type>/<github issue# (if there's one)>-<name>
Examples
ben/feature/renderer-cookies
niko/hotfix/dockerfile-base-image
andy-and-niko/issue/#132-broken-link
Workflow
- Here's a guide to our workflow using ZenHub.
- Note: if you're working on a task with no associated issue, create an issue. We do this so there's transparency and also to prevent anyone from unknowingly doing the same task.
Pull request guideline
- Keep the pull request small; a pull request should try it's very best to address only a single concern.
- Make sure all the tests pass and add additional tests for the code you submit.
- Document your reasoning behind the changes. Explain why you wrote the code in the way you did, not what it does.
- If there's an existing issue related to the pull request, reference to it. More info here
Please note that we squash all pull request. After a pull request is approved, we will remove the branch the PR is on unless you state it otherwise
Continuous Integration & Continuous Deployment
We are using Codeship for CI and CD. Codeship will run a build (in isolated environment for testing) for every push to this repository. Keep in mind that a passing-build does not necessarily mean the project won't run into any issues. Strive to write good tests for any chunk of code you wish to contribute. Only pushes to the deployment branch will evoke the CD portion of Codeship after CI passes. Our test suite is not perfect and sometimes a re-rerun is needed.
Skipping CI build (Not recommended)
You can skip CI by adding --skip-ci to your commit message. More info here.
CodeClimate and Simplecov
We are using CodeClimate to track code quality and code coverage. Codeclimate will grade the quality of the code of every PR but not the entirety of the project. If you feel that the current linting rule is unreasonable, feel free to submit a separate PR to change it. Fix any errors that Codeclimate provides and strive to leave code better than you found it.
Simplecov is a gem that is tracking the coverage of our test suite. Codeship will upload Simplecov data to CodeClimate. We are still in the early stage of using it so it may not provide an accurate measurement our of codebase.
Using simplecov locally
- Run
bundle exec rspec specorbin/rspec spec. You can run rspec on the whole project or a single file. - After rspec is complete, open
index.htmlwithin the coverage folder to view code coverages.
Run bin/rspecov to do all of this in one step