Giter Site home page Giter Site logo

ruby-science's Introduction

Ruby Science

The canonical reference for writing fantastic Rails applications from authors who have created hundreds.

You build web applications, and you love Ruby on Rails because it provides a framework for developing applications that are are fast, fun, and easy to change. Over time these applications can become bloated, development slows down, and changes to the codebase become painful.

Ruby Science helps you learn to detect and fix emerging problems in your codebase, while maintaining an application that will be fun to work on for years to come.

This repository includes both the Markdown source files for the book, as well as the companion example Rails application.

Support the book and thoughtbot

A web-based version of the book is available for free. EPUB and PDF versions are available in a "pay what you want" model. You can also sponsor us on GitHub.

Your purchase goes to support the ongoing maintenance of Ruby Science, our blog, and all of our open source projects.

About thoughtbot

thoughtbot

This repo is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects.

We are available for hire.

ruby-science's People

Contributors

acandael avatar arunagw avatar bpeicher avatar calleluks avatar cpytel avatar d1 avatar dskecse avatar elisuh avatar github-actions[bot] avatar harlow avatar jessieay avatar jferris avatar jhwist avatar joesims avatar navidmatin avatar r00k avatar sej3506 avatar sgrif avatar stefannibrasil avatar sylvain avatar theandrewgraham avatar trhodeos avatar ugisozols avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-science's Issues

git issue

I cloned an early edition of the repo last year; now can't do a pull.
$ git pull
Username for 'https://github.com': dgoldie
Password for 'https://[email protected]':
fatal: Authentication failed

But I can clone the current repo again to a new location....
...just curious why?

Access removed because I did not have two-factor auth

Hi there
I previously had access to thoughtbot's ruby-science and testing-rails repositories. This was removed as I had not set up two-factor authorization.

I have changed my account to have two-factor authorization.

Could you restore my access to this repository and to the testing-rails repository?

(The email from Github says to contact an owner in the org to get access restored. I did not have any email contacts, so I thought this was likely the best way to request access restoration).

Typo in Large Classes - Symptoms list

4th bulleted item in symptoms listing (bottom of page 4 in PDF as of 12/17/2012):

"The class has more private methods that public methods."

should be:

"The class has more private methods than public methods."

Typo in shotgun surgery chapter

Hi,

Thanks for the upcoming Ruby Science book. I can already
tell it is going to help me improve my skills quite a bit.
While reading the sample, I found one small typo. On page
7, under "Shotgun Surgery", the second symptom:

...because they ARE hard to keep track of.

(The word "are" is missing.)

Great work.

Thanks.
Adam

Links are not correct in .epub format

Page 18 clicking on the links:

Move Method
Extract Class
Replace Conditional with Polymorphism
...

Basically every link under the Solutions header is broken.

Tested in: Calibre and Kobo Glo

Keyword arguments and Long parameter list

The chapter on long parameters list doesn't mention Ruby 2 keyword arguments. While it doesn't solve the long list problem, unlike the mentioned alternative with hashes, Ruby will show the required names in an error message due to missing parameter, and the solution wouldn't require positional knowledge.

I think it makes for a worthy addition.

Database migration failure in example app

When running the example app using ruby 3.2.2 on my local machine the bin/setup command fails due to a failure with the database migrations:

StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Active Record release the migration was written for:

class CreateDieselClearanceUsers < ActiveRecord::Migration[7.0]

I got around this by just running bin/rails db:schema:load but the bin/setup command or migrations might need to be adjusted.

Rails console crashes in example_app

Hi!

I can run the rails server as per normal, but when I try to launch the rails console I get this error:

.rvm/gems/ruby-2.0.0-p0@ruby-science/gems/mocha-0.12.7/lib/mocha/integration/mini_test.rb:56:in `<class:TestCase>': No Mocha monkey-patch for MiniTest version (RuntimeError)

Any ideas please?

Thanks,

Petros

Chapter on Inject dependencies

Looks like the commit references are incorrect and the code is not being included.

Is there a branch or tag that hasn't been committed got GitHub?

Dependency installation got 404 error

Hi guys,

I failed to install the dependencies with this command, which show me 404 error.
brew install https://raw.github.com/adamv/homebrew-alt/master/non-free/kindlegen.rb

See attached please:
 2013-01-23 02 21 18

Chap. 25 Introduce Parameter Object

This chapter centers around creating a simple parameter object recipient to hold on to first_name, last_name and email but doesn't actually show the implementation for this parameter object. I found this strange given that the other chapters I've read so far seem to explicitly include all the pieces for implementing the particular refactoring. Not a big deal as I imagine the class is just something like:

class Recipient
  attr_reader :first_name, :last_name, :email
  def initialize(first_name, last_name, email)
    @first_name = first_name
    @last_name = last_name
    @email = email
  end
end

Would adding the simple implementation similar to the above to the chapter add or distract from the chapter? I'm not sure if this was already internally discussed but figured I'd share my thoughts.

How to stub external js libraries when writing Rails integration tests/specs?

When an app interfaces external services like Google Maps for geocoding or Stripe for payments, what's the best way to stub the external javascript libraries for integration testing?

For example, I use VCR to mock all requests to Google Maps and Stripe, which works great. But the libraries for both are still loaded in javascript_include_tags.

What's the best way to deal with this so that integration tests can run completely disconnected from the internet?

Paperback repo missing

Got this on bundle install:

$ bundle install
Fetching gem metadata from http://rubygems.org/..........
Fetching [email protected]:thoughtbot/paperback.git
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Git error: command `git clone '[email protected]:thoughtbot/paperback.git' ... has failed.

