rubyforgood / habitat_humanity

MIT License
6 stars 13 forks source link

Project Init Issues #94

Closed leesharma closed 8 years ago

leesharma commented 8 years ago

I'm taking this directly from the Slack conversation. When glroman forked the project, he encountered some issues:

System: Fedora 23

- Problem: no postgres database found
  Solution: install PostgreSQL and create a role that allows for DB
            creation.
    % su root
    % dnf install postgresql postgresql-plruby          \
                  postgresql-contrib postgresql-server
    % systemctl enable postgresql
    % systemctl start  postgresql
    % su postgres
    % createuser -d -e -P -r george
- Problem: Could not find a JavaScript runtime
    ~/.rvm/gems/ruby-2.3.1/gems/bundler-1.12.5/lib/bundler/runtime.rb:89:
    in `rescue in block (2 levels) in require':
    There was an error while trying to load the gem 'coffee-rails'.
    Gem Load Error is: Could not find a JavaScript runtime. See
    https://github.com/rails/execjs for a list of available runtimes.
  Solution: added the following to the Gemfile:
      group :development do
        gem 'therubyracer', :platforms => :ruby      # Add this
- Problem: ArgumentError: Factory not registered: work_site
    ~/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.7.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
    ~/src/h4h/db/seeds.rb:5:in `block in <top (required)>'
    ...
    ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
    ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
    -e:1:in `<main>'
    Tasks: TOP => db:setup => db:seed
    ...
    == Restarting application server ==
    touch: cannot touch 'tmp/restart.txt': No such file or directory
  Solution: require 'factory_girl_rails' rather than 'factory_girl' in
  db/seeds.rb.

- Problem: Tons of warnings
  Solution: remove Ruby warnings switch
     % unset RUBYOPT
- Problem: setup.rb generates an error.
  This command:
    system 'touch tmp/restart.txt'
  Yields this error:
    touch: cannot touch 'tmp/restart.txt': No such file or directory
  Solution: add a line to setup.rb:
    system '[[ ! -d tmp ]] && mkdir tmp'        # Add this
    system 'touch tmp/restart.txt'
- Problem: running `bundle exec rails s` doesn't work: puma doesn't read
  the config file in config/puma.rb.
  Solution: start app with `puma`
  More info: https://github.com/puma/puma/issues/512
- Problem: no admin user.
  Solution: create the admin user with this:
    % rake db:initialize_admin
  Which sets up an admin user with creds defined in config/secrets.yml
- Problem: get NoMethodError when running reports
    NoMethodError (undefined method `occurred_at' for nil:NilClass):
      app/models/shift.rb:69:in `block in breaks_duration'
      app/models/shift.rb:68:in `each'
      lib/csv_report_generator.rb:21:in `generate_report'
      app/reports/concerns/csv_generatable.rb:45:in `to_csv'
      app/controllers/hours_reports_controller.rb:11:in `block (2 levels) in show'
      app/controllers/hours_reports_controller.rb:10:in `show'
  Suspect this happens when EndBreakDateTime is nil.
  Solution: TBD
leesharma commented 8 years ago

