|
61 | 61 | end
|
62 | 62 | end
|
63 | 63 |
|
| 64 | + context 'when comparing two instances of an ActiveRecord model that does not have a primary key' do |
| 65 | + it 'produces the correct output' do |
| 66 | + as_both_colored_and_uncolored do |color_enabled| |
| 67 | + snippet = <<~TEST.strip |
| 68 | + actual = SuperDiff::Test::Models::ActiveRecord::TimeSeriesData.new( |
| 69 | + value: 456, |
| 70 | + at: Time.parse('2015-07-04T17:05:37Z'), |
| 71 | + ) |
| 72 | + expected = SuperDiff::Test::Models::ActiveRecord::TimeSeriesData.new( |
| 73 | + value: 123, |
| 74 | + at: Time.parse('2015-07-04T17:05:37Z'), |
| 75 | + ) |
| 76 | + expect(actual).to eq(expected) |
| 77 | + TEST |
| 78 | + program = make_program(snippet, color_enabled: color_enabled) |
| 79 | + |
| 80 | + expected_output = |
| 81 | + build_expected_output( |
| 82 | + color_enabled: color_enabled, |
| 83 | + snippet: 'expect(actual).to eq(expected)', |
| 84 | + newline_before_expectation: true, |
| 85 | + expectation: |
| 86 | + proc do |
| 87 | + line do |
| 88 | + plain 'Expected ' |
| 89 | + actual %(#<SuperDiff::Test::Models::ActiveRecord::TimeSeriesData at: #<Time 2015-07-04 17:05:37 +00:00 (UTC)>, value: 456>) |
| 90 | + end |
| 91 | + |
| 92 | + line do |
| 93 | + plain ' to eq ' |
| 94 | + expected %(#<SuperDiff::Test::Models::ActiveRecord::TimeSeriesData at: #<Time 2015-07-04 17:05:37 +00:00 (UTC)>, value: 123>) |
| 95 | + end |
| 96 | + end |
| 97 | + ) |
| 98 | + |
| 99 | + expect(program).to produce_output_when_run(expected_output).in_color( |
| 100 | + color_enabled |
| 101 | + ) |
| 102 | + end |
| 103 | + end |
| 104 | + end |
| 105 | + |
64 | 106 | context 'when comparing instances of two different ActiveRecord models' do
|
65 | 107 | it 'produces the correct output' do
|
66 | 108 | as_both_colored_and_uncolored do |color_enabled|
|
|
105 | 147 | end
|
106 | 148 | end
|
107 | 149 |
|
| 150 | + context 'when comparing instances of two different ActiveRecord models with one not having a primary key' do |
| 151 | + it 'produces the correct output' do |
| 152 | + as_both_colored_and_uncolored do |color_enabled| |
| 153 | + snippet = <<~TEST.strip |
| 154 | + actual = SuperDiff::Test::Models::ActiveRecord::Person.new( |
| 155 | + name: "Elliot", |
| 156 | + age: 31, |
| 157 | + ) |
| 158 | + expected = SuperDiff::Test::Models::ActiveRecord::TimeSeriesData.new( |
| 159 | + value: 123, |
| 160 | + at: Time.parse('2015-07-04T17:05:37Z'), |
| 161 | + ) |
| 162 | + expect(actual).to eq(expected) |
| 163 | + TEST |
| 164 | + program = make_program(snippet, color_enabled: color_enabled) |
| 165 | + |
| 166 | + expected_output = |
| 167 | + build_expected_output( |
| 168 | + color_enabled: color_enabled, |
| 169 | + snippet: 'expect(actual).to eq(expected)', |
| 170 | + newline_before_expectation: true, |
| 171 | + expectation: |
| 172 | + proc do |
| 173 | + line do |
| 174 | + plain 'Expected ' |
| 175 | + actual %(#<SuperDiff::Test::Models::ActiveRecord::Person person_id: nil, age: 31, name: "Elliot">) |
| 176 | + end |
| 177 | + |
| 178 | + line do |
| 179 | + plain ' to eq ' |
| 180 | + expected %(#<SuperDiff::Test::Models::ActiveRecord::TimeSeriesData at: #<Time 2015-07-04 17:05:37 +00:00 (UTC)>, value: 123>) |
| 181 | + end |
| 182 | + end |
| 183 | + ) |
| 184 | + |
| 185 | + expect(program).to produce_output_when_run(expected_output).in_color( |
| 186 | + color_enabled |
| 187 | + ) |
| 188 | + end |
| 189 | + end |
| 190 | + end |
| 191 | + |
108 | 192 | context 'when comparing an ActiveRecord object with nothing' do
|
109 | 193 | it 'produces the correct output' do
|
110 | 194 | as_both_colored_and_uncolored do |color_enabled|
|
|
0 commit comments