imap-backup 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,9 @@ module Imap
13
13
  def uids
14
14
  @connection.imap.examine(@folder)
15
15
  @connection.imap.uid_search(['ALL']).sort
16
+ rescue Net::IMAP::NoResponseError => e
17
+ warn "Folder '#{@folder}' does not exist"
18
+ []
16
19
  end
17
20
 
18
21
  def fetch(uid)
@@ -10,6 +10,7 @@ module Imap
10
10
 
11
11
  def run
12
12
  loop do
13
+ system('clear')
13
14
  Setup.highline.choose do |menu|
14
15
  password =
15
16
  if @account[:password] == ''
@@ -18,6 +18,7 @@ module Imap
18
18
  end
19
19
  @folders = @connection.folders
20
20
  loop do
21
+ system('clear')
21
22
  Setup.highline.choose do |menu|
22
23
  menu.header = 'Add/remove folders'
23
24
  menu.index = :number
@@ -17,6 +17,7 @@ module Imap
17
17
 
18
18
  def run
19
19
  loop do
20
+ system('clear')
20
21
  self.class.highline.choose do |menu|
21
22
  menu.header = 'Choose an action'
22
23
  @config.data[:accounts].each do |account|
@@ -2,8 +2,8 @@ module Imap
2
2
  module Backup
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- REVISION = 1
6
- VERSION = [ MAJOR, MINOR, REVISION ].map( &:to_s ).join( '.' )
5
+ REVISION = 2
6
+ VERSION = [MAJOR, MINOR, REVISION].map(&:to_s).join('.')
7
7
  end
8
8
  end
9
9
 
@@ -2,6 +2,8 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Imap::Backup::Account::Folder do
5
+ include InputOutputTestHelpers
6
+
5
7
  context 'with instance' do
6
8
  before :each do
7
9
  @imap = stub('Net::IMAP')
@@ -17,6 +19,20 @@ describe Imap::Backup::Account::Folder do
17
19
 
18
20
  subject.uids.should == [123, 5678]
19
21
  end
22
+
23
+ it 'returns an empty array for missing mailboxes' do
24
+ data = stub('Data', :text => 'Unknown Mailbox: my_folder')
25
+ response = stub('Response', :data => data)
26
+ error = Net::IMAP::NoResponseError.new(response)
27
+ @imap.
28
+ should_receive(:examine).
29
+ with('my_folder').
30
+ and_raise(error)
31
+
32
+ capturing_output do
33
+ expect(subject.uids).to eq([])
34
+ end
35
+ end
20
36
  end
21
37
 
22
38
  context '#fetch' do
@@ -38,11 +38,18 @@ describe Imap::Backup::Configuration::Account do
38
38
  @store = stub('Imap::Backup::Configuration::Store')
39
39
  @store.stub!(:data => @data)
40
40
  @input, @output = prepare_highline
41
+ subject.stub(:system => nil)
41
42
  end
42
43
 
43
44
  subject { Imap::Backup::Configuration::Account.new(@store, @account1) }
44
45
 
45
46
  context 'menu' do
47
+ it 'clears the screen' do
48
+ subject.should_receive(:system).with('clear')
49
+
50
+ subject.run
51
+ end
52
+
46
53
  it 'should show a menu' do
47
54
  subject.run
48
55
 
@@ -7,68 +7,93 @@ describe Imap::Backup::Configuration::FolderChooser do
7
7
  include InputOutputTestHelpers
8
8
 
9
9
  context '#run' do
