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
- .fixtures_path ⇒ Object
- .prefix_for(endpoint_name) ⇒ Object
- .regenerate(endpoint_name) ⇒ Object
- .regenerate_all ⇒ Object
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_search ⇒ 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.
47 48 49 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 47 def initialize(endpoint_name) @endpoint_name = endpoint_name.to_s end |
Class Method Details
.fixtures_path ⇒ Object
41 42 43 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 41 def self.fixtures_path File.('../../fixtures', __FILE__) end |
.prefix_for(endpoint_name) ⇒ Object
37 38 39 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 37 def self.prefix_for(endpoint_name) new(endpoint_name).path_prefix end |
.regenerate(endpoint_name) ⇒ Object
31 32 33 34 35 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 31 def self.regenerate(endpoint_name) builder = new(endpoint_name) builder.clobber builder.generate end |
.regenerate_all ⇒ Object
24 25 26 27 28 29 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 24 def self.regenerate_all public_instance_methods .map(&:to_s) .select { |method_name| method_name.start_with?('build') } .each { |method_name| regenerate(method_name.sub('build_', '')) } end |
Instance Method Details
#build_copy_batch ⇒ Object
65 66 67 68 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 65 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
70 71 72 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 70 def build_create_file_request client.upload("#{path_prefix}/regular_file.txt", 'Arkansas, dude.') end |
#build_delete ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 74 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
83 84 85 86 87 88 89 90 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 83 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
111 112 113 114 115 116 117 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 111 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
106 107 108 109 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 106 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
92 93 94 95 96 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 92 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_search ⇒ Object
119 120 121 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 119 def build_search client.upload("#{path_prefix}/findable_file.txt", 'Moo.') end |
#build_upload ⇒ Object
98 99 100 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 98 def build_upload # No need to set up anything end |
#build_upload_by_chunks ⇒ Object
102 103 104 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 102 def build_upload_by_chunks # No op end |
#client ⇒ Object
61 62 63 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 61 def client @client ||= DropboxApi::Client.new end |
#clobber ⇒ Object
51 52 53 54 55 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 51 def clobber client.delete path_prefix rescue DropboxApi::Errors::NotFoundError false # It's ok if it doesn't exist end |
#generate ⇒ Object
57 58 59 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 57 def generate send "build_#{@endpoint_name}" end |
#path_prefix ⇒ Object
We have a prefix for each endpoint to avoid conflicts across them
124 125 126 |
# File 'spec/support/dropbox_scaffold_builder.rb', line 124 def path_prefix File.join PREFIX, @endpoint_name end |