issue_1905_exchange_login_from_remote_id_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. require 'rails_helper'
  2. RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
  3. let(:backend) { ::Import::Exchange }
  4. it 'removes :item_id from attributes' do
  5. invalid_config = {
  6. attributes: {
  7. item_id: 'login',
  8. some: 'other',
  9. }
  10. }
  11. valid_config = ActiveSupport::HashWithIndifferentAccess.new(
  12. attributes: {
  13. some: 'other',
  14. }
  15. )
  16. expect(backend).to receive(:config).and_return(invalid_config) # rubocop:disable RSpec/StubbedMock
  17. allow(backend).to receive(:config).and_call_original
  18. migrate
  19. expect(backend.config).to eq(valid_config)
  20. end
  21. context 'no changes' do
  22. it 'performs no action for new systems', system_init_done: false do
  23. expect(backend).not_to receive(:config)
  24. migrate
  25. end
  26. shared_examples 'irrelevant config' do
  27. it 'does not change the config' do
  28. allow(backend).to receive(:config).and_return(config)
  29. expect(backend).not_to receive(:config=)
  30. migrate
  31. end
  32. end
  33. context 'blank config' do
  34. let(:config) { nil }
  35. it_behaves_like 'irrelevant config'
  36. end
  37. context 'blank attributes' do
  38. let(:config) do
  39. {
  40. some: 'config'
  41. }
  42. end
  43. it_behaves_like 'irrelevant config'
  44. end
  45. context 'blank attribute :item_id' do
  46. let(:config) do
  47. {
  48. attributes: {
  49. some: 'mapping'
  50. }
  51. }
  52. end
  53. it_behaves_like 'irrelevant config'
  54. end
  55. context 'attribute :item_id not mapping to login' do
  56. let(:config) do
  57. {
  58. attributes: {
  59. item_id: 'other_local_attribute'
  60. }
  61. }
  62. end
  63. it_behaves_like 'irrelevant config'
  64. end
  65. end
  66. end