Skip to content

Commit 6e19f68

Browse files
committed
Add inspect method for RawValue; add tests
1 parent dd07d91 commit 6e19f68

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

lib/mongoid/extensions/raw_value.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ def initialize(raw_value)
1414
@raw_value = raw_value
1515
end
1616

17-
# Delegate all missing methods to the raw value.
17+
# Returns a string containing a human-readable representation of
18+
# the object, including the inspection of the underlying value.
1819
#
19-
# @param [ String, Symbol ] method_name The name of the method.
20-
# @param [ Array ] args The arguments passed to the method.
21-
ruby2_keywords def method_missing(method_name, *args, &block)
22-
raw_value.send(method_name, *args, &block)
23-
end
24-
25-
# Delegate all missing methods to the raw value.
26-
#
27-
# @param [ String, Symbol ] method_name The name of the method.
28-
# @param [ true | false ] include_private Whether to check private methods.
29-
def respond_to_missing?(method_name, include_private = false)
30-
raw_value.respond_to?(method_name, include_private)
20+
# @return [ String ] The object inspection.
21+
def inspect
22+
"RawValue: #{raw_value.inspect}"
3123
end
3224
end
3325
end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
describe Mongoid::RawValue do
6+
7+
describe "::()" do
8+
subject { Mongoid::RawValue(raw_value).raw_value }
9+
10+
context 'when raw_value is a String' do
11+
let(:raw_value) { 'Hello World!' }
12+
13+
it 'returns the value' do
14+
is_expected.to eq 'Hello World!'
15+
end
16+
end
17+
18+
context 'when raw_value is an Integer' do
19+
let(:raw_value) { 42 }
20+
21+
it 'returns the value' do
22+
is_expected.to eq 42
23+
end
24+
end
25+
end
26+
27+
describe "#raw_value" do
28+
subject { described_class.new(raw_value).raw_value }
29+
30+
context 'when raw_value is a String' do
31+
let(:raw_value) { 'Hello World!' }
32+
33+
it 'returns the value' do
34+
is_expected.to eq 'Hello World!'
35+
end
36+
end
37+
38+
context 'when raw_value is an Integer' do
39+
let(:raw_value) { 42 }
40+
41+
it 'returns the value' do
42+
is_expected.to eq 42
43+
end
44+
end
45+
end
46+
47+
describe "#inspect" do
48+
subject { described_class.new(raw_value).inspect }
49+
50+
context 'when raw_value is a String' do
51+
let(:raw_value) { 'Hello World!' }
52+
53+
it 'returns the inspection' do
54+
is_expected.to eq 'RawValue: "Hello World!"'
55+
end
56+
end
57+
58+
context 'when raw_value is an Integer' do
59+
let(:raw_value) { 42 }
60+
61+
it 'returns the inspection' do
62+
is_expected.to eq 'RawValue: 42'
63+
end
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)