mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Improvements from Rails plugin template
This commit is contained in:
parent
96c5516d21
commit
21b2eff2ab
1
Gemfile
1
Gemfile
@ -50,4 +50,5 @@ end
|
|||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rubocop', '~> 0.36', require: false
|
gem 'rubocop', '~> 0.36', require: false
|
||||||
|
gem 'yard', require: false
|
||||||
end
|
end
|
||||||
|
|||||||
37
Rakefile
37
Rakefile
@ -1,11 +1,34 @@
|
|||||||
|
begin
|
||||||
|
require 'bundler/setup'
|
||||||
|
rescue LoadError
|
||||||
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
||||||
|
end
|
||||||
begin
|
begin
|
||||||
require 'simplecov'
|
require 'simplecov'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'bundler'
|
Bundler::GemHelper.install_tasks
|
||||||
Bundler.setup
|
|
||||||
require 'bundler/gem_tasks'
|
require 'yard'
|
||||||
|
|
||||||
|
namespace :yard do
|
||||||
|
YARD::Rake::YardocTask.new(:doc) do |t|
|
||||||
|
t.stats_options = ['--list-undoc']
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'start a gem server'
|
||||||
|
task :server do
|
||||||
|
sh 'bundle exec yard server --gems'
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'use Graphviz to generate dot graph'
|
||||||
|
task :graph do
|
||||||
|
output_file = 'doc/erd.dot'
|
||||||
|
sh "bundle exec yard graph --protected --full --dependencies > #{output_file}"
|
||||||
|
puts 'open doc/erd.dot if you have graphviz installed'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'rubocop'
|
require 'rubocop'
|
||||||
@ -31,7 +54,7 @@ else
|
|||||||
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
|
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
|
||||||
desc 'Execute rubocop'
|
desc 'Execute rubocop'
|
||||||
RuboCop::RakeTask.new(:rubocop) do |task|
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
||||||
task.options = ['--display-cop-names', '--display-style-guide']
|
task.options = ['--rails', '--display-cop-names', '--display-style-guide']
|
||||||
task.fail_on_error = true
|
task.fail_on_error = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -39,10 +62,10 @@ end
|
|||||||
|
|
||||||
require 'rake/testtask'
|
require 'rake/testtask'
|
||||||
|
|
||||||
Rake::TestTask.new do |t|
|
Rake::TestTask.new(:test) do |t|
|
||||||
t.libs << 'test'
|
|
||||||
t.libs << 'lib'
|
t.libs << 'lib'
|
||||||
t.test_files = FileList['test/**/*_test.rb']
|
t.libs << 'test'
|
||||||
|
t.pattern = 'test/**/*_test.rb'
|
||||||
t.ruby_opts = ['-r./test/test_helper.rb']
|
t.ruby_opts = ['-r./test/test_helper.rb']
|
||||||
t.ruby_opts << ' -w' unless ENV['NO_WARN'] == 'true'
|
t.ruby_opts << ' -w' unless ENV['NO_WARN'] == 'true'
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
|||||||
@ -2,16 +2,15 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
# This class hold all information about serializer's association.
|
# This class hold all information about serializer's association.
|
||||||
#
|
#
|
||||||
# @param [Symbol] name
|
# @attr [Symbol] name
|
||||||
# @param [ActiveModel::Serializer] serializer
|
# @attr [ActiveModel::Serializer] serializer
|
||||||
# @param [Hash{Symbol => Object}] options
|
# @attr [Hash{Symbol => Object}] options
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
# Association.new(:comments, CommentSummarySerializer)
|
# Association.new(:comments, CommentSummarySerializer)
|
||||||
#
|
#
|
||||||
Association = Struct.new(:name, :serializer, :options, :links, :meta) do
|
Association = Struct.new(:name, :serializer, :options, :links, :meta) do
|
||||||
# @return [Symbol]
|
# @return [Symbol]
|
||||||
#
|
|
||||||
def key
|
def key
|
||||||
options.fetch(:key, name)
|
options.fetch(:key, name)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -74,7 +74,7 @@ module ActiveModel
|
|||||||
# Sets +::_cache+ object to <tt>ActionController::Base.cache_store</tt>
|
# Sets +::_cache+ object to <tt>ActionController::Base.cache_store</tt>
|
||||||
# when Rails.configuration.action_controller.perform_caching
|
# when Rails.configuration.action_controller.perform_caching
|
||||||
#
|
#
|
||||||
# @params options [Hash] with valid keys:
|
# @param options [Hash] with valid keys:
|
||||||
# cache_store : @see ::_cache
|
# cache_store : @see ::_cache
|
||||||
# key : @see ::_cache_key
|
# key : @see ::_cache_key
|
||||||
# only : @see ::_cache_only
|
# only : @see ::_cache_only
|
||||||
|
|||||||
@ -26,7 +26,7 @@ module ActiveModelSerializers
|
|||||||
ActiveModelSerializers::Adapter.lookup(adapter)
|
ActiveModelSerializers::Adapter.lookup(adapter)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return Hash<adapter_name, adapter_class>
|
# @return [Hash<adapter_name, adapter_class>]
|
||||||
def adapter_map
|
def adapter_map
|
||||||
ADAPTER_MAP
|
ADAPTER_MAP
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,8 +8,8 @@ module ActiveModelSerializers
|
|||||||
# Builds a JSON API Errors Object
|
# Builds a JSON API Errors Object
|
||||||
# {http://jsonapi.org/format/#errors JSON API Errors}
|
# {http://jsonapi.org/format/#errors JSON API Errors}
|
||||||
#
|
#
|
||||||
# @param [ActiveModel::Serializer::ErrorSerializer]
|
# @param [ActiveModel::Serializer::ErrorSerializer] error_serializer
|
||||||
# @return [Array<Symbol, Array<String>] i.e. attribute_name, [attribute_errors]
|
# @return [Array<Symbol, Array<String>>] i.e. attribute_name, [attribute_errors]
|
||||||
def self.resource_errors(error_serializer)
|
def self.resource_errors(error_serializer)
|
||||||
error_serializer.as_json.flat_map do |attribute_name, attribute_errors|
|
error_serializer.as_json.flat_map do |attribute_name, attribute_errors|
|
||||||
attribute_error_objects(attribute_name, attribute_errors)
|
attribute_error_objects(attribute_name, attribute_errors)
|
||||||
|
|||||||
@ -52,8 +52,9 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
# find all cache_key for the collection_serializer
|
# find all cache_key for the collection_serializer
|
||||||
# @param collection_serializer
|
# @param serializers [ActiveModel::Serializer::CollectionSerializer]
|
||||||
# @param include_tree
|
# @param adapter_instance [ActiveModelSerializers::Adapter::Base]
|
||||||
|
# @param include_tree [ActiveModel::Serializer::IncludeTree]
|
||||||
# @return [Array] all cache_key of collection_serializer
|
# @return [Array] all cache_key of collection_serializer
|
||||||
def self.object_cache_keys(serializers, adapter_instance, include_tree)
|
def self.object_cache_keys(serializers, adapter_instance, include_tree)
|
||||||
cache_keys = []
|
cache_keys = []
|
||||||
|
|||||||
@ -2,8 +2,8 @@ module ActiveModelSerializers
|
|||||||
module Test
|
module Test
|
||||||
module Schema
|
module Schema
|
||||||
# A Minitest Assertion that test the response is valid against a schema.
|
# A Minitest Assertion that test the response is valid against a schema.
|
||||||
# @params schema_path [String] a custom schema path
|
# @param schema_path [String] a custom schema path
|
||||||
# @params message [String] a custom error message
|
# @param message [String] a custom error message
|
||||||
# @return [Boolean] true when the response is valid
|
# @return [Boolean] true when the response is valid
|
||||||
# @return [Minitest::Assertion] when the response is invalid
|
# @return [Minitest::Assertion] when the response is invalid
|
||||||
# @example
|
# @example
|
||||||
|
|||||||
@ -32,3 +32,14 @@ ActionController::TestCase.class_eval do
|
|||||||
key.nil? ? assigns : assigns[key]
|
key.nil? ? assigns : assigns[key]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
||||||
|
# ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
|
||||||
|
#
|
||||||
|
# Load fixtures from the engine
|
||||||
|
# if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
||||||
|
# ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
||||||
|
# ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
||||||
|
# ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
|
||||||
|
# ActiveSupport::TestCase.fixtures :all
|
||||||
|
# end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# Configure Rails Environment
|
||||||
|
ENV['RAILS_ENV'] = 'test'
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -35,10 +37,15 @@ else
|
|||||||
$minitest_version = 5
|
$minitest_version = 5
|
||||||
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
|
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
|
||||||
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
|
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
|
||||||
|
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
||||||
|
# to be shown.
|
||||||
|
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'support/rails_app'
|
require 'support/rails_app'
|
||||||
|
|
||||||
|
# require "rails/test_help"
|
||||||
|
|
||||||
require 'support/serialization_testing'
|
require 'support/serialization_testing'
|
||||||
|
|
||||||
require 'support/rails5_shims'
|
require 'support/rails5_shims'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user