Testing
Testing a project using JR very similar to testing a traditional Rails application, as described in the Rails Guides.
Models
JR Resources
are backed by ActiveRecord
models. As such models should be fully tested. This includes
validations, scopes, associations, and public methods.
Resources
Resources present a bit of a challenge to test. Many features can not be tested in isolation and require testing in controller or request tests. However the following types of resource features are testable in resource specific tests
Attributes
Computed Attributes Testing
require 'test_helper' |
Delegated Attributes Testing
class ContactResourceTest < ActiveSupport::TestCase |
Fetchable Attributes Testing
Fetchable fields are computed per resource instance and can use the context to control the inclusion of fields.
class ContactResourceTest < ActiveSupport::TestCase |
Creatable, Updatable, Sortable Attributes Testing
Testing these attribute methods can be done on the resource class.
class ContactResourceTest < ActiveSupport::TestCase |
Relationships, Filters, Pagination, and Sorting
These resource concerns interact with the controllers and operation processors and are easier tested with controller or integration tests.
Routes
You can assert routes using the Rails RoutingAssertions. There isn’t a way to refute a route with the built in RoutingAssertions, however this can be
Routes can be refuted using an integration test.
Controllers
The entire request can be tested with controller tests. For example:
class ContactsControllerTest < ActionController::TestCase |