googlecontacts 0.1.8 → 0.2.0

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.
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleContacts::Proxies::Emails do
4
4
  describe "with existing entries" do
@@ -14,21 +14,21 @@ describe GoogleContacts::Proxies::Emails do
14
14
  end
15
15
 
16
16
  it "should initialize on creation" do
17
- @proxy['foo@bar.example.com'].address .should == 'foo@bar.example.com'
18
- @proxy['foo@bar.example.com'].name .should == 'Foo Bar'
19
- @proxy['foo@bar.example.com'].label .should == 'Personal'
20
- @proxy['foo@bar.example.com'].rel .should be_nil
21
- @proxy['foo@bar.example.com'] .should_not be_primary
17
+ @proxy["foo@bar.example.com"].address .should == "foo@bar.example.com"
18
+ @proxy["foo@bar.example.com"].name .should == "Foo Bar"
19
+ @proxy["foo@bar.example.com"].label .should == "Personal"
20
+ @proxy["foo@bar.example.com"].rel .should be_nil
21
+ @proxy["foo@bar.example.com"] .should_not be_primary
22
22
 
23
- @proxy['fubar@gmail.com' ].address .should == 'fubar@gmail.com'
24
- @proxy['fubar@gmail.com' ].name .should be_nil
25
- @proxy['fubar@gmail.com' ].label .should be_nil
26
- @proxy['fubar@gmail.com' ].rel .should == 'http://schemas.google.com/g/2005#home'
27
- @proxy['fubar@gmail.com' ] .should be_primary
23
+ @proxy["fubar@gmail.com" ].address .should == "fubar@gmail.com"
24
+ @proxy["fubar@gmail.com" ].name .should be_nil
25
+ @proxy["fubar@gmail.com" ].label .should be_nil
26
+ @proxy["fubar@gmail.com" ].rel .should == "http://schemas.google.com/g/2005#home"
27
+ @proxy["fubar@gmail.com" ] .should be_primary
28
28
  end
29
29
 
30
30
  it "should be able to return the primary address" do
31
- @proxy.primary.should == @proxy['fubar@gmail.com']
31
+ @proxy.primary.should == @proxy["fubar@gmail.com"]
32
32
  end
33
33
 
34
34
  it "should initially be unchanged" do
@@ -41,23 +41,23 @@ describe GoogleContacts::Proxies::Emails do
41
41
  end
42
42
 
43
43
  it "when switching primary" do
44
- @proxy['foo@bar.example.com'].primary!
44
+ @proxy["foo@bar.example.com"].primary!
45
45
  end
46
46
 
47
47
  it "when modifying name" do
48
- @proxy['foo@bar.example.com'].name = 'Quux'
48
+ @proxy["foo@bar.example.com"].name = "Quux"
49
49
  end
50
50
 
51
51
  it "when modifying rel" do
52
- @proxy['foo@bar.example.com'].rel = 'http://some.rel'
52
+ @proxy["foo@bar.example.com"].rel = "http://some.rel"
53
53
  end
54
54
 
55
55
  it "when adding a new address" do
56
- @proxy << 'john@doe.com'
56
+ @proxy << "john@doe.com"
57
57
  end
58
58
 
59
59
  it "when removing an address" do
60
- @proxy.delete 'foo@bar.example.com'
60
+ @proxy.delete "foo@bar.example.com"
61
61
  end
62
62
  end
63
63
  end
@@ -72,59 +72,59 @@ describe GoogleContacts::Proxies::Emails do
72
72
 
73
73
  it "should be possible to add email address" do
74
74
  lambda {
75
- @proxy['foo@bar.com']
75
+ @proxy["foo@bar.com"]
76
76
  }.should change(@proxy, :size).by(1)
77
77
 
78
78
  lambda {
79
- @proxy << 'quux@bar.com'
79
+ @proxy << "quux@bar.com"
80
80
  }.should change(@proxy, :size).by(1)
81
81
  end
82
82
 
83
83
  it "should raise when adding a duplicate" do
84
- @proxy << 'quux@bar.com'
84
+ @proxy << "quux@bar.com"
85
85
  lambda {
86
- @proxy << 'quux@bar.com'
86
+ @proxy << "quux@bar.com"
87
87
  }.should raise_error
88
88
  end
