dewey 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -202,8 +202,8 @@ module Dewey
202
202
  # @see #get
203
203
  # @see #delete
204
204
  def convert(file, options = {})
205
- id = put(file, options[:title])
206
- converted = get(id, options[:format])
205
+ id = put(file, options)
206
+ converted = get(id, options)
207
207
 
208
208
  delete(id)
209
209
 
@@ -1,3 +1,3 @@
1
1
  module Dewey
2
- VERSION = '0.2.9'
2
+ VERSION = '0.2.10'
3
3
  end
@@ -1,17 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Dewey.convert" do
4
- before(:each) do
5
- stub_dewey_auth
3
+ describe Dewey, '#convert' do
4
+ let(:txt) { sample_file 'sample_document.txt' }
5
+ let(:doc) { sample_file 'sample_document.doc' }
6
6
 
7
- @txt = sample_file 'sample_document.txt'
8
- @doc = sample_file 'sample_document.doc'
7
+ before do
8
+ stub_dewey_auth
9
9
  end
10
10
 
11
- it "should put, get, and delete" do
12
- Dewey.should_receive(:put).with(@txt, 'sample').and_return('document:12345')
13
- Dewey.should_receive(:get).with('document:12345', :doc).and_return(@doc)
14
- Dewey.should_receive(:delete).with('document:12345').and_return(true)
15
- Dewey.convert(@txt, :title => 'sample', :format => :doc).should be(@doc)
11
+ it "puts, gets, and then deletes" do
12
+ # Put
13
+ stub_request(:post, Dewey::GOOGLE_FEED_URL).
14
+ to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/document:12345</id></entry></feed>")
15
+
16
+ # Get
17
+ stub_request(:get, "#{Dewey::GOOGLE_DOCUMENT_URL}?id=12345&exportFormat=doc&format=doc").
18
+ to_return(:body => doc)
19
+
20
+ # Delete
21
+ stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true")
22
+
23
+ returned = Dewey.convert(txt, :title => 'sample', :format => :doc)
24
+
25
+ returned.should be_instance_of(File)
26
+ returned.path.should match(/\.doc/)
16
27
  end
17
28
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Dewey.delete" do
4
- before(:each) { stub_dewey_auth }
3
+ describe Dewey, '#delete' do
4
+ before { stub_dewey_auth }
5
5
 
6
6
  it "deletes a resource from an id" do
7
7
  stub_request(:delete, "#{Dewey::GOOGLE_FEED_URL}/document:12345?delete=true")
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Dewey.get" do
4
- before(:each) { stub_dewey_auth }
3
+ describe Dewey, '#get' do
4
+ before { stub_dewey_auth }
5
5
 
6
6
  it "raises with an invalid format" do
7
7
  lambda { Dewey.get('document:12345', :format => :psd) }.should raise_exception(Dewey::DeweyError)
@@ -1,50 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Dewey.put' do
4
- before(:each) { stub_dewey_auth }
5
-
6
- before(:all) do
7
- @psd = sample_file 'sample_drawing.psd'
8
- @txt = sample_file 'sample_document.txt'
9
- @spr = sample_file 'sample_spreadsheet.xls'
10
- @bad = sample_file 'bad_mimetype'
11
- end
12
-
13
- after(:all) do
14
- [@psd, @txt, @spr, @bad].map(&:close)
15
- end
3
+ describe Dewey, '#put' do
4
+ let(:bad) { sample_file 'bad_mimetype' }
5
+ let(:psd) { sample_file 'sample_drawing.psd' }
6
+ let(:spr) { sample_file 'sample_spreadsheet.xls' }
7
+ let(:txt) { sample_file 'sample_document.txt' }
16
8
 
17
- it "should raise when uploading unsupported file types" do
18
- lambda { Dewey.put(@psd) }.should raise_exception(Dewey::DeweyError)
19
- end
9
+ before { stub_dewey_auth }
20
10
 
21
- it "should raise when uploading a document with a bad mimetype" do
22
- lambda { Dewey.put(@bad) }.should raise_exception(Dewey::DeweyError)
11
+ it "raises when uploading unsupported file types" do
12
+ lambda { Dewey.put(psd) }.should raise_exception(Dewey::DeweyError)
23
13
  end
24
14
 
