Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Update parts of the link spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Nov 8, 2014
1 parent a44b324 commit 92c2603
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/redditkit/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def image_link?
end

def permalink
@permalink ||= URI.join('http://reddit.com', URI.encode(@attributes[:permalink])).to_s
@permalink ||= URI.join('http://www.reddit.com', URI.encode(@attributes[:permalink])).to_s
end

# Returns the short URL for a link.
Expand Down
43 changes: 33 additions & 10 deletions spec/redditkit/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'spec_helper'

describe RedditKit::Link do

before :all do
attributes = { :data => { :id => '12345', :title => "&", :url => 'http://example.com/test.png', :permalink => 'permalink', :created_utc => Time.now.to_i } }
@link = RedditKit::Link.new attributes
Expand All @@ -19,7 +18,7 @@
end

it "decodes HTML entities in link titles" do
expect(@link.title).to eq '&'
expect(@link.title).to eq '&'
end

it "decodes HTML entities in link URLs" do
Expand All @@ -34,19 +33,43 @@
expect(@old_link.showing_link_score?).to be true
end

it "determines whether the link has an image extension" do
expect(@link.image_link?).to be true
describe 'image_link?' do
it 'returns true if the link has an image extension' do
attributes = { :data => { :id => '12345', :url => 'http://example.com/test.png' } }
link = RedditKit::Link.new attributes

expect(link.image_link?).to be_truthy
end

it 'returns false if the link does not have an image extension' do
attributes = { :data => { :id => '12345', :url => 'http://example.com/' } }
link = RedditKit::Link.new attributes

expect(link.image_link?).to be_falsy
end
end

it "returns the link's permalink" do
expect(@link.permalink).to eq 'http://reddit.com/permalink'
describe 'permalink' do
it "returns the link's permalink" do
attributes = { :data => { :id => '12345', :title => 'Permalink', :url => 'http://example.com/test.png', :permalink => 'permalink', :created_utc => Time.now.to_i } }
link = RedditKit::Link.new attributes

expect(link.permalink).to eq 'http://www.reddit.com/permalink'
end

it 'does not allow duplicate forward slashes' do
attributes = { :data => { :id => '12345', :title => 'Permalink', :url => 'http://example.com/test.png', :permalink => '/r/technology/comments/2lndtl/pirate_bay_is_still_online_even_though_all_of_its/', :created_utc => Time.now.to_i } }
link = RedditKit::Link.new attributes

expect(link.permalink).to eq 'http://www.reddit.com/r/technology/comments/2lndtl/pirate_bay_is_still_online_even_though_all_of_its/'
end

it "returns the link's encoded permalink" do
expect(@link_with_unicode.permalink).to eq 'http://www.reddit.com/%EC%9D%B4%EA%B2%83%EC%9D%80_%EC%9B%B9_%ED%8E%98%EC%9D%B4%EC%A7%80%EC%9E%85%EB%8B%88'
end
end

it "returns the link's short URL" do
expect(@link.short_link).to eq 'http://redd.it/12345'
end

it "returns the link's encoded permalink" do
expect(@link_with_unicode.permalink).to eq 'http://reddit.com/%EC%9D%B4%EA%B2%83%EC%9D%80_%EC%9B%B9_%ED%8E%98%EC%9D%B4%EC%A7%80%EC%9E%85%EB%8B%88'
end
end

0 comments on commit 92c2603

Please sign in to comment.