Class: DropboxScaffoldBuilder
- Inherits:
-
Object
- Object
- DropboxScaffoldBuilder
- Defined in:
- spec/support/dropbox_scaffold_builder.rb
Overview
This class is useful to set up an existing Dropbox account in a state which is ready to pass the tests.
For example, on the tests for the delete
endpoint you may be deleting the
file at /delete/file.txt
, so we need to upload a file at that location or
the test won't pass. That's exactly what #delete is
expected to do.
Other endpoints' tests will have different requirements and this class is to provide an automated way to fulfill these. For each endpoint we need to test, you may have a method here that sets up everything that the tests for that endpoint needs.
Note that, paradoxically, the methods here use the same methods we want to test. This shouldn't be a problem as the purpose of this is to allow us to regenerate the VCR cassettes, so if this automated mechanism fails you can always do the job manually and record the VCR cassette without using this.
The Dropbox server may introduce minor changes over time so it's good to regenerate the cassettes every now and then, but we don't need to do it in every execution of the test suite.
Constant Summary collapse
- PREFIX =
"/dropbox_api_fixtures"
Class Method Summary collapse
Instance Method Summary collapse
- #build_copy_batch ⇒ Object
- #build_create_file_request ⇒ Object
- #build_delete ⇒ Object
- #build_get_metadata ⇒ Object
- #build_get_shared_link_metadata ⇒ Object
- #build_get_thumbnail_batch ⇒ Object
- #build_list_folder ⇒ Object
- #build_upload ⇒ Object
- #build_upload_by_chunks ⇒ Object
- #client ⇒ Object
- #clobber ⇒ Object
- #generate ⇒ Object
-
#initialize(endpoint_name) ⇒ DropboxScaffoldBuilder
constructor
A new instance of DropboxScaffoldBuilder.
-
#path_prefix ⇒ Object
We have a prefix for each endpoint to avoid conflicts across them.
Constructor Details
#initialize(endpoint_name) ⇒ DropboxScaffoldBuilder
Returns a new instance of DropboxScaffoldBuilder
39 40 41 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 39 def initialize(endpoint_name) @endpoint_name = endpoint_name.to_s end |
Class Method Details
.fixtures_path ⇒ Object
33 34 35 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 33 def self.fixtures_path File.('../../fixtures', __FILE__) end |
.prefix_for(endpoint_name) ⇒ Object
29 30 31 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 29 def self.prefix_for(endpoint_name) new(endpoint_name).path_prefix end |
.regenerate(endpoint_name) ⇒ Object
23 24 25 26 27 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 23 def self.regenerate(endpoint_name) builder = new(endpoint_name) builder.clobber builder.generate end |
Instance Method Details
#build_copy_batch ⇒ Object
57 58 59 60 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 57 def build_copy_batch client.upload("#{path_prefix}/regular_file.txt", "Che primo! aon vas?") client.upload("#{path_prefix}/regular_file_2.txt", "Pal Calvari, amic") end |
#build_create_file_request ⇒ Object
62 63 64 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 62 def build_create_file_request client.upload("#{path_prefix}/regular_file.txt", "Arkansas, dude.") end |
#build_delete ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 66 def build_delete file_contents = "Tijuana, amigo." client.upload "#{path_prefix}/will_be_deleted.txt", file_contents client.upload "#{path_prefix}/wont_be_deleted.txt", file_contents client.upload "#{path_prefix}/folder/a.txt", file_contents client.upload "#{path_prefix}/folder/b.txt", file_contents end |
#build_get_metadata ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 75 def client.upload("#{path_prefix}/file.txt", "This is a test file.", { :client_modified => Time.new(1988, 12, 8, 1, 1, 0, "+00:00") }) client.create_folder("#{path_prefix}/folder") client.upload("#{path_prefix}/deleted_file.txt", "This is a test file.") client.delete("#{path_prefix}/deleted_file.txt") end |
#build_get_shared_link_metadata ⇒ Object
103 104 105 106 107 108 109 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 103 def client.create_folder("#{path_prefix}/shared_folder") client.create_shared_link_with_settings("#{path_prefix}/shared_folder") client.upload("#{path_prefix}/shared_file.txt", "I shall be shared.") client.create_shared_link_with_settings("#{path_prefix}/shared_file.txt") end |
#build_get_thumbnail_batch ⇒ Object
98 99 100 101 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 98 def build_get_thumbnail_batch file_content = IO.read File.join(self.class.fixtures_path, "img.png") client.upload("#{path_prefix}/img.png", file_content) end |
#build_list_folder ⇒ Object
84 85 86 87 88 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 84 def build_list_folder client.create_folder("#{path_prefix}/shared_folder") client.create_shared_link_with_settings("#{path_prefix}/shared_folder") client.upload("#{path_prefix}/shared_folder/cow.txt", "Moo.") end |
#build_upload ⇒ Object
90 91 92 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 90 def build_upload # No need to set up anything end |
#build_upload_by_chunks ⇒ Object
94 95 96 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 94 def build_upload_by_chunks # No op end |
#client ⇒ Object
53 54 55 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 53 def client @client ||= DropboxApi::Client.new end |
#clobber ⇒ Object
43 44 45 46 47 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 43 def clobber client.delete path_prefix rescue DropboxApi::Errors::NotFoundError false # It's ok if it doesn't exist end |
#generate ⇒ Object
49 50 51 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 49 def generate send "build_#{@endpoint_name}" end |
#path_prefix ⇒ Object
We have a prefix for each endpoint to avoid conflicts across them
112 113 114 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 112 def path_prefix File.join PREFIX, @endpoint_name end |