twitter_sync_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. require 'rails_helper'
  2. RSpec.describe TwitterSync do
  3. subject(:twitter_sync) { described_class.new(channel.options[:auth]) }
  4. let(:channel) { create(:twitter_channel) }
  5. describe '.preferences_cleanup' do
  6. shared_examples 'for normalizing input' do
  7. it 'is converted (from bare hash)' do
  8. expect(described_class.preferences_cleanup(raw_preferences)).to include(clean_preferences)
  9. end
  10. it 'is converted (from article.preferences hash)' do
  11. expect(described_class.preferences_cleanup(twitter: raw_preferences)).to match({ twitter: hash_including(clean_preferences) })
  12. end
  13. end
  14. describe ':geo key' do
  15. context 'when absent' do
  16. let(:raw_preferences) { {} }
  17. let(:clean_preferences) { { geo: {} } }
  18. include_examples 'for normalizing input'
  19. end
  20. context 'when instance_of(Twitter::NullOjbect)' do
  21. let(:raw_preferences) { { geo: Twitter::NullObject.new } }
  22. let(:clean_preferences) { { geo: {} } }
  23. include_examples 'for normalizing input'
  24. end
  25. context 'when instance_of(Twitter::Geo.new)' do
  26. let(:raw_preferences) { { geo: Twitter::Geo.new(coordinates: [1, 1]) } }
  27. let(:clean_preferences) { { geo: { coordinates: [1, 1] } } }
  28. include_examples 'for normalizing input'
  29. end
  30. end
  31. describe ':place key' do
  32. context 'when absent' do
  33. let(:raw_preferences) { {} }
  34. let(:clean_preferences) { { place: {} } }
  35. include_examples 'for normalizing input'
  36. end
  37. context 'when instance_of(Twitter::NullOjbect)' do
  38. let(:raw_preferences) { { place: Twitter::NullObject.new } }
  39. let(:clean_preferences) { { place: {} } }
  40. include_examples 'for normalizing input'
  41. end
  42. context 'when instance_of(Twitter::Place.new)' do
  43. let(:raw_preferences) { { place: Twitter::Place.new({ country: 'da', name: 'do', woeid: 1, id: 1 }) } }
  44. let(:clean_preferences) { { place: { country: 'da', name: 'do', woeid: 1, id: 1 } } }
  45. include_examples 'for normalizing input'
  46. end
  47. end
  48. describe ':mention_ids key' do
  49. let(:raw_preferences) { { mention_ids: [1_234_567_890] } }
  50. let(:clean_preferences) { { mention_ids: [1_234_567_890] } }
  51. include_examples 'for normalizing input'
  52. end
  53. end
  54. end