89
89
 
90
90
  it "should provide sensible defaults for new addresses" do
91
- @proxy['john@doe.com'].address.should == 'john@doe.com'
92
- @proxy['john@doe.com'].rel.should == 'http://schemas.google.com/g/2005#home'
93
- @proxy['john@doe.com'].label.should be_nil
91
+ @proxy["john@doe.com"].address.should == "john@doe.com"
92
+ @proxy["john@doe.com"].rel.should == "http://schemas.google.com/g/2005#home"
93
+ @proxy["john@doe.com"].label.should be_nil
94
94
  end
95
95
 
96
96
  it "should set the first created entry to be primary" do
97
- @proxy['john@doe.com'].should be_primary
97
+ @proxy["john@doe.com"].should be_primary
98
98
  end
99
99
 
100
100
  it "should only allow one entry to be primary" do
101
- @proxy['john@doe.com'].should be_primary
102
- @proxy['jane@doe.com'].should_not be_primary
103
- @proxy['jane@doe.com'].primary!
104
- @proxy['john@doe.com'].should_not be_primary
105
- @proxy['jane@doe.com'].should be_primary
101
+ @proxy["john@doe.com"].should be_primary
102
+ @proxy["jane@doe.com"].should_not be_primary
103
+ @proxy["jane@doe.com"].primary!
104
+ @proxy["john@doe.com"].should_not be_primary
105
+ @proxy["jane@doe.com"].should be_primary
106
106
  end
107
107
 
108
108
  it "should only allow either rel or label to be set" do
109
- @proxy['john@doe.com'].rel = 'foo'
110
- @proxy['john@doe.com'].label = 'foo'
111
- @proxy['john@doe.com'].rel.should be_nil
109
+ @proxy["john@doe.com"].rel = "foo"
110
+ @proxy["john@doe.com"].label = "foo"
111
+ @proxy["john@doe.com"].rel.should be_nil
112
112
 
113
- @proxy['john@doe.com'].label = 'foo'
114
- @proxy['john@doe.com'].rel = 'foo'
115
- @proxy['john@doe.com'].label.should be_nil
113
+ @proxy["john@doe.com"].label = "foo"
114
+ @proxy["john@doe.com"].rel = "foo"
115
+ @proxy["john@doe.com"].label.should be_nil
116
116
  end
117
117
 
118
118
  it "should raise when attempting to modify the address" do
119
119
  lambda {
120
- @proxy['john@doe.com'].address = 'foo'
120
+ @proxy["john@doe.com"].address = "foo"
121
121
  }.should raise_error(/cannot modify/i)
122
122
  end
123
123
 
124
124
  it "should allow email addresses to be removed" do
125
- @proxy << 'john@doe.com'
125
+ @proxy << "john@doe.com"
126
126
  lambda {
127
- @proxy.delete('john@doe.com')
127
+ @proxy.delete("john@doe.com")
128
128
  }.should change(@proxy, :size).from(1).to(0)
129
129
  end
130
130
  end
@@ -138,28 +138,30 @@ describe GoogleContacts::Proxies::Emails do
138
138
  end
139
139
 
140
140
  it "should clear existing email tags" do
141
- @proxy << 'john@doe.com'
142
- @parent.expects(:remove_xml).with('./gd:email')
143
- @parent.stubs(:insert_xml)
141
+ @proxy << "john@doe.com"
142
+ @parent.should_receive(:remove_xml).with("./gd:email")
143
+ @parent.stub(:insert_xml)
144
144
  @proxy.synchronize
145
145
  end
146
146
 
147
147
  it "should add every email address" do
148
- @proxy << 'john@doe.com'
149
- @proxy << 'jane@doe.com'
150
-
151
- @parent.stubs(:remove_xml)
152
- @parent.expects(:insert_xml).with('gd:email', has_entries(
153
- 'address' => 'john@doe.com',
154
- 'primary' => 'true'))
155
- @parent.expects(:insert_xml).with('gd:email', has_entries(
156
- 'address' => 'jane@doe.com'))
148
+ @proxy << "john@doe.com"
149
+ @proxy << "jane@doe.com"
150
+
151
+ @parent.stub(:remove_xml)
152
+ @parent.should_receive(:insert_xml).
153
+ with("gd:email", include(
154
+ "address" => "john@doe.com",
155
+ "primary" => "true"))
156
+ @parent.should_receive(:insert_xml).
157
+ with("gd:email", include(
158
+ "address" => "jane@doe.com"))
157
159
  @proxy.synchronize
