Commit Graph

17 Commits

Author SHA1 Message Date
Krzysztof Rybka
873cf4add2 Add frozen_string_literal pragma to ruby files 2018-12-17 16:54:56 +01:00
Benjamin Fleischer
d5babdd060 Add Model#attributes helper; make test attributes explicit 2017-01-07 21:50:11 -06:00
Benjamin Fleischer
a5423dab20 Merge pull request #2017 from bf4/remove_warnings
Fix mt6 assert_nil warnings
2017-01-07 16:26:34 -06:00
Benjamin Fleischer
6370e5c72a Fix read_attribute_for_serialization not seeing parent serializer methods
Fixes #1653, #1658, #1660

Define "scope_name" on instance singleton, not all instances
2016-04-04 12:29:26 -05:00
Benjamin Fleischer
2edd39d2c2 Need to teardown the dynamically added method 2016-04-01 12:05:44 -05:00
Benjamin Fleischer
a065bc28d1 Fix serialization scope options 2016-04-01 05:43:46 -05:00
Benjamin Fleischer
1b2f5ec774 Differentiate exception behavior in Rails 4.0 vs. others
NoMethodError is current_user is nil, so nil.admin?
NameError is a superclass of NoMethodError (which Rails 4.0 won't allow)
  and means current_user might not be defined
2016-03-12 19:59:43 -06:00
Benjamin Fleischer
85658c0230 Add better serialization_scope tests; uncover bug 2016-03-12 19:59:43 -06:00
Benjamin Fleischer
6588dee22c Rails5 requires x_action 2015-11-25 22:06:20 -06:00
Benjamin Fleischer
dc44b136aa Remove unnecessarily silenced warnings 2015-10-07 05:54:57 -05:00
Benjamin Fleischer
af99c0d9e6 Ensure inheritance hooks run
I was seeing transient failures where adapters may not be registered.

e.g. https://travis-ci.org/rails-api/active_model_serializers/builds/77735382

Since we're using the Adapter, JsonApi, and Json classes
as namespaces, some of the conventions we use for modules don't apply.
Basically, we don't want to define the class anywhere besides itself.
Otherwise, the inherited hooks may not run, and some adapters may not
be registered.

For example:

If we have a class Api `class Api; end`
And Api is also used as a namespace for `Api::Product`
And the classes are defined in different files.

In one file:

```ruby
class Api
  autoload :Product
  def self.inherited(subclass)
    puts
    p [:inherited, subclass.name]
    puts
  end
end
```

And in another:

```ruby
class Api
  class Product < Api
    def sell_sell_sell!
      # TODO: sell
    end
  end
end
```

If we load the Api class file first, the inherited hook will be defined on the class
so that when we load the Api::Product class, we'll see the output:

```plain
[ :inherited, Api::Product]
```

However, if we load the Api::Product class first, since it defines the `Api` class
and then inherited from it, the Api file was never loaded, the hook never defined,
and thus never run.

By defining the class as `class Api::Product < Api` We ensure the the Api class
MUST be defined, and thus, the hook will be defined and run and so sunshine and unicorns.

Appendix:

The below would work, but triggers a circular reference warning.
It's also not recommended to mix require with autoload.

```ruby
require 'api'
class Api
  class Product < Api
    def sell_sell_sell!
      # TODO: sell
    end
  end
end
```

This failure scenario was introduced by removing the circular reference warnings in
https://github.com/rails-api/active_model_serializers/pull/1067

Style note:

To make diffs on the adapters smalleer and easier to read, I've maintained the same
identention that was in the original file.  I've decided to prefer ease of reading
the diff over style, esp. since we may later return to the preferred class declaration style.

 with '#' will be ignored, and an empty message aborts the commit.
2015-09-09 08:55:20 -05:00
Benjamin Fleischer
d315151e8a Fix warnings
JRuby-specific: fix 'warning: (...) interpreted as grouped expression'
2015-08-26 09:22:02 -05:00
Benedikt Deicke
ca41901fb8 Adjusts JsonApi adapter to serialize attributes in a nested attributes hash 2015-05-21 16:23:01 +02:00
Mateo Murphy
9480b567ef Refactor TestUser in SerializationScopeNameTest
Use the same base class we use for other test models
2015-03-23 13:44:30 -04:00
Mateo Murphy
33f3a88ba0 Implement included and id and type as per spec 2015-03-22 20:43:56 -04:00
Mateo Murphy
da86747a3e Use symbol for root in jsonapi, fix tests 2015-03-22 20:38:29 -04:00
Mateo Murphy
232e367560 Add serialization_scope_name_test 2015-02-12 17:48:43 -05:00