|
1 | 1 | module Graphiti
|
2 | 2 | class SchemaDiff
|
3 | 3 | def initialize(old, new)
|
4 |
| - @old = old.deep_symbolize_keys |
5 |
| - @new = new.deep_symbolize_keys |
| 4 | + @old = JSON.parse(old.to_json).deep_symbolize_keys |
| 5 | + @new = JSON.parse(new.to_json).deep_symbolize_keys |
6 | 6 | @errors = []
|
7 | 7 | end
|
8 | 8 |
|
@@ -135,12 +135,12 @@ def compare_sorts(old_resource, new_resource)
|
135 | 135 | end
|
136 | 136 |
|
137 | 137 | if new_sort[:only] && !old_sort[:only]
|
138 |
| - @errors << "#{old_resource[:name]}: sort #{name.inspect} now limited to only #{new_sort[:only].inspect}." |
| 138 | + @errors << "#{old_resource[:name]}: sort #{name.inspect} now limited to only #{new_sort[:only].to_sym.inspect}." |
139 | 139 | end
|
140 | 140 |
|
141 | 141 | if new_sort[:only] && old_sort[:only]
|
142 | 142 | if new_sort[:only] != old_sort[:only]
|
143 |
| - @errors << "#{old_resource[:name]}: sort #{name.inspect} was limited to only #{old_sort[:only].inspect}, now limited to only #{new_sort[:only].inspect}." |
| 143 | + @errors << "#{old_resource[:name]}: sort #{name.inspect} was limited to only #{old_sort[:only].to_sym.inspect}, now limited to only #{new_sort[:only].to_sym.inspect}." |
144 | 144 | end
|
145 | 145 | end
|
146 | 146 | end
|
@@ -212,28 +212,30 @@ def compare_filter_group(old_resource, new_resource)
|
212 | 212 | new_names = new_resource[:filter_group][:names]
|
213 | 213 | old_names = old_resource[:filter_group][:names]
|
214 | 214 | diff = new_names - old_names
|
215 |
| - if !diff.empty? && new_resource[:filter_group][:required] == :all |
216 |
| - @errors << "#{old_resource[:name]}: all required filter group #{old_names.inspect} added #{"member".pluralize(diff.length)} #{diff.inspect}." |
| 215 | + if !diff.empty? && new_resource[:filter_group][:required] == "all" |
| 216 | + @errors << "#{old_resource[:name]}: all required filter group #{old_names.map(&:to_sym).inspect} added #{"member".pluralize(diff.length)} #{diff.map(&:to_sym).inspect}." |
217 | 217 | end
|
218 | 218 |
|
219 | 219 | old_required = old_resource[:filter_group][:required]
|
220 | 220 | new_required = new_resource[:filter_group][:required]
|
221 |
| - if old_required == :any && new_required == :all |
222 |
| - @errors << "#{old_resource[:name]}: filter group #{old_names.inspect} moved from required: :any to required: :all" |
| 221 | + if old_required == "any" && new_required == "all" |
| 222 | + @errors << "#{old_resource[:name]}: filter group #{old_names.map(&:to_sym).inspect} moved from required: :any to required: :all" |
223 | 223 | end
|
224 | 224 | else
|
225 |
| - @errors << "#{old_resource[:name]}: filter group #{new_resource[:filter_group][:names].inspect} was added." |
| 225 | + @errors << "#{old_resource[:name]}: filter group #{new_resource[:filter_group][:names].map(&:to_sym).inspect} was added." |
226 | 226 | end
|
227 | 227 | end
|
228 | 228 | end
|
229 | 229 |
|
230 | 230 | def compare_stats(old_resource, new_resource)
|
| 231 | + return unless old_resource.key?(:stats) |
| 232 | + |
231 | 233 | old_resource[:stats].each_pair do |name, old_calculations|
|
232 | 234 | new_calculations = new_resource[:stats][name]
|
233 | 235 | if new_calculations
|
234 | 236 | old_calculations.each do |calc|
|
235 | 237 | unless new_calculations.include?(calc)
|
236 |
| - @errors << "#{old_resource[:name]}: calculation #{calc.inspect} was removed from stat #{name.inspect}." |
| 238 | + @errors << "#{old_resource[:name]}: calculation #{calc.to_sym.inspect} was removed from stat #{name.inspect}." |
237 | 239 | end
|
238 | 240 | end
|
239 | 241 | else
|
|
0 commit comments