This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Bookmark < Struct.new(:url) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class BookmarkCatalogue | ||
def bookmark(attrs = {}) | ||
url = attrs[:url] | ||
|
||
raise BookmarkInvalid if url.blank? | ||
|
||
bookmarks << Bookmark.new(url) | ||
end | ||
|
||
def bookmarks | ||
@@bookmarks ||= [] | ||
end | ||
|
||
def clear | ||
@@bookmarks = [] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class BookmarkInvalid < StandardError | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
describe BookmarkCatalogue do | ||
verify_contract(:bookmark_catalogue) | ||
|
||
let(:bookmark_catalogue) { isolate(BookmarkCatalogue) } | ||
|
||
before { bookmark_catalogue.clear } | ||
|
||
it "saves bookmarks" do | ||
bookmark_catalogue.bookmark(url: "cool.site") | ||
bookmark_catalogue.bookmarks.should include(Bookmark.new("cool.site")) | ||
end | ||
|
||
it "is empty prior to bookmarking" do | ||
bookmark_catalogue.bookmarks.should be_empty | ||
end | ||
|
||
it "raises exception with invalid url" do | ||
expect { | ||
bookmark_catalogue.bookmark(url: "") | ||
}.to raise_error(BookmarkInvalid) | ||
end | ||
|
||
it "persists the bookmarks" do | ||
isolate(BookmarkCatalogue).bookmark(url: 'cool.site') | ||
isolate(BookmarkCatalogue).bookmarks.should_not be_empty | ||
end | ||
end |