awesome_print 1.9.2 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/Appraisals +2 -33
  4. data/CHANGELOG.md +6 -15
  5. data/CONTRIBUTING.md +0 -1
  6. data/README.md +7 -49
  7. data/lib/ap.rb +1 -5
  8. data/lib/awesome_print.rb +7 -29
  9. data/lib/awesome_print/colorize.rb +2 -0
  10. data/lib/awesome_print/core_ext/active_support.rb +7 -0
  11. data/lib/awesome_print/core_ext/awesome_method_array.rb +0 -6
  12. data/lib/awesome_print/core_ext/class.rb +0 -5
  13. data/lib/awesome_print/core_ext/kernel.rb +0 -5
  14. data/lib/awesome_print/core_ext/logger.rb +0 -5
  15. data/lib/awesome_print/core_ext/object.rb +0 -5
  16. data/lib/awesome_print/core_ext/string.rb +0 -5
  17. data/lib/awesome_print/custom_defaults.rb +1 -1
  18. data/lib/awesome_print/formatter.rb +38 -106
  19. data/lib/awesome_print/formatters/array_formatter.rb +11 -8
  20. data/lib/awesome_print/formatters/base_formatter.rb +20 -53
  21. data/lib/awesome_print/formatters/bigdecimal_formatter.rb +20 -0
  22. data/lib/awesome_print/formatters/class_formatter.rb +5 -6
  23. data/lib/awesome_print/formatters/dir_formatter.rb +4 -6
  24. data/lib/awesome_print/formatters/ext/active_model_error_formatter.rb +44 -0
  25. data/lib/awesome_print/formatters/ext/active_record_attributeset_formatter.rb +27 -0
  26. data/lib/awesome_print/formatters/ext/active_record_class_formatter.rb +43 -0
  27. data/lib/awesome_print/formatters/ext/active_record_instance_formatter.rb +48 -0
  28. data/lib/awesome_print/formatters/ext/active_record_relation_formatter.rb +19 -0
  29. data/lib/awesome_print/formatters/ext/bson_objectid_formatter.rb +20 -0
  30. data/lib/awesome_print/formatters/ext/hash_with_indifferent_access_formatter.rb +20 -0
  31. data/lib/awesome_print/formatters/ext/mongoid_document_formatter.rb +59 -0
  32. data/lib/awesome_print/formatters/ext/nokogiri_document_formatter.rb +30 -0
  33. data/lib/awesome_print/formatters/ext/nokogiri_node_formatter.rb +29 -0
  34. data/lib/awesome_print/formatters/ext/nokogiri_nodeset_formatter.rb +32 -0
  35. data/lib/awesome_print/formatters/ext/sequel_dataset_formatter.rb +20 -0
  36. data/lib/awesome_print/formatters/ext/sequel_model_class_formatter.rb +25 -0
  37. data/lib/awesome_print/formatters/ext/sequel_model_formatter.rb +26 -0
  38. data/lib/awesome_print/formatters/ext/time_with_zone_formatter.rb +24 -0
  39. data/lib/awesome_print/formatters/fallback_formatter.rb +55 -0
  40. data/lib/awesome_print/formatters/false_class_formatter.rb +15 -0
  41. data/lib/awesome_print/formatters/file_formatter.rb +4 -6
  42. data/lib/awesome_print/formatters/hash_formatter.rb +12 -7
  43. data/lib/awesome_print/formatters/integer_formatter.rb +11 -0
  44. data/lib/awesome_print/formatters/method_formatter.rb +8 -6
  45. data/lib/awesome_print/formatters/module_formatter.rb +18 -0
  46. data/lib/awesome_print/formatters/nil_class_formatter.rb +19 -0
  47. data/lib/awesome_print/formatters/object_formatter.rb +19 -9
  48. data/lib/awesome_print/formatters/open_struct.rb +19 -0
  49. data/lib/awesome_print/formatters/range_formatter.rb +11 -0
  50. data/lib/awesome_print/formatters/rational_formatter.rb +15 -0
  51. data/lib/awesome_print/formatters/set_formatter.rb +19 -0
  52. data/lib/awesome_print/formatters/simple_formatter.rb +10 -8
  53. data/lib/awesome_print/formatters/string_formatter.rb +14 -0
  54. data/lib/awesome_print/formatters/struct_formatter.rb +8 -6
  55. data/lib/awesome_print/formatters/symbol_formatter.rb +18 -0
  56. data/lib/awesome_print/formatters/true_class_formatter.rb +15 -0
  57. data/lib/awesome_print/formatters/unbound_method_formatter.rb +15 -0
  58. data/lib/awesome_print/inspector.rb +18 -17
  59. data/lib/awesome_print/limiter.rb +63 -0
  60. data/lib/awesome_print/registrar.rb +20 -0
  61. data/lib/awesome_print/version.rb +6 -6
  62. data/spec/formatters/array_spec.rb +251 -0
  63. data/spec/formatters/big_decimal_spec.rb +28 -0
  64. data/spec/formatters/class_spec.rb +91 -0
  65. data/spec/formatters/dir_file_spec.rb +43 -0
  66. data/spec/{ext → formatters/ext}/active_record_spec.rb +14 -58
  67. data/spec/{ext → formatters/ext}/active_support_spec.rb +7 -11
  68. data/spec/{ext → formatters/ext}/mongoid_spec.rb +2 -2
  69. data/spec/{ext → formatters/ext}/nokogiri_spec.rb +0 -0
  70. data/spec/formatters/hash_spec.rb +284 -0
  71. data/spec/{methods_spec.rb → formatters/methods_spec.rb} +3 -5
  72. data/spec/{objects_spec.rb → formatters/objects_spec.rb} +0 -0
  73. data/spec/{ext → formatters}/ostruct_spec.rb +1 -0
  74. data/spec/formatters/set_spec.rb +49 -0
  75. data/spec/formatters/struct_spec.rb +61 -0
  76. data/spec/merge_options_spec.rb +13 -0
  77. data/spec/misc_spec.rb +3 -10
  78. data/spec/spec_helper.rb +2 -9
  79. data/spec/support/ext_verifier.rb +0 -15
  80. data/spec/support/mongoid_versions.rb +4 -8
  81. data/spec/support/rails_versions.rb +2 -32
  82. metadata +100 -78
  83. data/awesome_print.gemspec +0 -33
  84. data/init.rb +0 -1
  85. data/lib/awesome_print/core_ext/method.rb +0 -21
  86. data/lib/awesome_print/ext/action_view.rb +0 -22
  87. data/lib/awesome_print/ext/active_record.rb +0 -103
  88. data/lib/awesome_print/ext/active_support.rb +0 -47
  89. data/lib/awesome_print/ext/mongo_mapper.rb +0 -124
  90. data/lib/awesome_print/ext/mongoid.rb +0 -67
  91. data/lib/awesome_print/ext/nobrainer.rb +0 -52
  92. data/lib/awesome_print/ext/nokogiri.rb +0 -45
  93. data/lib/awesome_print/ext/ostruct.rb +0 -27
  94. data/lib/awesome_print/ext/ripple.rb +0 -71
  95. data/lib/awesome_print/ext/sequel.rb +0 -58
  96. data/spec/ext/action_view_spec.rb +0 -21
  97. data/spec/ext/mongo_mapper_spec.rb +0 -261
  98. data/spec/ext/nobrainer_spec.rb +0 -59
  99. data/spec/ext/ripple_spec.rb +0 -48
  100. data/spec/formats_spec.rb +0 -779
  101. data/spec/support/active_record_data/3_2_diana.txt +0 -24
  102. data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
  103. data/spec/support/active_record_data/3_2_multi.txt +0 -50
  104. data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
  105. data/spec/support/active_record_data/4_0_diana.txt +0 -98
  106. data/spec/support/active_record_data/4_0_multi.txt +0 -198
  107. data/spec/support/active_record_data/4_1_diana.txt +0 -97
  108. data/spec/support/active_record_data/4_1_multi.txt +0 -196
  109. data/spec/support/active_record_data/4_2_diana.txt +0 -109
  110. data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
  111. data/spec/support/active_record_data/4_2_multi.txt +0 -220
  112. data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
  113. data/spec/support/active_record_data/6_0_diana.txt +0 -104
  114. data/spec/support/active_record_data/6_0_multi.txt +0 -210
  115. data/spec/support/active_record_data/6_1_diana.txt +0 -109
  116. data/spec/support/active_record_data/6_1_multi.txt +0 -220