25
- it "should return nil on a failed request" do
15
+ it "returns nil on a failed request" do
26
16
  stub_request(:post, Dewey::GOOGLE_FEED_URL).to_return(:status => 300)
27
17
 
28
- Dewey.put(@txt).should be_nil
18
+ Dewey.put(txt).should be_nil
29
19
  end
30
20
 
31
21
  it "get a resource id after putting a document" do
32
22
  stub_request(:post, Dewey::GOOGLE_FEED_URL).
33
23
  to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/document:12345</id></entry></feed>")
34
24
 
35
- Dewey.put(@txt).should eq('document:12345')
25
+ Dewey.put(txt).should eq('document:12345')
36
26
  end
37
27
 
38
28
  it "get a resource id after putting a spreadsheet" do
39
29
  stub_request(:post, Dewey::GOOGLE_FEED_URL).
40
30
  to_return(:status => 201, :body => "<feed><entry><id>https://docs.google.com/feeds/id/spreadsheet:12345</id></entry></feed>")
41
31
 
42
- Dewey.put(@spr).should eq('spreadsheet:12345')
32
+ Dewey.put(spr).should eq('spreadsheet:12345')
43
33
  end
44
34
 
45
35
  it "specifies an optional title in the header" do
46
36
  stub_request(:post, Dewey::GOOGLE_FEED_URL)
47
- Dewey.put(@txt, :title => 'Secret')
37
+ Dewey.put(txt, :title => 'Secret')
48
38
 
49
39
  a_request(:post, Dewey::GOOGLE_FEED_URL).
50
40
  with(:headers => { 'Slug' => 'Secret' }).should have_been_made
@@ -53,19 +43,21 @@ describe 'Dewey.put' do
53
43
  it "specifies the filesize in the header" do
54
44
  stub_request(:post, Dewey::GOOGLE_FEED_URL)
55
45
 
56
- Dewey.put(@txt)
46
+ Dewey.put(txt)
57
47
 
58
48
  a_request(:post, Dewey::GOOGLE_FEED_URL).
59
- with(:headers => { 'Content-Length' => @txt.size }).should have_been_made
49
+ with(:headers => { 'Content-Length' => txt.size }).should have_been_made
60
50
  end
61
51
  end
62
52
 
63
- describe "Dewey.put!" do
64
- before(:each) { stub_dewey_auth }
53
+ describe Dewey, '#put' do
54
+ let(:txt) { sample_file 'sample_document.txt' }
55
+
56
+ before { stub_dewey_auth }
65
57
 
66
58
  it "raises an error on a failed request" do
67
- txt = sample_file 'sample_document.txt'
68
59
  stub_request(:post, Dewey::GOOGLE_FEED_URL).to_return(:status => 300)
60
+
69
61
  lambda { Dewey.put!(txt) }.should raise_exception(Dewey::DeweyError)
70
62
  end
71
63
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Dewey.search" do
3
+ describe Dewey, '#search' do
4
4
  before(:each) { stub_dewey_auth }
5
5
 
6
6
  it "can exactly match a single document" do
@@ -1,64 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dewey::Mime do
4
+ let(:csv) { sample_file 'sample_spreadsheet.csv' }
5
+ let(:doc) { sample_file 'sample_document.doc' }
6
+ let(:docx) { sample_file 'sample_document.docx' }
7
+ let(:nxt) { sample_file 'sample_document' }
8
+ let(:pdf) { sample_file 'sample_document.pdf' }
9
+ let(:png) { sample_file 'sample_drawing.png' }
10
+ let(:ppt) { sample_file 'sample_presentation.ppt' }
11
+ let(:rtf) { sample_file 'sample_document.rtf' }
12
+ let(:xls) { sample_file 'sample_spreadsheet.xls' }
4
13
 
5
14
  describe "Interpreting mime types from files" do
6
15
  it "should provide the correct document mime type" do
7
- @doc = sample_file 'sample_document.doc'
8
- @pdf = sample_file 'sample_document.pdf'
9
- @rtf = sample_file 'sample_document.rtf'
10
-
11
- Dewey::Mime.mime_type(@doc).should eq('application/msword')
12
- Dewey::Mime.mime_type(@pdf).should eq('application/pdf')
13
- Dewey::Mime.mime_type(@rtf).should eq('application/rtf')
16
+ Dewey::Mime.mime_type(doc).should eq('application/msword')
17
+ Dewey::Mime.mime_type(pdf).should eq('application/pdf')
18
+ Dewey::Mime.mime_type(rtf).should eq('application/rtf')
14
19
  end
