Commit Graph

48 Commits

Author SHA1 Message Date
Benjamin Fleischer
6a7d864605 Fix CI on 0-10-stable (#2181)
* Loosen pry, pry-byebug depencency

```
Resolving dependencies...
byebug-9.1.0 requires ruby version >= 2.2.0, which is
incompatible with the current version, ruby 2.1.10p492
```

* Adjust nokogiri version constraint for CI

Update appveyor Ruby to 2.3 to work around:

```
Gem::InstallError: nokogiri requires Ruby version < 2.5, >= 2.2.

An error occurred while installing nokogiri (1.8.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.8.0'` succeeds before bundling.
```

and not 2.4 since:

https://ci.appveyor.com/project/bf4/active-model-serializers/build/1.0.1052-fix_ci/job/0q3itabsnvnxr83u

```
nokogiri-1.6.8.1-x86-mingw32 requires ruby version < 2.4, which is incompatible with the current version, ruby 2.4.1p111
```

* Include rails gem in Gemfile

(For Rails5)

In Rails5, checking for Rails::Railtie is better

* Rails5 test env requires Rails.application.class.name

rails-42d09f6b49da/railties/lib/rails/application.rb

```ruby
def secret_key_base
  if Rails.env.test? || Rails.env.development?
  Digest::MD5.hexdigest self.class.name
```

* Reformat exclude matrix to be easier to read

* Simplify jruby-travis config per rails/rails

* Organize .travis.yml per rails/rails

* Allow JRuby failure on Rails 5+; try rails-5 db adapter branch

https://github.com/jruby/activerecord-jdbc-adapter/issues/708

```
uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
```

see https://travis-ci.org/rails-api/active_model_serializers/jobs/277112008
2017-09-19 05:27:02 -04:00
Benjamin Fleischer
d5babdd060 Add Model#attributes helper; make test attributes explicit 2017-01-07 21:50:11 -06:00
L. Preston Sego III
d31d741f43 Make serializer lookup configurable (#1757) 2016-11-16 18:38:40 +01:00
Lucas Hosseini
f48fd2a327 Extract IncludeTree. (#1685) 2016-05-28 10:07:11 -04:00
Ben Woosley
8c18d18cdb Add default_includes configuration
This is useful to set application-wide default behavior - e.g. in
previous versions of AMS the default behavior was to serialize the
full object graph by default - equivalent to the '**' include tree.

Currently just the global setting, but I think this could also work
on a per-serializer basis, with more attention.
2016-05-26 00:16:14 +00:00
Benjamin Fleischer
1e10c20ac0 Consolidate and simplify caching code 2016-04-13 01:08:09 -05:00
Andreas Eger
af2b38c43b add require for active_support/json to fix #1656 2016-04-04 09:26:48 +02:00
Yohan Robert
21cb896802 Move SerializableResource to ActiveModelSerializers namespace
Ref. https://github.com/rails-api/active_model_serializers/pull/1310
2016-03-30 11:33:04 +02:00
Benjamin Fleischer
eda8ff1737 Move serializer caching from adapter 2016-03-13 19:57:59 -05:00
Benjamin Fleischer
b50195fde7 Add a deprecation DSL 2016-03-07 01:07:06 -06:00
Benjamin Fleischer
0ba944dabf RFC: Json Api Errors (WIP)
- ActiveModelSerializers::JsonPointer
- ActiveModel::Serializer::Adapter::JsonApi::Error
- ActiveModel::Serializer::Adapter::JsonApi::Error.attributes
- Fix rubocop config
2016-03-06 12:03:14 -06:00
Benjamin Fleischer
e35390623d Improve adapter test coverage per groyoh 2016-02-25 23:08:20 -06:00
bobba surendranath chowdary
252f9c4ae9 Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace
Changed the namespace in adapters and folder to active_model_serializers from active_model::serializer

Changed namespace of adapters in serializers and other folders

Moved adapter_for_test file to active_model_serializers folder and changed namespace of adapter inside the test file

Require ActiveSupport's string/inflections

We depend on string/inflections to define String#underscore.

Refactor JsonApi adapter to avoid redundant computations.

Update readme.md to link to v0.10.0.rc4

changed namespace of adapter folder testcases

Changed all namespaces of adapter under active_moder_serializers

Namespaced IncludeTree which is from serializer module, so needed to namespace it properly

Fixed wrong namsepacing of fieldset

namespace change in deserializer json_api

Fixed the namespace for collection serializer when used inside adapter, changed namespace for adapter to new namespace which I had forgotten previously

Modified logging test and adapter test cases to make the testcases pass

Changed the yardoc links,as old links are not taking to documentation pages,proper links for 0.10,0.9 and 0.8 in rubydoc

Rubocop errors are fixed by underscore naming unused variables

Moved the require of adapter to serializable resource

Remoeved adapter dependency inside serializer and added warning to Serializer::adapter method

Fixed frament cache test which is calling Serializer.adapter

Changed the name of lookup_adapter_from_config to configured_adapter

Changed the docs which will show the new namespace of adapters

Rubocop fix
2016-02-23 21:49:58 -06:00
Benjamin Fleischer
509221c1e0 Only call railtie when Rails is defined; assume controller loaded
Isolated Testing

- Rake test inspired by https://github.com/rails/rails/blob/v5.0.0.beta1/activejob/Rakefile
- Isolated unit inspired by
  - https://github.com/rails/rails/blob/v5.0.0.beta1/railties/test/isolation/abstract_unit.rb
  - https://github.com/rails/rails/blob/v5.0.0.beta1/activemodel/test/cases/railtie_test.rb

Misc

- Turns out `mattr_accessor(:logger) {
  ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }`
  was always nil until the Railtie was loaded, since mattr_accessor
  block defaults don't really work on modules, but on the classes that
  include them.
- Commented on important on Rails being required first for caching to
  work.
- In isolated tests, `active_support/core_ext/object/with_options` is required.
2016-01-15 01:54:07 -06:00
Benjamin Fleischer
fe015d17f2 Fix load-order issues 2016-01-15 01:54:07 -06:00
Benjamin Fleischer
0c2153ac5e Collect more Rails initialization code in the Railtie 2016-01-15 01:52:27 -06:00
Mauro George
c0b99c980c Bring back assert_serializer for controller testing
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]: https://github.com/rails-api/active_model_serializers/pull/596
[2]: 610aeb2e92

- 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
2016-01-13 20:54:22 -06:00
Lucas Hosseini
20a58d7f5c Add support for JSON API deserialization (experimental). 2016-01-13 05:48:06 +01:00
Mauro George
5fb7cceafb Remove ActiveModelSerializers.silence_warnings dead code
The ActiveModelSerializers.silence_warnings was used to avoid warnings on the
Ruby interpreter when define a private attr_acessor. This method is not used in
any part of the code and the recommend way to handle this case is to use
protected instead the silence_warnings [1].

This patch remove the method from the project, this way we avoid people using
this by mistake.

[1]: https://bugs.ruby-lang.org/issues/10967
2015-12-23 19:25:48 -02:00
Benjamin Fleischer
a9ce4fb766 Move caching initialization to Railtie
Also
- Add reference to config from ActiveModelSerializers.config
- correctly call super in FragmentCacheTest#setup
- rename test rails app from Foo to ActiveModelSerializers::RailsApplication
2015-11-25 21:56:01 -06:00
Benjamin Fleischer
d1c44c719d Update for review per maurogeorge feedback 2015-11-19 12:41:51 -06:00
Benjamin Fleischer
b36cc42f03 Separate out callbacks per ActiveJob pattern 2015-11-10 03:09:24 -06:00
Benjamin Fleischer
21bb306d38 Keep Logging in the ActiveModelSerializers namespace 2015-11-10 03:09:24 -06:00
L. Preston Sego III
17be650538 Revert "rename context to serialization_context and add url helpers" 2015-10-29 08:16:47 -04:00
tchak
d08ee5994f rename context to serialization_context and add url helpers 2015-10-22 22:28:54 +02:00
Benjamin Fleischer
124faaa829 Add PORO serializable base class: ActiveModelSerializers::Model 2015-10-14 21:33:02 -05:00
Benjamin Fleischer
dc44b136aa Remove unnecessarily silenced warnings 2015-10-07 05:54:57 -05:00
Benjamin Fleischer
8e8cfd45ff Fix bundle console no longer tries to load I18n::Rails 2015-10-01 23:08:34 -05:00
Benjamin Fleischer
c9ae868bfb Comment private accessor warnings 2015-09-17 14:32:22 -05:00
L. Preston Sego III
a34cb998c7 rubocop-fixes 2015-09-15 14:58:04 -04:00
L. Preston Sego III
1bff6173d1 Merge pull request #1089 from bf4/add_logger
Add ActiveModelSerializers.logger with default null device
2015-09-15 14:51:29 -04:00
Benjamin Fleischer
228cc1c92a Rubocop: Consistent spacing 2015-09-03 20:51:40 -05:00
Benjamin Fleischer
005f71e2c2 Add ActiveModelSerializers.logger with default null device 2015-08-30 23:26:31 -05:00
Benjamin Fleischer
e3d3d92201 Clarify AMS dependencies 2015-08-30 22:26:25 -05:00
Benjamin Fleischer
d315151e8a Fix warnings
JRuby-specific: fix 'warning: (...) interpreted as grouped expression'
2015-08-26 09:22:02 -05:00
elliotlarson
b99a6350cc only require railtie if Rails is present 2015-07-31 12:51:57 -07:00
Benjamin Fleischer
a66df3009a Encapsulate serialization in ActiveModel::SerializableResource
Usage: ActiveModel::SerializableResource.serialize(resource, options)
2015-07-23 11:05:23 -05:00
Santiago Pastorino
4752e6723a Make resource generator invoke serializer generator 2015-06-10 20:45:33 -03:00
lsylvester
2b0c5ee084 clear the cache between requests 2015-03-11 09:53:47 +11:00
Joao Moura
8a432ad2b3 Adding cache support to version 0.10.0
It's a new implementation of cache based on ActiveSupport::Cache.
The implementation abstracts the cache in Adapter class on a
private method called cached_object, this method is intended
to be used on Adapters inside serializable_hash method in order
to cache each instance of the object that will be returned by
the serializer.

Some of its features are:
- A different syntax. (no longer need the cache_key method).
- An options argument that have the same arguments of ActiveSupport::Cache::Store, plus a key option that will be the prefix of the object cache on a pattern "#{key}-#{object.id}".
- It cache the objects individually and not the whole Serializer return, re-using it in different requests (as a show and a index method for example.)
2015-02-02 14:53:34 -02:00
Aaron Renoir
39bee48ae6 implement sparse fieldsets http://jsonapi.org/format/#fetching-sparse-fieldsets 2014-10-26 13:04:14 -07:00
Tema Bolshakov
6496b08464 rename simple adapter to json 2014-08-29 11:01:39 +04:00
Tema Bolshakov
f00fe5595d * Rename NullAdapter to SimpleAdapter
* Introduce abstract Adapter class
* Organaze test structure to match convemtions
2014-08-27 08:21:08 +04:00
Tema Bolshakov
d39a3e0aec serializer_for Array 2014-08-26 12:50:47 +04:00
Steve Klabnik
970b542549 Implement basic rendering
Woo actioncontroller
2014-07-09 17:52:31 -04:00
Steve Klabnik
1ea83c8bee Implement a NullAdapter.
This adapter basically doesn't do anything, and just serializes
the attributes into plain old JSON.
2014-07-09 16:51:30 -04:00
Steve Klabnik
729a823868 Getting started: attributes.
Super super basic collection of attributes. Nothing fancy.
2014-07-09 16:16:39 -04:00
Steve Klabnik
c718915075 Generate a basic gem 2014-07-05 00:53:48 -04:00