amazing_print 1.5.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +68 -38
- data/README.md +2 -2
- data/lib/amazing_print/core_ext/awesome_method_array.rb +1 -1
- data/lib/amazing_print/custom_defaults.rb +7 -1
- data/lib/amazing_print/ext/active_record.rb +32 -2
- data/lib/amazing_print/ext/mongoid.rb +14 -2
- data/lib/amazing_print/ext/nobrainer.rb +2 -2
- data/lib/amazing_print/ext_loader.rb +27 -0
- data/lib/amazing_print/formatters/base_formatter.rb +12 -3
- data/lib/amazing_print/formatters/hash_formatter.rb +28 -11
- data/lib/amazing_print/formatters/mswin_helper.rb +4 -4
- data/lib/amazing_print/formatters/object_formatter.rb +1 -1
- data/lib/amazing_print/formatters/struct_formatter.rb +1 -1
- data/lib/amazing_print/inspector.rb +6 -3
- data/lib/amazing_print/version.rb +1 -1
- data/lib/amazing_print.rb +2 -8
- metadata +7 -61
- data/.gitignore +0 -35
- data/Appraisals +0 -50
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -83
- data/LICENSE +0 -22
- data/Rakefile +0 -25
- data/spec/active_record_helper.rb +0 -43
- data/spec/colors_spec.rb +0 -120
- data/spec/core_ext/logger_spec.rb +0 -70
- data/spec/ext/action_controller_spec.rb +0 -40
- data/spec/ext/action_view_spec.rb +0 -24
- data/spec/ext/active_model_spec.rb +0 -37
- data/spec/ext/active_record_spec.rb +0 -298
- data/spec/ext/active_support_spec.rb +0 -37
- data/spec/ext/mongo_mapper_spec.rb +0 -265
- data/spec/ext/mongoid_spec.rb +0 -72
- data/spec/ext/nobrainer_spec.rb +0 -64
- data/spec/ext/nokogiri_spec.rb +0 -52
- data/spec/ext/ostruct_spec.rb +0 -24
- data/spec/ext/ripple_spec.rb +0 -53
- data/spec/ext/sequel_spec.rb +0 -45
- data/spec/formats_spec.rb +0 -792
- data/spec/methods_spec.rb +0 -520
- data/spec/misc_spec.rb +0 -206
- data/spec/objects_spec.rb +0 -225
- data/spec/sequel_helper.rb +0 -18
- data/spec/spec_helper.rb +0 -112
- data/spec/support/active_record_data/3_2_diana.txt +0 -24
- data/spec/support/active_record_data/3_2_diana_legacy.txt +0 -24
- data/spec/support/active_record_data/3_2_multi.txt +0 -50
- data/spec/support/active_record_data/3_2_multi_legacy.txt +0 -50
- data/spec/support/active_record_data/4_0_diana.txt +0 -98
- data/spec/support/active_record_data/4_0_multi.txt +0 -198
- data/spec/support/active_record_data/4_1_diana.txt +0 -97
- data/spec/support/active_record_data/4_1_multi.txt +0 -196
- data/spec/support/active_record_data/4_2_diana.txt +0 -109
- data/spec/support/active_record_data/4_2_diana_legacy.txt +0 -109
- data/spec/support/active_record_data/4_2_multi.txt +0 -220
- data/spec/support/active_record_data/4_2_multi_legacy.txt +0 -220
- data/spec/support/active_record_data/5_0_diana.txt +0 -105
- data/spec/support/active_record_data/5_0_multi.txt +0 -212
- data/spec/support/active_record_data/5_1_diana.txt +0 -104
- data/spec/support/active_record_data/5_1_multi.txt +0 -210
- data/spec/support/active_record_data/5_2_diana.txt +0 -104
- data/spec/support/active_record_data/5_2_multi.txt +0 -210
- data/spec/support/active_record_data/6_0_diana.txt +0 -104
- data/spec/support/active_record_data/6_0_multi.txt +0 -210
- data/spec/support/active_record_data/6_1_diana.txt +0 -109
- data/spec/support/active_record_data/6_1_multi.txt +0 -220
- data/spec/support/active_record_data.rb +0 -22
- data/spec/support/ext_verifier.rb +0 -46
- data/spec/support/mongoid_versions.rb +0 -24
- data/spec/support/rails_versions.rb +0 -57
@@ -1,298 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'active_record_helper'
|
5
|
-
|
6
|
-
RSpec.describe 'AmazingPrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }.call do
|
7
|
-
describe 'ActiveRecord instance, attributes only (default)' do
|
8
|
-
before do
|
9
|
-
ActiveRecord::Base.default_timezone = :utc
|
10
|
-
@diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
|
11
|
-
@laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
|
12
|
-
@ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'display single record' do
|
16
|
-
out = @ap.awesome(@diana)
|
17
|
-
str = <<~EOS.strip
|
18
|
-
#<User:placeholder_id> {
|
19
|
-
:admin => false,
|
20
|
-
:created_at => ?,
|
21
|
-
:id => nil,
|
22
|
-
:name => "Diana",
|
23
|
-
:rank => 1
|
24
|
-
}
|
25
|
-
EOS
|
26
|
-
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
27
|
-
expect(out).to be_similar_to(str)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'display multiple records' do
|
31
|
-
out = @ap.awesome([@diana, @laura])
|
32
|
-
str = <<~EOS.strip
|
33
|
-
[
|
34
|
-
[0] #<User:placeholder_id> {
|
35
|
-
:admin => false,
|
36
|
-
:created_at => ??,
|
37
|
-
:id => nil,
|
38
|
-
:name => "Diana",
|
39
|
-
:rank => 1
|
40
|
-
},
|
41
|
-
[1] #<User:placeholder_id> {
|
42
|
-
:admin => true,
|
43
|
-
:created_at => ?!,
|
44
|
-
:id => nil,
|
45
|
-
:name => "Laura",
|
46
|
-
:rank => 2
|
47
|
-
}
|
48
|
-
]
|
49
|
-
EOS
|
50
|
-
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
51
|
-
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
52
|
-
expect(out).to be_similar_to(str)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'display multiple records on a relation' do
|
56
|
-
@diana.save
|
57
|
-
@laura.save
|
58
|
-
out = @ap.awesome(User.all)
|
59
|
-
str = <<~EOS.strip
|
60
|
-
[
|
61
|
-
[0] #<User:placeholder_id> {
|
62
|
-
:admin => false,
|
63
|
-
:created_at => ??,
|
64
|
-
:id => 1,
|
65
|
-
:name => "Diana",
|
66
|
-
:rank => 1
|
67
|
-
},
|
68
|
-
[1] #<User:placeholder_id> {
|
69
|
-
:admin => true,
|
70
|
-
:created_at => ?!,
|
71
|
-
:id => 2,
|
72
|
-
:name => "Laura",
|
73
|
-
:rank => 2
|
74
|
-
}
|
75
|
-
]
|
76
|
-
EOS
|
77
|
-
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
78
|
-
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
79
|
-
expect(out).to be_similar_to(str)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe 'Linked records (joins)' do
|
84
|
-
before do
|
85
|
-
@ap = AmazingPrint::Inspector.new(plain: true)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'shows the entire record' do
|
89
|
-
e = Email.create(email_address: 'foo@bar.com')
|
90
|
-
u = User.last
|
91
|
-
u.emails << e
|
92
|
-
email_record = User.joins(:emails).select('users.id, emails.email_address').last
|
93
|
-
out = @ap.awesome(email_record)
|
94
|
-
raw_object_string = <<~EOS.strip
|
95
|
-
#<User:placeholder_id> {
|
96
|
-
"id" => #{u.id},
|
97
|
-
"email_address" => "#{e.email_address}"
|
98
|
-
}
|
99
|
-
EOS
|
100
|
-
expect(out).to be_similar_to(raw_object_string)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
#------------------------------------------------------------------------------
|
105
|
-
describe 'ActiveRecord instance (raw)' do
|
106
|
-
before do
|
107
|
-
ActiveRecord::Base.default_timezone = :utc
|
108
|
-
@diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
|
109
|
-
@laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
|
110
|
-
@ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true, raw: true)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'display single record' do
|
114
|
-
out = @ap.awesome(@diana)
|
115
|
-
|
116
|
-
raw_object_string =
|
117
|
-
if activerecord_6_1?
|
118
|
-
ActiveRecordData.raw_6_1_diana
|
119
|
-
elsif activerecord_6_0?
|
120
|
-
ActiveRecordData.raw_6_0_diana
|
121
|
-
elsif activerecord_5_2?
|
122
|
-
ActiveRecordData.raw_5_2_diana
|
123
|
-
elsif activerecord_5_1?
|
124
|
-
ActiveRecordData.raw_5_1_diana
|
125
|
-
elsif activerecord_5_0?
|
126
|
-
ActiveRecordData.raw_5_0_diana
|
127
|
-
elsif activerecord_4_2?
|
128
|
-
ActiveRecordData.raw_4_2_diana
|
129
|
-
elsif activerecord_4_1?
|
130
|
-
ActiveRecordData.raw_4_1_diana
|
131
|
-
elsif activerecord_4_0?
|
132
|
-
ActiveRecordData.raw_4_0_diana
|
133
|
-
elsif activerecord_3_2?
|
134
|
-
ActiveRecordData.raw_3_2_diana
|
135
|
-
end
|
136
|
-
|
137
|
-
if RUBY_PLATFORM == 'java' && !activerecord_6_1?
|
138
|
-
raw_object_string.gsub!(
|
139
|
-
'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
|
140
|
-
'ArJdbc::SQLite3::SQLite3Integer'
|
141
|
-
)
|
142
|
-
end
|
143
|
-
raw_object_string.sub!('?', '1992-10-10 12:30:00')
|
144
|
-
expect(out).to be_similar_to(raw_object_string)
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'display multiple records' do
|
148
|
-
out = @ap.awesome([@diana, @laura])
|
149
|
-
|
150
|
-
raw_object_string =
|
151
|
-
if activerecord_6_1?
|
152
|
-
ActiveRecordData.raw_6_1_multi
|
153
|
-
elsif activerecord_6_0?
|
154
|
-
ActiveRecordData.raw_6_0_multi
|
155
|
-
elsif activerecord_5_2?
|
156
|
-
ActiveRecordData.raw_5_2_multi
|
157
|
-
elsif activerecord_5_1?
|
158
|
-
ActiveRecordData.raw_5_1_multi
|
159
|
-
elsif activerecord_5_0?
|
160
|
-
ActiveRecordData.raw_5_0_multi
|
161
|
-
elsif activerecord_4_2?
|
162
|
-
ActiveRecordData.raw_4_2_multi
|
163
|
-
elsif activerecord_4_1?
|
164
|
-
ActiveRecordData.raw_4_1_multi
|
165
|
-
elsif activerecord_4_0?
|
166
|
-
ActiveRecordData.raw_4_0_multi
|
167
|
-
elsif activerecord_3_2?
|
168
|
-
ActiveRecordData.raw_3_2_multi
|
169
|
-
end
|
170
|
-
|
171
|
-
if RUBY_PLATFORM == 'java' && !activerecord_6_1?
|
172
|
-
raw_object_string.gsub!(
|
173
|
-
'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer',
|
174
|
-
'ArJdbc::SQLite3::SQLite3Integer'
|
175
|
-
)
|
176
|
-
end
|
177
|
-
raw_object_string.sub!('?', '1992-10-10 12:30:00')
|
178
|
-
raw_object_string.sub!('?', '2003-05-26 14:15:00')
|
179
|
-
expect(out).to be_similar_to(raw_object_string)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
#------------------------------------------------------------------------------
|
184
|
-
describe 'ActiveRecord class' do
|
185
|
-
before do
|
186
|
-
@ap = AmazingPrint::Inspector.new(plain: true)
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'prints the class' do
|
190
|
-
expect(@ap.awesome(User)).to eq <<~EOS.strip
|
191
|
-
class User < ActiveRecord::Base {
|
192
|
-
:id => :integer,
|
193
|
-
:name => :string,
|
194
|
-
:rank => :integer,
|
195
|
-
:admin => :boolean,
|
196
|
-
:created_at => :datetime
|
197
|
-
}
|
198
|
-
EOS
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'prints the class for non-direct subclasses of ActiveRecord::Base' do
|
202
|
-
out = @ap.awesome(SubUser)
|
203
|
-
expect(out).to eq <<~EOS.strip
|
204
|
-
class SubUser < User {
|
205
|
-
:id => :integer,
|
206
|
-
:name => :string,
|
207
|
-
:rank => :integer,
|
208
|
-
:admin => :boolean,
|
209
|
-
:created_at => :datetime
|
210
|
-
}
|
211
|
-
EOS
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'prints ActiveRecord::Base objects (ex. ancestors)' do
|
215
|
-
expect { @ap.awesome(User.ancestors) }.not_to raise_error
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'prints valid HTML for subclasses' do
|
219
|
-
@ap = AmazingPrint::Inspector.new(html: true)
|
220
|
-
expect(@ap.awesome(SubUser)).to match('SubUser < User')
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
#------------------------------------------------------------------------------
|
225
|
-
describe 'ActiveRecord methods formatting' do
|
226
|
-
before do
|
227
|
-
@ap = AmazingPrint::Inspector.new(plain: true)
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'formats class methods properly' do
|
231
|
-
# spec 1
|
232
|
-
out = @ap.awesome(User.methods.grep(/first/))
|
233
|
-
|
234
|
-
if ActiveRecord::VERSION::STRING >= '3.2'
|
235
|
-
if RUBY_PLATFORM == 'java'
|
236
|
-
expect(out).to match(
|
237
|
-
/\s+first\(\*args,\s&block\)\s+#<Class:\w+>\s+\(ActiveRecord::Querying\)/
|
238
|
-
)
|
239
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')
|
240
|
-
expect(out).to match(
|
241
|
-
/\s*first\(\*(\*|args),\s+\?,\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
|
242
|
-
)
|
243
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
244
|
-
expect(out).to match(
|
245
|
-
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:User> \(ActiveRecord::Querying\)/
|
246
|
-
)
|
247
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
|
248
|
-
expect(out).to match(
|
249
|
-
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+User/
|
250
|
-
)
|
251
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7')
|
252
|
-
expect(out).to match(
|
253
|
-
/\s*first\(\*(\*|args),\s+&(&|block)\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::Querying\)/
|
254
|
-
)
|
255
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4')
|
256
|
-
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User/)
|
257
|
-
end
|
258
|
-
else
|
259
|
-
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
260
|
-
end
|
261
|
-
|
262
|
-
# spec 2
|
263
|
-
out = @ap.awesome(User.methods.grep(/primary_key/))
|
264
|
-
if RUBY_PLATFORM == 'java'
|
265
|
-
expect(out).to match(
|
266
|
-
/\sprimary_key\(.*?\)\s+#<Class:\w+>\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
|
267
|
-
)
|
268
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
269
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:User> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
270
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.7') && Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7.0')
|
271
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/)
|
272
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
|
273
|
-
expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
|
274
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
275
|
-
expect(out).to match(
|
276
|
-
/\sprimary_key\(.*?\)\s+.+Class.+\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/
|
277
|
-
)
|
278
|
-
end
|
279
|
-
|
280
|
-
# spec 3
|
281
|
-
out = @ap.awesome(User.methods.grep(/validate/))
|
282
|
-
|
283
|
-
if ActiveRecord::VERSION::MAJOR < 3
|
284
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
285
|
-
elsif RUBY_PLATFORM == 'java'
|
286
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:\w+> \(ActiveModel::Validations::ClassMethods\)/)
|
287
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
|
288
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+#<Class:User> \(ActiveModel::Validations::ClassMethods\)/)
|
289
|
-
elsif (Gem::Version.new('2.6.7')..Gem::Version.new('2.7.1')).cover? Gem::Version.new(RUBY_VERSION)
|
290
|
-
expect(out).to match(
|
291
|
-
/\svalidate\(\*args.*?\)\s+#<Class:ActiveRecord::Base> \(ActiveModel::Validations::ClassMethods\)/
|
292
|
-
)
|
293
|
-
elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.4') || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.2')
|
294
|
-
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'AmazingPrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails? }.call do
|
6
|
-
let(:expected_ar_time_str) do
|
7
|
-
if activerecord_6_1?
|
8
|
-
'15:30:45.000000000'
|
9
|
-
else
|
10
|
-
'15:30:45'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
@ap = AmazingPrint::Inspector.new
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'formats ActiveSupport::TimeWithZone as regular Time' do
|
19
|
-
Time.zone = 'Eastern Time (US & Canada)'
|
20
|
-
time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone
|
21
|
-
expect(@ap.send(:awesome, time))
|
22
|
-
.to eq("\e[0;32mSat, 10 Feb 2007 #{expected_ar_time_str} EST -05:00\e[0m")
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'formats HashWithIndifferentAccess as regular Hash' do
|
26
|
-
hash = HashWithIndifferentAccess.new({ hello: 'world' })
|
27
|
-
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
|
28
|
-
end
|
29
|
-
|
30
|
-
# ActiveSupport sticks in instance variables to the date object. Make sure
|
31
|
-
# we ignore that and format Date instance as regular date.
|
32
|
-
it 'formates Date object as date' do
|
33
|
-
date = Date.new(2003, 5, 26)
|
34
|
-
expect(date.ai(plain: true)).to eq('Mon, 26 May 2003')
|
35
|
-
expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m")
|
36
|
-
end
|
37
|
-
end
|
@@ -1,265 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
|
-
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
RSpec.describe 'AmazingPrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_mapper? }.call do
|
8
|
-
if ExtVerifier.has_mongo_mapper?
|
9
|
-
before :all do
|
10
|
-
class MongoUser
|
11
|
-
include MongoMapper::Document
|
12
|
-
|
13
|
-
key :first_name, String
|
14
|
-
key :last_name, String
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
after :all do
|
19
|
-
Object.instance_eval { remove_const :MongoUser }
|
20
|
-
Object.instance_eval { remove_const :Chamelion }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
before do
|
25
|
-
@ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true)
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'with the raw option set to true' do
|
29
|
-
# before { @ap.options[:raw] = true }
|
30
|
-
before { @ap = AmazingPrint::Inspector.new(plain: true, sort_keys: true, raw: true) }
|
31
|
-
|
32
|
-
it 'prints class instance' do
|
33
|
-
user = MongoUser.new(first_name: 'Al', last_name: 'Capone')
|
34
|
-
|
35
|
-
out = @ap.send(:awesome, user)
|
36
|
-
.gsub(/#<Proc:.+?>/, 'amazing_print_PROC_STUB')
|
37
|
-
.gsub(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')")
|
38
|
-
|
39
|
-
str = if MongoMapper::Version >= '0.13'
|
40
|
-
<<~EOS.strip
|
41
|
-
#<MongoUser:placeholder_id
|
42
|
-
@__mm_default_keys = [
|
43
|
-
[0] #<MongoMapper::Plugins::Keys::Key:placeholder_id
|
44
|
-
@dynamic = false,
|
45
|
-
@embeddable = false,
|
46
|
-
@has_default = true,
|
47
|
-
@is_id = true,
|
48
|
-
@typecast = nil,
|
49
|
-
attr_accessor :accessors = [],
|
50
|
-
attr_accessor :default = amazing_print_PROC_STUB,
|
51
|
-
attr_accessor :ivar = :@_id,
|
52
|
-
attr_accessor :name = "_id",
|
53
|
-
attr_accessor :options = {
|
54
|
-
:default => amazing_print_PROC_STUB
|
55
|
-
},
|
56
|
-
attr_accessor :type = ObjectId < Object
|
57
|
-
>
|
58
|
-
],
|
59
|
-
@__mm_keys = {
|
60
|
-
"_id" => #<MongoMapper::Plugins::Keys::Key:placeholder_id
|
61
|
-
@dynamic = false,
|
62
|
-
@embeddable = false,
|
63
|
-
@has_default = true,
|
64
|
-
@is_id = true,
|
65
|
-
@typecast = nil,
|
66
|
-
attr_accessor :accessors = [],
|
67
|
-
attr_accessor :default = amazing_print_PROC_STUB,
|
68
|
-
attr_accessor :ivar = :@_id,
|
69
|
-
attr_accessor :name = "_id",
|
70
|
-
attr_accessor :options = {
|
71
|
-
:default => amazing_print_PROC_STUB
|
72
|
-
},
|
73
|
-
attr_accessor :type = ObjectId < Object
|
74
|
-
>,
|
75
|
-
"first_name" => #<MongoMapper::Plugins::Keys::Key:placeholder_id
|
76
|
-
@dynamic = false,
|
77
|
-
@embeddable = false,
|
78
|
-
@has_default = false,
|
79
|
-
@is_id = false,
|
80
|
-
@typecast = nil,
|
81
|
-
attr_accessor :accessors = [],
|
82
|
-
attr_accessor :ivar = :@first_name,
|
83
|
-
attr_accessor :name = "first_name",
|
84
|
-
attr_accessor :options = {},
|
85
|
-
attr_accessor :type = String < Object
|
86
|
-
>,
|
87
|
-
"last_name" => #<MongoMapper::Plugins::Keys::Key:placeholder_id
|
88
|
-
@dynamic = false,
|
89
|
-
@embeddable = false,
|
90
|
-
@has_default = false,
|
91
|
-
@is_id = false,
|
92
|
-
@typecast = nil,
|
93
|
-
attr_accessor :accessors = [],
|
94
|
-
attr_accessor :ivar = :@last_name,
|
95
|
-
attr_accessor :name = "last_name",
|
96
|
-
attr_accessor :options = {},
|
97
|
-
attr_accessor :type = String < Object
|
98
|
-
>
|
99
|
-
},
|
100
|
-
@__mm_pre_cast = {
|
101
|
-
"first_name" => "Al",
|
102
|
-
"last_name" => "Capone"
|
103
|
-
},
|
104
|
-
@_dynamic_attributes = {},
|
105
|
-
@_new = true,
|
106
|
-
attr_accessor :_id = BSON::ObjectId('123456789'),
|
107
|
-
attr_accessor :attributes = nil,
|
108
|
-
attr_accessor :first_name = "Al",
|
109
|
-
attr_accessor :last_name = "Capone",
|
110
|
-
attr_reader :changed_attributes = {
|
111
|
-
"first_name" => nil,
|
112
|
-
"last_name" => nil
|
113
|
-
}
|
114
|
-
>
|
115
|
-
EOS
|
116
|
-
else
|
117
|
-
<<~EOS.strip
|
118
|
-
#<MongoUser:placeholder_id
|
119
|
-
@_new = true,
|
120
|
-
attr_accessor :first_name = "Al",
|
121
|
-
attr_accessor :last_name = "Capone",
|
122
|
-
attr_reader :changed_attributes = {
|
123
|
-
"first_name" => nil,
|
124
|
-
"last_name" => nil
|
125
|
-
},
|
126
|
-
attr_reader :first_name_before_type_cast = "Al",
|
127
|
-
attr_reader :last_name_before_type_cast = "Capone"
|
128
|
-
>
|
129
|
-
EOS
|
130
|
-
end
|
131
|
-
expect(out).to be_similar_to(str)
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'prints the class' do
|
135
|
-
expect(@ap.send(:awesome, MongoUser)).to eq <<~EOS.strip
|
136
|
-
class MongoUser < Object {
|
137
|
-
"_id" => :object_id,
|
138
|
-
"first_name" => :string,
|
139
|
-
"last_name" => :string
|
140
|
-
}
|
141
|
-
EOS
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'prints the class when type is undefined' do
|
145
|
-
class Chamelion
|
146
|
-
include MongoMapper::Document
|
147
|
-
key :last_attribute
|
148
|
-
end
|
149
|
-
|
150
|
-
expect(@ap.send(:awesome, Chamelion)).to eq <<~EOS.strip
|
151
|
-
class Chamelion < Object {
|
152
|
-
"_id" => :object_id,
|
153
|
-
"last_attribute" => :undefined
|
154
|
-
}
|
155
|
-
EOS
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe 'with associations' do
|
160
|
-
if ExtVerifier.has_mongo_mapper?
|
161
|
-
before :all do
|
162
|
-
class Child
|
163
|
-
include MongoMapper::EmbeddedDocument
|
164
|
-
key :data
|
165
|
-
end
|
166
|
-
|
167
|
-
class Sibling
|
168
|
-
include MongoMapper::Document
|
169
|
-
key :title
|
170
|
-
end
|
171
|
-
|
172
|
-
class Parent
|
173
|
-
include MongoMapper::Document
|
174
|
-
key :name
|
175
|
-
|
176
|
-
one :child
|
177
|
-
one :sibling
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe 'with show associations turned off (default)' do
|
183
|
-
it 'renders the class as normal' do
|
184
|
-
expect(@ap.send(:awesome, Parent)).to eq <<~EOS.strip
|
185
|
-
class Parent < Object {
|
186
|
-
"_id" => :object_id,
|
187
|
-
"name" => :undefined
|
188
|
-
}
|
189
|
-
EOS
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'renders an instance as normal' do
|
193
|
-
parent = Parent.new(name: 'test')
|
194
|
-
out = @ap.send(:awesome, parent)
|
195
|
-
str = <<~EOS.strip
|
196
|
-
#<Parent:placeholder_id> {
|
197
|
-
"_id" => placeholder_bson_id,
|
198
|
-
"name" => "test"
|
199
|
-
}
|
200
|
-
EOS
|
201
|
-
expect(out).to be_similar_to(str)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe 'with show associations turned on and inline embedded turned off' do
|
206
|
-
before do
|
207
|
-
@ap = AmazingPrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true })
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'renders the class with associations shown' do
|
211
|
-
expect(@ap.send(:awesome, Parent)).to eq <<~EOS.strip
|
212
|
-
class Parent < Object {
|
213
|
-
"_id" => :object_id,
|
214
|
-
"name" => :undefined,
|
215
|
-
"child" => embeds one Child,
|
216
|
-
"sibling" => one Sibling
|
217
|
-
}
|
218
|
-
EOS
|
219
|
-
end
|
220
|
-
|
221
|
-
it 'renders an instance with associations shown' do
|
222
|
-
parent = Parent.new(name: 'test')
|
223
|
-
out = @ap.send(:awesome, parent)
|
224
|
-
str = <<~EOS.strip
|
225
|
-
#<Parent:placeholder_id> {
|
226
|
-
"_id" => placeholder_bson_id,
|
227
|
-
"name" => "test",
|
228
|
-
"child" => embeds one Child,
|
229
|
-
"sibling" => one Sibling
|
230
|
-
}
|
231
|
-
EOS
|
232
|
-
expect(out).to be_similar_to(str)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
describe 'with show associations turned on and inline embedded turned on' do
|
237
|
-
before do
|
238
|
-
@ap = AmazingPrint::Inspector.new plain: true,
|
239
|
-
mongo_mapper: {
|
240
|
-
show_associations: true,
|
241
|
-
inline_embedded: true
|
242
|
-
}
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'renders an instance with associations shown and embeds there' do
|
246
|
-
parent = Parent.new(name: 'test', child: Child.new(data: 5))
|
247
|
-
out = @ap.send(:awesome, parent)
|
248
|
-
str = <<~EOS.strip
|
249
|
-
#<Parent:placeholder_id> {
|
250
|
-
"_id" => placeholder_bson_id,
|
251
|
-
"name" => "test",
|
252
|
-
"child" => embedded #<Child:placeholder_id> {
|
253
|
-
"_id" => placeholder_bson_id,
|
254
|
-
"data" => 5
|
255
|
-
},
|
256
|
-
"sibling" => one Sibling
|
257
|
-
}
|
258
|
-
EOS
|
259
|
-
expect(out).to be_similar_to(str)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# rubocop:enable Lint/ConstantDefinitionInBlock
|
data/spec/ext/mongoid_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
|
-
|
5
|
-
require 'spec_helper'
|
6
|
-
|
7
|
-
RSpec.describe 'AmazingPrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do
|
8
|
-
if ExtVerifier.has_mongoid?
|
9
|
-
before :all do
|
10
|
-
class MongoUser
|
11
|
-
include Mongoid::Document
|
12
|
-
|
13
|
-
field :first_name, type: String
|
14
|
-
field :last_name, type: String
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
after :all do
|
19
|
-
Object.instance_eval { remove_const :MongoUser }
|
20
|
-
Object.instance_eval { remove_const :Chamelion }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
before do
|
25
|
-
@ap = AmazingPrint::Inspector.new plain: true, sort_keys: true
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'prints class instance' do
|
29
|
-
user = MongoUser.new first_name: 'Al', last_name: 'Capone'
|
30
|
-
out = @ap.send :awesome, user
|
31
|
-
|
32
|
-
object_id = user.id.inspect
|
33
|
-
str = <<~EOS.strip
|
34
|
-
#<MongoUser:placeholder_id> {
|
35
|
-
:_id => #{object_id},
|
36
|
-
:first_name => "Al",
|
37
|
-
:last_name => "Capone"
|
38
|
-
}
|
39
|
-
EOS
|
40
|
-
expect(out).to be_similar_to(str, { skip_bson: true })
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'prints the class' do
|
44
|
-
class_spec = <<~EOS.strip
|
45
|
-
class MongoUser < Object {
|
46
|
-
:_id => :"bson/object_id",
|
47
|
-
:first_name => :string,
|
48
|
-
:last_name => :string
|
49
|
-
}
|
50
|
-
EOS
|
51
|
-
|
52
|
-
expect(@ap.send(:awesome, MongoUser)).to eq class_spec
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'prints the class when type is undefined' do
|
56
|
-
class Chamelion
|
57
|
-
include Mongoid::Document
|
58
|
-
field :last_attribute
|
59
|
-
end
|
60
|
-
|
61
|
-
class_spec = <<~EOS.strip
|
62
|
-
class Chamelion < Object {
|
63
|
-
:_id => :"bson/object_id",
|
64
|
-
:last_attribute => :object
|
65
|
-
}
|
66
|
-
EOS
|
67
|
-
|
68
|
-
expect(@ap.send(:awesome, Chamelion)).to eq class_spec
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# rubocop:enable Lint/ConstantDefinitionInBlock
|