Skip to content

DrTom/Surveys

Repository files navigation

What it is

A online survey system for the particular use case of assessing virtual workplaces. There are a few particular requirements that make "out of the box" solutions not applicable.

It is programmed as a ruby on rails 3 webapplication.

Entities

There are users, surveys, _questionnaires, virtualdesktops and masterimages. The relations should be rather obvious.

Roles

There exists three roles:

  1. clients submit questionnaires,
  2. admins administrate everything, and
  3. managers can view the reports generated from the results.

Status

The application is complete.

Remarks

Database

We use Postgres throughout development, testing and of course production.

Views

There exists models which are purely based on SQL-views. E.g. the computation of the reports is done within the database (by simple SQL and using existing functions) and modeled as a sql-view.

This will run as it is on Postgres only. It could be made to run on MySQL with a little bit of more effort. I don't know how difficult/easy it would be to adopt it for sqlite.

The really tricky part is to set up raw sql-schema definition instead of a ruby-schema file, the latter doesn't preserve e.g. views.

Views and Subqueries

The model notifyuser is based on a view which iself is defined by so called subqueries. I wrote a post about this and you might want to consult it for details.

The summary is that subqueries make the code very concise yet clear and readable. Summaries are available in ProstgreSQL and Oracle only.

Users, log-in and sessions

In production the whole application is behind apache httpd authentication which itself talks to an external directory service.

For tests, there is a simple login controller and a corresponding view. I would suggest to use devise if the application must/should provide self-contained user management.

Design

There is no business case for this application to be pretty. So, it is not!

Deployment

We deploy with Git and Passenger and run it ourself with RVM and Postgres on Linux (Debian derivative). I'd rather recommend to use Heroku if one is allowed to do so.

Mentionable features and used techniques

About test

The coverage is not complete. Major aspects are covered.

Testing BDD

We use cucumber with capybara and RSpec. The interaction with clients and managers is well covered. The interaction for administrators is not.

Testing models

The major functionality in the models is tested with RSpec.

Testing views and controllers

The coverage is by far not complete. The views are largely covered by Cucumber tests. Routes and controllers are only tested if there is diversion from the default rails convention.

Extending routes of resources with custom actions

The surveys resource has the custom actions open and close which are defined in config/routes.rb:

resources :surveys do
  post :open, :on => :member
  post :close, :on => :member
end

See the surveys_controller and the index view of the same entity for further usage.

Custom validation by extending ActiveModel::EachValidator

See the file lib/immutable_validator.rb and the model questionnaire. There are of course also other custom validators.

Transactional insurance of model consistency

There must only be at most one survey having the status set to open at a time. This is ensured with an after_save-hook in the corresponding model.

Creating test data with a factory

factory girl is used to create data for testing. Have a look into spec/fatories.rb for examples.

Mock objects turned out to be a pain to work with once there are intertwined relation between entities (and for other reasons, too). Fixtures ain't much better.

Faker

An other helpful gem for testing is faker. It conveniently generates random data in various formats. However, I just use rand() for simple cases, too.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published