apdm 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +4 -0
  5. data/README.md +223 -0
  6. data/Rakefile +1 -0
  7. data/apdm.gemspec +34 -0
  8. data/bin/apdm +6 -0
  9. data/features/ad_tech.feature +11 -0
  10. data/features/step_definitions/ad_tech_steps.rb +19 -0
  11. data/features/support/env.rb +5 -0
  12. data/fixtures/approvals/ad_tech_loader_scripts.approved.txt +42 -0
  13. data/fixtures/approvals/ad_tech_placeholders.approved.txt +6 -0
  14. data/lib/apdm.rb +24 -0
  15. data/lib/apdm/ad_tech.rb +96 -0
  16. data/lib/apdm/ad_tech/ad_loader.rb +67 -0
  17. data/lib/apdm/ad_tech/ads.csv +475 -0
  18. data/lib/apdm/ad_tech/data.rb +47 -0
  19. data/lib/apdm/channel.rb +87 -0
  20. data/lib/apdm/channels.rb +569 -0
  21. data/lib/apdm/credentials.rb +26 -0
  22. data/lib/apdm/design_elements.rb +60 -0
  23. data/lib/apdm/design_elements/api.rb +75 -0
  24. data/lib/apdm/feed.rb +65 -0
  25. data/lib/apdm/issues.rb +14 -0
  26. data/lib/apdm/issues/aasavis.rb +51 -0
  27. data/lib/apdm/issues/amta.rb +253 -0
  28. data/lib/apdm/issues/an.rb +302 -0
  29. data/lib/apdm/issues/auraavis.rb +154 -0
  30. data/lib/apdm/issues/austagderblad.rb +154 -0
  31. data/lib/apdm/issues/avisa-hordaland.rb +154 -0
  32. data/lib/apdm/issues/avisa-valdres.rb +177 -0
  33. data/lib/apdm/issues/ba.rb +352 -0
  34. data/lib/apdm/issues/bladet.rb +154 -0
  35. data/lib/apdm/issues/blv.rb +254 -0
  36. data/lib/apdm/issues/bygdeposten.rb +154 -0
  37. data/lib/apdm/issues/demokraten.rb +154 -0
  38. data/lib/apdm/issues/eikerbladet.rb +409 -0
  39. data/lib/apdm/issues/enebakkavis.rb +51 -0
  40. data/lib/apdm/issues/etl.rb +79 -0
  41. data/lib/apdm/issues/eub.rb +254 -0
  42. data/lib/apdm/issues/finnmarkdagblad.rb +302 -0
  43. data/lib/apdm/issues/finnmarken.rb +302 -0
  44. data/lib/apdm/issues/firda.rb +302 -0
  45. data/lib/apdm/issues/firdaposten.rb +153 -0
  46. data/lib/apdm/issues/fremover.rb +304 -0
  47. data/lib/apdm/issues/gd.rb +304 -0
  48. data/lib/apdm/issues/glomdalen.rb +302 -0
  49. data/lib/apdm/issues/ha-halden.rb +302 -0
  50. data/lib/apdm/issues/hadeland.rb +251 -0
  51. data/lib/apdm/issues/hardanger-folkeblad.rb +151 -0
  52. data/lib/apdm/issues/helgeland-arbeiderblad.rb +304 -0
  53. data/lib/apdm/issues/import.csv +12821 -0
  54. data/lib/apdm/issues/indre.rb +151 -0
  55. data/lib/apdm/issues/jarlsbergavis.rb +154 -0
  56. data/lib/apdm/issues/kvinnheringen.rb +202 -0
  57. data/lib/apdm/issues/lofot-tidende.rb +102 -0
  58. data/lib/apdm/issues/lofotposten.rb +304 -0
  59. data/lib/apdm/issues/mb.rb +103 -0
  60. data/lib/apdm/issues/namdalsavisa.rb +302 -0
  61. data/lib/apdm/issues/nordhordland.rb +103 -0
  62. data/lib/apdm/issues/nordlys.rb +304 -0
  63. data/lib/apdm/issues/oa.rb +302 -0
  64. data/lib/apdm/issues/op.rb +304 -0
  65. data/lib/apdm/issues/opdalingen.rb +150 -0
  66. data/lib/apdm/issues/oyene.rb +51 -0
  67. data/lib/apdm/issues/pd.rb +254 -0
  68. data/lib/apdm/issues/r-a.rb +152 -0
  69. data/lib/apdm/issues/ranablad.rb +304 -0
  70. data/lib/apdm/issues/rb.rb +302 -0
  71. data/lib/apdm/issues/retten.rb +151 -0
  72. data/lib/apdm/issues/ringblad.rb +304 -0
  73. data/lib/apdm/issues/rogalandsavis.rb +302 -0
  74. data/lib/apdm/issues/sa.rb +304 -0
  75. data/lib/apdm/issues/smaalenene.rb +304 -0
  76. data/lib/apdm/issues/sognavis.rb +254 -0
  77. data/lib/apdm/issues/ta.rb +304 -0
  78. data/lib/apdm/issues/tk.rb +304 -0
  79. data/lib/apdm/issues/tvedestrandsposten.rb +150 -0
  80. data/lib/apdm/issues/vestbyavis.rb +51 -0
  81. data/lib/apdm/local_paper_area.rb +21 -0
  82. data/lib/apdm/network.rb +49 -0
  83. data/lib/apdm/null_cache.rb +15 -0
  84. data/lib/apdm/origo.rb +46 -0
  85. data/lib/apdm/saxo.rb +58 -0
  86. data/lib/apdm/saxo/iptc.rb +69 -0
  87. data/lib/apdm/saxo/metadata.rb +36 -0
  88. data/lib/apdm/saxo/remote.rb +67 -0
  89. data/lib/apdm/sinatra.rb +85 -0
  90. data/lib/apdm/version.rb +3 -0
  91. data/lib/cli.rb +12 -0
  92. data/spec/ad_tech/ad_loader_spec.rb +27 -0
  93. data/spec/ad_tech/data_spec.rb +14 -0
  94. data/spec/ad_tech_spec.rb +70 -0
  95. data/spec/approvals_helper.rb +6 -0
  96. data/spec/channel_spec.rb +91 -0
  97. data/spec/channels_spec.rb +9 -0
  98. data/spec/credentials_integration_spec.rb +13 -0
  99. data/spec/credentials_spec.rb +34 -0
  100. data/spec/design_elements_spec.rb +132 -0
  101. data/spec/feed_spec.rb +49 -0
  102. data/spec/fixtures/ad_tech.csv +6 -0
  103. data/spec/fixtures/approvals/adtech/ad_loader.approved.txt +9 -0
  104. data/spec/fixtures/approvals/apdm_adtech/data/handles_artikkelboard.approved.txt +10 -0
  105. data/spec/fixtures/approvals/apdm_adtech/data/handles_bunnbanner.approved.txt +10 -0
  106. data/spec/fixtures/approvals/apdm_adtech/data/handles_skyskraper_1.approved.txt +10 -0
  107. data/spec/fixtures/approvals/apdm_adtech/data/handles_toppbanner.approved.txt +10 -0
  108. data/spec/fixtures/approvals/apdm_adtech/data/is_ok_with_new_bandwagon_data.approved.txt +10 -0
  109. data/spec/fixtures/approvals/apdm_adtech/data/loads_default_data.approved.txt +10 -0
  110. data/spec/fixtures/approvals/apdm_designelements/css/via_api.approved.txt +23 -0
  111. data/spec/fixtures/approvals/apdm_designelements/footer_html/via_api.approved.html +85 -0
  112. data/spec/fixtures/approvals/apdm_designelements/header_html/via_api.approved.html +40 -0
  113. data/spec/fixtures/approvals/apdm_designelements/tracking_scripts/api/keyword.approved.txt +54 -0
  114. data/spec/fixtures/approvals/apdm_designelements/tracking_scripts/api/placeholder.approved.txt +54 -0
  115. data/spec/fixtures/issues.csv +3 -0
  116. data/spec/fixtures/test.jpg +0 -0
  117. data/spec/fixtures/vcr_cassettes/apdm_credentials.yml +44 -0
  118. data/spec/fixtures/vcr_cassettes/css.yml +5588 -0
  119. data/spec/fixtures/vcr_cassettes/footer-html.yml +178 -0
  120. data/spec/fixtures/vcr_cassettes/header-html.yml +132 -0
  121. data/spec/fixtures/vcr_cassettes/origo_someone_credentials.yml +43 -0
  122. data/spec/fixtures/vcr_cassettes/origo_westerdal_credentials.yml +56 -0
  123. data/spec/fixtures/vcr_cassettes/site_stat.yml +172 -0
  124. data/spec/fixtures/vcr_cassettes/site_stat_custom_category.yml +172 -0
  125. data/spec/geo_spec.rb +10 -0
  126. data/spec/issues_etl_spec.rb +41 -0
  127. data/spec/mockcached.rb +36 -0
  128. data/spec/network_spec.rb +43 -0
  129. data/spec/null_cache_spec.rb +29 -0
  130. data/spec/origo_spec.rb +24 -0
  131. data/spec/saxo/iptc_spec.rb +105 -0
  132. data/spec/saxo/metadata_spec.rb +79 -0
  133. data/spec/saxo/remote_spec.rb +71 -0
  134. data/spec/saxo/saxo_spec.rb +82 -0
  135. data/spec/spec_helper.rb +22 -0
  136. data/spec/vcr_helper.rb +6 -0
  137. data/test/fixtures/config-example.yml +6 -0
  138. data/test/saxo/acceptance_spec.rb +109 -0
  139. metadata +427 -0
