Skip to content

Commit

Permalink
Merge pull request #1515 from CristinaRO/0.9.13-issue-3574-wwwwww
Browse files Browse the repository at this point in the history
Use our nifty URL detector library to check for previous import
  • Loading branch information
elzj committed Feb 8, 2014
2 parents 7da4e4d + dd3b9b9 commit 6891cd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/models/story_parser.rb
Expand Up @@ -248,10 +248,9 @@ def download_and_parse_chaptered_story(source, location, options = {})
end


#Updated as elz suggested now getting www and non www, Stephanie 1-11-2014
# our custom url finder checks for previously imported URL in almost any format it may have been presented
def check_for_previous_import(location)
urls = [location, location.gsub('www.', '')].uniq
if Work.where(imported_from_url: urls).exists?
if Work.find_by_url(location).present?
raise Error, "A work has already been imported from #{location}."
end
end
Expand Down
24 changes: 20 additions & 4 deletions spec/models/story_parser_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe StoryParser do

before(:each) do
@sp = StoryParser.new
end
Expand Down Expand Up @@ -94,10 +94,27 @@
# @sp.get_source_if_known(StoryParser::KNOWN_STORY_LOCATIONS, url).should eq("lj")
# end
end

# TODO: KNOWN_STORY_PARSERS
end


describe "check_for_previous_import" do
let(:location_with_www) { "http://www.testme.org/welcome_to_test_vale.html" }
let(:location_no_www) { "http://testme.org/welcome_to_test_vale.html" }

it "should recognise previously imported www. works" do
@work = FactoryGirl.create(:work, imported_from_url: location_with_www)

expect { @sp.check_for_previous_import(location_no_www) }.to raise_exception
end

it "should recognise previously imported non-www. works" do
@work = FactoryGirl.create(:work, imported_from_url: location_no_www)

expect { @sp.check_for_previous_import(location_with_www) }.to raise_exception
end
end

describe "#parse_common" do
it "should convert relative to absolute links" do
# This one doesn't work because the sanitizer is converting the & to &
Expand All @@ -119,5 +136,4 @@
end
end
end

end

0 comments on commit 6891cd7

Please sign in to comment.