bitsa 0.20 → 0.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +26 -20
- data/HISTORY +11 -1
- data/README.rdoc +11 -2
- data/bin/bitsa +0 -1
- data/bitsa.gemspec +4 -4
- data/lib/bitsa.rb +24 -14
- data/lib/bitsa/args_processor.rb +7 -3
- data/lib/bitsa/contacts_cache.rb +8 -7
- data/lib/bitsa/gmail_contacts_loader.rb +19 -13
- data/lib/bitsa/settings.rb +8 -0
- data/lib/bitsa/version.rb +1 -1
- data/rvmrc +1 -0
- data/spec/helper.rb +5 -1
- data/spec/lib/bitsa/args_processor_spec.rb +123 -0
- data/spec/lib/bitsa/confg_file_spec.rb +34 -0
- data/spec/lib/bitsa/contacts_cache_spec.rb +331 -0
- data/spec/lib/bitsa/gmail_contacts_loader_spec.rb +203 -0
- data/spec/lib/bitsa/settings_spec.rb +50 -0
- data/spec/lib/bitsa_spec.rb +2 -0
- data/tasks/spec.rake +5 -5
- metadata +64 -46
- data/spec/args_processor_spec.rb +0 -66
- data/spec/confg_file_spec.rb +0 -32
- data/spec/contacts_cache_spec.rb +0 -294
- data/spec/gmail_contacts_loader_spec.rb +0 -89
- data/spec/settings_spec.rb +0 -34
@@ -0,0 +1,50 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
require "bitsa/config_file"
|
4
|
+
require "bitsa/settings"
|
5
|
+
|
6
|
+
describe Bitsa::Settings do
|
7
|
+
context "login specified in config file"
|
8
|
+
it "should read a value from config file if it wasn't passed in options" do
|
9
|
+
settings = load_settings({})
|
10
|
+
expect(settings.login).to eq "test@gmail.com"
|
11
|
+
expect(settings.password).to eq "myPassword"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should use values passed in options to override those in the config file" do
|
15
|
+
settings = load_settings({:login => "somebody@example.com"})
|
16
|
+
expect(settings.login).to eq "somebody@example.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should still use values in config file when other options passed" do
|
20
|
+
settings = load_settings({:login => "somebody@example.com"})
|
21
|
+
expect(settings.password).to eq "myPassword"
|
22
|
+
end
|
23
|
+
|
24
|
+
context "default value" do
|
25
|
+
let(:settings) { empty_settings }
|
26
|
+
|
27
|
+
context :auto_check do
|
28
|
+
specify { expect(settings.auto_check).to eq 1}
|
29
|
+
end
|
30
|
+
|
31
|
+
context :cache_file_path do
|
32
|
+
specify { expect(settings.cache_file_path).to eq "~/.bitsa_cache.yml" }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def load_settings(options)
|
39
|
+
settings = Bitsa::Settings.new
|
40
|
+
settings.load(Bitsa::ConfigFile.new("spec/data/config.yml"), options)
|
41
|
+
settings
|
42
|
+
end
|
43
|
+
|
44
|
+
def empty_settings()
|
45
|
+
settings = Bitsa::Settings.new
|
46
|
+
settings.load(Bitsa::ConfigFile.new("/tmp/non-existent"), {})
|
47
|
+
settings
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/tasks/spec.rake
CHANGED
@@ -2,8 +2,8 @@ require 'rspec/core/rake_task'
|
|
2
2
|
|
3
3
|
RSpec::Core::RakeTask.new(:spec) {}
|
4
4
|
|
5
|
-
desc "Run all specs with rcov"
|
6
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
5
|
+
# desc "Run all specs with rcov"
|
6
|
+
# RSpec::Core::RakeTask.new(:rcov) do |t|
|
7
|
+
# t.rcov = true
|
8
|
+
# t.rcov_opts = %w{--exclude spec\/,gems\/}
|
9
|
+
# end
|
metadata
CHANGED
@@ -1,93 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitsa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.30'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Colin Noel Bell
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: trollop
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - =
|
17
|
+
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '2.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: gdata_19
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ~>
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 1.1.3
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.3
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: bundler
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: 1.0.0
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: rspec
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
61
|
+
version: 3.1.0
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: fakeweb
|
60
|
-
requirement:
|
61
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
73
|
- - ~>
|
64
74
|
- !ruby/object:Gem::Version
|
65
|
-
version: 1.
|
75
|
+
version: 1.3.0
|
66
76
|
type: :development
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: simplecov
|
71
|
-
requirement:
|
72
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- -
|
87
|
+
- - '>='
|
75
88
|
- !ruby/object:Gem::Version
|
76
89
|
version: '0'
|
77
90
|
type: :development
|
78
91
|
prerelease: false
|
79
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
80
97
|
- !ruby/object:Gem::Dependency
|
81
98
|
name: rake
|
82
|
-
requirement:
|
83
|
-
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
84
100
|
requirements:
|
85
|
-
- -
|
101
|
+
- - '>='
|
86
102
|
- !ruby/object:Gem::Version
|
87
103
|
version: '0'
|
88
104
|
type: :development
|
89
105
|
prerelease: false
|
90
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
91
111
|
description: Allows you to lookup GMail contacts and cache contacts locally from the
|
92
112
|
command line.
|
93
113
|
email:
|
@@ -118,19 +138,22 @@ files:
|
|
118
138
|
- lib/bitsa/gmail_contacts_loader.rb
|
119
139
|
- lib/bitsa/settings.rb
|
120
140
|
- lib/bitsa/version.rb
|
121
|
-
-
|
122
|
-
- spec/confg_file_spec.rb
|
123
|
-
- spec/contacts_cache_spec.rb
|
141
|
+
- rvmrc
|
124
142
|
- spec/data/bitsa_cache.yml
|
125
143
|
- spec/data/config.yml
|
126
|
-
- spec/gmail_contacts_loader_spec.rb
|
127
144
|
- spec/helper.rb
|
128
|
-
- spec/
|
145
|
+
- spec/lib/bitsa/args_processor_spec.rb
|
146
|
+
- spec/lib/bitsa/confg_file_spec.rb
|
147
|
+
- spec/lib/bitsa/contacts_cache_spec.rb
|
148
|
+
- spec/lib/bitsa/gmail_contacts_loader_spec.rb
|
149
|
+
- spec/lib/bitsa/settings_spec.rb
|
150
|
+
- spec/lib/bitsa_spec.rb
|
129
151
|
- tasks/create_tags.rake
|
130
152
|
- tasks/retrieve_one_page.rake
|
131
153
|
- tasks/spec.rake
|
132
154
|
homepage: https://github.com/colbell/bitsa
|
133
155
|
licenses: []
|
156
|
+
metadata: {}
|
134
157
|
post_install_message:
|
135
158
|
rdoc_options:
|
136
159
|
- --main
|
@@ -138,24 +161,19 @@ rdoc_options:
|
|
138
161
|
require_paths:
|
139
162
|
- lib
|
140
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
164
|
requirements:
|
143
|
-
- -
|
165
|
+
- - '>='
|
144
166
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
146
|
-
segments:
|
147
|
-
- 0
|
148
|
-
hash: -3627828178775541145
|
167
|
+
version: 1.9.0
|
149
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
169
|
requirements:
|
152
|
-
- -
|
170
|
+
- - '>='
|
153
171
|
- !ruby/object:Gem::Version
|
154
172
|
version: 1.3.6
|
155
173
|
requirements: []
|
156
174
|
rubyforge_project:
|
157
|
-
rubygems_version:
|
175
|
+
rubygems_version: 2.0.3
|
158
176
|
signing_key:
|
159
|
-
specification_version:
|
177
|
+
specification_version: 4
|
160
178
|
summary: Command line GMail Contacts lookup tool.
|
161
179
|
test_files: []
|
data/spec/args_processor_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "bitsa/args_processor"
|
3
|
-
|
4
|
-
describe Bitsa::ArgsProcessor do
|
5
|
-
context "when created" do
|
6
|
-
before(:all) { @ap = Bitsa::ArgsProcessor.new }
|
7
|
-
|
8
|
-
it "should recognise the 'update' command" do
|
9
|
-
@ap.parse(["update"])
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should throw raise SystemExit if an invalid command passed" do
|
13
|
-
lambda {@ap.parse(['unknown'])}.should raise_error(SystemExit)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should throw raise SystemExit if nothing passed" do
|
17
|
-
lambda {@ap.parse([])}.should raise_error(SystemExit)
|
18
|
-
end
|
19
|
-
|
20
|
-
context "and being passed valid commands" do
|
21
|
-
[["reload"], ["search", "data"], ["update"]].each do |ar|
|
22
|
-
cmd = ar[0]
|
23
|
-
it "should recognise the #{cmd} command" do
|
24
|
-
@ap.parse(ar)
|
25
|
-
@ap.cmd.should == cmd
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should recognise valid long arguments" do
|
31
|
-
args = []
|
32
|
-
args << "--config-file"
|
33
|
-
args << "somefile"
|
34
|
-
args << "--login"
|
35
|
-
args << "someone"
|
36
|
-
args << "--password"
|
37
|
-
args << "mypassword"
|
38
|
-
args << "update"
|
39
|
-
|
40
|
-
@ap.parse(args)
|
41
|
-
|
42
|
-
@ap.global_opts[:config_file].should == "somefile"
|
43
|
-
@ap.global_opts[:login].should == "someone"
|
44
|
-
@ap.global_opts[:password].should == "mypassword"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should recognise valid short arguments" do
|
48
|
-
args = []
|
49
|
-
args << "-c"
|
50
|
-
args << "somefile"
|
51
|
-
args << "-l"
|
52
|
-
args << "someone"
|
53
|
-
args << "-p"
|
54
|
-
args << "mypassword"
|
55
|
-
args << "update"
|
56
|
-
|
57
|
-
@ap.parse(args)
|
58
|
-
|
59
|
-
@ap.global_opts[:config_file].should == "somefile"
|
60
|
-
@ap.global_opts[:login].should == "someone"
|
61
|
-
@ap.global_opts[:password].should == "mypassword"
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
data/spec/confg_file_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "bitsa/config_file"
|
3
|
-
|
4
|
-
describe Bitsa::ConfigFile do
|
5
|
-
context "An existing configuration file" do
|
6
|
-
before(:all) { @config = Bitsa::ConfigFile.new("spec/data/config.yml") }
|
7
|
-
it "should read values from config file" do
|
8
|
-
@config.data[:login].should == "test@gmail.com"
|
9
|
-
@config.data[:password].should == "myPassword"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "An non-existent configuration file" do
|
14
|
-
before(:all) { @config = Bitsa::ConfigFile.new("/tmp/i-dont-exist") }
|
15
|
-
it "should have no values" do
|
16
|
-
@config.data.should == {}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "An existing configuration file that I have no read rights to" do
|
21
|
-
before(:all) do
|
22
|
-
@tmp_file = Tempfile.open("cache")
|
23
|
-
FileUtils.cp("spec/data/config.yml", @tmp_file.path)
|
24
|
-
FileUtils.chmod(0222, @tmp_file.path)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should throw an exception when I try to read from it" do
|
28
|
-
lambda { Bitsa::ConfigFile.new(@tmp_file.path) }.should raise_error(Errno::EACCES)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/contacts_cache_spec.rb
DELETED
@@ -1,294 +0,0 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
require "tempfile"
|
3
|
-
|
4
|
-
require "helper"
|
5
|
-
|
6
|
-
require "bitsa/contacts_cache"
|
7
|
-
|
8
|
-
describe Bitsa::ContactsCache do
|
9
|
-
context "cache" do
|
10
|
-
it "should build successfully if cache file empty" do
|
11
|
-
tmp_file = create_empty_temp_file
|
12
|
-
cache = Bitsa::ContactsCache.new(tmp_file.path, 1)
|
13
|
-
should_be_an_empty_cache cache
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should build successfully if cache file does not exist" do
|
17
|
-
cache = Bitsa::ContactsCache.new("/tmp/idonotexististhatoky", 1)
|
18
|
-
should_be_an_empty_cache cache
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should fail with exception if user not authorised to read cache file" do
|
22
|
-
tmp_file = create_empty_temp_file
|
23
|
-
FileUtils.chmod(0222, tmp_file.path)
|
24
|
-
lambda { Bitsa::ContactsCache.new(tmp_file.path, 1).should raise_error(Errno::EACCES) }
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should not be stale if last updated today" do
|
28
|
-
create_cache(DateTime.now, 1)
|
29
|
-
@cache.stale?.should_not be_true
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should be stale if last updated yesterday and lifespan is 1 day" do
|
33
|
-
create_cache(DateTime.now-1, 1)
|
34
|
-
@cache.stale?.should be_true
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should not be stale if last updated yesterday and lifespan is 2 days" do
|
38
|
-
create_cache(DateTime.now-1, 2)
|
39
|
-
@cache.stale?.should_not be_true
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "clearing the cache" do
|
44
|
-
before(:each) do
|
45
|
-
create_cache
|
46
|
-
@cache.should have_at_least(1).entries
|
47
|
-
@cache.empty?.should be_false
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should leave the cache empty" do
|
51
|
-
@cache.clear!
|
52
|
-
@cache.size.should == 0
|
53
|
-
@cache.empty?.should be_true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "searching the test data" do
|
58
|
-
# 4 contacts with 5 email addresses
|
59
|
-
before(:all) { create_cache }
|
60
|
-
|
61
|
-
it "should have read the correct number of contacts" do
|
62
|
-
@cache.size.should == 4
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should return all entries if blank searched for" do
|
66
|
-
results = @cache.search('')
|
67
|
-
results.size.should == 5
|
68
|
-
results.flatten(0).sort.should == read_test_data
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should return all entries if a nill string searched for" do
|
72
|
-
results = @cache.search(nil)
|
73
|
-
results.size.should == 5
|
74
|
-
results.flatten(0).sort.should == read_test_data
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should find correctly when searching by start of email address" do
|
78
|
-
results = @cache.search('test1')
|
79
|
-
results.should =~ [["test1@example.com", "My Tester"]]
|
80
|
-
|
81
|
-
results = @cache.search('jo')
|
82
|
-
expected = [["john_smith@here.org", ""], ["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
83
|
-
results.should =~ expected
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should find correctly when searching by end of email address" do
|
87
|
-
results = @cache.search('org')
|
88
|
-
expected = [["john_smith@here.org", ""]]
|
89
|
-
results.should =~ expected
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should find correctly when searching by middle of email address" do
|
93
|
-
results = @cache.search('n_s')
|
94
|
-
expected = [["john_smith@here.org", ""]]
|
95
|
-
results.should =~ expected
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should find correctly when searching by email address irrespective of case" do
|
99
|
-
results = @cache.search('N_sMI')
|
100
|
-
expected = [["john_smith@here.org", ""]]
|
101
|
-
results.should =~ expected
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should find correctly when searching by start of name" do
|
105
|
-
results = @cache.search('Joan Blo')
|
106
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
107
|
-
results.should =~ expected
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should find correctly when searching by end of name" do
|
111
|
-
results = @cache.search('ggshere')
|
112
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
113
|
-
results.should =~ expected
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should find correctly when searching by middle of name" do
|
117
|
-
results = @cache.search('n Bl')
|
118
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
119
|
-
results.should =~ expected
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should find correctly when searching by name irrespective of case" do
|
123
|
-
results = @cache.search('N BL')
|
124
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
125
|
-
results.should =~ expected
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should find no results if nothing to find" do
|
129
|
-
results = @cache.search('nothing is here')
|
130
|
-
results.size.should == 0
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should return all email addresses on a contact with multiple email addresses when matching on name" do
|
134
|
-
results = @cache.search('multip')
|
135
|
-
expected = [["email2@somewhere.com", "Mr Multiple"], ["email1@somewhere.com", "Mr Multiple"]]
|
136
|
-
results.should =~ expected
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should return only the matched email address on a contact with multiple email addresses" do
|
140
|
-
results = @cache.search('email1')
|
141
|
-
expected = [["email1@somewhere.com", "Mr Multiple"]]
|
142
|
-
results.should =~ expected
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should find by ID correctly" do
|
146
|
-
id = "http://www.google.com/m8/feeds/contacts/person%40example.org/base/685e301a549c176e"
|
147
|
-
results = @cache.get(id)
|
148
|
-
expected = [["email1@somewhere.com", "Mr Multiple"],
|
149
|
-
["email2@somewhere.com", "Mr Multiple"]]
|
150
|
-
results.should =~ expected
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should return nil if finding by a non-existent ID" do
|
154
|
-
id = "http://www.google.com/m8/feeds/contacts/person%40example.org/base/4783783783"
|
155
|
-
@cache.get(id).should be_nil
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "updating the test data" do
|
160
|
-
# 4 contacts with 5 email addresses
|
161
|
-
before(:each) { create_cache }
|
162
|
-
|
163
|
-
it "should handle update with a single email address correctly" do
|
164
|
-
id = "http://www.google.com/m8/feeds/contacts/person%40example.org/base/637e301a549c176e"
|
165
|
-
results = @cache.get(id)
|
166
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
167
|
-
results.should =~ expected
|
168
|
-
|
169
|
-
@cache.update(id, "Tammy Smith", ["tammy5@example.com"])
|
170
|
-
results = @cache.get(id)
|
171
|
-
expected = [["tammy5@example.com", "Tammy Smith"]]
|
172
|
-
results.should =~ expected
|
173
|
-
end
|
174
|
-
|
175
|
-
it "should handle update with two email addresses correctly" do
|
176
|
-
id = "http://www.google.com/m8/feeds/contacts/person%40example.org/base/637e301a549c176e"
|
177
|
-
results = @cache.get(id)
|
178
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
179
|
-
results.should =~ expected
|
180
|
-
|
181
|
-
@cache.update(id, "Tammy Smith", ["tammy5@example.com", "smithtammy@exampel.org"])
|
182
|
-
results = @cache.get(id)
|
183
|
-
expected = [["smithtammy@exampel.org", "Tammy Smith"], ["tammy5@example.com", "Tammy Smith"]]
|
184
|
-
results.should =~ expected
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context "deleting a non-existent entry" do
|
189
|
-
before(:each) { create_cache }
|
190
|
-
|
191
|
-
it "should no longer contain the deleted entry" do
|
192
|
-
@cache.delete("NONEXISTENT")
|
193
|
-
@cache.get("NONEXISTENT").should be_nil
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should not change the number of entries in the cache" do
|
197
|
-
lambda {
|
198
|
-
@cache.delete("NONEXISTENT")
|
199
|
-
}.should_not change(@cache, :size)
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should return nil" do
|
203
|
-
@cache.delete("NONEXISTENT").should be_nil
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
context "deleting an existing entry" do
|
208
|
-
before(:each) do
|
209
|
-
create_cache
|
210
|
-
@id = "http://www.google.com/m8/feeds/contacts/person%40example.org/base/637e301a549c176e"
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should_change the number of entries by -1" do
|
214
|
-
lambda {
|
215
|
-
@cache.delete(@id)
|
216
|
-
}.should change(@cache, :size).by(-1)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should return the deleted entry" do
|
220
|
-
results = @cache.delete(@id)
|
221
|
-
expected = [["Joan.bloggs@somewhere.com.au", "Joan Bloggshere"]]
|
222
|
-
results.should =~ expected
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should no longer contain the deleted entry" do
|
226
|
-
@cache.delete(@id)
|
227
|
-
@cache.get(@id).should be_nil
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context "saving the test data" do
|
232
|
-
before(:each) { create_cache }
|
233
|
-
it "should save changes to existing contacts" do
|
234
|
-
id = "http://www.google.com/m8/feeds/contacts/person%40example.org/base/637e301a549c176e"
|
235
|
-
@cache.update(id, "The Changed Name", ["change1@somewhere.org"])
|
236
|
-
@cache.save
|
237
|
-
new_cache = Bitsa::ContactsCache.new(@tmp_file.path, 1)
|
238
|
-
expected = [["change1@somewhere.org", "The Changed Name"]]
|
239
|
-
new_cache.get(id).should =~ expected
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should save newly added entries" do
|
243
|
-
id = "NONEXISTENT"
|
244
|
-
@cache.update(id, "The Changed Name", ["change1@somewhere.org"])
|
245
|
-
@cache.save
|
246
|
-
new_cache = Bitsa::ContactsCache.new(@tmp_file.path, 1)
|
247
|
-
expected = [["change1@somewhere.org", "The Changed Name"]]
|
248
|
-
new_cache.get(id).should =~ expected
|
249
|
-
end
|
250
|
-
|
251
|
-
context "to a file that I have no write rights to" do
|
252
|
-
before(:each) { FileUtils.chmod(0444, @tmp_file.path) }
|
253
|
-
|
254
|
-
it "should throw an exception when I try to write to it" do
|
255
|
-
lambda {@cache.save}.should raise_error(Errno::EACCES)
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
private
|
262
|
-
|
263
|
-
def create_cache(last_modified = nil, lifespan_days = 1)
|
264
|
-
source_last_modified, addresses = YAML::load_file("spec/data/bitsa_cache.yml")
|
265
|
-
source_last_modified = last_modified.to_s if last_modified
|
266
|
-
|
267
|
-
@tmp_file = Tempfile.open("cache")
|
268
|
-
File.open(@tmp_file.path, "w") do |f|
|
269
|
-
f.write(YAML::dump([source_last_modified, addresses]))
|
270
|
-
end
|
271
|
-
@cache = Bitsa::ContactsCache.new(@tmp_file.path, lifespan_days)
|
272
|
-
end
|
273
|
-
|
274
|
-
def create_empty_temp_file
|
275
|
-
tmp_file = Tempfile.open("cache")
|
276
|
-
File.open(tmp_file.path, "w") do |f|
|
277
|
-
f.write('')
|
278
|
-
end
|
279
|
-
tmp_file
|
280
|
-
end
|
281
|
-
|
282
|
-
def should_be_an_empty_cache cache
|
283
|
-
cache.should_not be_nil
|
284
|
-
cache.size.should == 0
|
285
|
-
cache.source_last_modified.should be_nil
|
286
|
-
cache.stale?.should be_true
|
287
|
-
end
|
288
|
-
|
289
|
-
def read_test_data
|
290
|
-
source_last_modified, addresses = YAML::load_file(@tmp_file.path)
|
291
|
-
addresses.values.flatten(1).sort
|
292
|
-
end
|
293
|
-
|
294
|
-
end
|