forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemails_spec.rb
More file actions
110 lines (91 loc) · 3.35 KB
/
emails_spec.rb
File metadata and controls
110 lines (91 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'spec_helper'
describe Github::Users::Emails do
let(:github) { Github.new }
before { github.oauth_token = OAUTH_TOKEN }
after { reset_authentication_for github }
describe "#list" do
it { github.users.emails.should respond_to :all }
context "resource found for an authenticated user" do
before do
stub_get("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
to_return(:body => fixture('users/emails.json'),
:status => 200,
:headers => {:content_type => "application/json; charset=utf-8"})
end
it "should get the resources" do
github.users.emails.list
a_get("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
should have_been_made
end
it "should return resource" do
emails = github.users.emails.list
emails.should be_an Array
emails.should have(2).items
end
it "should get emails information" do
emails = github.users.emails.list
emails.first.should == email
end
it "should yield to a block" do
github.users.emails.should_receive(:list).and_yield('web')
github.users.emails.list { |param| 'web' }
end
end
context "resource not found for a user" do
before do
stub_get("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
to_return(:body => "", :status => [404, "Not Found"])
end
it "should return 404 with a message 'Not Found'" do
expect {
github.users.emails.list
}.to raise_error(Github::Error::NotFound)
end
end
end # emails
context '#add' do
let(:params) { { :per_page => 21, :page => 1 }}
before do
stub_post("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
to_return(:body => fixture('users/emails.json'),
:status => 200,
:headers => {:content_type => "application/json; charset=utf-8"})
end
it 'extracts request parameters and email data' do
github.users.emails.should_receive(:post_request).
with("/user/emails", { "per_page" => 21, "page" => 1, "data" => [email] })
github.users.emails.add email, params
end
it 'submits request successfully' do
github.users.emails.add email
a_post("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
should have_been_made
end
end # add
context '#delete' do
let(:params) { { :per_page => 21, :page => 1 }}
before do
stub_delete("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
to_return(:body => fixture('users/emails.json'), :status => 204,
:headers => {:content_type => "application/json; charset=utf-8"})
end
it 'extracts request parameters and email data' do
github.users.emails.should_receive(:delete_request).
with("/user/emails", { "per_page" => 21, "page" => 1, 'data' => [email] })
github.users.emails.delete email, params
end
it 'submits request successfully' do
github.users.emails.delete email
a_delete("/user/emails").
with(:query => { :access_token => "#{OAUTH_TOKEN}" } ).
should have_been_made
end
end # delete
end # Github::Users::Emails