@@ -0,0 +1,3 @@
1
+ module APDM
2
+ VERSION = "0.0.15"
3
+ end
@@ -0,0 +1,12 @@
1
+ module APDM
2
+
3
+ class CLI < Thor
4
+
5
+ desc "import_issues", "Import publication dates from csv file"
6
+ def import_issues
7
+ require_relative './apdm/issues/etl'
8
+ APDM::Issues::ETL.import './lib/apdm/issues/import.csv'
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'approvals_helper'
2
+ require 'apdm/ad_tech/ad_loader'
3
+
4
+ describe 'adtech' do
5
+ let(:options) do
6
+ {
7
+ :key => :banner,
8
+ :context_key => 'awesome-app',
9
+ :channel_name => 'Avisnavn',
10
+ :placement_id => 987,
11
+ :placement_name => "Origo Bunnbanner 980x150",
12
+ :creative_size_id => 10101,
13
+ :height => 150,
14
+ :width => 980,
15
+ :dimensions_id => 1744,
16
+ :group_id => 1234567890
17
+ }
18
+ end
19
+
20
+ subject { APDM::AdTech::AdLoader.new(options) }
21
+
22
+ specify "ad loader" do
23
+ verify { subject }
24
+ end
25
+
26
+ its(:key) { should eq(:banner) }
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'csv'
2
+ require 'apdm/ad_tech/data'
3
+
4
+ describe APDM::AdTech::Data do
5
+
6
+ let(:data) { APDM::AdTech::Data.new('spec/fixtures/ad_tech.csv') }
7
+ let(:channel) { stub(:ad_tech_id => 1112306) }
8
+
9
+ specify "#for(channel)" do
10
+ expected = {:ad_tech_id=>1112306, :channel_name=>"Origin - Avisnavn", :placement_id=>4195700, :placement_name=>"Origo-Toppbanner-980 x 150", :height=>150, :width=>980, :key=>:toppbanner, :dimensions_id=>"1744"}
11
+ data.for(channel)[:toppbanner].should eq(expected)
12
+ end
13
+
14
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ require 'approvals_helper'
3
+ require 'apdm/network'
4
+ require 'apdm/channel'
5
+ require 'apdm/channels'
6
+ require 'apdm/ad_tech'
7
+
8
+ describe APDM::AdTech do
9
+ let(:avisnavn) { APDM::Channel.find('avisnavn') }
10
+
11
+ it "defaults to the production data" do
12
+ APDM::AdTech.path_to_csv_file = nil
13
+ APDM::AdTech.path_to_csv_file.should match(/lib\/apdm\/ad_tech\/ads.csv$/)
14
+ end
15
+
16
+ context "data" do
17
+ before(:each) do
18
+ APDM::AdTech.path_to_csv_file = 'spec/fixtures/ad_tech.csv'
19
+ APDM::AdTech.load
20
+ end
21
+
22
+ it "loads default data" do
23
+ APDM::AdTech.data = nil
24
+ verify :format => :hash do
25
+ APDM::AdTech.data.for(avisnavn)[:toppbanner]
26
+ end
27
+ end
28
+
29
+ it "is ok with new bandwagon data" do
30
+ APDM::AdTech.data = nil
31
+ verify :format => :hash do
32
+ APDM::AdTech.data.for(avisnavn)[:artikkelboard_lokal]
33
+ end
34
+ end
35
+
36
+ APDM::AdTech::FORMATS.each do |format|
37
+ it "handles #{format}" do
38
+ verify :format => :hash do
39
+ APDM::AdTech.new(avisnavn).data[format]
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ it "creates unique group id" do
46
+ group_ids = []
47
+ 10.times do
48
+ group_ids << APDM::AdTech.new(stub, :data => stub).group_id
49
+ end
50
+ group_ids.uniq.size.should eq(10)
51
+ end
52
+
53
+ describe "context key" do
54
+ subject { APDM::AdTech.new(stub(:channel), :data => stub, :context_key => 'magic') }
55
+
56
+ it "uses what is passed in" do
57
+ subject.context_key.should eq('magic')
58
+ end
59
+
60
+ it "optionally takes a refinement to the context key" do
61
+ subject.context_key('unicorn').should eq('magic+unicorn')
62
+ end
63
+
64
+ # Eeeeew.
65
+ it "passes the refined key to the loader" do
66
+ subject.should_receive(:data_for).with(:thing, :local_context => 'unicorn') { {} }
67
+ subject.slot(:thing, :local_context => 'unicorn')
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ require 'approvals'
2
+ require 'approvals/rspec'
3
+
4
+ Approvals.configure do |c|
5
+ c.approvals_path = 'spec/fixtures/approvals/'
6
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'apdm/design_elements'
3
+ require 'apdm/channel'
4
+ require 'apdm/network'
5
+ require 'apdm/channels'
6
+
7
+ describe APDM::Channel do
8
+ describe "finders" do
9
+
10
+ specify ".all" do
11
+ APDM::Channel.all.map(&:label).should eq(APDM::CHANNELS.map(&:label))
12
+ end
13
+
14
+ specify ".find(label)" do
15
+ APDM::Channel.find('ba').domain.should eq("ba.no")
16
+ end
17
+
18
+ specify ".find(url)" do
19
+ APDM::Channel.find('ba.no').domain.should eq("ba.no")
20
+ end
21
+
22
+ specify ".find('nosuch')" do
23
+ APDM::Channel.find('nosuch').should == nil
24
+ end
25
+
26
+ specify ".find_by_url" do
27
+ APDM::Channel.find_by_url('http://www.ba.no').domain.should eq("ba.no")
28
+ end
29
+
30
+ specify ".find_by_domain is deprecated" do
31
+ APDM::Channel.find_by_domain('http://www.ba.no').domain.should eq("ba.no")
32
+ end
33
+
34
+ specify ".find_by_ad_tech_id" do
35
+ APDM::Channel.find_by_ad_tech_id(1112306).label.should eq('avisnavn')
36
+ end
37
+
38
+ specify ".find_by_ad_tech_id(some_string)" do
39
+ APDM::Channel.find_by_ad_tech_id("1112306").label.should eq('avisnavn')
40
+ end
41
+ end
42
+
43
+ describe "basic attributes" do
44
+ let(:attributes) do
45
+ {
46
+ :label => 'avisnavn',
47
+ :name => 'Avisnavn',
48
+ :origo_sandbox_id => 1,
49
+ :abbreviation => 'TeSt',
50
+ :payment_account => '123',
51
+ :locale => :en,
52
+ :ad_tech_id => 246
53
+ }
54
+ end
55
+ subject { APDM::Channel.new(attributes) }
56
+
57
+ describe "#==" do
58
+ it "is equal to itself" do
59
+ APDM::Channel.new(attributes).should == APDM::Channel.new(attributes)
60
+ end
61
+ end
62
+
63
+ its(:label) { should eq('avisnavn') }
64
+ its(:name) { should eq('Avisnavn') }
65
+ its(:domain) { should eq('avisnavn.no') }
66
+ its(:hostname) { should eq('www.avisnavn.no') }
67
+ its(:homepage) { should eq('http://www.avisnavn.no') }
68
+ its(:abbreviation) { should eq('test') }
69
+ its(:locale) { should eq(:en) }
70
+ its(:logo_src) { should eq('http://r.api.no/local/v3/publications/www.avisnavn.no/gfx/normal_logo.gif') }
71
+ its(:low_res_logo_src) { should eq('http://r.api.no/local/v3/publications/www.avisnavn.no/gfx/lav_logo.gif') }
72
+ its(:ad_tech_id) { should eq(246) }
73
+ its(:origo_sandbox_id) { should eq(1) }
74
+
75
+ describe "saxo configuration" do
76
+ before :each do
77
+ APDM.stub(:saxo_server) { {:server=>"ftp.example.com", :username=>"user", :password=>"pass"} }
78
+ end
79
+
80
+ its(:saxo_config) { should eq({:server => 'ftp.example.com', :username => 'user', :password => 'pass', :remote_dir => 'TEST'}) }
81
+ end
82
+
83
+ describe "payment configuration" do
84
+ before :each do
85
+ APDM.stub(:merchant_account) { {:id => '987', :key1 => 'key1', :key2 => 'key2'} }
86
+ end
87
+
88
+ its(:payment_config) { should eq(:id => '987', :key1 => 'key1', :key2 => 'key2', :account => '123') }
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,9 @@
1
+ require 'apdm/channel'
2
+ require 'apdm/network'
3
+ require 'apdm/channels'
4
+
5
+ describe APDM::CHANNELS do
6
+ specify "with saxo dirs" do
7
+ # APDM::CHANNELS.reject {|c| c.saxo_dir}.map {|c| c.name }.inspect
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'apdm/credentials'
2
+ require 'apdm/origo'
3
+ require 'vcr_helper'
4
+
5
+ describe APDM::Credentials do
6
+ let(:kveim) { 3330 }
7
+
8
+ it "works" do
9
+ VCR.use_cassette('apdm.credentials') do
10
+ APDM::Credentials.for(kveim).authorized?.should == true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ require 'apdm/credentials'
2
+ require 'apdm/origo'
3
+
4
+ describe APDM::Credentials do
5
+
6
+ describe "wiring" do
7
+
8
+ specify "fetching credentials" do
9
+ APDM::Origo.should_receive(:fetch_credentials).with(13).and_return :whatever
10
+ APDM::Credentials.should_receive(:new).with(:whatever)
11
+ APDM::Credentials.for(13)
12
+ end
13
+
14
+ end
15
+
16
+ context "status" do
17
+
18
+ let(:with_authorization) {
19
+ {"organization" => {"id" => 42, "title" => "A Localpaper"}, "privileged" => nil, "role" => "writer", "authorized" => true}
20
+ }
21
+
22
+ let(:no_authorization) {
23
+ # don't be fooled by a privilege bit
24
+ {"organization" => {"id" => 42, "title" => "A Localpaper"}, "privileged" => true, "role" => "writer", "authorized" => false}
25
+ }
26
+
27
+ specify { APDM::Credentials.new([]).authorized?.should == false }
28
+ specify { APDM::Credentials.new([no_authorization]).authorized?.should == false }
29
+ specify { APDM::Credentials.new([with_authorization]).authorized?.should == true }
30
+ specify { APDM::Credentials.new([no_authorization, with_authorization]).authorized?.should == true }
31
+
32
+ end
33
+ end
34
+
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+ require 'approvals_helper'
3
+ require 'vcr_helper'
4
+ require 'apdm'
5
+
6
+ describe APDM::DesignElements do
7
+ it "defaults to v4" do
8
+ APDM::DesignElements::VERSION.should eq(4)
9
+ end
10
+
11
+ it "delivers the host with v3, strangely enough" do
12
+ APDM::DesignElements::HOST.should eq('http://r.api.no/local/v3/publications/')
13
+ end
14
+
15
+ let(:cache) { stub(:cache, :get => nil, :set => nil) }
16
+
17
+ before(:each) do
18
+ APDM.cache = cache
19
+ end
20
+
21
+ subject { APDM::DesignElements.new('avisnavn', :api_key => 'automated-test-key') }
22
+
23
+ its(:api_key) { should eq('automated-test-key') }
24
+
25
+ it "has a channel" do
26
+ subject.channel.homepage.should eq('http://www.avisnavn.no')
27
+ end
28
+
29
+ context "header html" do
30
+ specify "via api" do
31
+ verify :format => :html do
32
+ VCR.use_cassette('header-html') do
33
+ subject.header
34
+ end
35
+ end
36
+ end
37
+
38
+ it "caches" do
39
+ api = stub(:api, :fetch_html => 'the html')
40
+ subject.stub(:api => api)
41
+
42
+ cache.should_receive(:set).with('api.header.avisnavn', 'the html', 86400)
43
+ subject.header
44
+ end
45
+
46
+ it "fetches from cache" do
47
+ cache.should_receive(:get).with('api.header.avisnavn').and_return 'stuff'
48
+ subject.header
49
+ end
50
+ end
51
+
52
+ context "footer html" do
53
+ specify "via api" do
54
+ verify :format => :html do
55
+ VCR.use_cassette('footer-html') do
56
+ subject.footer
57
+ end
58
+ end
59
+ end
60
+
61
+ it "caches" do
62
+ api = stub(:api, :fetch_html => 'the html')
63
+ subject.stub(:api => api)
64
+
65
+ cache.should_receive(:set).with('api.footer.avisnavn', 'the html', 86400)
66
+ subject.footer
67
+ end
68
+
69
+ it "fetches from cache" do
70
+ cache.should_receive(:get).with('api.footer.avisnavn').and_return 'stuff'
71
+ subject.footer
72
+ end
73
+ end
74
+
75
+ context "css" do
76
+ specify "via api" do
77
+ verify do
78
+ VCR.use_cassette('css') do
79
+ subject.css
80
+ end
81
+ end
82
+ end
83
+
84
+ it "caches" do
85
+ api = stub(:api, :fetch_css=> 'the css')
86
+ subject.stub(:api => api)
87
+
88
+ cache.should_receive(:set).with('api.css.avisnavn', 'the css', 86400)
89
+ subject.css
90
+ end
91
+
92
+ it "fetches from cache" do
93
+ cache.should_receive(:get).with('api.css.avisnavn').and_return 'stuff'
94
+ subject.css
95
+ end
96
+ end
97
+
98
+ context "tracking scripts" do
99
+
100
+ context "api" do
101
+ specify "placeholder" do
102
+ verify do
103
+ VCR.use_cassette('site_stat') do
104
+ subject.site_stat
105
+ end
106
+ end
107
+ end
108
+
109
+ specify "keyword" do
110
+ verify do
111
+ VCR.use_cassette('site_stat_custom_category') do
112
+ subject.site_stat('awesomesauce')
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ it "caches" do
119
+ api = stub(:api, :fetch_site_stat => 'the awesomesauce tracking script')
120
+ subject.stub(:api => api)
121
+
122
+ cache.should_receive(:set).with('api.site_stat.awesomesauce.avisnavn', 'the awesomesauce tracking script', 86400)
123
+ subject.site_stat('awesomesauce')
124
+ end
125
+
126
+ it "fetches from cache" do
127
+ cache.should_receive(:get).with('api.site_stat.awesomesauce.avisnavn').and_return 'stuff'
128
+ subject.site_stat('awesomesauce')
129
+ end
130
+ end
131
+
132
+ end
@@ -0,0 +1,49 @@
1
+ require 'mockcached'
2
+ require 'apdm'
3
+
4
+ describe APDM::Feed do
5
+
6
+ let(:test_channel) { APDM::Channel.find("firda") }
7
+
8
+ before(:each) do
9
+ APDM.cache = Mockcached.new
10
+ end
11
+
12
+ subject { APDM::Feed.new(test_channel) }
13
+
14
+ it "can fetch a feed" do
15
+ entries = subject.fetch
16
+ entries.first["url"].should_not be_nil
17
+ entries.first["published"].should_not be_nil
18
+ end
19
+
20
+ it "can fetch a feed with extra url parameters" do
21
+ entries = subject.fetch({"amount" => "2"})
22
+ entries.count.should eq 2
23
+ end
24
+
25
+ it "returns an error code if the request is messed up" do
26
+ entries = subject.fetch({"sectionId" => "no_such_section_could_possibly_exist"})
27
+ entries.should eq nil
28
+ end
29
+
30
+ describe "cache keys" do
31
+ specify do
32
+ options1 = {:one => 1, :two => 2}
33
+ options2 = {:two => 2, :one => 1}
34
+ key1 = subject.cache_key(options1)
35
+ key2 = subject.cache_key(options2)
36
+ key1.should eq(key2)
37
+ end
38
+
39
+ specify do
40
+ options1 = {:one => 1, :two => 2}
41
+ options2 = {:two => 2, :one => "uno"}
42
+ key1 = subject.cache_key(options1)
43
+ key2 = subject.cache_key(options2)
44
+ [key1, key2].uniq.size.should eq(2)
45
+ end
46
+
47
+ end
48
+
49
+ end