@@ -1,45 +0,0 @@
1
- # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
- #
3
- # Awesome Print is freely distributable under the terms of MIT license.
4
- # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
- #------------------------------------------------------------------------------
6
- module AwesomePrint
7
- module Nokogiri
8
-
9
- def self.included(base)
10
- base.send :alias_method, :cast_without_nokogiri, :cast
11
- base.send :alias_method, :cast, :cast_with_nokogiri
12
- end
13
-
14
- # Add Nokogiri XML Node and NodeSet names to the dispatcher pipeline.
15
- #------------------------------------------------------------------------------
16
- def cast_with_nokogiri(object, type)
17
- cast = cast_without_nokogiri(object, type)
18
- if (defined?(::Nokogiri::XML::Node) && object.is_a?(::Nokogiri::XML::Node)) ||
19
- (defined?(::Nokogiri::XML::NodeSet) && object.is_a?(::Nokogiri::XML::NodeSet))
20
- cast = :nokogiri_xml_node
21
- end
22
- cast
23
- end
24
-
25
- #------------------------------------------------------------------------------
26
- def awesome_nokogiri_xml_node(object)
27
- if object.is_a?(::Nokogiri::XML::NodeSet) && object.empty?
28
- return '[]'
29
- end
30
- xml = object.to_xml(indent: 2)
31
- #
32
- # Colorize tag, id/class name, and contents.
33
- #
34
- xml.gsub!(/(<)(\/?[A-Za-z1-9]+)/) { |tag| "#{$1}#{colorize($2, :keyword)}" }
35
- xml.gsub!(/(id|class)="[^"]+"/i) { |id| colorize(id, :class) }
36
- xml.gsub!(/>([^<]+)</) do |contents|
37
- contents = colorize($1, :trueclass) if contents && !contents.empty?
38
- ">#{contents}<"
39
- end
40
- xml
41
- end
42
- end
43
- end
44
-
45
- AwesomePrint::Formatter.send(:include, AwesomePrint::Nokogiri)
@@ -1,27 +0,0 @@
1
- # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
- #
3
- # Awesome Print is freely distributable under the terms of MIT license.
4
- # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
- #------------------------------------------------------------------------------
6
- module AwesomePrint
7
- module OpenStruct
8
- def self.included(base)
9
- base.send :alias_method, :cast_without_ostruct, :cast
10
- base.send :alias_method, :cast, :cast_with_ostruct
11
- end
12
-
13
- def cast_with_ostruct(object, type)
14
- cast = cast_without_ostruct(object, type)
15
- if (defined?(::OpenStruct)) && (object.is_a?(::OpenStruct))
16
- cast = :open_struct_instance
17
- end
18
- cast
19
- end
20
-
21
- def awesome_open_struct_instance(object)
22
- "#{object.class} #{awesome_hash(object.marshal_dump)}"
23
- end
24
- end
25
- end
26
-
27
- AwesomePrint::Formatter.send(:include, AwesomePrint::OpenStruct)
@@ -1,71 +0,0 @@
1
- # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
- #
3
- # Awesome Print is freely distributable under the terms of MIT license.
4
- # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
- #------------------------------------------------------------------------------
6
- module AwesomePrint
7
- module Ripple
8
-
9
- def self.included(base)
10
- base.send :alias_method, :cast_without_ripple, :cast
11
- base.send :alias_method, :cast, :cast_with_ripple
12
- end
13
-
14
- # Add Ripple class names to the dispatcher pipeline.
15
- #------------------------------------------------------------------------------
16
- def cast_with_ripple(object, type)
17
- cast = cast_without_ripple(object, type)
18
- return cast if !defined?(::Ripple)
19
-
20
- if object.is_a?(::Ripple::AttributeMethods) # Module used to access attributes across documents and embedded documents
21
- cast = :ripple_document_instance
22
- elsif object.is_a?(::Ripple::Properties) # Used to access property metadata on Ripple classes
23
- cast = :ripple_document_class
24
- end
25
- cast
26
- end
27
-
28
- private
29
-
30
- # Format Ripple instance object.
31
- #
32
- # NOTE: by default only instance attributes are shown. To format a Ripple document instance
33
- # as a regular object showing its instance variables and accessors use :raw => true option:
34
- #
35
- # ap document, :raw => true
36
- #
37
- #------------------------------------------------------------------------------
38
- def awesome_ripple_document_instance(object)
39
- return object.inspect if !defined?(::ActiveSupport::OrderedHash)
40
- return awesome_object(object) if @options[:raw]
41
- exclude_assoc = @options[:exclude_assoc] or @options[:exclude_associations]
42
-
43
- data = object.attributes.inject(::ActiveSupport::OrderedHash.new) do |hash, (name, value)|
44
- hash[name.to_sym] = object.send(name)
45
- hash
46
- end
47
-
48
- unless exclude_assoc
49
- data = object.class.embedded_associations.inject(data) do |hash, assoc|
50
- hash[assoc.name] = object.get_proxy(assoc) # Should always be array or Ripple::EmbeddedDocument for embedded associations
51
- hash
52
- end
53
- end
54
-
55
- "#{object} " << awesome_hash(data)
56
- end
57
-
58
- # Format Ripple class object.
59
- #------------------------------------------------------------------------------
60
- def awesome_ripple_document_class(object)
61
- return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
62
-
63
- name = "class #{awesome_simple(object.to_s, :class)}"
64
- base = "< #{awesome_simple(object.superclass.to_s, :class)}"
65
-
66
- [name, base, awesome_hash(data)].join(' ')
67
- end
68
- end
69
- end
70
-
71
- AwesomePrint::Formatter.send(:include, AwesomePrint::Ripple)
@@ -1,58 +0,0 @@
1
- # Copyright (c) 2010-2016 Michael Dvorkin and contributors
2
- #
3
- # Awesome Print is freely distributable under the terms of MIT license.
4
- # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
- #------------------------------------------------------------------------------
6
- module AwesomePrint
7
- module Sequel
8
-
9
- def self.included(base)
10
- base.send :alias_method, :cast_without_sequel, :cast
11
- base.send :alias_method, :cast, :cast_with_sequel
12
- end
13
-
14
- # Add Sequel class names to the dispatcher pipeline.
15
- #------------------------------------------------------------------------------
16
- def cast_with_sequel(object, type)
17
- cast = cast_without_sequel(object, type)
18
- if defined?(::Sequel::Model) && object.is_a?(::Sequel::Model)
19
- cast = :sequel_document
20
- elsif defined?(::Sequel::Model) && object.is_a?(Class) && object.ancestors.include?(::Sequel::Model)
21
- cast = :sequel_model_class
22
- elsif defined?(::Sequel::Mysql2::Dataset) && object.class.ancestors.include?(::Sequel::Mysql2::Dataset)
23
- cast = :sequel_dataset
24
- end
25
- cast
26
- end
27
-
28
- # Format Sequel Document object.
29
- #------------------------------------------------------------------------------
30
- def awesome_sequel_document(object)
31
- data = object.values.sort_by { |key| key.to_s }.inject({}) do |hash, c|
32
- hash[c[0].to_sym] = c[1]
33
- hash
34
- end
35
- data = { errors: object.errors, values: data } if !object.errors.empty?
36
- "#{object} #{awesome_hash(data)}"
37
- end
38
-
39
- # Format Sequel Dataset object.
40
- #------------------------------------------------------------------------------
41
- def awesome_sequel_dataset(dataset)
42
- [awesome_array(dataset.to_a), awesome_print(dataset.sql)].join("\n")
43
- end
44
-
45
- # Format Sequel Model class.
46
- #------------------------------------------------------------------------------
47
- def awesome_sequel_model_class(object)
48
- data = object.db_schema.inject({}) { |h, (prop, defn)| h.merge(prop => defn[:db_type]) }
49
- name = "class #{awesome_simple(object.to_s, :class)}"
50
- base = "< #{awesome_simple(object.superclass.to_s, :class)}"
51
-
52
- [name, base, awesome_hash(data)].join(' ')
53
- end
54
- end
55
-
56
- end
57
-
58
- AwesomePrint::Formatter.send(:include, AwesomePrint::Sequel)
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'AwesomePrint ActionView extensions', skip: -> { !ExtVerifier.has_rails? }.call do
4
- before do
5
- @view = if rails_6_1?
6
- ActionView::Base.new(ActionView::LookupContext.new([]), {}, {})
7
- else
8
- ActionView::Base.new
9
- end
10
- end
11
-
12
- it "uses HTML and adds 'debug_dump' class to plain <pre> tag" do
13
- markup = rand
14
- expect(@view.ap(markup, plain: true)).to eq(%Q|<pre class="debug_dump">#{markup}</pre>|)
15
- end
16
-
17
- it "uses HTML and adds 'debug_dump' class to colorized <pre> tag" do
18
- markup = ' &<hello>'
19
- expect(@view.ap(markup)).to eq('<pre class="debug_dump"><kbd style="color:brown">&quot; &amp;&lt;hello&gt;&quot;</kbd></pre>')
20
- end
21
- end
@@ -1,261 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_mapper? }.call do
4
- if ExtVerifier.has_mongo_mapper?
5
- before :all do
6
- class MongoUser
7
- include MongoMapper::Document
8
-
9
- key :first_name, String
10
- key :last_name, String
11
- end
12
- end
13
-
14
- after :all do
15
- Object.instance_eval { remove_const :MongoUser }
16
- Object.instance_eval { remove_const :Chamelion }
17
- end
18
- end
19
-
20
- before do
21
- @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true)
22
- end
23
-
24
- describe 'with the raw option set to true' do
25
- # before { @ap.options[:raw] = true }
26
- before { @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true, raw: true) }
27
-
28
- it 'should print class instance' do
29
- user = MongoUser.new(first_name: 'Al', last_name: 'Capone')
30
-
31
- out = @ap.send(:awesome, user)
32
- out.gsub!(/#\<Proc:.+?\>/, 'AWESOME_PRINT_PROC_STUB')
33
- out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
34
-
35
- str = if MongoMapper::Version >= '0.13'
36
- <<-EOS.strip
37
- #<MongoUser:placeholder_id
38
- @__mm_default_keys = [
39
- [0] #<MongoMapper::Plugins::Keys::Key:placeholder_id
40
- @dynamic = false,
41
- @embeddable = false,
42
- @has_default = true,
43
- @is_id = true,
44
- @typecast = nil,
45
- attr_accessor :accessors = [],
46
- attr_accessor :default = AWESOME_PRINT_PROC_STUB,
47
- attr_accessor :ivar = :@_id,
48
- attr_accessor :name = "_id",
49
- attr_accessor :options = {
50
- :default => AWESOME_PRINT_PROC_STUB
51
- },
52
- attr_accessor :type = ObjectId < Object
53
- >
54
- ],
55
- @__mm_keys = {
56
- "_id" => #<MongoMapper::Plugins::Keys::Key:placeholder_id
57
- @dynamic = false,
58
- @embeddable = false,
59
- @has_default = true,
60
- @is_id = true,
61
- @typecast = nil,
62
- attr_accessor :accessors = [],
63
- attr_accessor :default = AWESOME_PRINT_PROC_STUB,
64
- attr_accessor :ivar = :@_id,
65
- attr_accessor :name = "_id",
66
- attr_accessor :options = {
67
- :default => AWESOME_PRINT_PROC_STUB
68
- },
69
- attr_accessor :type = ObjectId < Object
70
- >,
71
- "first_name" => #<MongoMapper::Plugins::Keys::Key:placeholder_id
72
- @dynamic = false,
73
- @embeddable = false,
74
- @has_default = false,
75
- @is_id = false,
76
- @typecast = nil,
77
- attr_accessor :accessors = [],
78
- attr_accessor :ivar = :@first_name,
79
- attr_accessor :name = "first_name",
80
- attr_accessor :options = {},
81
- attr_accessor :type = String < Object
82
- >,
83
- "last_name" => #<MongoMapper::Plugins::Keys::Key:placeholder_id
84
- @dynamic = false,
85
- @embeddable = false,
86
- @has_default = false,
87
- @is_id = false,
88
- @typecast = nil,
89
- attr_accessor :accessors = [],
90
- attr_accessor :ivar = :@last_name,
91
- attr_accessor :name = "last_name",
92
- attr_accessor :options = {},
93
- attr_accessor :type = String < Object
94
- >
95
- },
96
- @__mm_pre_cast = {
97
- "first_name" => "Al",
98
- "last_name" => "Capone"
99
- },
100
- @_dynamic_attributes = {},
101
- @_new = true,
102
- attr_accessor :_id = BSON::ObjectId('123456789'),
103
- attr_accessor :attributes = nil,
104
- attr_accessor :first_name = "Al",
105
- attr_accessor :last_name = "Capone",
106
- attr_reader :changed_attributes = {
107
- "first_name" => nil,
108
- "last_name" => nil
109
- }
110
- >
111
- EOS
112
- else
113
- <<-EOS.strip
114
- #<MongoUser:placeholder_id
115
- @_new = true,
116
- attr_accessor :first_name = "Al",
117
- attr_accessor :last_name = "Capone",
118
- attr_reader :changed_attributes = {
119
- "first_name" => nil,
120
- "last_name" => nil
121
- },
122
- attr_reader :first_name_before_type_cast = "Al",
123
- attr_reader :last_name_before_type_cast = "Capone"
124
- >
125
- EOS
126
- end
127
- expect(out).to be_similar_to(str)
128
- end
129
-
130
- it 'should print the class' do
131
- expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip
132
- class MongoUser < Object {
133
- "_id" => :object_id,
134
- "first_name" => :string,
135
- "last_name" => :string
136
- }
137
- EOS
138
- end
139
-
140
- it 'should print the class when type is undefined' do
141
- class Chamelion
142
- include MongoMapper::Document
143
- key :last_attribute
144
- end
145
-
146
- expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip
147
- class Chamelion < Object {
148
- "_id" => :object_id,
149
- "last_attribute" => :undefined
150
- }
151
- EOS
152
- end
153
- end
154
-
155
- describe 'with associations' do
156
-
157
- if ExtVerifier.has_mongo_mapper?
158
- before :all do
159
- class Child
160
- include MongoMapper::EmbeddedDocument
161
- key :data
162
- end
163
-
164
- class Sibling
165
- include MongoMapper::Document
166
- key :title
167
- end
168
-
169
- class Parent
170
- include MongoMapper::Document
171
- key :name
172
-
173
- one :child
174
- one :sibling
175
- end
176
- end
177
- end
178
-
179
- describe 'with show associations turned off (default)' do
180
- it 'should render the class as normal' do
181
- expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
182
- class Parent < Object {
183
- "_id" => :object_id,
184
- "name" => :undefined
185
- }
186
- EOS
187
- end
188
-
189
- it 'should render an instance as normal' do
190
- parent = Parent.new(name: 'test')
191
- out = @ap.send(:awesome, parent)
192
- str = <<-EOS.strip
193
- #<Parent:placeholder_id> {
194
- "_id" => placeholder_bson_id,
195
- "name" => "test"
196
- }
197
- EOS
198
- expect(out).to be_similar_to(str)
199
- end
200
- end
201
-
202
- describe 'with show associations turned on and inline embedded turned off' do
203
- before :each do
204
- @ap = AwesomePrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true })
205
- end
206
-
207
- it 'should render the class with associations shown' do
208
- expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip
209
- class Parent < Object {
210
- "_id" => :object_id,
211
- "name" => :undefined,
212
- "child" => embeds one Child,
213
- "sibling" => one Sibling
214
- }
215
- EOS
216
- end
217
-
218
- it 'should render an instance with associations shown' do
219
- parent = Parent.new(name: 'test')
220
- out = @ap.send(:awesome, parent)
221
- str = <<-EOS.strip
222
- #<Parent:placeholder_id> {
223
- "_id" => placeholder_bson_id,
224
- "name" => "test",
225
- "child" => embeds one Child,
226
- "sibling" => one Sibling
227
- }
228
- EOS
229
- expect(out).to be_similar_to(str)
230
- end
231
- end
232
-
233
- describe 'with show associations turned on and inline embedded turned on' do
234
- before :each do
235
- @ap = AwesomePrint::Inspector.new(plain: true,
236
- mongo_mapper: {
237
- show_associations: true,
238
- inline_embedded: true
239
- }
240
- )
241
- end
242
-
243
- it 'should render an instance with associations shown and embeds there' do
244
- parent = Parent.new(name: 'test', child: Child.new(data: 5))
245
- out = @ap.send(:awesome, parent)
246
- str = <<-EOS.strip
247
- #<Parent:placeholder_id> {
248
- "_id" => placeholder_bson_id,
249
- "name" => "test",
250
- "child" => embedded #<Child:placeholder_id> {
251
- "_id" => placeholder_bson_id,
252
- "data" => 5
253
- },
254
- "sibling" => one Sibling
255
- }
256
- EOS
257
- expect(out).to be_similar_to(str)
258
- end
259
- end
260
- end
261
- end