myfdb_utilities 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +25 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +14 -0
- data/Rakefile +12 -0
- data/bin/myfdb +54 -0
- data/lib/command/helpers.rb +19 -0
- data/lib/command/settings.rb +27 -0
- data/lib/myfdb.rb +3 -0
- data/lib/myfdb/batch.rb +44 -0
- data/lib/myfdb/batch/images.rb +69 -0
- data/lib/myfdb/uploader.rb +33 -0
- data/lib/version.rb +3 -0
- data/myfdb_utilities.gemspec +31 -0
- data/spec/fixtures/images/.gitkeep +0 -0
- data/spec/fixtures/join_images/0_test_0-a.jpg +0 -0
- data/spec/fixtures/join_images/0_test_1-a.jpg +0 -0
- data/spec/fixtures/join_images/1_test_0-aa.jpg +0 -0
- data/spec/fixtures/join_images/1_test_1-aa.jpg +0 -0
- data/spec/fixtures/join_images/2_test_0-b.jpg +0 -0
- data/spec/fixtures/join_images/2_test_1-b.jpg +0 -0
- data/spec/fixtures/join_images/3_test_0-bb.jpg +0 -0
- data/spec/fixtures/join_images/3_test_1-bb.jpg +0 -0
- data/spec/fixtures/join_images/4_test_0-bbb.jpg +0 -0
- data/spec/fixtures/join_images/4_test_1-bbb.jpg +0 -0
- data/spec/fixtures/join_images/4_test_2-bbb.jpg +0 -0
- data/spec/myfdb/batch/images_spec.rb +95 -0
- data/spec/myfdb/batch_spec.rb +206 -0
- data/spec/myfdb/bin/myfdb_spec.rb +7 -0
- data/spec/myfdb/uploader_spec.rb +5 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/fakeweb.rb +0 -0
- metadata +159 -0
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
.bundle/*
|
23
|
+
Gemfile.lock
|
24
|
+
|
25
|
+
*.gem
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 My Fashion Database
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
= Myfdb Utilities
|
2
|
+
|
3
|
+
== Installation as a gem:
|
4
|
+
|
5
|
+
gem install 'myfdb'
|
6
|
+
|
7
|
+
== Settings
|
8
|
+
|
9
|
+
Run `myfdb init`
|
10
|
+
|
11
|
+
You will be asked for your api_key and api_secret and if you want a cron task created.
|
12
|
+
The cron task will allow you to drop a folder in the main directory and have the upload happen automatically
|
13
|
+
|
14
|
+
If you choose to install the cron task, your done. To upload images, place a folder of images in ~/MyFDB_Uploads.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
desc "Run all examples"
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
|
+
t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
|
9
|
+
t.pattern = 'spec/**/*_spec.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
data/bin/myfdb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'myfdb'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'cronedit'
|
9
|
+
require 'version'
|
10
|
+
require 'commander/import'
|
11
|
+
require 'command/helpers'
|
12
|
+
require 'command/settings'
|
13
|
+
|
14
|
+
include Command::Helpers
|
15
|
+
|
16
|
+
program :name, 'MyFDB Utilities'
|
17
|
+
program :version, Myfdb::VERSION
|
18
|
+
program :description, 'Misc tasks related to myfdb.com'
|
19
|
+
|
20
|
+
command :init do |c|
|
21
|
+
c.syntax = 'myfdb init'
|
22
|
+
c.description = 'Set up api key, folders and crontask for myfdb'
|
23
|
+
|
24
|
+
c.action do |args, options|
|
25
|
+
settings = ask('API Key: ') + '|'
|
26
|
+
settings << ask('API Secret: ') + '|'
|
27
|
+
settings << ask('Domain: ') { |q| q.default = "www.myfdb.com" }
|
28
|
+
|
29
|
+
File.open(settings_file, "w") {|f| f.write(settings) }
|
30
|
+
|
31
|
+
unless File.exists?(main_directory)
|
32
|
+
FileUtils.mkdir main_directory
|
33
|
+
say "A directory has been created in #{main_directory}"
|
34
|
+
end
|
35
|
+
|
36
|
+
if agree('Install cron task for processing (yes/no)?')
|
37
|
+
CronEdit::Crontab.Add \
|
38
|
+
'myfdb',
|
39
|
+
:minute => 1,
|
40
|
+
:command => "myfdb upload_images >> #{main_directory}/error.log"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
command :upload_images do |c|
|
46
|
+
c.syntax = 'myfdb upload_images'
|
47
|
+
c.description = 'Upload images directly to My Fashion Database'
|
48
|
+
|
49
|
+
c.action do |args, options|
|
50
|
+
Myfdb::Uploader.process(settings) unless process_running?('upload_images')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Command
|
2
|
+
module Helpers
|
3
|
+
def settings
|
4
|
+
@settings ||= Settings.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def settings_file
|
8
|
+
settings.file
|
9
|
+
end
|
10
|
+
|
11
|
+
def main_directory
|
12
|
+
settings.directory
|
13
|
+
end
|
14
|
+
|
15
|
+
def process_running?(command)
|
16
|
+
! %x(ps ux | awk '/#{command}/ && !/#{Process.ppid}/ && !/#{Process.pid}/ && !/awk/ {print $2}').empty?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Settings
|
2
|
+
attr_reader :key, :secret, :host
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@key, @secret, @host = parse_settings
|
6
|
+
end
|
7
|
+
|
8
|
+
def directory
|
9
|
+
File.join home_directory, 'MyFDB_Uploads'
|
10
|
+
end
|
11
|
+
|
12
|
+
def file
|
13
|
+
"#{ENV['HOME']}/.myfdb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_settings
|
17
|
+
File.read(file).split('|')
|
18
|
+
end
|
19
|
+
|
20
|
+
def home_directory
|
21
|
+
running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
|
22
|
+
end
|
23
|
+
|
24
|
+
def running_on_windows?
|
25
|
+
RUBY_PLATFORM =~ /mswin32|mingw32/
|
26
|
+
end
|
27
|
+
end
|
data/lib/myfdb.rb
ADDED
data/lib/myfdb/batch.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'myfdb/batch/images'
|
2
|
+
|
3
|
+
module Myfdb
|
4
|
+
class Batch
|
5
|
+
include ::Batch::Images
|
6
|
+
|
7
|
+
attr_reader :directory, :uri, :errors
|
8
|
+
|
9
|
+
def initialize(directory, uri)
|
10
|
+
@directory = directory
|
11
|
+
@errors = []
|
12
|
+
@uri = uri
|
13
|
+
end
|
14
|
+
|
15
|
+
def store!
|
16
|
+
id && process_images if images?
|
17
|
+
end
|
18
|
+
|
19
|
+
def id
|
20
|
+
@id ||= File.read(File.join directory, 'issue_id')
|
21
|
+
rescue Errno::ENOENT
|
22
|
+
response = create_issue
|
23
|
+
response.is_a?(Integer) ? @id = response : errors << response
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create_issue
|
29
|
+
response = Net::HTTP.post_form(self.uri + '/upload/issues', {})
|
30
|
+
if response.code == '200'
|
31
|
+
id = response.body.to_i
|
32
|
+
File.open(File.join(directory, 'issue_id'), 'w') do |f|
|
33
|
+
f.print id
|
34
|
+
end
|
35
|
+
id
|
36
|
+
else
|
37
|
+
"Unknown response, body: #{response.body}, code: #{response.code}"
|
38
|
+
end
|
39
|
+
rescue => error
|
40
|
+
"Error creating issue, error: #{error.class}, message: #{error.message}"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'net/http/post/multipart'
|
2
|
+
|
3
|
+
module Batch
|
4
|
+
module Images
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
attr_reader :directory, :id, :uri
|
9
|
+
|
10
|
+
def errors
|
11
|
+
@errors ||= []
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def images?
|
17
|
+
!images.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def images
|
21
|
+
Dir.glob(File.join directory, '*.{jpeg,JPEG,jpg,JPG}')
|
22
|
+
end
|
23
|
+
|
24
|
+
def process_images
|
25
|
+
upload if id
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def upload
|
31
|
+
images.each do |image|
|
32
|
+
begin
|
33
|
+
uri_path = '/upload/tear_sheets'
|
34
|
+
upload_io = UploadIO.new(image, 'image/jpeg')
|
35
|
+
multipart = Net::HTTP::Post::Multipart.new(uri_path, 'issue_id' => id.to_s, 'tear_sheet[image]' => upload_io)
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
38
|
+
multipart.basic_auth uri.user, uri.password
|
39
|
+
http.request multipart
|
40
|
+
end
|
41
|
+
|
42
|
+
if error = parse_response(response)
|
43
|
+
errors << error
|
44
|
+
else
|
45
|
+
delete(image)
|
46
|
+
end
|
47
|
+
rescue => error
|
48
|
+
errors << "Error creating tear sheet '#{File.basename(image)}', error: #{error.class}, message: #{error.message}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_response(response)
|
54
|
+
case response.code
|
55
|
+
when '200'
|
56
|
+
nil
|
57
|
+
when '422'
|
58
|
+
"Invalid image, response: #{response.body}"
|
59
|
+
else
|
60
|
+
"Unknown response, issue: #{id}, response: #{response.body}, code: #{response.code}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete(image)
|
65
|
+
FileUtils.rm(image) and return nil
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'myfdb/batch'
|
2
|
+
|
3
|
+
module Myfdb
|
4
|
+
module Uploader
|
5
|
+
|
6
|
+
def self.process(options)
|
7
|
+
uri = URI.parse "http://#{options.key}:#{options.secret}@#{options.host}"
|
8
|
+
batches = []
|
9
|
+
|
10
|
+
Dir.glob("#{options.directory}/*") do |directory|
|
11
|
+
batch = Myfdb::Batch.new(directory, uri)
|
12
|
+
batch.store!
|
13
|
+
batches << batch
|
14
|
+
end
|
15
|
+
|
16
|
+
process_errors batches
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.process_errors(batches)
|
22
|
+
batches.each do |batch|
|
23
|
+
unless batch.errors.empty?
|
24
|
+
puts "Errors for issue ##{batch.id}:"
|
25
|
+
batch.errors.compact.each do |error|
|
26
|
+
puts error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require 'version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "myfdb_utilities"
|
9
|
+
s.version = Myfdb::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ['Larry Sprock']
|
12
|
+
s.email = ['development@myfdb.com']
|
13
|
+
s.homepage = "http://rubygems.org/gems/myfdb_utilities"
|
14
|
+
s.summary = "Utilities gem for myfdb"
|
15
|
+
s.description = "A collection of purpose built utilities for doing tasks specific to MyFDB"
|
16
|
+
|
17
|
+
s.required_rubygems_version = ">= 1.3.6"
|
18
|
+
|
19
|
+
s.add_development_dependency "rspec", ["~> 2.6.0"]
|
20
|
+
s.add_development_dependency "mocha", ["~> 0.9"]
|
21
|
+
s.add_development_dependency "fakeweb"
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
|
24
|
+
s.add_dependency 'multipart-post'
|
25
|
+
s.add_dependency 'commander'
|
26
|
+
s.add_dependency 'cronedit'
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.executables = 'myfdb'
|
30
|
+
s.require_path = 'lib'
|
31
|
+
end
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'myfdb/batch/images'
|
3
|
+
|
4
|
+
class TestImageProcessor
|
5
|
+
include Batch::Images
|
6
|
+
|
7
|
+
def initialize(directory, uri)
|
8
|
+
@directory = directory
|
9
|
+
@uri = URI.parse uri
|
10
|
+
@id = 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Batch::Images do
|
15
|
+
let(:test_processor) { TestImageProcessor.new directory, 'https://me:123@test.com' }
|
16
|
+
|
17
|
+
after do
|
18
|
+
delete_images
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#images' do
|
22
|
+
it 'returns an array' do
|
23
|
+
test_processor.images.should be_an(Array)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns an array of paths' do
|
27
|
+
create_images
|
28
|
+
|
29
|
+
test_processor.images.should have(4).paths
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#images?' do
|
34
|
+
it 'returns false if images is empty' do
|
35
|
+
test_processor.images?.should be_false
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns false if images is empty' do
|
39
|
+
Dir.stubs(:glob).returns([1,2,3,4,5])
|
40
|
+
test_processor.images?.should be_true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context '#process_images' do
|
45
|
+
it 'invokes #seperate_images_to_join, #join, #upload if id' do
|
46
|
+
test_processor.expects(:upload)
|
47
|
+
test_processor.process_images
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'does nothing if id not set' do
|
51
|
+
test_processor.expects(:id).returns(nil)
|
52
|
+
test_processor.expects(:upload).never
|
53
|
+
test_processor.process_images
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#upload' do
|
58
|
+
context 'error' do
|
59
|
+
before do
|
60
|
+
%x(touch #{directory}/test.jpg)
|
61
|
+
Net::HTTP.
|
62
|
+
expects(:start).
|
63
|
+
at_least_once.
|
64
|
+
with('test.com', 443).
|
65
|
+
raises(NoMethodError, 'General error')
|
66
|
+
test_processor.send(:upload)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'connection error' do
|
70
|
+
test_processor.errors.first.should eql("Error creating tear sheet 'test.jpg', error: NoMethodError, message: General error")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def directory
|
78
|
+
fixtures_directory + '/images'
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_images
|
82
|
+
%w(jpeg JPEG jpg JPG tiff).each_with_index do |ext, i|
|
83
|
+
%x(touch #{directory}/#{i}_test.#{ext})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_join_images
|
88
|
+
FileUtils.cp_r Dir.glob("#{fixtures_directory}/join_images/*"), directory
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete_images
|
92
|
+
Dir.glob directory + '/*' do |f|
|
93
|
+
%x(rm #{f})
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'myfdb/batch'
|
3
|
+
|
4
|
+
describe Myfdb::Batch do
|
5
|
+
describe '.upload' do
|
6
|
+
before(:each) do
|
7
|
+
@from_directory = FIXTURES
|
8
|
+
@to_host = HOST
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with a new issue' do
|
12
|
+
before(:each) do
|
13
|
+
@issue = Issue.new
|
14
|
+
@issue_directory = File.join @from_directory, @issue.name
|
15
|
+
FileUtils.mkdir @issue_directory
|
16
|
+
FileUtils.touch File.join(@issue_directory, 'image.jpg')
|
17
|
+
FileUtils.touch File.join(@issue_directory, 'image.gif')
|
18
|
+
|
19
|
+
@old_untitled_tear_sheet_count = @issue.untitled_tear_sheets.count
|
20
|
+
TearSheet.
|
21
|
+
any_instance.
|
22
|
+
stubs(:save_attached_files)
|
23
|
+
|
24
|
+
FakeWeb.register_uri(:post,
|
25
|
+
%r{#{@to_host}/upload/issues},
|
26
|
+
:body => @issue.id.to_s)
|
27
|
+
FakeWeb.register_uri(:post,
|
28
|
+
%r{#{@to_host}/upload/tear_sheets},
|
29
|
+
:body => '',
|
30
|
+
:status => '200')
|
31
|
+
end
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
FileUtils.rm_rf @issue_directory
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'uploads its images' do
|
38
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
39
|
+
|
40
|
+
puts error_report.inspect
|
41
|
+
error_report.should be_empty
|
42
|
+
|
43
|
+
id_file_exists = File.exists? File.join(@issue_directory, 'issue_id')
|
44
|
+
id_file_exists.should be
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with an issue that was partially uploaded' do
|
49
|
+
before(:each) do
|
50
|
+
@issue = Issue.new
|
51
|
+
@issue_directory = File.join @from_directory, @issue.name
|
52
|
+
FileUtils.mkdir @issue_directory
|
53
|
+
File.open(File.join(@issue_directory, 'issue_id'), 'w') do |file|
|
54
|
+
file.puts @issue.id
|
55
|
+
end
|
56
|
+
FileUtils.touch File.join(@issue_directory, 'image.jpg')
|
57
|
+
|
58
|
+
TearSheet.
|
59
|
+
any_instance.
|
60
|
+
stubs(:save_attached_files)
|
61
|
+
|
62
|
+
FakeWeb.register_uri(:post,
|
63
|
+
%r{#{@to_host}/upload/tear_sheets},
|
64
|
+
:body => '',
|
65
|
+
:status => '200')
|
66
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
FileUtils.rm_rf @issue_directory
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'uploads its images to the existing issue' do
|
73
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
74
|
+
error_report.should be_empty
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with a unknown response when creating a new issue' do
|
79
|
+
before(:each) do
|
80
|
+
issue = Issue.new
|
81
|
+
@issue_directory = File.join @from_directory, issue.name
|
82
|
+
FileUtils.mkdir @issue_directory
|
83
|
+
FileUtils.touch File.join(@issue_directory, 'image.jpg')
|
84
|
+
@response_code = '500'
|
85
|
+
@response_body = 'error'
|
86
|
+
FakeWeb.register_uri(:post,
|
87
|
+
%r{#{@to_host}/upload/issues},
|
88
|
+
:body => @response_body,
|
89
|
+
:status => @response_code)
|
90
|
+
end
|
91
|
+
|
92
|
+
after(:each) do
|
93
|
+
FileUtils.rm_rf @issue_directory
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns an error report about the unknown response' do
|
97
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
98
|
+
error_report.should == "Unknown response, body: #{@response_body}, code: #{@response_code}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with an error when creating a new issue' do
|
103
|
+
before(:each) do
|
104
|
+
issue = Issue.new
|
105
|
+
@issue_directory = File.join @from_directory, issue.name
|
106
|
+
FileUtils.mkdir @issue_directory
|
107
|
+
FileUtils.touch File.join(@issue_directory, 'image.jpg')
|
108
|
+
Net::HTTP.
|
109
|
+
expects(:post_form).
|
110
|
+
raises('error')
|
111
|
+
end
|
112
|
+
|
113
|
+
after(:each) do
|
114
|
+
FileUtils.rm_rf @issue_directory
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'returns an error report about the error' do
|
118
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
119
|
+
error_report.should == "Error creating issue, error: RuntimeError, message: error"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with a issue with an invalid image' do
|
124
|
+
before(:each) do
|
125
|
+
issue = Issue.new
|
126
|
+
@issue_directory = File.join @from_directory, issue.name
|
127
|
+
FileUtils.mkdir @issue_directory
|
128
|
+
File.open(File.join(@issue_directory, 'issue_id'), 'w') do |file|
|
129
|
+
file.puts issue.id
|
130
|
+
end
|
131
|
+
FileUtils.touch File.join(@issue_directory, 'image.jpg')
|
132
|
+
|
133
|
+
@response_body = 'response_body'
|
134
|
+
FakeWeb.register_uri(:post,
|
135
|
+
%r{#{HOST}/upload/tear_sheets},
|
136
|
+
:body => @response_body,
|
137
|
+
:status => '422')
|
138
|
+
end
|
139
|
+
|
140
|
+
after(:each) do
|
141
|
+
FileUtils.rm_rf @issue_directory
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns an error report about the invalid image' do
|
145
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
146
|
+
error_report.should == "Invalid image, response: #{@response_body}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'with a issue with an unknown response when uploading an image' do
|
151
|
+
before(:each) do
|
152
|
+
@issue = Issue.new
|
153
|
+
@issue_directory = File.join @from_directory, @issue.name
|
154
|
+
FileUtils.mkdir @issue_directory
|
155
|
+
File.open(File.join(@issue_directory, 'issue_id'), 'w') do |file|
|
156
|
+
file.puts @issue.id
|
157
|
+
end
|
158
|
+
@image = 'image.jpg'
|
159
|
+
FileUtils.touch File.join(@issue_directory, @image)
|
160
|
+
|
161
|
+
@response_body = 'response_body'
|
162
|
+
@response_code = '500'
|
163
|
+
FakeWeb.register_uri(:post,
|
164
|
+
%r{#{HOST}/upload/tear_sheets},
|
165
|
+
:body => @response_body,
|
166
|
+
:status => @response_code)
|
167
|
+
end
|
168
|
+
|
169
|
+
after(:each) do
|
170
|
+
FileUtils.rm_rf @issue_directory
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'returns an error report about the unknown response' do
|
174
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
175
|
+
error_report.should == "Unknown response, issue: #{@issue.id}, image: #{@issue.name}/#{@image}, response: #{@response_body}, code: #{@response_code}"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'with an error when uploading an image' do
|
180
|
+
before(:each) do
|
181
|
+
@issue = Issue.new
|
182
|
+
@issue_directory = File.join @from_directory, @issue.name
|
183
|
+
FileUtils.mkdir @issue_directory
|
184
|
+
File.open(File.join(@issue_directory, 'issue_id'), 'w') do |file|
|
185
|
+
file.puts @issue.id
|
186
|
+
end
|
187
|
+
@image = 'image.jpg'
|
188
|
+
FileUtils.touch File.join(@issue_directory, @image)
|
189
|
+
|
190
|
+
@error = 'error'
|
191
|
+
Net::HTTP.
|
192
|
+
expects(:start).
|
193
|
+
raises(@error)
|
194
|
+
end
|
195
|
+
|
196
|
+
after(:each) do
|
197
|
+
FileUtils.rm_rf @issue_directory
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'returns an error report about the error' do
|
201
|
+
error_report = IssuesUploader.upload @from_directory, @to_host
|
202
|
+
error_report.should == "Error creating tear sheet '#{@issue.name}/#{@image}', error: RuntimeError, message: #{@error}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
RSpec.configure do |c|
|
9
|
+
c.mock_with :mocha
|
10
|
+
end
|
11
|
+
|
12
|
+
def fixtures_directory
|
13
|
+
File.expand_path('../fixtures', __FILE__)
|
14
|
+
end
|
15
|
+
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: myfdb_utilities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Larry Sprock
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70129867288320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.6.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70129867288320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &70129867287620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.9'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70129867287620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakeweb
|
38
|
+
requirement: &70129867287200 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70129867287200
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70129867286360 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70129867286360
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: multipart-post
|
60
|
+
requirement: &70129867285700 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70129867285700
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: commander
|
71
|
+
requirement: &70129867285100 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70129867285100
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: cronedit
|
82
|
+
requirement: &70129867284420 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70129867284420
|
91
|
+
description: A collection of purpose built utilities for doing tasks specific to MyFDB
|
92
|
+
email:
|
93
|
+
- development@myfdb.com
|
94
|
+
executables:
|
95
|
+
- myfdb
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- .gitignore
|
100
|
+
- .rspec
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE
|
103
|
+
- README.rdoc
|
104
|
+
- Rakefile
|
105
|
+
- bin/myfdb
|
106
|
+
- lib/command/helpers.rb
|
107
|
+
- lib/command/settings.rb
|
108
|
+
- lib/myfdb.rb
|
109
|
+
- lib/myfdb/batch.rb
|
110
|
+
- lib/myfdb/batch/images.rb
|
111
|
+
- lib/myfdb/uploader.rb
|
112
|
+
- lib/version.rb
|
113
|
+
- myfdb_utilities.gemspec
|
114
|
+
- spec/fixtures/images/.gitkeep
|
115
|
+
- spec/fixtures/join_images/0_test_0-a.jpg
|
116
|
+
- spec/fixtures/join_images/0_test_1-a.jpg
|
117
|
+
- spec/fixtures/join_images/1_test_0-aa.jpg
|
118
|
+
- spec/fixtures/join_images/1_test_1-aa.jpg
|
119
|
+
- spec/fixtures/join_images/2_test_0-b.jpg
|
120
|
+
- spec/fixtures/join_images/2_test_1-b.jpg
|
121
|
+
- spec/fixtures/join_images/3_test_0-bb.jpg
|
122
|
+
- spec/fixtures/join_images/3_test_1-bb.jpg
|
123
|
+
- spec/fixtures/join_images/4_test_0-bbb.jpg
|
124
|
+
- spec/fixtures/join_images/4_test_1-bbb.jpg
|
125
|
+
- spec/fixtures/join_images/4_test_2-bbb.jpg
|
126
|
+
- spec/myfdb/batch/images_spec.rb
|
127
|
+
- spec/myfdb/batch_spec.rb
|
128
|
+
- spec/myfdb/bin/myfdb_spec.rb
|
129
|
+
- spec/myfdb/uploader_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/fakeweb.rb
|
132
|
+
homepage: http://rubygems.org/gems/myfdb_utilities
|
133
|
+
licenses: []
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
hash: 3244499532377322121
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.3.6
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 1.8.10
|
156
|
+
signing_key:
|
157
|
+
specification_version: 3
|
158
|
+
summary: Utilities gem for myfdb
|
159
|
+
test_files: []
|