10
- before :each do
11
- empty_account = {
10
+ let(:connection) do
11
+ stub(
12
+ 'Imap::Backup::Account::Connection'
13
+ )
14
+ end
15
+ let(:existing_account) do
16
+ {
17
+ :folders => [{:name => 'my_folder'}]
18
+ }
19
+ end
20
+ let(:empty_account) do
21
+ {
12
22
  :folders => []
13
23
  }
14
- @connection = setup_account(empty_account, [])
15
- @input, @output = prepare_highline
24
+ end
25
+ let(:remote_folders) do
26
+ folder1 = stub('folder', :name => 'my_folder') # this one is already backed up
27
+ folder2 = stub('folder', :name => 'another_folder')
28
+ [folder1, folder2]
16
29
  end
17
30
 
18
- def setup_account(account, remote_folders)
19
- @account = account
20
- connection = stub('Imap::Backup::Account::Connection')
21
- connection.stub!(:folders).and_return(remote_folders)
22
- Imap::Backup::Account::Connection.stub!(:new).with(account).and_return(connection)
23
- connection
31
+ before do
32
+ @input, @output = prepare_highline
24
33
  end
25
34
 
26
- subject { Imap::Backup::Configuration::FolderChooser.new(@account) }
35
+ context 'empty account' do
36
+ let(:account) { empty_account }
27
37
 
28
- it 'should connect to the account' do
29
- Imap::Backup::Account::Connection.should_receive(:new).with(@account).and_return(@connection)
38
+ subject { Imap::Backup::Configuration::FolderChooser.new(account) }
30
39
 
31
- subject.run
32
- end
40
+ before do
41
+ connection.stub!(:folders).and_return([])
42
+ Imap::Backup::Account::Connection.stub!(:new).with(account).and_return(connection)
43
+ subject.stub(:system).with('clear')
44
+ end
33
45
 
34
- it 'should handle connection errors' do
35
- Imap::Backup::Account::Connection.should_receive(:new).with(@account).and_raise('error')
36
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with('Press a key ')
46
+ it 'should connect to the account' do
47
+ Imap::Backup::Account::Connection.should_receive(:new).with(account).and_return(connection)
37
48
 
38
- capturing_output do
39
49
  subject.run
40
- end.should =~ /connection failed/i
41
- end
50
+ end
42
51
 
43
- it 'should get a list of account folders' do
44
- @connection.should_receive(:folders).and_return([])
52
+ it 'should handle connection errors' do
53
+ Imap::Backup::Account::Connection.should_receive(:new).with(account).and_raise('error')
54
+ Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with('Press a key ')
45
55
 
46
- subject.run
47
- end
56
+ capturing_output do
57
+ subject.run
58
+ end.should =~ /connection failed/i
59
+ end
48
60
 
49
- it 'should show the menu' do
50
- subject.run
51
-
52
- @output.string.should =~ %r{Add/remove folders}
53
- end
61
+ it 'should get a list of account folders' do
62
+ connection.should_receive(:folders).and_return([])
54
63
 
55
- it 'should return to the account menu' do
56
- @input.should_receive(:gets).and_return("return\n")
64
+ subject.run
65
+ end
66
+
67
+ it 'clears the screen' do
68
+ subject.should_receive(:system).with('clear')
57
69
 
58
- subject.run
59
-
60
- @output.string.should =~ %r{return to the account menu}
70
+ subject.run
71
+ end
72
+
73
+ it 'should show the menu' do
74
+ subject.run
75
+
76
+ @output.string.should =~ %r{Add/remove folders}
77
+ end
78
+
79
+ it 'should return to the account menu' do
80
+ @input.should_receive(:gets).and_return("return\n")
81
+
82
+ subject.run
83
+
84
+ @output.string.should =~ %r{return to the account menu}
85
+ end
61
86
  end
62
87
 
63
88
  context 'folder listing' do
64
- before :each do
65
- account = {
66
- :folders => [{:name => 'my_folder'}]
67
- }
68
- folder1 = stub('folder', :name => 'my_folder') # this one is already backed up
69
- folder2 = stub('folder', :name => 'another_folder')
70
- remote_folders = [folder1, folder2]
71
- @connection = setup_account(account, remote_folders)
89
+ let(:account) { existing_account }
90
+
91
+ subject { Imap::Backup::Configuration::FolderChooser.new(account) }
92
+
93
+ before do
94
+ connection.stub!(:folders).and_return(remote_folders)
95
+ Imap::Backup::Account::Connection.stub!(:new).with(account).and_return(connection)
96
+ subject.stub(:system).with('clear')
72
97
  end
73
98
 
74
99
  it 'should list folders' do
@@ -99,7 +124,7 @@ describe Imap::Backup::Configuration::FolderChooser do
99
124
  subject.run
100
125
 
101
126
  @output.string.should =~ /\d+\. \+ another_folder/
102
- @account[:folders].should include( { :name => 'another_folder' } )
127
+ account[:folders].should include( { :name => 'another_folder' } )
103
128
  end
104
129
 
105
130
  it 'should remove folders' do
@@ -117,7 +142,7 @@ describe Imap::Backup::Configuration::FolderChooser do
117
142
  subject.run
118
143
 
119
144
  @output.string.should =~ /\d+\. \- my_folder/
120
- @account[:folders].should_not include( { :name => 'my_folder' } )
145
+ account[:folders].should_not include( { :name => 'my_folder' } )
121
146
  end
122
147
  end
123
148
  end
@@ -16,6 +16,7 @@ describe Imap::Backup::Configuration::Setup do
16
16
  before :each do
17
17
  prepare_store
18
18
  @input, @output = prepare_highline
19
+ subject.stub(:system => nil)
19
20
  end
20
21
 
21
22
  def prepare_store
@@ -39,6 +40,12 @@ describe Imap::Backup::Configuration::Setup do
39
40
  @output.string.should =~ /quit/
40
41
  end
41
42
 
43
+ it 'clears the screen' do
44
+ subject.should_receive(:system).with('clear')
45
+
46
+ subject.run
47
+ end
48
+
42
49
  it 'should list accounts' do
43
50
  subject.run
44
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -187,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  segments:
189
189
  - 0
190
- hash: 1867766777440441483
190
+ hash: -2027383479193417702
191
191
  required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  none: false
193
193
  requirements:
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  segments:
198
198
  - 0
199
- hash: 1867766777440441483
199
+ hash: -2027383479193417702
200
200
  requirements: []
201
201
  rubyforge_project:
202
202
  rubygems_version: 1.8.23