15
20
 
16
21
  it "should provide the correct drawing mime type" do
17
- @png = sample_file 'sample_drawing.png'
18
-
19
- Dewey::Mime.mime_type(@png).should eq('image/png')
22
+ Dewey::Mime.mime_type(png).should eq('image/png')
20
23
  end
21
24
 
22
25
  it "should provide the correct presentation mime type" do
23
- @ppt = sample_file 'sample_presentation.ppt'
24
-
25
- Dewey::Mime.mime_type(@ppt).should eq('application/vnd.ms-powerpoint')
26
+ Dewey::Mime.mime_type(ppt).should eq('application/vnd.ms-powerpoint')
26
27
  end
27
28
 
28
29
  it "should provide the correct spreadsheet mime type" do
29
- @xls = sample_file 'sample_spreadsheet.xls'
30
- @csv = sample_file 'sample_spreadsheet.csv'
31
-
32
- Dewey::Mime.mime_type(@xls).should eq('application/vnd.ms-excel')
33
- Dewey::Mime.mime_type(@csv).should eq('text/csv')
30
+ Dewey::Mime.mime_type(xls).should eq('application/vnd.ms-excel')
31
+ Dewey::Mime.mime_type(csv).should eq('text/csv')
34
32
  end
35
33
 
36
34
  it "should coerce problematic mime types" do
37
- @docx = sample_file 'sample_document.docx'
38
35
 
39
- Dewey::Mime.mime_type(@docx).should eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
36
+ Dewey::Mime.mime_type(docx).should eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
40
37
  end
41
38
 
42
39
  it "should correctly guess from a file without an extension" do
43
- @noext = sample_file 'sample_document'
44
-
45
- Dewey::Mime.mime_type(@noext).should eq('application/msword')
40
+ Dewey::Mime.mime_type(nxt).should eq('application/msword')
46
41
  end
47
42
  end
48
43
 
49
44
  describe "Determining file extesion from files" do
50
45
  context "when the filename has an extension" do
51
46
  it "should pull the extension off the filename" do
52
- @docx = sample_file 'sample_document.docx'
53
-
54
- Dewey::Mime.extension(@docx).should eq('docx')
47
+ Dewey::Mime.extension(docx).should eq('docx')
55
48
  end
56
49
  end
57
50
  context "when the filename does not have an extension" do
58
51
  it "should pull the extension off the filename" do
59
- @docx = sample_file 'sample_document'
60
-
61
- Dewey::Mime.extension(@docx).should eq('doc')
52
+ Dewey::Mime.extension(nxt).should eq('doc')
62
53
  end
63
54
  end
64
55
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dewey::Validation do
4
-
5
4
  it "should return true for valid upload formats" do
6
5
  Dewey::Validation.valid_upload_format?(:txt, :document).should be_true
7
6
  Dewey::Validation.valid_upload_format?(:svg, :drawing).should be_true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dewey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-02 00:00:00.000000000 -05:00
12
+ date: 2011-12-01 00:00:00.000000000 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &2156571360 !ruby/object:Gem::Requirement
17
+ requirement: &2156551460 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.8.7
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2156571360
25
+ version_requirements: *2156551460
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2156570320 !ruby/object:Gem::Requirement
28
+ requirement: &2156550560 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.6.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2156570320
36
+ version_requirements: *2156550560
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: webmock
39
- requirement: &2156569560 !ruby/object:Gem::Requirement
39
+ requirement: &2156549380 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.7.6
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2156569560
47
+ version_requirements: *2156549380
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: yard
50
- requirement: &2156568900 !ruby/object:Gem::Requirement
50
+ requirement: &2156546480 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 0.7.2
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2156568900
58
+ version_requirements: *2156546480
59
59
  description: Light, simple Google Docs library for Ruby.
60
60
  email:
61
61
  - parker@sorentwo.com
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  segments:
121
121
  - 0
122
- hash: -1290362203853795856
122
+ hash: 2270030557536834632
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  none: false
125
125
  requirements:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: -1290362203853795856
131
+ hash: 2270030557536834632
132
132
  requirements: []
133
133
  rubyforge_project: dewey
134
134
  rubygems_version: 1.6.2