From b5579dfaac79ce943068a13008e01acf9aa99671 Mon Sep 17 00:00:00 2001 From: Elliot Foster Date: Thu, 5 Dec 2013 17:11:47 -0800 Subject: [PATCH 1/5] Fetcher model, for fetching things --- models/fetcher.js | 4 ++++ test/models/fetcher.js | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 models/fetcher.js create mode 100644 test/models/fetcher.js diff --git a/models/fetcher.js b/models/fetcher.js new file mode 100644 index 0000000..1bd22d7 --- /dev/null +++ b/models/fetcher.js @@ -0,0 +1,4 @@ +function Fetcher() { +} + +module.exports = Fetcher; diff --git a/test/models/fetcher.js b/test/models/fetcher.js new file mode 100644 index 0000000..077d187 --- /dev/null +++ b/test/models/fetcher.js @@ -0,0 +1,11 @@ +var models = require('../../models') + , expect = require('chai').expect +; + +describe("Fetcher model", function() { + it("can be instantiated", function() { + var fetcher = new models.fetcher(); + + expect(fetcher).to.be.an.instanceof(models.fetcher); + }); +}); From eb635f510809f6aebd32d907afee979d8fa3ac1e Mon Sep 17 00:00:00 2001 From: Elliot Foster Date: Thu, 5 Dec 2013 18:04:57 -0800 Subject: [PATCH 2/5] Feed#asRequestOptions --- models/Feed.js | 9 +++++++++ test/models/Feed.js | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/models/Feed.js b/models/Feed.js index 85ccfee..1feb8cd 100644 --- a/models/Feed.js +++ b/models/Feed.js @@ -138,6 +138,15 @@ function init(Sequelize, sequelize, name, models) { this.save().done(done); }; + methods.asRequestOptions = function() { + return { + url: this.url + , headers: { + 'Last-Modified': moment(this.last_fetched).format("ddd, DD MMM YYYY HH:mm:ss ZZ") + } + } + }; + var Klass = sequelize.define( name , attrs diff --git a/test/models/Feed.js b/test/models/Feed.js index 7993162..c19aeeb 100644 --- a/test/models/Feed.js +++ b/test/models/Feed.js @@ -427,6 +427,19 @@ describe("Feed model (RDBMS)", function() { }); }); }); + + describe("#asRequestOptions", function() { + it("returns a `request` ready options object", function() { + var options = this.feed.asRequestOptions(); + + expect(options).to.have.keys(['url', 'headers']); + expect(options.url).to.equal('http://example.com/feed_methods'); + expect(options.headers).to.have.keys(['Last-Modified']); + + // This assertion is stupid. The reason for this stupidity is due to timezone differences. + expect(options.headers['Last-Modified']).to.match(/^\w{3}, \d{2} \w{3} \d{4} \d\d:\d\d:\d\d [-+]?\d{4}$/); + }); + }); }); }); From 10ea75582e145e07e3aa6bd66f3bf5fe3f77b026 Mon Sep 17 00:00:00 2001 From: Elliot Foster Date: Thu, 5 Dec 2013 19:24:41 -0800 Subject: [PATCH 3/5] Have a specific testing APP_FQDN --- Makefile | 4 ++-- test/models/Article.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f22c903..7b109a9 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ coverage: GOOGLE_OAUTH_SECRET="test" \ GOOGLE_OAUTH_ID="test" \ GOOGLE_OAUTH_FQDN="test" \ - APP_FQDN="rssmtp.firetaco.com" \ + APP_FQDN="testing-fqdn.rssmtp.example.com" \ APP_SECRET="test" \ APP_SMTP_HOST="smtp.example.com" \ APP_SMTP_PORT="465" \ @@ -29,7 +29,7 @@ test: GOOGLE_OAUTH_SECRET="test" \ GOOGLE_OAUTH_ID="test" \ GOOGLE_OAUTH_FQDN="test" \ - APP_FQDN="rssmtp.firetaco.com" \ + APP_FQDN="testing-fqdn.rssmtp.example.com" \ APP_SECRET="test" \ APP_SMTP_HOST="smtp.example.com" \ APP_SMTP_PORT="465" \ diff --git a/test/models/Article.js b/test/models/Article.js index ed02e84..b34dbad 100644 --- a/test/models/Article.js +++ b/test/models/Article.js @@ -238,7 +238,7 @@ describe("Article model (RDBMS)", function() { "

article title here: with <brackets & such>

", "

article content here, with and &'s

", "

", - "unsubscribe" + "unsubscribe" ].join(''); expect(emailData.bcc).to.have.length(2); @@ -251,9 +251,9 @@ describe("Article model (RDBMS)", function() { , subject: "article title here: with " , date: this.data.date , headers: { - "List-ID": this.feed.id + '.rssmtp.firetaco.com' - , "List-Unsubscribe": 'http://rssmtp.firetaco.com/feed/' + this.feed.id - , "List-Subscribe": 'http://rssmtp.firetaco.com/feed/' + this.feed.id + "List-ID": this.feed.id + '.testing-fqdn.rssmtp.example.com' + , "List-Unsubscribe": 'http://testing-fqdn.rssmtp.example.com/feed/' + this.feed.id + , "List-Subscribe": 'http://testing-fqdn.rssmtp.example.com/feed/' + this.feed.id } , html: expectedHTML , generateTextFromHTML: true From 8a6a7cc949078224f67ce4801df5dd2571979de9 Mon Sep 17 00:00:00 2001 From: Elliot Foster Date: Thu, 5 Dec 2013 19:25:17 -0800 Subject: [PATCH 4/5] Fetcher#updateFeed first pass; non-functional --- models/fetcher.js | 23 ++++++++++++++++ test/models/fetcher.js | 61 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/models/fetcher.js b/models/fetcher.js index 1bd22d7..a82250c 100644 --- a/models/fetcher.js +++ b/models/fetcher.js @@ -1,4 +1,27 @@ +var request = require('request') +; + function Fetcher() { } +Fetcher.prototype.updateFeed = function(feed, done) { + var options = feed.asRequestOptions() + , agent = [ + 'RSSMTP (https://github.com/elliotf/rssmtp; ' + , 'http://', process.env.APP_FQDN + , ')' + ].join(''); + ; + + options = { + headers: { + 'User-Agent': ['RSSMTP (https://github.com/elliotf/rssmtp; http://', process.env.APP_FQDN, ')'].join('') + } + }; + + request.get(options, function(err, whatever){ + done(); + }); +}; + module.exports = Fetcher; diff --git a/test/models/fetcher.js b/test/models/fetcher.js index 077d187..9b8008b 100644 --- a/test/models/fetcher.js +++ b/test/models/fetcher.js @@ -1,11 +1,64 @@ -var models = require('../../models') - , expect = require('chai').expect +var models = require('../../models') + , expect = require('chai').expect + , request = require('request') ; describe("Fetcher model", function() { + beforeEach(function() { + this.fetcher = new models.fetcher(); + + this.fakeHttpErr = null; //{fake: 'HttpErr'}; + this.fakeHttpResponse = {fake: 'HttpResponse'}; + this.fakeHttpBody = [ + '' + , '' + , 'a title' + , '' + ].join(''); + + this.sinon.stub(request, 'get', function(args, done){ + done(this.fakeHttpErr, this.fakeHttpResponse, this.fakeHttpBody); + }.bind(this)); + }); + it("can be instantiated", function() { - var fetcher = new models.fetcher(); + expect(this.fetcher).to.be.an.instanceof(models.fetcher); + }); + + describe("#updateFeed", function() { + beforeEach(function() { + this.feed = models.Feed.build({ + name: 'Feed methods feed' + , url: 'http://example.com/feed_methods' + }); + + this.sinon.stub(this.feed, 'asRequestOptions', function() { + return { + fake: 'requestOptions' + , url: 'http://fakeRequestOptions.example.com' + , headers: { + 'Last-Modified': 'fakeLastModified' + } + } + }); + }); + + it("adds a user agent to the request options", function(done) { + this.fetcher.updateFeed(this.feed, function(err, meta, articles){ + expect(err).to.not.exist; + + expect(this.feed.asRequestOptions).to.have.been.called; + expect(request.get).to.have.been.called; + + var options = request.get.args[0][0]; + + expect(options.headers['User-Agent']).to.exist; + expect(options.headers['User-Agent']).to.contain('RSSMTP'); + expect(options.headers['User-Agent']).to.contain('https://github.com/elliotf/rssmtp'); + expect(options.headers['User-Agent']).to.contain('http://testing-fqdn.rssmtp.example.com'); - expect(fetcher).to.be.an.instanceof(models.fetcher); + done(); + }.bind(this)); + }); }); }); From ad00c277cd1182e629309f82244b392c3dcb1129 Mon Sep 17 00:00:00 2001 From: Elliot Foster Date: Sun, 8 Dec 2013 13:53:59 -0800 Subject: [PATCH 5/5] Don't need to install mongodb anymore But this *should* probably install PostgreSQL? --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7b109a9..db4f9f8 100644 --- a/Makefile +++ b/Makefile @@ -45,13 +45,9 @@ install: # for node.js sudo apt-get -y install python-software-properties sudo add-apt-repository -y ppa:chris-lea/node.js - # for mongodb - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 - sudo sh -c 'echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" > /etc/apt/sources.list.d/10gen.list' # install packages sudo apt-get update - sudo apt-get install -y build-essential mongodb-10gen nodejs + sudo apt-get install -y build-essential nodejs npm install - npm install mongodb --mongodb:native .PHONY: cov coverage dev supper test testwatch