I'm going to number the list for easier reference. We'll probably need to split the issues that need code changes out into separate GitHub issues.


  1. Problem: no postgres database found Solution: install PostgreSQL and create a role that allows for DB creation.

     % su root
     % dnf install postgresql postgresql-plruby          \
                   postgresql-contrib postgresql-server
     % systemctl enable postgresql
     % systemctl start  postgresql
     % su postgres
     % createuser -d -e -P -r george
  2. Problem: Could not find a JavaScript runtime

    ~/.rvm/gems/ruby-2.3.1/gems/bundler-1.12.5/lib/bundler/runtime.rb:89:
    in `rescue in block (2 levels) in require':
    There was an error while trying to load the gem 'coffee-rails'.
    Gem Load Error is: Could not find a JavaScript runtime. See
    https://github.com/rails/execjs for a list of available runtimes.

    Solution: added the following to the Gemfile:

       group :development do
         gem 'therubyracer', :platforms => :ruby      # Add this
  3. Problem:

    ArgumentError: Factory not registered: work_site
     ~/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.7.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
     ~/src/h4h/db/seeds.rb:5:in `block in <top (required)>'
     ...
     ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
     ~/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
     -e:1:in `<main>'
     Tasks: TOP => db:setup => db:seed
     ...
     == Restarting application server ==
     touch: cannot touch 'tmp/restart.txt': No such file or directory

    Solution: require 'factory_girl_rails' rather than 'factory_girl' in db/seeds.rb.

  4. Problem: Tons of warnings Solution: remove Ruby warnings switch

     % unset RUBYOPT
  5. Problem: setup.rb generates an error. This command: system 'touch tmp/restart.txt' Yields this error: touch: cannot touch 'tmp/restart.txt': No such file or directory Solution: add a line to setup.rb:

     system '[[ ! -d tmp ]] && mkdir tmp'        # Add this
     system 'touch tmp/restart.txt'
  6. Problem: running bundle exec rails s doesn't work: puma doesn't read the config file in config/puma.rb. Solution: start app with puma More info: https://github.com/puma/puma/issues/512
  7. Problem: no admin user. Solution: create the admin user with this: % rake db:initialize_admin Which sets up an admin user with creds defined in config/secrets.yml
  8. Problem: get NoMethodError when running reports

    NoMethodError (undefined method `occurred_at' for nil:NilClass):
     app/models/shift.rb:69:in `block in breaks_duration'
     app/models/shift.rb:68:in `each'
     lib/csv_report_generator.rb:21:in `generate_report'
     app/reports/concerns/csv_generatable.rb:45:in `to_csv'
     app/controllers/hours_reports_controller.rb:11:in `block (2 levels) in show'
     app/controllers/hours_reports_controller.rb:10:in `show'

    Suspect this happens when EndBreakDateTime is nil. Solution: TBD

leesharma commented 8 years ago

First, thank you to glroman for taking notes during his setup process. Hopefully solving these will make project setup easier for folks without a rails dev setup in the future.

Here are some of my initial thoughts about the issues:

bjmllr commented 8 years ago

I agree with using node for execjs. I don't see a good way to automate installing node from this project, but if someone has issues installing therubyracer, it's probably going to be harder to troubleshoot.

(4) is caused by RUBYOPT, which lets you set CLI options for all ruby processes. I guess many ruby developers never set it because many gem developers ignore warnings.

Regarding (5) we could also use FileUtils instead of system for file operations. Options!

FileUtils.rm_f 'log/*'
FileUtils.rm_rf 'tmp/cache'
...
FileUtils.mkdir('tmp') unless File.directory?('tmp')
FileUtils.mkdir_p 'tmp'
FileUtils.touch 'tmp/restart.txt'

I couldn't reproduce (6) - if I put a puts in config/puma.rb then I can see the message printed on the terminal after running bundle exec rails s - so it may be environmental in some sense.

leesharma commented 8 years ago

RE 6: I think the issue is that Puma starts before config/puma.rb is read, so the configuration options don't get set. If you change the default port in config/puma.rb to 4002 or something, does it register?

One monster issue may have been a mistake. Let me break the definite bugs/doc requests out into separate issues. It looks like they'll need a few pull requests to solve them.

leesharma commented 8 years ago

Okay, I opened separate issues for 1, 2, 3, 5, 6, and 8–they should be fleshed out enough that they're easy for someone to pick up/solve.

I believe that 7 is already implemented, and 4 is a ruby installation/options issue that shouldn't be addressed in our docs.

I'm going to tag this issue with wontfix and close it. Any objections? (@bjmllr)

bjmllr commented 8 years ago

You're right (about 6), I took "read" too literally in the original report.