Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Adds bookmark catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
yundt committed Aug 6, 2012
1 parent 057193a commit 91e5889
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/bookmarks/bookmark.rb
@@ -0,0 +1,2 @@
class Bookmark < Struct.new(:url)
end
17 changes: 17 additions & 0 deletions app/bookmarks/bookmark_catalogue.rb
@@ -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
2 changes: 2 additions & 0 deletions app/bookmarks/bookmark_invalid.rb
@@ -0,0 +1,2 @@
class BookmarkInvalid < StandardError
end
29 changes: 29 additions & 0 deletions spec/bookmarks/bookmark_catalogue_spec.rb
@@ -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

0 comments on commit 91e5889

Please sign in to comment.