158
160
  end
159
161
  end
160
162
 
161
163
  def create_proxy_from_xml(str)
162
- @parent = stub('parent', :xml => Nokogiri::XML.parse(str).root)
164
+ @parent = stub("parent", :xml => Nokogiri::XML.parse(str).root)
163
165
  @proxy = GoogleContacts::Proxies::Emails.new(@parent)
164
166
  end
165
167
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleContacts::Proxies::Hash do
4
4
  describe "with existing entries" do
@@ -11,7 +11,7 @@ describe GoogleContacts::Proxies::Hash do
11
11
  end
12
12
 
13
13
  it "should initialize on creation" do
14
- @proxy[:foo].should == 'bar'
14
+ @proxy[:foo].should == "bar"
15
15
  @proxy.should have(1).entry
16
16
  end
17
17
  end
@@ -22,13 +22,13 @@ describe GoogleContacts::Proxies::Hash do
22
22
  end
23
23
 
24
24
  it "should allow setting a value" do
25
- @proxy[:foo] = 'bar'
25
+ @proxy[:foo] = "bar"
26
26
  @proxy.should have(1).entry
27
- @proxy[:foo].should == 'bar'
27
+ @proxy[:foo].should == "bar"
28
28
  end
29
29
 
30
30
  it "should allow clearing" do
31
- @proxy[:foo] = 'bar'
31
+ @proxy[:foo] = "bar"
32
32
  @proxy.clear
33
33
  @proxy.should have(:no).entries
34
34
  end
@@ -45,13 +45,13 @@ describe GoogleContacts::Proxies::Hash do
45
45
 
46
46
  it "should work when a new value was set" do
47
47
  lambda {
48
- @proxy[:foo] = 'quux'
48
+ @proxy[:foo] = "quux"
49
49
  }.should change(@proxy, :changed?).from(false).to(true)
50
50
  end
51
51
 
52
52
  it "should not be changed when the new value equals the old one" do
53
53
  lambda {
54
- @proxy[:foo] = 'foo'
54
+ @proxy[:foo] = "foo"
55
55
  }.should_not change(@proxy, :changed?).from(false)
56
56
  end
57
57
  end
@@ -62,17 +62,17 @@ describe GoogleContacts::Proxies::Hash do
62
62
  end
63
63
 
64
64
  it "should update the group entries" do
65
- @proxy[:foo] = 'quux'
66
- @proxy[:baz] = 'bar'
67
- @parent.expects(:remove_xml).with('./prop')
68
- @parent.expects(:insert_xml).with('prop', { 'name' => 'foo', 'value' => 'quux' })
69
- @parent.expects(:insert_xml).with('prop', { 'name' => 'baz', 'value' => 'bar' })
65
+ @proxy[:foo] = "quux"
66
+ @proxy[:baz] = "bar"
67
+ @parent.should_receive(:remove_xml).with("./prop")
68
+ @parent.should_receive(:insert_xml).with("prop", { "name" => "foo", "value" => "quux" })
69
+ @parent.should_receive(:insert_xml).with("prop", { "name" => "baz", "value" => "bar" })
70
70
  @proxy.synchronize
71
71
  end
72
72
  end
73
73
 
74
74
  def create_proxy_from_xml(str)
75
- @parent = stub('parent', :xml => Nokogiri::XML.parse(str).root)
76
- @proxy = GoogleContacts::Proxies::Hash.new(@parent, :tag => 'prop', :key => 'name', :value => 'value')
75
+ @parent = stub("parent", :xml => Nokogiri::XML.parse(str).root)
76
+ @proxy = GoogleContacts::Proxies::Hash.new(@parent, :tag => "prop", :key => "name", :value => "value")
77
77
  end
78
78
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleContacts::Proxies::Tag do
4
4
  describe "with existing entries" do
@@ -11,7 +11,7 @@ describe GoogleContacts::Proxies::Tag do
11
11
  end
12
12
 
13
13
  it "should initialize" do
