Skip to content

Test::Unit assert_serializer implemented #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2014

Conversation

bolshakov
Copy link

Rails uses ActiveSupport::Notifications to collect information about rendered views. So its possible to implement assert_templete method to test that template specified have been rendered.

In order to test integration between controller and serializers we implemented same feature for ActiveModel::Serializer.

We wrapped as_json method with ActiveSupport::Notifications.instrumentand collect information about rendered serializers for each test case.

assert_serializer method uses this information to make assertions.

      # assert that the "PostSerializer" serializer was rendered
      assert_serializer "PostSerializer"

      # assert that the "PostSerializer" serializer was rendered
      assert_serializer :post_serializer

      # assert that the rendered serializer starts with "Post"
      assert_serializer %r{\APost.+\Z}

      # assert that no serializer was rendered
      assert_serializer nil

In case of failure it generate useful message:

assert_serializer 'PostSerializer'
# Raises exception with message 'expecting <"PostSerializer"> but rendering with <["ProfileSerializer"]'>

Tema Bolshakov and Dmitry Myaskovskiy and others added 5 commits August 18, 2014 18:04
steveklabnik added a commit that referenced this pull request Aug 22, 2014
Test::Unit assert_serializer implemented
@steveklabnik steveklabnik merged commit 92f1db0 into rails-api:master Aug 22, 2014
@steveklabnik
Copy link
Contributor

Thank you!

bf4 pushed a commit to bf4/active_model_serializers that referenced this pull request Dec 22, 2015
The `assert_serializer` test helper was added in 0.9.0.apha1[1],
and was not included in 0.10.

This patch brings back the `assert_serializer` test helper. This is the last
revision[2] that has the helper. The original helper was used as base.

[1]: rails-api#596
[2]: https://github.com/rails-api/active_model_serializers/tree/610aeb2e9297fa31b8d561f0be9a4597f0258f8c

- Create the AssertSerializer

- Use the Test namespace

- Make the tests pass on the Rails master
  - Rails 5 does not include `assert_template` but we need this on the tests of
the helper.
  - This add the `rails-controller-testing` to keep support on `assert_template`.

- Only load test helpers in the test environment
bf4 pushed a commit to bf4/active_model_serializers that referenced this pull request Dec 23, 2015
The `assert_serializer` test helper was added in 0.9.0.apha1[1],
and was not included in 0.10.

This patch brings back the `assert_serializer` test helper. This is the last
revision[2] that has the helper. The original helper was used as base.

[1]: rails-api#596
[2]: https://github.com/rails-api/active_model_serializers/tree/610aeb2e9297fa31b8d561f0be9a4597f0258f8c

- Create the AssertSerializer

- Use the Test namespace

- Make the tests pass on the Rails master
  - Rails 5 does not include `assert_template` but we need this on the tests of
the helper.
  - This add the `rails-controller-testing` to keep support on `assert_template`.

- Only load test helpers in the test environment
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Dec 23, 2015
In 0.9 (which this implementation is based on), the instrumentation
was `!serialize.active_model_serializers`.

rails-api#596

The '!' in the event name meant the event wasn't meant for
production.

https://github.com/rails/rails/pull/10446/files#r4075679

Since we intend the event for production and have a log subscriber,
if we unsubscribe from `render.active_model_serializers`, we'll
break other tests that are relying on that event being subscribed.
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Dec 23, 2015
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Dec 23, 2015
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 pushed a commit to bf4/active_model_serializers that referenced this pull request Jan 4, 2016
The `assert_serializer` test helper was added in 0.9.0.apha1[1],
and was not included in 0.10.

This patch brings back the `assert_serializer` test helper. This is the last
revision[2] that has the helper. The original helper was used as base.

[1]: rails-api#596
[2]: https://github.com/rails-api/active_model_serializers/tree/610aeb2e9297fa31b8d561f0be9a4597f0258f8c

- Create the AssertSerializer

- Use the Test namespace

- Make the tests pass on the Rails master
  - Rails 5 does not include `assert_template` but we need this on the tests of
the helper.
  - This add the `rails-controller-testing` to keep support on `assert_template`.

- Only load test helpers in the test environment
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 4, 2016
In 0.9 (which this implementation is based on), the instrumentation
was `!serialize.active_model_serializers`.

rails-api#596

The '!' in the event name meant the event wasn't meant for
production.

https://github.com/rails/rails/pull/10446/files#r4075679

Since we intend the event for production and have a log subscriber,
if we unsubscribe from `render.active_model_serializers`, we'll
break other tests that are relying on that event being subscribed.
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 4, 2016
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 4, 2016
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 pushed a commit to bf4/active_model_serializers that referenced this pull request Jan 13, 2016
The `assert_serializer` test helper was added in 0.9.0.apha1[1],
and was not included in 0.10.

This patch brings back the `assert_serializer` test helper. This is the last
revision[2] that has the helper. The original helper was used as base.

[1]: rails-api#596
[2]: https://github.com/rails-api/active_model_serializers/tree/610aeb2e9297fa31b8d561f0be9a4597f0258f8c

- Create the AssertSerializer

- Use the Test namespace

- Make the tests pass on the Rails master
  - Rails 5 does not include `assert_template` but we need this on the tests of
the helper.
  - This add the `rails-controller-testing` to keep support on `assert_template`.

- Only load test helpers in the test environment
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 13, 2016
In 0.9 (which this implementation is based on), the instrumentation
was `!serialize.active_model_serializers`.

rails-api#596

The '!' in the event name meant the event wasn't meant for
production.

https://github.com/rails/rails/pull/10446/files#r4075679

Since we intend the event for production and have a log subscriber,
if we unsubscribe from `render.active_model_serializers`, we'll
break other tests that are relying on that event being subscribed.
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 13, 2016
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 pushed a commit to bf4/active_model_serializers that referenced this pull request Jan 14, 2016
The `assert_serializer` test helper was added in 0.9.0.apha1[1],
and was not included in 0.10.

This patch brings back the `assert_serializer` test helper. This is the last
revision[2] that has the helper. The original helper was used as base.

[1]: rails-api#596
[2]: https://github.com/rails-api/active_model_serializers/tree/610aeb2e9297fa31b8d561f0be9a4597f0258f8c

- Create the AssertSerializer

- Use the Test namespace

- Make the tests pass on the Rails master
  - Rails 5 does not include `assert_template` but we need this on the tests of
the helper.
  - This add the `rails-controller-testing` to keep support on `assert_template`.

- Only load test helpers in the test environment
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 14, 2016
In 0.9 (which this implementation is based on), the instrumentation
was `!serialize.active_model_serializers`.

rails-api#596

The '!' in the event name meant the event wasn't meant for
production.

https://github.com/rails/rails/pull/10446/files#r4075679

Since we intend the event for production and have a log subscriber,
if we unsubscribe from `render.active_model_serializers`, we'll
break other tests that are relying on that event being subscribed.
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 14, 2016
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 14, 2016
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jan 14, 2016
This commit revises 0ce4ad3
`Remove unused/unusable unsubscribe since we don't want to unsubscribe`

Looking at Rails implementation of assert_template
which was likely the inspiration for assert_serializer:

https://github.com/rails/rails-controller-testing/blob/f756b33c138c593eabe37f6085f8bac477b99bfe/lib/rails/controller/testing/template_assertions.rb

Ref:

- rails-api#596
- rails-api#620
- rails-api#616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants