|
3 | 3 | app_require "repositories/story_repository"
|
4 | 4 |
|
5 | 5 | describe StoryRepository do
|
| 6 | + describe '.add' do |
| 7 | + let(:feed) { double(url: 'http://blog.golang.org/feed.atom') } |
| 8 | + before do |
| 9 | + Story.stub(:create) |
| 10 | + end |
| 11 | + |
| 12 | + it 'normalizes story urls' do |
| 13 | + entry = double(url: '//blog.golang.org/context', content: '').as_null_object |
| 14 | + StoryRepository.should receive(:normalize_url).with(entry.url, feed.url) |
| 15 | + |
| 16 | + StoryRepository.add(entry, feed) |
| 17 | + end |
| 18 | + end |
| 19 | + |
6 | 20 | describe ".expand_absolute_urls" do
|
7 | 21 | it "preserves existing absolute urls" do
|
8 | 22 | content = '<a href="http://foo">bar</a>'
|
|
98 | 112 | end
|
99 | 113 | end
|
100 | 114 | end
|
| 115 | + |
| 116 | + describe ".normalize_url" do |
| 117 | + it "resolves scheme-less urls" do |
| 118 | + %w{http https}.each do |scheme| |
| 119 | + feed_url = "#{scheme}://blog.golang.org/feed.atom" |
| 120 | + |
| 121 | + url = StoryRepository.normalize_url("//blog.golang.org/context", feed_url) |
| 122 | + url.should eq "#{scheme}://blog.golang.org/context" |
| 123 | + end |
| 124 | + end |
| 125 | + |
| 126 | + it "leaves urls with a scheme intact" do |
| 127 | + input = 'http://blog.golang.org/context' |
| 128 | + normalized_url = StoryRepository.normalize_url(input, 'http://blog.golang.org/feed.atom') |
| 129 | + normalized_url.should eq(input) |
| 130 | + end |
| 131 | + |
| 132 | + it "falls back to http if the base_url is also sheme less" do |
| 133 | + url = StoryRepository.normalize_url("//blog.golang.org/context", "//blog.golang.org/feed.atom") |
| 134 | + url.should eq 'http://blog.golang.org/context' |
| 135 | + end |
| 136 | + end |
101 | 137 | end
|
0 commit comments