active_model_serializers
active_model_serializers copied to clipboard
Installing active_model_serializers causes unexpected http_status_code changes in specs
I'm super confused. I think I'm encountering some kind of bug. Could use some help. I had passing specs (passed dozens of times on local and CI server), but then I ONLY added the active_model_serializers, a UserSerializer class, and now my specs are failing. It's saying the response from my controllers (not using serializers) is :unauthorized which isn't even possible, b/c I'm calling render status: :created.
This is the commit with all changes b/w passing and failing specs: https://github.com/codeblooded/atc-api/commit/a75978a9d9a65a5e8b592685a53045e9fe6d1d91
Here's one of the failing specs (it should have nothing to do with active_model_serializers): https://github.com/codeblooded/atc-api/blob/weird-rspec-behavior/spec/controllers/traditions_controller_spec.rb#L23
Expected behavior vs actual behavior
Expected: To have serialized json rendered which do not affect my specs.
Actual Behavior: I installed 'active_model_serializers' and all unrelated tests fail. It's saying my unserialized controllers are rendering status :unauthorized which isn't even possible. I'm directly calling render status: :created.
Steps to reproduce
It's OSS, so I can share the actual failing/succeeding branches.
The specs started failing with only these changes: https://github.com/codeblooded/atc-api/commit/a75978a9d9a65a5e8b592685a53045e9fe6d1d9
This is one of the lines that is supposedly rendering 401: https://github.com/codeblooded/atc-api/blob/master/app/controllers/colors_controller.rb#L12
The specs succeeded again with the gem removed in this branch: https://github.com/codeblooded/atc-api/tree/rm-active-model-serializers
Environment
ActiveModelSerializers Version (commit ref if not on tag): 0.10.6
Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
OS Type & Version: macOS Version 10.12.5 (16F73)
Integrated application and version (e.g., Rails, Grape, etc): Rails 5.1.2
Bundle list:
Gems included by the bundle:
* actioncable (5.1.2)
* actionmailer (5.1.2)
* actionpack (5.1.2)
* actionview (5.1.2)
* active_model_serializers (0.10.6)
* activejob (5.1.2)
* activemodel (5.1.2)
* activerecord (5.1.2)
* activesupport (5.1.2)
* arel (8.0.0)
* aws-sdk (2.10.17)
* aws-sdk-core (2.10.17)
* aws-sdk-resources (2.10.17)
* aws-sigv4 (1.0.1)
* bcrypt (3.1.11)
* better_errors (2.1.1)
* binding_of_caller (0.7.2)
* brakeman (3.7.0)
* builder (3.2.3)
* bundler (1.15.3)
* byebug (9.0.6)
* case_transform (0.2)
* codacy-coverage (1.1.6)
* coderay (1.1.1)
* concurrent-ruby (1.0.5)
* connection_pool (2.2.1)
* database_cleaner (1.6.1)
* debug_inspector (0.0.3)
* diff-lcs (1.3)
* docile (1.1.5)
* domain_name (0.5.20170404)
* dotenv (2.2.1)
* dotenv-rails (2.2.1)
* erubi (1.6.1)
* erubis (2.7.0)
* factory_girl (4.8.0)
* factory_girl_rails (4.8.0)
* faraday (0.12.1)
* ffi (1.9.18)
* globalid (0.4.0)
* http-cookie (1.0.3)
* i18n (0.8.6)
* jmespath (1.3.1)
* json (2.1.0)
* jsonapi-renderer (0.1.3)
* listen (3.1.5)
* loofah (2.0.3)
* mail (2.6.6)
* method_source (0.8.2)
* mime-types (3.1)
* mime-types-data (3.2016.0521)
* mini_magick (4.8.0)
* mini_portile2 (2.2.0)
* minitest (5.10.2)
* multipart-post (2.0.0)
* mysql2 (0.4.8)
* netrc (0.11.0)
* nio4r (2.1.0)
* nokogiri (1.8.0)
* pry (0.10.4)
* pry-rails (0.3.6)
* puma (3.9.1)
* rack (2.0.3)
* rack-protection (2.0.0)
* rack-test (0.6.3)
* rack-timeout (0.4.2)
* rails (5.1.2)
* rails-dom-testing (2.0.3)
* rails-html-sanitizer (1.0.3)
* railties (5.1.2)
* rake (12.0.0)
* rb-fsevent (0.10.2)
* rb-inotify (0.9.10)
* redis (3.3.3)
* rest-client (2.0.2)
* rspec-core (3.6.0)
* rspec-expectations (3.6.0)
* rspec-mocks (3.6.0)
* rspec-rails (3.6.0)
* rspec-support (3.6.0)
* ruby_dep (1.5.0)
* sentry-raven (2.5.3)
* sidekiq (5.0.0)
* simplecov (0.14.1)
* simplecov-html (0.10.1)
* slop (3.6.0)
* spring (2.0.2)
* spring-watcher-listen (2.0.1)
* sprockets (3.7.1)
* sprockets-rails (3.2.0)
* thor (0.19.4)
* thread_safe (0.3.6)
* tzinfo (1.2.3)
* unf (0.1.4)
* unf_ext (0.0.7.4)
* websocket-driver (0.6.5)
* websocket-extensions (0.1.2)
That is indeed strange. I looked over the diffs and nothing stood out
@bf4 I know I feel crazy. Isn't that like the weirdest thing you've ever seen? Trying to find a workaround.
@codeblooded Try this:
Define in the problem controller and step through some of these breakpoints.
require 'pry-byebug'
def _render_with_renderer_json(object, options)
stack = caller
binding.pry
p [object, options. stack[0..5]]
super
end
def status=(value)
binding.pry
p value
super
end
def response_body=(value)
binding.pry
p value
super
end