Skip to content

Commit

Permalink
add unit tests for nested classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bencornelis committed Sep 20, 2015
1 parent fff5fb6 commit ac6492f
Show file tree
Hide file tree
Showing 2 changed files with 356 additions and 73 deletions.
24 changes: 14 additions & 10 deletions app/models/agents/evernote_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class EvernoteAgent < Agent
If a note with the above title and notebook did note exist already, one would be created.
- When `mode` is `read` the values are search parameters.
Note: The `content` parameter is not used for searching.
Note: The `content` parameter is not used for searching. Setting `title` only filters
notes whose titles contain `title` as a substring, not as the exact title.
For example, to find all notes with tag 'CS' in the notebook 'xkcd', use:
Expand Down Expand Up @@ -190,9 +191,11 @@ def initialize(en_note_store)

def create_or_update_note(params)
search = Search.new(self, {title: params[:title], notebook: params[:notebook]})

# evernote search can only filter notes with titles containing a substring;
# this finds a note with the exact title
note = search.notes.detect {|note| note.title == params[:title]}

if note
# a note with specified title and notebook exists, so update it
update_note(params.merge(guid: note.guid, notebookGuid: note.notebookGuid))
Expand All @@ -218,6 +221,7 @@ def update_note(params)
params = with_wrapped_content(params)

# append specified tags instead of replacing current tags
# evernote will create any new tags
tags = getNoteTagNames(params[:guid])
tags.each { |tag|
params[:tagNames] << tag unless params[:tagNames].include?(tag) }
Expand All @@ -234,7 +238,7 @@ def find_note(guid)
end

def build_note(en_note)
notebook = find_notebook(guid: en_note.notebookGuid).name
notebook = find_notebook(guid: en_note.notebookGuid).try(:name)
tags = en_note.tagNames || find_tags(en_note.tagGuids.to_a).map(&:name)
Note.new(en_note, notebook, tags)
end
Expand Down Expand Up @@ -276,11 +280,6 @@ def initialize(note_store, opts)
@opts = opts
end

def filtered_metadata
filter, spec = create_filter, create_spec
metadata = note_store.findNotesMetadata(filter, 0, 100, spec).notes
end

def note_guids
filtered_metadata.map(&:guid)
end
Expand All @@ -295,7 +294,7 @@ def notes
# and notes that recently had the specified tags added
metadata.select! do |note_data|
note_data.updated > opts[:last_checked_at] ||
(!opts[:notes_with_tags].include?(note_data.guid) && note_data.created > opts[:agent_created_at])
!opts[:notes_with_tags].include?(note_data.guid)
end

elsif opts[:last_checked_at]
Expand All @@ -306,8 +305,6 @@ def notes
metadata
end

private

def create_filter
filter = Evernote::EDAM::NoteStore::NoteFilter.new

Expand All @@ -323,6 +320,13 @@ def create_filter
filter
end

private

def filtered_metadata
filter, spec = create_filter, create_spec
metadata = note_store.findNotesMetadata(filter, 0, 100, spec).notes
end

def create_spec
Evernote::EDAM::NoteStore::NotesMetadataResultSpec.new(
includeTitle: true,
Expand Down
Loading

0 comments on commit ac6492f

Please sign in to comment.