tumblr_likes_agent_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'rails_helper'
  2. describe Agents::TumblrLikesAgent do
  3. before do
  4. allow_any_instance_of(Agents::TumblrLikesAgent).to receive(:tumblr) {
  5. double.tap { |obj|
  6. allow(obj).to receive(:blog_likes).with('wendys.tumblr.com', after: 0) {
  7. JSON.parse File.read(Rails.root.join('spec/data_fixtures/tumblr_likes.json'))
  8. }
  9. allow(obj).to receive(:blog_likes).with('notfound.tumblr.com', after: 0) { { 'status' => 404, 'msg' => 'Not Found' } }
  10. }
  11. }
  12. end
  13. describe 'a blog which returns likes' do
  14. before do
  15. @agent = Agents::TumblrLikesAgent.new(name: "Wendy's Tumblr Likes", options: {
  16. blog_name: 'wendys.tumblr.com',
  17. expected_update_period_in_days: 10
  18. })
  19. @agent.service = services(:generic)
  20. @agent.user = users(:bob)
  21. @agent.save!
  22. end
  23. it 'creates events based on likes' do
  24. expect { @agent.check }.to change { Event.count }.by(20)
  25. end
  26. end
  27. describe 'a blog which returns an error' do
  28. before do
  29. @broken_agent = Agents::TumblrLikesAgent.new(name: "Fake Blog Likes", options: {
  30. blog_name: 'notfound.tumblr.com',
  31. expected_update_period_in_days: 10
  32. })
  33. @broken_agent.user = users(:bob)
  34. @broken_agent.service = services(:generic)
  35. @broken_agent.save!
  36. end
  37. it 'creates an error message when status and msg are returned instead of liked_posts' do
  38. expect { @broken_agent.check }.to change { @broken_agent.logs.count }.by(1)
  39. end
  40. end
  41. end