Quby
====
[![Dependency Status](https://gemnasium.com/roqua/quby_engine.svg)](https://gemnasium.com/roqua/quby_engine)

## Usage

Quby is a Rails mountable engine, which means that you have to mount it
into your existing Rails application. First, you need to include Quby as a gem in your Gemfile:

```ruby
gem 'quby',         git: "git@github.com:roqua/quby_engine.git"
gem 'quby-mongoid'
```

Then, mount it at a path in your application. You can do this by putting a line
in config/routes.rb. Note that "/quby" could be anything you want.

```ruby
mount Quby::Engine => "/quby", :as => "quby_engine"
```

In config/initializers/quby.rb, you need to tell Quby where it can find its questionnaire definitions,
and where it can store its answers.

```ruby
Quby.questionnaire_repo      = Quby::Questionnaires::Repos::DiskRepo.new(Rails.root.join("db/questionnaires/definitions"))
Quby.answer_repo             = Quby::Answers::Repos::MongoidRepo.new
Quby::Settings.shared_secret = ENV["QUBY_SHARED_SECRET"]
```

If you use an OpenCPU server you can configure it through environment variables (or directly through OpenCPU.configure).

```ruby
ENV['OPENCPU_ENDPOINT_URL'] = 'http://opencpu.dev/ocpu'
ENV['OPENCPU_USERNAME']     = 'optional_basicauth_username'
ENV['OPENCPU_PASSWORD']     = 'optional_basicauth_password'
ENV['OPENCPU_TIMEOUT']      = '30' # request timeout in seconds.
```

To generate PDF files, the html_to_pdf docker container must be running and an environment variable with the address of this container should be configured.

```ruby
ENV['GOTENBERG_URL']      = 'http://127.0.0.1:8080'
```

## Docker

```bash
docker-compose build
docker-compose run test appraisal install # generate lockfiles in mounted local gemfiles. alernatively remove volume.
docker-compose run --rm test bundle exec appraisal rails60 rspec
docker-compose run --rm test bundle exec appraisal rails60 teaspoon -r spec/teaspoon_env.rb
```

## Testing

When testing with guard or teaspoon, choose the Rails version you want to use and set the teaspoon environment:

```ruby
bundle exec appraisal rails60 bundle # install dependencies for Rails 6.0
TEASPOON_RAILS_ENV=test bundle exec appraisal rails60 guard
```

## Contributing to Quby

* Check out the latest master to make sure the feature hasn't been implemented
  or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it
  and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to
  have your own version, or is otherwise necessary, that is fine, but please
  isolate to its own commit so I can cherry-pick around it.