14
- @proxy.should == 'Example'
14
+ @proxy.should == "Example"
15
15
  end
16
16
 
17
17
  it "should not be changed when initialized" do
@@ -32,7 +32,7 @@ describe GoogleContacts::Proxies::Tag do
32
32
  end
33
33
 
34
34
  it "should not create the tag when initializing" do
35
- @parent.xml.xpath('./atom:title').should have(:no).entries
35
+ @parent.xml.xpath("./atom:title").should have(:no).entries
36
36
  end
37
37
 
38
38
  it "should not be changed when initialized" do
@@ -55,8 +55,9 @@ describe GoogleContacts::Proxies::Tag do
55
55
  end
56
56
 
57
57
  it "should create the tag" do
58
- @node = mock('node') { expects(:content=).with('Example') }
59
- @parent.expects(:insert_xml).with('atom:title').returns(@node)
58
+ @node = double("node")
59
+ @node.should_receive(:content=).with("Example")
60
+ @parent.should_receive(:insert_xml).with("atom:title").and_return(@node)
60
61
  @proxy.replace("Example")
61
62
  @proxy.synchronize
62
63
  end
@@ -74,14 +75,14 @@ describe GoogleContacts::Proxies::Tag do
74
75
  it "should update the tag" do
75
76
  @proxy.replace("Replacement")
76
77
  @proxy.synchronize
77
- @parent.xml.at('./atom:title').content.should == 'Replacement'
78
+ @parent.xml.at("./atom:title").content.should == "Replacement"
78
79
  end
79
80
  end
80
81
  end
81
82
 
82
83
  def create_proxy_from_xml(str)
83
- @parent = stub('parent', :xml => Nokogiri::XML.parse(str).root)
84
- @proxy = GoogleContacts::Proxies::Tag.new(@parent, :tag => 'atom:title')
84
+ @parent = stub("parent", :xml => Nokogiri::XML.parse(str).root)
85
+ @proxy = GoogleContacts::Proxies::Tag.new(@parent, :tag => "atom:title")
85
86
  end
86
87
  end
87
88
 
@@ -1,18 +1,10 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rubygems'
4
- require 'spec'
5
- require 'spec/autorun'
6
- require 'pp'
7
-
8
- require 'fakeweb'
9
- FakeWeb.allow_net_connect = false
10
-
11
- require 'google_contacts'
1
+ require "rspec"
2
+ require "fakeweb"
3
+ require "google_contacts"
12
4
 
13
5
  module Helpers
14
6
  def consumer
15
- ::OAuth::AccessToken.new(GoogleContacts::Auth.consumer, 'key', 'secret')
7
+ ::OAuth::AccessToken.new(GoogleContacts::Auth.consumer, "key", "secret")
16
8
  end
17
9
 
18
10
  def wrapper
@@ -28,7 +20,8 @@ module Helpers
28
20
  end
29
21
  end
30
22
 
31
- Spec::Runner.configure do |config|
32
- config.include(Helpers)
33
- config.mock_with :mocha
23
+ FakeWeb.allow_net_connect = false
24
+
25
+ RSpec.configure do |config|
26
+ config.include Helpers
34
27
  end
@@ -1,15 +1,15 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe GoogleContacts::Wrapper do
4
4
  describe "fetching" do
5
5
  before(:each) do
6
- @options = { 'max-results' => 200, 'start-index' => 1 }
6
+ @options = { "max-results" => 200, "start-index" => 1 }
7
7
  end
8
8
 
9
9
  def params(overrides)
10
10
  @options.merge(overrides).map do |tuple|
11
- tuple.join('=')
12
- end.join('&')
11
+ tuple.join("=")
12
+ end.join("&")
13
13
  end
14
14
 
15
15
  def register(type, options = {})
@@ -18,27 +18,27 @@ describe GoogleContacts::Wrapper do
18
18
  end
19
19
 
20
20
  it "should be able to get list of contacts" do
21
- register(:contacts) { asset('contacts_full') }
21
+ register(:contacts) { asset("contacts_full") }
22
22
  result = wrapper.contacts.find(:all)
23
23
  result.should have(1).contact
24
24
  result.first.should be_a GoogleContacts::Contact
25
25
  end
26
26
 
27
27
  it "should be able to get list of contacts when result is paginated" do
