Skip to content

Commit 53c7e6e

Browse files
committed
Merge pull request #1649 from bf4/rails_template_update
[DOC] Improvements from Rails plugin template
2 parents 96c5516 + 21b2eff commit 53c7e6e

File tree

11 files changed

+61
-19
lines changed

11 files changed

+61
-19
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ end
5050

5151
group :development, :test do
5252
gem 'rubocop', '~> 0.36', require: false
53+
gem 'yard', require: false
5354
end

LICENSE.txt renamed to MIT-LICENSE

File renamed without changes.

Rakefile

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
begin
2+
require 'bundler/setup'
3+
rescue LoadError
4+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5+
end
16
begin
27
require 'simplecov'
38
rescue LoadError
49
end
510

6-
require 'bundler'
7-
Bundler.setup
8-
require 'bundler/gem_tasks'
11+
Bundler::GemHelper.install_tasks
12+
13+
require 'yard'
14+
15+
namespace :yard do
16+
YARD::Rake::YardocTask.new(:doc) do |t|
17+
t.stats_options = ['--list-undoc']
18+
end
19+
20+
desc 'start a gem server'
21+
task :server do
22+
sh 'bundle exec yard server --gems'
23+
end
24+
25+
desc 'use Graphviz to generate dot graph'
26+
task :graph do
27+
output_file = 'doc/erd.dot'
28+
sh "bundle exec yard graph --protected --full --dependencies > #{output_file}"
29+
puts 'open doc/erd.dot if you have graphviz installed'
30+
end
31+
end
932

1033
begin
1134
require 'rubocop'
@@ -31,18 +54,18 @@ else
3154
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
3255
desc 'Execute rubocop'
3356
RuboCop::RakeTask.new(:rubocop) do |task|
34-
task.options = ['--display-cop-names', '--display-style-guide']
57+
task.options = ['--rails', '--display-cop-names', '--display-style-guide']
3558
task.fail_on_error = true
3659
end
3760
end
3861
end
3962

4063
require 'rake/testtask'
4164

42-
Rake::TestTask.new do |t|
43-
t.libs << 'test'
65+
Rake::TestTask.new(:test) do |t|
4466
t.libs << 'lib'
45-
t.test_files = FileList['test/**/*_test.rb']
67+
t.libs << 'test'
68+
t.pattern = 'test/**/*_test.rb'
4669
t.ruby_opts = ['-r./test/test_helper.rb']
4770
t.ruby_opts << ' -w' unless ENV['NO_WARN'] == 'true'
4871
t.verbose = true

lib/active_model/serializer/association.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ module ActiveModel
22
class Serializer
33
# This class hold all information about serializer's association.
44
#
5-
# @param [Symbol] name
6-
# @param [ActiveModel::Serializer] serializer
7-
# @param [Hash{Symbol => Object}] options
5+
# @attr [Symbol] name
6+
# @attr [ActiveModel::Serializer] serializer
7+
# @attr [Hash{Symbol => Object}] options
88
#
99
# @example
1010
# Association.new(:comments, CommentSummarySerializer)
1111
#
1212
Association = Struct.new(:name, :serializer, :options, :links, :meta) do
1313
# @return [Symbol]
14-
#
1514
def key
1615
options.fetch(:key, name)
1716
end

lib/active_model/serializer/caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def fragmented(serializer)
7474
# Sets +::_cache+ object to <tt>ActionController::Base.cache_store</tt>
7575
# when Rails.configuration.action_controller.perform_caching
7676
#
77-
# @params options [Hash] with valid keys:
77+
# @param options [Hash] with valid keys:
7878
# cache_store : @see ::_cache
7979
# key : @see ::_cache_key
8080
# only : @see ::_cache_only

lib/active_model_serializers/adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def adapter_class(adapter)
2626
ActiveModelSerializers::Adapter.lookup(adapter)
2727
end
2828

29-
# @return Hash<adapter_name, adapter_class>
29+
# @return [Hash<adapter_name, adapter_class>]
3030
def adapter_map
3131
ADAPTER_MAP
3232
end

lib/active_model_serializers/adapter/json_api/error.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module Error
88
# Builds a JSON API Errors Object
99
# {http://jsonapi.org/format/#errors JSON API Errors}
1010
#
11-
# @param [ActiveModel::Serializer::ErrorSerializer]
12-
# @return [Array<Symbol, Array<String>] i.e. attribute_name, [attribute_errors]
11+
# @param [ActiveModel::Serializer::ErrorSerializer] error_serializer
12+
# @return [Array<Symbol, Array<String>>] i.e. attribute_name, [attribute_errors]
1313
def self.resource_errors(error_serializer)
1414
error_serializer.as_json.flat_map do |attribute_name, attribute_errors|
1515
attribute_error_objects(attribute_name, attribute_errors)

lib/active_model_serializers/cached_serializer.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def object_cache_key
5252
end
5353

5454
# find all cache_key for the collection_serializer
55-
# @param collection_serializer
56-
# @param include_tree
55+
# @param serializers [ActiveModel::Serializer::CollectionSerializer]
56+
# @param adapter_instance [ActiveModelSerializers::Adapter::Base]
57+
# @param include_tree [ActiveModel::Serializer::IncludeTree]
5758
# @return [Array] all cache_key of collection_serializer
5859
def self.object_cache_keys(serializers, adapter_instance, include_tree)
5960
cache_keys = []

lib/active_model_serializers/test/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module ActiveModelSerializers
22
module Test
33
module Schema
44
# A Minitest Assertion that test the response is valid against a schema.
5-
# @params schema_path [String] a custom schema path
6-
# @params message [String] a custom error message
5+
# @param schema_path [String] a custom schema path
6+
# @param message [String] a custom error message
77
# @return [Boolean] true when the response is valid
88
# @return [Minitest::Assertion] when the response is invalid
99
# @example

test/support/rails_app.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@ def assigns(key = nil)
3232
key.nil? ? assigns : assigns[key]
3333
end
3434
end
35+
36+
# ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
37+
# ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
38+
#
39+
# Load fixtures from the engine
40+
# if ActiveSupport::TestCase.respond_to?(:fixture_path=)
41+
# ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
42+
# ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
43+
# ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
44+
# ActiveSupport::TestCase.fixtures :all
45+
# end

test/test_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Configure Rails Environment
2+
ENV['RAILS_ENV'] = 'test'
13
require 'bundler/setup'
24

35
begin
@@ -35,10 +37,15 @@
3537
$minitest_version = 5
3638
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
3739
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
40+
# Filter out Minitest backtrace while allowing backtrace from other libraries
41+
# to be shown.
42+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
3843
end
3944

4045
require 'support/rails_app'
4146

47+
# require "rails/test_help"
48+
4249
require 'support/serialization_testing'
4350

4451
require 'support/rails5_shims'

0 commit comments

Comments
 (0)