Please make the repository public or add us to the repo.

Testing Practices

I wanted to get your thoughts on testing in isolation and how to then do integration tests to test the isolated components together.

Currently I unit test controller and models etc but when creating integration tests to ensure these components are working correctly together, I am unsure how much testing needs to be done to ensure that the two components work correctly together?

Large Class Question

In the section on the "Large Class" code smell, one symptom is listed as "The class has more private methods than public methods."

This seems (to me) contrary to much of what I've learned about writing clean maintainable code. I've got plenty of classes with a single public method (not including initialize), with 3 or 4 small private supporting methods. This is, relatively, quite a bit more private methods than public, but it feels perfectly reasonable to me at this scale.

What am I missing or not getting here? I think this symptom would benefit from some clarification.

ActiveSupport::Concern

I didn't see anything in the index that specifically mentioned module extraction, so I thought I'd throw this into discussion. Granted, Concerns can be a different way to implement Extract Method or Extract Service Object.

I've used this technique to fight the God Class. I've had some classes that end up looking like:

class User
  include Concerns::User::Feature1
  include Concerns::User::Feature2
  include Concerns::User::Feature3
  include Concerns::User::Feature4

  ...

I'm curious if/how others are using Concerns and what your thoughts are on if its a better to control large classes or introduces too much responsibility into one class?

How To Read This Book, indeed

At first I really liked all the inter-linking, but then I became confused as to how I should read the book.

I think it's more of a reference, or maybe a choose-your-own adventure that doesn't really end. Calling it a book implies it can be read, but as described in the text, an expected way I might read may be:

  1. Introduction
  2. Case Statement, click Divergent Change
  3. Read Divergent change till Solutions
  4. Click Extract Class, read, then click on Large Class (or Divergent Change?)
  5. Skip Divergent Change link, we've done that, read to solutions, click 'Move Method'
  6. Click 'Feature Envy', that looks interesting
  7. Oh yeah, 'Tell, Don't Ask', click, what was I doing again?
  8. Great chapter, and hey, there's Case Statement again! Do I want to go back to that? Sure
  9. Ok, Solutions, 'Replace Type Code with Subclasses',
  10. STI? Click
  11. 'Composition over inheritance'! I knew a guy who preferred inheritance over composition. He was a super guy (@tenderlove)
  12. 'Extract Decorators', et cetera

I've tried to demonstrate how confusing the process of reading the book can be, with all the context switches. Am I doing this wrong? Maybe there should be backlinks in the margins like the letters on the spine of a dictionary?

There seems to be some internal logic linking all the sections together that isn't quite surfaced.

Do you think you'll have a summary table/page at any point that references all the sections?

Method error in signout process

To reproduce:

  • clone repo

  • cd ruby-science/example_app

  • bundle && bundle exec rake db:migrate && bundle exec rails server

  • navigate to main page, create account, sign in, create survey

  • view surveys

  • click signout
    Error Produced:

    Routing Error
    No route matches [GET] "/sign_out"
    Try running rake routes for more information on available routes.
    

Running rake routes gets:

         sign_out DELETE /sign_out(.:format)                             clearance/sessions#destroy

for this instance,
and if we grep out sign_out (the path that would be used for this) out....

    โžœ  example_app git:(master) grep -r sign_out *
    app/views/shared/_header.html.erb:  <%= link_to 'Sign out', sign_out_path, method: :delete %>

As you can see, you use the delete method so I don't know what is causing the error, and have not had time to truly debug it.

Fix smart quotes in code samples

From Jaymo:

The upquote TeX package is required to correctly render single quotes in source listings. Assuming
you installed the BasicTeX package above, install this with the TeXLive manager commandline tool:

sudo tlmgr update --self
sudo tlmgr install upquote

Link commits to their github URL

It'd be handy if the book's references to commits could be linked to github's commit view, rather than requiring a trip to the command line.

MetricFu

FWIW, I'm reviving the metric_fu project. CodeClimate is great, but some people may want to run their metrics locally. I'm still actively working on updating and managing dependencies, but it does work. See https://github.com/metricfu/metric_fu if you want to mention it now, or keep it in mind for the Metrics section.

Links in .mobi format not correct in kindle app on Android device.

Links within the book do not go where they are supposed to when I view the book in the kindle app on my android device (Nexus 10). For instance, in the "Long Method" section, the link to the "Extract Method" solution actually goes to "Replace conditional with Null Object"

Steps to reproduce:

  1. download the .mobi version from /release
  2. email file to device's @kindle.com address
  3. open the book up in the kindle app on the device
  4. click link.
  5. be confused

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.