mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
910 lines
28 KiB
HTML
910 lines
28 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>
|
|
Module: ActiveModel::Serializer::Lint::Tests
|
|
|
|
— Documentation by YARD 0.8.7.6
|
|
|
|
</title>
|
|
|
|
<link rel="stylesheet" href="../../../css/style.css" type="text/css" charset="utf-8" />
|
|
|
|
<link rel="stylesheet" href="../../../css/common.css" type="text/css" charset="utf-8" />
|
|
|
|
<script type="text/javascript" charset="utf-8">
|
|
hasFrames = window.top.frames.main ? true : false;
|
|
relpath = '../../../';
|
|
framesUrl = "../../../frames.html#!ActiveModel/Serializer/Lint/Tests.html";
|
|
</script>
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
|
|
|
|
<script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
|
|
|
|
|
|
</head>
|
|
<body>
|
|
<div id="header">
|
|
<div id="menu">
|
|
|
|
<a href="../../../_index.html">Index (T)</a> »
|
|
<span class='title'><span class='object_link'><a href="../../../ActiveModel.html" title="ActiveModel (module)">ActiveModel</a></span></span> » <span class='title'><span class='object_link'><a href="../../Serializer.html" title="ActiveModel::Serializer (class)">Serializer</a></span></span> » <span class='title'><span class='object_link'><a href="../Lint.html" title="ActiveModel::Serializer::Lint (module)">Lint</a></span></span>
|
|
»
|
|
<span class="title">Tests</span>
|
|
|
|
|
|
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
|
</div>
|
|
|
|
<div id="search">
|
|
|
|
<a class="full_list_link" id="class_list_link"
|
|
href="../../../class_list.html">
|
|
Class List
|
|
</a>
|
|
|
|
<a class="full_list_link" id="method_list_link"
|
|
href="../../../method_list.html">
|
|
Method List
|
|
</a>
|
|
|
|
<a class="full_list_link" id="file_list_link"
|
|
href="../../../file_list.html">
|
|
File List
|
|
</a>
|
|
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>
|
|
|
|
<iframe id="search_frame"></iframe>
|
|
|
|
<div id="content"><h1>Module: ActiveModel::Serializer::Lint::Tests
|
|
|
|
|
|
|
|
</h1>
|
|
|
|
<dl class="box">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="r1 last">Defined in:</dt>
|
|
<dd class="r1 last">lib/active_model/serializer/lint.rb</dd>
|
|
|
|
</dl>
|
|
<div class="clear"></div>
|
|
|
|
<h2>Overview</h2><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<h2 id="label-Active+Model+Serializer+Lint+Tests">Active Model Serializer Lint Tests</h2>
|
|
|
|
<p>You can test whether an object is compliant with the Active Model
|
|
Serializers API by including
|
|
<code>ActiveModel::Serializer::Lint::Tests</code> in your TestCase. It will
|
|
include tests that tell you whether your object is fully compliant, or if
|
|
not, which aspects of the API are not implemented.</p>
|
|
|
|
<p>Note an object is not required to implement all APIs in order to work with
|
|
Active Model Serializers. This module only intends to provide guidance in
|
|
case you want all features out of the box.</p>
|
|
|
|
<p>These tests do not attempt to determine the semantic correctness of the
|
|
returned values. For instance, you could implement
|
|
<code>serializable_hash</code> to always return <tt>{}</tt>, and the tests would
|
|
pass. It is up to you to ensure that the values are semantically
|
|
meaningful.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2>
|
|
Instance Method Summary
|
|
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
|
</h2>
|
|
|
|
<ul class="summary">
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_active_model_errors-instance_method" title="#test_active_model_errors (instance method)">- (Object) <strong>test_active_model_errors</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_active_model_errors_human_attribute_name-instance_method" title="#test_active_model_errors_human_attribute_name (instance method)">- (Object) <strong>test_active_model_errors_human_attribute_name</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_active_model_errors_lookup_ancestors-instance_method" title="#test_active_model_errors_lookup_ancestors (instance method)">- (Object) <strong>test_active_model_errors_lookup_ancestors</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_as_json-instance_method" title="#test_as_json (instance method)">- (Object) <strong>test_as_json</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to as_json and if it takes zero or one
|
|
arguments.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_cache_key-instance_method" title="#test_cache_key (instance method)">- (Object) <strong>test_cache_key</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to cache_key Fails otherwise.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_id-instance_method" title="#test_id (instance method)">- (Object) <strong>test_id</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to id and if it takes no arguments.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_model_name-instance_method" title="#test_model_name (instance method)">- (Object) <strong>test_model_name</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object's class responds to model_name and if it is in an
|
|
instance of <code>ActiveModel::Name</code>.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_read_attribute_for_serialization-instance_method" title="#test_read_attribute_for_serialization (instance method)">- (Object) <strong>test_read_attribute_for_serialization</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to read_attribute_for_serialization and if it
|
|
requires one argument (the attribute to be read).</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_serializable_hash-instance_method" title="#test_serializable_hash (instance method)">- (Object) <strong>test_serializable_hash</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to serializable_hash and if it takes zero or
|
|
one arguments.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_to_json-instance_method" title="#test_to_json (instance method)">- (Object) <strong>test_to_json</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to to_json and if it takes zero or one
|
|
arguments.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#test_updated_at-instance_method" title="#test_updated_at (instance method)">- (Object) <strong>test_updated_at</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Passes if the object responds to updated_at and if it takes no arguments.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<div id="instance_method_details" class="method_details_list">
|
|
<h2>Instance Method Details</h2>
|
|
|
|
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="test_active_model_errors-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_active_model_errors</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
122
|
|
123
|
|
124</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 122</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_active_model_errors'>test_active_model_errors</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:errors</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_active_model_errors_human_attribute_name-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_active_model_errors_human_attribute_name</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
126
|
|
127
|
|
128
|
|
129</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 126</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_active_model_errors_human_attribute_name'>test_active_model_errors_human_attribute_name</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='comma'>,</span> <span class='symbol'>:human_attribute_name</span>
|
|
<span class='id identifier rubyid_assert_equal'>assert_equal</span><span class='lparen'>(</span><span class='op'>-</span><span class='int'>2</span><span class='comma'>,</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_method'>method</span><span class='lparen'>(</span><span class='symbol'>:human_attribute_name</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_active_model_errors_lookup_ancestors-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_active_model_errors_lookup_ancestors</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
131
|
|
132
|
|
133
|
|
134</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 131</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_active_model_errors_lookup_ancestors'>test_active_model_errors_lookup_ancestors</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='comma'>,</span> <span class='symbol'>:lookup_ancestors</span>
|
|
<span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_method'>method</span><span class='lparen'>(</span><span class='symbol'>:lookup_ancestors</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_as_json-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_as_json</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to <code>as_json</code> and if it takes zero
|
|
or one arguments. Fails otherwise.</p>
|
|
|
|
<p><code>as_json</code> returns a hash representation of a serialized object.
|
|
It may delegate to <code>serializable_hash</code> Typically, it is
|
|
implemented either by including ActiveModel::Serialization which includes
|
|
ActiveModel::Serializers::JSON. or by the JSON gem when required.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
54
|
|
55
|
|
56
|
|
57
|
|
58</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 54</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_as_json'>test_as_json</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:as_json</span>
|
|
<span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_as_json'>as_json</span>
|
|
<span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_as_json'>as_json</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_cache_key-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_cache_key</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to <code>cache_key</code> Fails otherwise.</p>
|
|
|
|
<p><code>cache_key</code> returns a (self-expiring) unique key for the object,
|
|
and is part of the (self-expiring) cache_key, which is used by the adapter.
|
|
It is not required unless caching is enabled.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
79
|
|
80
|
|
81
|
|
82
|
|
83</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 79</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_cache_key'>test_cache_key</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:cache_key</span>
|
|
<span class='id identifier rubyid_actual_arity'>actual_arity</span> <span class='op'>=</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_method'>method</span><span class='lparen'>(</span><span class='symbol'>:cache_key</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span>
|
|
<span class='id identifier rubyid_assert_includes'>assert_includes</span> <span class='lbracket'>[</span><span class='op'>-</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>0</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_actual_arity'>actual_arity</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>expected </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_arity'>actual_arity</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'> to be 0 or -1</span><span class='tstring_end'>"</span></span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_id-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_id</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to <code>id</code> and if it takes no
|
|
arguments. Fails otherwise.</p>
|
|
|
|
<p><code>id</code> returns a unique identifier for the object. It is not
|
|
required unless caching is enabled.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
104
|
|
105
|
|
106
|
|
107</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 104</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_id'>test_id</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:id</span>
|
|
<span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_method'>method</span><span class='lparen'>(</span><span class='symbol'>:id</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_model_name-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_model_name</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object's class responds to <code>model_name</code> and if
|
|
it is in an instance of <code>ActiveModel::Name</code>. Fails otherwise.</p>
|
|
|
|
<p><code>model_name</code> returns an ActiveModel::Name instance. It is used
|
|
by the serializer to identify the object's type. It is not required
|
|
unless caching is enabled.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
116
|
|
117
|
|
118
|
|
119
|
|
120</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 116</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_model_name'>test_model_name</span>
|
|
<span class='id identifier rubyid_resource_class'>resource_class</span> <span class='op'>=</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource_class'>resource_class</span><span class='comma'>,</span> <span class='symbol'>:model_name</span>
|
|
<span class='id identifier rubyid_assert_instance_of'>assert_instance_of</span> <span class='id identifier rubyid_resource_class'>resource_class</span><span class='period'>.</span><span class='id identifier rubyid_model_name'>model_name</span><span class='comma'>,</span> <span class='const'>ActiveModel</span><span class='op'>::</span><span class='const'>Name</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_read_attribute_for_serialization-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_read_attribute_for_serialization</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to
|
|
<code>read_attribute_for_serialization</code> and if it requires one
|
|
argument (the attribute to be read). Fails otherwise.</p>
|
|
|
|
<p><code>read_attribute_for_serialization</code> gets the attribute value for
|
|
serialization Typically, it is implemented by including
|
|
ActiveModel::Serialization.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
36
|
|
37
|
|
38
|
|
39
|
|
40
|
|
41
|
|
42
|
|
43</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 36</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_read_attribute_for_serialization'>test_read_attribute_for_serialization</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:read_attribute_for_serialization</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>The resource should respond to read_attribute_for_serialization</span><span class='tstring_end'>'</span></span>
|
|
<span class='id identifier rubyid_actual_arity'>actual_arity</span> <span class='op'>=</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_method'>method</span><span class='lparen'>(</span><span class='symbol'>:read_attribute_for_serialization</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span>
|
|
<span class='comment'># using absolute value since arity is:
|
|
</span> <span class='comment'># 1 for def read_attribute_for_serialization(name); end
|
|
</span> <span class='comment'># -1 for alias :read_attribute_for_serialization :send
|
|
</span> <span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='int'>1</span><span class='comma'>,</span> <span class='id identifier rubyid_actual_arity'>actual_arity</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>expected </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_arity'>actual_arity</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_content'>.abs to be 1 or -1</span><span class='tstring_end'>"</span></span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_serializable_hash-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_serializable_hash</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to <code>serializable_hash</code> and if it
|
|
takes zero or one arguments. Fails otherwise.</p>
|
|
|
|
<p><code>serializable_hash</code> returns a hash representation of a
|
|
object's attributes. Typically, it is implemented by including
|
|
ActiveModel::Serialization.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
24
|
|
25
|
|
26
|
|
27
|
|
28</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 24</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_serializable_hash'>test_serializable_hash</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:serializable_hash</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>The resource should respond to serializable_hash</span><span class='tstring_end'>'</span></span>
|
|
<span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_serializable_hash'>serializable_hash</span>
|
|
<span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_serializable_hash'>serializable_hash</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_to_json-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_to_json</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to <code>to_json</code> and if it takes zero
|
|
or one arguments. Fails otherwise.</p>
|
|
|
|
<p><code>to_json</code> returns a string representation (JSON) of a serialized
|
|
object. It may be called on the result of <code>as_json</code>. Typically,
|
|
it is implemented on all objects when the JSON gem is required.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
67
|
|
68
|
|
69
|
|
70
|
|
71</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 67</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_to_json'>test_to_json</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:to_json</span>
|
|
<span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
|
|
<span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='lparen'>(</span><span class='kw'>nil</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="test_updated_at-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>test_updated_at</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Passes if the object responds to <code>updated_at</code> and if it takes no
|
|
arguments. Fails otherwise.</p>
|
|
|
|
<p><code>updated_at</code> returns a Time object or iso8601 string and is part
|
|
of the (self-expiring) cache_key, which is used by the adapter. It is not
|
|
required unless caching is enabled.</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
92
|
|
93
|
|
94
|
|
95
|
|
96</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/active_model/serializer/lint.rb', line 92</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_test_updated_at'>test_updated_at</span>
|
|
<span class='id identifier rubyid_assert_respond_to'>assert_respond_to</span> <span class='id identifier rubyid_resource'>resource</span><span class='comma'>,</span> <span class='symbol'>:updated_at</span>
|
|
<span class='id identifier rubyid_actual_arity'>actual_arity</span> <span class='op'>=</span> <span class='id identifier rubyid_resource'>resource</span><span class='period'>.</span><span class='id identifier rubyid_method'>method</span><span class='lparen'>(</span><span class='symbol'>:updated_at</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span>
|
|
<span class='id identifier rubyid_assert_equal'>assert_equal</span> <span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_actual_arity'>actual_arity</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="footer">
|
|
Generated on Wed Jun 15 10:31:27 2016 by
|
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
0.8.7.6 (ruby-2.2.4).
|
|
</div>
|
|
|
|
</body>
|
|
</html> |