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.
There are users, surveys, _questionnaires, virtualdesktops and masterimages. The relations should be rather obvious.
There exists three roles:
- clients submit questionnaires,
- admins administrate everything, and
- managers can view the reports generated from the results.
The application is complete.
We use Postgres throughout development, testing and of course production.
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.
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.
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.
There is no business case for this application to be pretty. So, it is not!
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.
The coverage is not complete. Major aspects are covered.
We use cucumber with capybara and RSpec. The interaction with clients and managers is well covered. The interaction for administrators is not.
The major functionality in the models is tested with RSpec.
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.
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.
See the file lib/immutable_validator.rb
and the model questionnaire
.
There are of course also other custom validators.
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.
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.
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.