awesome_print 1.2.0 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -2
- data/Appraisals +62 -0
- data/CHANGELOG.md +180 -0
- data/CONTRIBUTING.md +82 -0
- data/Gemfile +3 -2
- data/LICENSE +16 -19
- data/README.md +112 -87
- data/Rakefile +17 -4
- data/awesome_print.gemspec +33 -0
- data/init.rb +1 -0
- data/lib/ap.rb +2 -2
- data/lib/awesome_print.rb +22 -16
- data/lib/awesome_print/colorize.rb +24 -0
- data/lib/awesome_print/core_ext/{array.rb → awesome_method_array.rb} +16 -18
- data/lib/awesome_print/core_ext/class.rb +3 -2
- data/lib/awesome_print/core_ext/kernel.rb +1 -1
- data/lib/awesome_print/core_ext/logger.rb +1 -1
- data/lib/awesome_print/core_ext/method.rb +2 -2
- data/lib/awesome_print/core_ext/object.rb +3 -2
- data/lib/awesome_print/core_ext/string.rb +3 -3
- data/lib/awesome_print/custom_defaults.rb +57 -0
- data/lib/awesome_print/ext/action_view.rb +8 -4
- data/lib/awesome_print/ext/active_record.rb +47 -13
- data/lib/awesome_print/ext/active_support.rb +1 -1
- data/lib/awesome_print/ext/mongo_mapper.rb +16 -13
- data/lib/awesome_print/ext/mongoid.rb +9 -7
- data/lib/awesome_print/ext/nobrainer.rb +52 -0
- data/lib/awesome_print/ext/nokogiri.rb +4 -4
- data/lib/awesome_print/ext/ostruct.rb +27 -0
- data/lib/awesome_print/ext/ripple.rb +6 -7
- data/lib/awesome_print/ext/sequel.rb +7 -6
- data/lib/awesome_print/formatter.rb +54 -327
- data/lib/awesome_print/formatters.rb +15 -0
- data/lib/awesome_print/formatters/array_formatter.rb +139 -0
- data/lib/awesome_print/formatters/base_formatter.rb +140 -0
- data/lib/awesome_print/formatters/class_formatter.rb +25 -0
- data/lib/awesome_print/formatters/dir_formatter.rb +22 -0
- data/lib/awesome_print/formatters/file_formatter.rb +22 -0
- data/lib/awesome_print/formatters/hash_formatter.rb +106 -0
- data/lib/awesome_print/formatters/method_formatter.rb +22 -0
- data/lib/awesome_print/formatters/object_formatter.rb +78 -0
- data/lib/awesome_print/formatters/simple_formatter.rb +21 -0
- data/lib/awesome_print/formatters/struct_formatter.rb +71 -0
- data/lib/awesome_print/indentator.rb +18 -0
- data/lib/awesome_print/inspector.rb +92 -94
- data/lib/awesome_print/version.rb +2 -2
- data/spec/active_record_helper.rb +30 -0
- data/spec/colors_spec.rb +31 -31
- data/spec/core_ext/logger_spec.rb +43 -0
- data/spec/core_ext/string_spec.rb +20 -0
- data/spec/ext/action_view_spec.rb +21 -0
- data/spec/ext/active_record_spec.rb +260 -0
- data/spec/ext/active_support_spec.rb +30 -0
- data/spec/ext/mongo_mapper_spec.rb +261 -0
- data/spec/ext/mongoid_spec.rb +67 -0
- data/spec/ext/nobrainer_spec.rb +59 -0
- data/spec/ext/nokogiri_spec.rb +46 -0
- data/spec/ext/ostruct_spec.rb +22 -0
- data/spec/ext/ripple_spec.rb +48 -0
- data/spec/formats_spec.rb +272 -205
- data/spec/methods_spec.rb +173 -177
- data/spec/misc_spec.rb +129 -105
- data/spec/objects_spec.rb +162 -27
- data/spec/spec_helper.rb +75 -37
- data/spec/support/active_record_data.rb +20 -0
- data/spec/support/active_record_data/3_2_diana.txt +24 -0
- data/spec/support/active_record_data/3_2_diana_legacy.txt +24 -0
- data/spec/support/active_record_data/3_2_multi.txt +50 -0
- data/spec/support/active_record_data/3_2_multi_legacy.txt +50 -0
- data/spec/support/active_record_data/4_0_diana.txt +98 -0
- data/spec/support/active_record_data/4_0_multi.txt +198 -0
- data/spec/support/active_record_data/4_1_diana.txt +97 -0
- data/spec/support/active_record_data/4_1_multi.txt +196 -0
- data/spec/support/active_record_data/4_2_diana.txt +109 -0
- data/spec/support/active_record_data/4_2_diana_legacy.txt +109 -0
- data/spec/support/active_record_data/4_2_multi.txt +220 -0
- data/spec/support/active_record_data/4_2_multi_legacy.txt +220 -0
- data/spec/support/active_record_data/5_0_diana.txt +105 -0
- data/spec/support/active_record_data/5_0_multi.txt +212 -0
- data/spec/support/active_record_data/5_1_diana.txt +104 -0
- data/spec/support/active_record_data/5_1_multi.txt +210 -0
- data/spec/support/active_record_data/5_2_diana.txt +104 -0
- data/spec/support/active_record_data/5_2_multi.txt +210 -0
- data/spec/support/active_record_data/6_0_diana.txt +104 -0
- data/spec/support/active_record_data/6_0_multi.txt +210 -0
- data/spec/support/active_record_data/6_1_diana.txt +109 -0
- data/spec/support/active_record_data/6_1_multi.txt +220 -0
- data/spec/support/ext_verifier.rb +42 -0
- data/spec/support/mongoid_versions.rb +26 -0
- data/spec/support/rails_versions.rb +55 -0
- metadata +163 -32
- data/CHANGELOG +0 -96
- data/lib/awesome_print/ext/no_brainer.rb +0 -58
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright (c) 2010-
|
1
|
+
# Copyright (c) 2010-2016 Michael Dvorkin and contributors
|
2
2
|
#
|
3
3
|
# Awesome Print is freely distributable under the terms of MIT license.
|
4
4
|
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
|
5
5
|
#------------------------------------------------------------------------------
|
6
6
|
module AwesomePrint
|
7
7
|
def self.version
|
8
|
-
|
8
|
+
'1.9.2'
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
if ExtVerifier.has_rails?
|
2
|
+
# Required to use the column support
|
3
|
+
module Rails
|
4
|
+
def self.env
|
5
|
+
{}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# Establish connection to in-memory SQLite DB
|
10
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
11
|
+
|
12
|
+
# Create the users table
|
13
|
+
ActiveRecord::Migration.verbose = false
|
14
|
+
ActiveRecord::Migration.create_table :users do |t|
|
15
|
+
t.string :name
|
16
|
+
t.integer :rank
|
17
|
+
t.boolean :admin
|
18
|
+
t.datetime :created_at
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveRecord::Migration.create_table :emails do |t|
|
22
|
+
t.references :user
|
23
|
+
t.string :email_address
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create models
|
27
|
+
class User < ActiveRecord::Base; has_many :emails; end
|
28
|
+
class SubUser < User; end
|
29
|
+
class Email < ActiveRecord::Base; belongs_to :user; end
|
30
|
+
end
|
data/spec/colors_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
RSpec.describe 'AwesomePrint' do
|
4
4
|
def stub_tty!(output = true, stream = STDOUT)
|
5
5
|
if output
|
6
6
|
stream.instance_eval { def tty?; true; end }
|
@@ -9,94 +9,94 @@ describe "AwesomePrint" do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
stub_dotfile!
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "colorization" do
|
12
|
+
describe 'colorization' do
|
17
13
|
PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]'
|
18
14
|
COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]"
|
19
15
|
|
20
16
|
before do
|
21
|
-
ENV['TERM'] =
|
17
|
+
ENV['TERM'] = 'xterm-colors'
|
22
18
|
ENV.delete('ANSICON')
|
23
|
-
@arr = [
|
19
|
+
@arr = [1, :two, 'three', [nil, [true, false]]]
|
24
20
|
end
|
25
21
|
|
26
|
-
describe
|
22
|
+
describe 'default settings (no forced colors)' do
|
27
23
|
before do
|
28
24
|
AwesomePrint.force_colors! false
|
29
25
|
end
|
30
26
|
|
31
|
-
it
|
27
|
+
it 'colorizes tty processes by default' do
|
32
28
|
stub_tty!
|
33
|
-
@arr.ai(:
|
29
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
34
30
|
end
|
35
31
|
|
36
32
|
it "colorizes processes with ENV['ANSICON'] by default" do
|
37
33
|
begin
|
38
34
|
stub_tty!
|
39
|
-
term
|
40
|
-
|
35
|
+
term = ENV['ANSICON']
|
36
|
+
ENV['ANSICON'] = '1'
|
37
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
41
38
|
ensure
|
42
39
|
ENV['ANSICON'] = term
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
it
|
43
|
+
it 'does not colorize tty processes running in dumb terminals by default' do
|
47
44
|
begin
|
48
45
|
stub_tty!
|
49
|
-
term
|
50
|
-
|
46
|
+
term = ENV['TERM']
|
47
|
+
ENV['TERM'] = 'dumb'
|
48
|
+
expect(@arr.ai(multiline: false)).to eq(PLAIN)
|
51
49
|
ensure
|
52
50
|
ENV['TERM'] = term
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
it
|
54
|
+
it 'does not colorize subprocesses by default' do
|
57
55
|
begin
|
58
56
|
stub_tty! false
|
59
|
-
@arr.ai(:
|
57
|
+
expect(@arr.ai(multiline: false)).to eq(PLAIN)
|
60
58
|
ensure
|
61
59
|
stub_tty!
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
66
|
-
describe
|
64
|
+
describe 'forced colors override' do
|
67
65
|
before do
|
68
66
|
AwesomePrint.force_colors!
|
69
67
|
end
|
70
|
-
|
71
|
-
it
|
68
|
+
|
69
|
+
it 'still colorizes tty processes' do
|
72
70
|
stub_tty!
|
73
|
-
@arr.ai(:
|
71
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
74
72
|
end
|
75
73
|
|
76
74
|
it "colorizes processes with ENV['ANSICON'] set to 0" do
|
77
75
|
begin
|
78
76
|
stub_tty!
|
79
|
-
term
|
80
|
-
|
77
|
+
term = ENV['ANSICON']
|
78
|
+
ENV['ANSICON'] = '1'
|
79
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
81
80
|
ensure
|
82
81
|
ENV['ANSICON'] = term
|
83
82
|
end
|
84
83
|
end
|
85
|
-
|
86
|
-
it
|
84
|
+
|
85
|
+
it 'colorizes dumb terminals' do
|
87
86
|
begin
|
88
87
|
stub_tty!
|
89
|
-
term
|
90
|
-
|
88
|
+
term = ENV['TERM']
|
89
|
+
ENV['TERM'] = 'dumb'
|
90
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
91
91
|
ensure
|
92
92
|
ENV['TERM'] = term
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
it
|
96
|
+
it 'colorizes subprocess' do
|
97
97
|
begin
|
98
98
|
stub_tty! false
|
99
|
-
@arr.ai(:
|
99
|
+
expect(@arr.ai(multiline: false)).to eq(COLORIZED)
|
100
100
|
ensure
|
101
101
|
stub_tty!
|
102
102
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
require 'logger'
|
5
|
+
require 'awesome_print/core_ext/logger'
|
6
|
+
|
7
|
+
RSpec.describe 'AwesomePrint logging extensions' do
|
8
|
+
before(:all) do
|
9
|
+
@logger = Logger.new('/dev/null') rescue Logger.new('nul')
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'ap method' do
|
13
|
+
it 'should awesome_inspect the given object' do
|
14
|
+
object = double
|
15
|
+
expect(object).to receive(:ai)
|
16
|
+
@logger.ap object
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'the log level' do
|
20
|
+
before do
|
21
|
+
AwesomePrint.defaults = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should fallback to the default :debug log level' do
|
25
|
+
expect(@logger).to receive(:debug)
|
26
|
+
@logger.ap(nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should use the global user default if no level passed' do
|
30
|
+
AwesomePrint.defaults = { log_level: :info }
|
31
|
+
expect(@logger).to receive(:info)
|
32
|
+
@logger.ap(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should use the passed in level' do
|
36
|
+
expect(@logger).to receive(:warn)
|
37
|
+
@logger.ap(nil, :warn)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'String extensions' do
|
4
|
+
[:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white].each_with_index do |color, i|
|
5
|
+
it "should have #{color} color" do
|
6
|
+
expect(color.to_s.send(color)).to eq("\e[1;#{30 + i}m#{color}\e[0m")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have #{color}ish color" do
|
10
|
+
expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30 + i}m#{color}\e[0m")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have black and pale colors' do
|
15
|
+
expect('black'.send(:black)).to eq('black'.send(:grayish))
|
16
|
+
expect('pale'.send(:pale)).to eq('pale'.send(:whiteish))
|
17
|
+
expect('pale'.send(:pale)).to eq("\e[0;37mpale\e[0m")
|
18
|
+
expect('whiteish'.send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m")
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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">" &<hello>"</kbd></pre>')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,260 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_record_helper'
|
3
|
+
|
4
|
+
RSpec.describe 'AwesomePrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }.call do
|
5
|
+
describe 'ActiveRecord instance, attributes only (default)' do
|
6
|
+
before do
|
7
|
+
ActiveRecord::Base.default_timezone = :utc
|
8
|
+
@diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
|
9
|
+
@laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
|
10
|
+
@ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'display single record' do
|
14
|
+
out = @ap.awesome(@diana)
|
15
|
+
str = <<-EOS.strip
|
16
|
+
#<User:placeholder_id> {
|
17
|
+
:admin => false,
|
18
|
+
:created_at => ?,
|
19
|
+
:id => nil,
|
20
|
+
:name => "Diana",
|
21
|
+
:rank => 1
|
22
|
+
}
|
23
|
+
EOS
|
24
|
+
|
25
|
+
expect(RUBY_VERSION).to be >= '2.5'
|
26
|
+
|
27
|
+
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
28
|
+
|
29
|
+
expect(out).to be_similar_to(str)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'display multiple records' do
|
33
|
+
out = @ap.awesome([@diana, @laura])
|
34
|
+
str = <<-EOS.strip
|
35
|
+
[
|
36
|
+
[0] #<User:placeholder_id> {
|
37
|
+
:admin => false,
|
38
|
+
:created_at => ??,
|
39
|
+
:id => nil,
|
40
|
+
:name => "Diana",
|
41
|
+
:rank => 1
|
42
|
+
},
|
43
|
+
[1] #<User:placeholder_id> {
|
44
|
+
:admin => true,
|
45
|
+
:created_at => ?!,
|
46
|
+
:id => nil,
|
47
|
+
:name => "Laura",
|
48
|
+
:rank => 2
|
49
|
+
}
|
50
|
+
]
|
51
|
+
EOS
|
52
|
+
|
53
|
+
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
54
|
+
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
55
|
+
|
56
|
+
expect(out).to be_similar_to(str)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'display multiple records on a relation' do
|
60
|
+
@diana.save
|
61
|
+
@laura.save
|
62
|
+
out = @ap.awesome(User.all)
|
63
|
+
str = <<-EOS.strip
|
64
|
+
[
|
65
|
+
[0] #<User:placeholder_id> {
|
66
|
+
:admin => false,
|
67
|
+
:created_at => ??,
|
68
|
+
:id => 1,
|
69
|
+
:name => "Diana",
|
70
|
+
:rank => 1
|
71
|
+
},
|
72
|
+
[1] #<User:placeholder_id> {
|
73
|
+
:admin => true,
|
74
|
+
:created_at => ?!,
|
75
|
+
:id => 2,
|
76
|
+
:name => "Laura",
|
77
|
+
:rank => 2
|
78
|
+
}
|
79
|
+
]
|
80
|
+
EOS
|
81
|
+
|
82
|
+
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
83
|
+
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
84
|
+
|
85
|
+
expect(out).to be_similar_to(str)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'Linked records (joins)' do
|
90
|
+
before do
|
91
|
+
@ap = AwesomePrint::Inspector.new(plain: true)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should show the entire record' do
|
95
|
+
e = Email.create(email_address: 'foo@bar.com')
|
96
|
+
u = User.last
|
97
|
+
u.emails << e
|
98
|
+
email_record = User.joins(:emails).select('users.id, emails.email_address').last
|
99
|
+
out = @ap.awesome(email_record)
|
100
|
+
raw_object_string = <<-EOS.strip
|
101
|
+
#<User:placeholder_id> {
|
102
|
+
"id" => #{u.id},
|
103
|
+
"email_address" => "#{e.email_address}"
|
104
|
+
}
|
105
|
+
EOS
|
106
|
+
expect(out).to be_similar_to(raw_object_string)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
#------------------------------------------------------------------------------
|
111
|
+
describe 'ActiveRecord instance (raw)' do
|
112
|
+
before do
|
113
|
+
ActiveRecord::Base.default_timezone = :utc
|
114
|
+
@diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00')
|
115
|
+
@laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00')
|
116
|
+
@ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true, raw: true)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'display single record' do
|
120
|
+
out = @ap.awesome(@diana)
|
121
|
+
|
122
|
+
raw_object_string =
|
123
|
+
if activerecord_6_1?
|
124
|
+
ActiveRecordData.raw_6_1_diana
|
125
|
+
elsif activerecord_6_0?
|
126
|
+
ActiveRecordData.raw_6_0_diana
|
127
|
+
elsif activerecord_5_2?
|
128
|
+
ActiveRecordData.raw_5_2_diana
|
129
|
+
elsif activerecord_5_1?
|
130
|
+
ActiveRecordData.raw_5_1_diana
|
131
|
+
elsif activerecord_5_0?
|
132
|
+
ActiveRecordData.raw_5_0_diana
|
133
|
+
elsif activerecord_4_2?
|
134
|
+
ActiveRecordData.raw_4_2_diana
|
135
|
+
elsif activerecord_4_1?
|
136
|
+
ActiveRecordData.raw_4_1_diana
|
137
|
+
elsif activerecord_4_0?
|
138
|
+
ActiveRecordData.raw_4_0_diana
|
139
|
+
elsif activerecord_3_2?
|
140
|
+
ActiveRecordData.raw_3_2_diana
|
141
|
+
end
|
142
|
+
raw_object_string.sub!('?', '1992-10-10 12:30:00')
|
143
|
+
expect(out).to be_similar_to(raw_object_string)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'display multiple records' do
|
147
|
+
out = @ap.awesome([@diana, @laura])
|
148
|
+
|
149
|
+
raw_object_string =
|
150
|
+
if activerecord_6_1?
|
151
|
+
ActiveRecordData.raw_6_1_multi
|
152
|
+
elsif activerecord_6_0?
|
153
|
+
ActiveRecordData.raw_6_0_multi
|
154
|
+
elsif activerecord_5_2?
|
155
|
+
ActiveRecordData.raw_5_2_multi
|
156
|
+
elsif activerecord_5_1?
|
157
|
+
ActiveRecordData.raw_5_1_multi
|
158
|
+
elsif activerecord_5_0?
|
159
|
+
ActiveRecordData.raw_5_0_multi
|
160
|
+
elsif activerecord_4_2?
|
161
|
+
ActiveRecordData.raw_4_2_multi
|
162
|
+
elsif activerecord_4_1?
|
163
|
+
ActiveRecordData.raw_4_1_multi
|
164
|
+
elsif activerecord_4_0?
|
165
|
+
ActiveRecordData.raw_4_0_multi
|
166
|
+
elsif activerecord_3_2?
|
167
|
+
ActiveRecordData.raw_3_2_multi
|
168
|
+
end
|
169
|
+
raw_object_string.sub!('?', '1992-10-10 12:30:00')
|
170
|
+
raw_object_string.sub!('?', '2003-05-26 14:15:00')
|
171
|
+
expect(out).to be_similar_to(raw_object_string)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
#------------------------------------------------------------------------------
|
176
|
+
describe 'ActiveRecord class' do
|
177
|
+
before do
|
178
|
+
@ap = AwesomePrint::Inspector.new(plain: true)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should print the class' do
|
182
|
+
expect(@ap.awesome(User)).to eq <<-EOS.strip
|
183
|
+
class User < ActiveRecord::Base {
|
184
|
+
:id => :integer,
|
185
|
+
:name => :string,
|
186
|
+
:rank => :integer,
|
187
|
+
:admin => :boolean,
|
188
|
+
:created_at => :datetime
|
189
|
+
}
|
190
|
+
EOS
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should print the class for non-direct subclasses of ActiveRecord::Base' do
|
194
|
+
out = @ap.awesome(SubUser)
|
195
|
+
expect(out).to eq <<-EOS.strip
|
196
|
+
class SubUser < User {
|
197
|
+
:id => :integer,
|
198
|
+
:name => :string,
|
199
|
+
:rank => :integer,
|
200
|
+
:admin => :boolean,
|
201
|
+
:created_at => :datetime
|
202
|
+
}
|
203
|
+
EOS
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should print ActiveRecord::Base objects (ex. ancestors)' do
|
207
|
+
expect { @ap.awesome(User.ancestors) }.not_to raise_error
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
#------------------------------------------------------------------------------
|
212
|
+
describe 'ActiveRecord methods formatting' do
|
213
|
+
before do
|
214
|
+
@ap = AwesomePrint::Inspector.new(plain: true)
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should format class methods properly' do
|
218
|
+
# spec 1
|
219
|
+
out = @ap.awesome(User.methods.grep(/first/))
|
220
|
+
|
221
|
+
if RUBY_VERSION >= '3.0.0'
|
222
|
+
expect(out).to match(/\sfirst\(\*\*,\s&&\)/)
|
223
|
+
elsif RUBY_VERSION >= '2.7.0'
|
224
|
+
if ActiveRecord::VERSION::STRING >= '3.2'
|
225
|
+
expect(out).to match(/\sfirst\(\*\*,\s&&\)\s+User/)
|
226
|
+
else
|
227
|
+
expect(out).to match(/\sfirst\(\*\*,\s&&\)\s+User \(ActiveRecord::Base\)/)
|
228
|
+
end
|
229
|
+
else
|
230
|
+
if ActiveRecord::VERSION::STRING >= '3.2'
|
231
|
+
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User/)
|
232
|
+
else
|
233
|
+
expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# spec 2
|
238
|
+
out = @ap.awesome(User.methods.grep(/primary_key/))
|
239
|
+
if RUBY_VERSION >= '3.0.0'
|
240
|
+
expect(out).to match(/\sprimary_key\(.*?\)/)
|
241
|
+
else
|
242
|
+
expect(out).to match(/\sprimary_key\(.*?\)\s+User/)
|
243
|
+
end
|
244
|
+
|
245
|
+
# spec 3
|
246
|
+
out = @ap.awesome(User.methods.grep(/validate/))
|
247
|
+
if ActiveRecord::VERSION::MAJOR < 3
|
248
|
+
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/)
|
249
|
+
else
|
250
|
+
if RUBY_VERSION >= '3.0.0'
|
251
|
+
expect(out).to match(/\svalidate\(\*arg.*?\)/)
|
252
|
+
else
|
253
|
+
expect(out).to match(/\svalidate\(\*arg.*?\)\s+User/)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|