tumblr_likes_agent_spec.rb 1.4 KB

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