28
- register(:contacts, 'start-index' => 1) { asset('contacts_full_page1') }
29
- register(:contacts, 'start-index' => 26) { asset('contacts_full_page2') }
28
+ register(:contacts, "start-index" => 1) { asset("contacts_full_page1") }
29
+ register(:contacts, "start-index" => 26) { asset("contacts_full_page2") }
30
30
  result = wrapper.contacts.find(:all)
31
31
  result.should have(2).contacts
32
32
  end
33
33
 
34
34
  it "should be possible to specify the max-results parameter" do
35
- register(:contacts, 'max-results' => 25) { asset('contacts_full') }
36
- result = wrapper.contacts.find(:all, 'max-results' => 25)
35
+ register(:contacts, "max-results" => 25) { asset("contacts_full") }
36
+ result = wrapper.contacts.find(:all, "max-results" => 25)
37
37
  result.should have(1).contact
38
38
  end
39
39
 
40
40
  it "should be able to get list of groups" do
41
- register(:groups) { asset('groups_full') }
41
+ register(:groups) { asset("groups_full") }
42
42
  result = wrapper.groups.find(:all)
43
43
  result.should have(2).groups
44
44
  result.first.should be_a GoogleContacts::Group
@@ -53,48 +53,48 @@ describe GoogleContacts::Wrapper do
53
53
  end
54
54
 
55
55
  it "should collect operations in a batch" do
56
- wrapper.expects(:post).never
56
+ wrapper.should_not_receive(:post)
57
57
  document = wrapper.batch(:return_documents => true) do
58
- wrapper.contacts.build(:name => 'c1').save
59
- wrapper.contacts.build(:name => 'c2').save
58
+ wrapper.contacts.build(:name => "c1").save
59
+ wrapper.contacts.build(:name => "c2").save
60
60
  end.first
61
61
 
62
- document.xpath('.//xmlns:entry').should have(2).entries
63
- document.xpath('.//batch:operation').each do |operation|
64
- operation['type'].should == 'insert'
62
+ document.xpath(".//xmlns:entry").should have(2).entries
63
+ document.xpath(".//batch:operation").each do |operation|
64
+ operation["type"].should == "insert"
65
65
  end
66
66
  end
67
67
 
68
68
  it "should flush batches in chunks of 100" do
69
- wrapper.expects(:post).with(regexp_matches(%r!/contacts/!), is_a(String)).twice
69
+ wrapper.should_receive(:post).with(%r@/contacts/@, kind_of(String)).twice
70
70
  wrapper.batch do
71
- contact = wrapper.contacts.build(:name => 'contact')
71
+ contact = wrapper.contacts.build(:name => "contact")
72
72
  101.times { contact.save }
73
73
  end
74
74
  end
75
75
 
76
76
  it "should not flush when there are no operations to execute" do
77
- wrapper.expects(:post).never
77
+ wrapper.should_not_receive(:post)
78
78
  wrapper.batch {}
79
79
  end
80
80
 
81
81
  it "should raise when mixing contacts and groups in one batch" do
82
82
  lambda {
83
83
  wrapper.batch {
84
- wrapper.contacts.build(:name => 'contact').save
85
- wrapper.groups.build(:name => 'group').save
84
+ wrapper.contacts.build(:name => "contact").save
85
+ wrapper.groups.build(:name => "group").save
86
86
  }
87
87
  }.should raise_error(/cannot mix/i)
88
88
  end
89
89
 
90
90
  it "should POST a single-operation batch to contacts when not batching" do
91
- wrapper.expects(:post).with(regexp_matches(%r!/contacts/!), is_a(String))
92
- wrapper.contacts.build(:name => 'contact').save
91
+ wrapper.should_receive(:post).with(%r@/contacts/@, kind_of(String))
92
+ wrapper.contacts.build(:name => "contact").save
93
93
  end
94
94
 
95
95
  it "should POST a single-operation batch to groups when not batching" do
96
- wrapper.expects(:post).with(regexp_matches(%r!/groups/!), is_a(String))
97
- wrapper.groups.build(:name => 'group').save
96
+ wrapper.should_receive(:post).with(%r@/groups/@, kind_of(String))
97
+ wrapper.groups.build(:name => "group").save
98
98
  end
99
99
  end
100
100
  end