Skip to content

Instantly share code, notes, and snippets.

@louisscruz
Last active July 13, 2017 05:55
Show Gist options
  • Save louisscruz/7f66123d1c489aced9da7d3abaf0fc6d to your computer and use it in GitHub Desktop.
Save louisscruz/7f66123d1c489aced9da7d3abaf0fc6d to your computer and use it in GitHub Desktop.
Reddit On Rails Notes

Reddit on Rails Update

What follows are the things I had to do to update the Reddit on Rails project to Rails 5.

Create A New Project

rails new reddit_on_rails --database=postgresql

Add Gems

Comment in BCrypt.

Add:

gem 'jquery-rails'

Add to :development, :test:

gem 'shoulda-matchers', git: 'https://github.com/thoughtbot/shoulda-matchers.git', branch: 'rails-5'
gem 'rails-controller-testing'
gem 'rspec-rails', '~> 3.5'
gem 'factory-girl-rails'

Add to :development:

gem 'pry-rails'
gem 'byebug'
gem 'better_errors'
gem 'binding_of_caller'

Run bundle install.

Setup RSpec

Run rails g rspec:install.

Add shoulda_matchers configuration. In the rails_helper.rb:

require 'shoulda/matchers'

RSpec.configure do |config|
#...

  Shoulda::Matchers.configure do |config|
    config.integrate do |with|
      with.test_framework :rspec
      with.library :rails
    end
  end

#...
end

Generate The Models

Run rails db:create. The create the following:

User

Run rails g model User name:string:index password_digest:string session_token:string:index.

Edit the resulting migration, then run rails db:migrate.

Paste the contents of the old project's user model specs into that of the new project.

Paste the contents of the old project's user model into that of the new project.

Most tests pass. Create the other models that are required to get them all to pass.

Sub

Run rails g model Sub moderator_id:integer:index name:string:index description:text.

Edit the resulting migration, then run rails db:migrate.

Paste the contents of the old project's sub model specs into that of the new project.

Paste the contents of the old project's sub model into that of the new project.

Most tests pass. Create the other models that are required to get them all to pass.

Post

Run rails g model Post title:string url:string content:text user_id:integer:index.

Edit the resulting migration, then run rails db:migrate.

Paste the contents of the old project's post model specs into that of the new project.

Paste the contents of the old project's post model into that of the new project.

Most tests pass. Create the other models that are required to get them all to pass.

PostSub

Run rails g model PostSub post_id:integer:index sub_id:integer:index.

Edit the resulting migration, then run rails db:migrate.

Paste the contents of the old project's post sub model specs into that of the new project.

Paste the contents of the old project's post sub model into that of the new project.

Most tests pass. Create the other models that are required to get them all to pass.

Comment

Run rails g model Comment body:text parent_comment_id:integer:index post_id:integer:index user_id:integer:index.

Edit the resulting migration, then run rails db:migrate.

Paste the contents of the old project's comment model specs into that of the new project.

Paste the contents of the old project's comment model into that of the new project.

Most tests pass. Create the other models that are required to get them all to pass.

UserVote

Run rails g model UserVote user_id:integer:index value:integer.

Edit the resulting migration, then run rails db:migrate.

Paste the contents of the old project's user vote model specs into that of the new project.

Paste the contents of the old project's user vote model into that of the new project.

Most tests pass. Create the other models that are required to get them all to pass.

Routes

I then copied all of the routes in.

Controllers

Users

Copy the controller content.

Copy the controller tests.

Make sure that the params are properly nested in the controller tests.

Views

I then copied and pasted all of the non-layout views folders into the new project.

Remove initialized .git

Rails initializes with a git folder. Remove it.

Re-Zip

Zip the project up.

Readme

After all of this, I made sure that the Readme was good to go.

@niartenyaw
Copy link

For the Gemfile, "factory-girl-rails" should be "factory_girl_rails".

@louisscruz
Copy link
Author

@niartenyam Whoops!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment