20161124065838_add_templates_to_resolve_url_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. load 'spec/rails_helper.rb'
  2. load File.join('db/migrate', File.basename(__FILE__, '_spec.rb') + '.rb')
  3. describe AddTemplatesToResolveUrl do
  4. let :valid_options do
  5. {
  6. 'name' => "XKCD",
  7. 'expected_update_period_in_days' => "2",
  8. 'type' => "html",
  9. 'url' => "http://xkcd.com",
  10. 'mode' => 'on_change',
  11. 'extract' => {
  12. 'url' => { 'css' => "#comic img", 'value' => "@src" },
  13. 'title' => { 'css' => "#comic img", 'value' => "@alt" },
  14. 'hovertext' => { 'css' => "#comic img", 'value' => "@title" }
  15. }
  16. }
  17. end
  18. let :agent do
  19. Agents::WebsiteAgent.create!(
  20. user: users(:bob),
  21. name: "xkcd",
  22. options: valid_options,
  23. keep_events_for: 2.days
  24. )
  25. end
  26. it 'should add a template for an existing WebsiteAgent with `url`' do
  27. expect(agent.options).not_to include('template')
  28. AddTemplatesToResolveUrl.new.up
  29. agent.reload
  30. expect(agent.options).to include(
  31. 'template' => {
  32. 'url' => '{{ url | to_uri: _response_.url }}'
  33. }
  34. )
  35. end
  36. end