|
84 | 84 | end
|
85 | 85 | end
|
86 | 86 | end
|
| 87 | + |
| 88 | + describe "#pretty_inspect" do |
| 89 | + |
| 90 | + context "when not allowing dynamic fields" do |
| 91 | + |
| 92 | + let(:person) do |
| 93 | + Person.new(title: "CEO") |
| 94 | + end |
| 95 | + |
| 96 | + let(:pretty_inspected) do |
| 97 | + person.pretty_inspect |
| 98 | + end |
| 99 | + |
| 100 | + it "includes the model type" do |
| 101 | + expect(pretty_inspected).to include("#<Person") |
| 102 | + end |
| 103 | + |
| 104 | + it "displays the id" do |
| 105 | + expect(pretty_inspected).to include("_id: #{person.id}") |
| 106 | + end |
| 107 | + |
| 108 | + it "displays defined fields" do |
| 109 | + expect(pretty_inspected).to include(%q,title: "CEO",) |
| 110 | + end |
| 111 | + |
| 112 | + it "displays field aliases" do |
| 113 | + expect(pretty_inspected).to include("t(test):") |
| 114 | + end |
| 115 | + |
| 116 | + it "displays the default discriminator key" do |
| 117 | + expect(pretty_inspected).to include(%q,_type: "Person",) |
| 118 | + end |
| 119 | + end |
| 120 | + |
| 121 | + context "when using a custom discriminator key" do |
| 122 | + |
| 123 | + before do |
| 124 | + Person.discriminator_key = "dkey" |
| 125 | + end |
| 126 | + |
| 127 | + after do |
| 128 | + Person.discriminator_key = nil |
| 129 | + end |
| 130 | + |
| 131 | + let(:person) do |
| 132 | + Person.new(title: "CEO") |
| 133 | + end |
| 134 | + |
| 135 | + let(:pretty_inspected) do |
| 136 | + person.pretty_inspect |
| 137 | + end |
| 138 | + |
| 139 | + it "displays the new discriminator key" do |
| 140 | + expect(pretty_inspected).to include(%q,dkey: "Person",) |
| 141 | + end |
| 142 | + end |
| 143 | + |
| 144 | + context "when allowing dynamic fields" do |
| 145 | + |
| 146 | + let(:person) do |
| 147 | + Person.new(title: "CEO", some_attribute: "foo") |
| 148 | + end |
| 149 | + |
| 150 | + let(:pretty_inspected) do |
| 151 | + person.pretty_inspect |
| 152 | + end |
| 153 | + |
| 154 | + it "includes dynamic attributes" do |
| 155 | + expect(pretty_inspected).to include(%q,some_attribute: "foo",) |
| 156 | + end |
| 157 | + end |
| 158 | + |
| 159 | + context 'when id is unaliased' do |
| 160 | + let(:shirt) { Shirt.new(id: 1, _id: 2) } |
| 161 | + |
| 162 | + it 'shows the correct _id and id values' do |
| 163 | + shirt.pretty_inspect.should == "#<Shirt _id: 2, color: nil, id: \"1\">\n" |
| 164 | + end |
| 165 | + end |
| 166 | + end |
87 | 167 | end
|
0 commit comments