Skip to content

Commit

Permalink
Refactor google drive trashed filter to use api parameter
Browse files Browse the repository at this point in the history
Now use the api `trashed` parameter to filter out trashed docs instead
of doing our own filtering.

Test Plan:
-Set up Google Drive
-Create the following:
	-Valid file at root
	-Valid folder containing valid file
	-Trashed file formerly at root
	-Trashed folder containing a file
-Verify that the trashed items are not displayed, but valid items are

Closes CNVS-25959

Change-Id: I9054d48910f6b8cbd5ebcecf15d35bf98d6fe3d0
Reviewed-on: https://gerrit.instructure.com/68740
Tested-by: Jenkins
Reviewed-by: Matthew Wheeler <[email protected]>
QA-Review: Heath Hales <[email protected]>
Product-Review: Gentry Beckmann <[email protected]>
  • Loading branch information
beckesea committed Dec 21, 2015
1 parent b5f593a commit d8b00e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gems/google_docs/lib/google_docs/drive_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def self.config
def list(extensions)
client_params = {
api_method: drive.files.list,
parameters: { maxResults: 0 }
parameters: { maxResults: 0, q: 'trashed=false' }
}
list_data = client_execute!(client_params).data.to_hash
folderize_list(list_data, extensions)
Expand Down Expand Up @@ -216,7 +216,7 @@ def folderize_list(documents, extensions)
root = root.select { |e| extensions.include?(e.extension) }
end

root.select { |e| !e.in_trash? }
root
end

def get_folder_name_by_id(entries, folder_id)
Expand Down
4 changes: 0 additions & 4 deletions gems/google_docs/lib/google_docs/drive_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def download_url
get_file_data[:url]
end

def in_trash?
@entry['labels']['trashed']
end

def to_hash
{
:name => display_name,
Expand Down
21 changes: 20 additions & 1 deletion gems/google_docs/spec/google_docs/drive_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
fake_client = Class.new do
attr_reader :token
attr_writer :responses
attr_accessor :inputs

def initialize(input=nil)
@input = input
Expand Down Expand Up @@ -62,7 +63,12 @@ def get
"/api_method"
end

def execute!(*_args)
def list
"/api_method"
end

def execute!(*args)
@inputs = args
response = @responses[@calls]
@calls += 1
response
Expand Down Expand Up @@ -164,6 +170,19 @@ def execute(*args)
connection.send(:set_api_client, client)
end

describe "#list_with_extension_filter" do
before do
client.responses = [
stub(status: 200, data: { "items" => [] })
]
end

it "should submit `trashed = false` parameter" do
connection.list_with_extension_filter('.txt')
expect(client.inputs.last[:parameters][:q]).to eql 'trashed=false'
end
end

describe "#download" do
before do
client.responses = [
Expand Down

0 comments on commit d8b00e3

Please sign in to comment.