forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers_spec.rb
More file actions
128 lines (105 loc) · 3.77 KB
/
Copy pathusers_spec.rb
File metadata and controls
128 lines (105 loc) · 3.77 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require 'spec_helper'
describe Github::Users do
let(:github) { Github.new }
let(:user) { 'peter-murach' }
let(:repo) { 'github' }
after { reset_authentication_for github }
describe "#get" do
it { github.users.should respond_to :find }
context "resource found for a user" do
before do
stub_get("/users/#{user}").
to_return(:body => fixture('users/user.json'),
:status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should get the resources" do
github.users.get :user => user
a_get("/users/#{user}").should have_been_made
end
it "should return resource" do
user_resource = github.users.get :user => user
user_resource.should be_a Hash
end
it "should be a mash type" do
user_resource = github.users.get :user => user
user_resource.should be_a Hashie::Mash
end
it "should get org information" do
user_resource = github.users.get :user => user
user_resource.login.should == 'octocat'
end
it "should yield to a block" do
github.users.should_receive(:get).with(:user => user).and_yield('web')
github.users.get(:user => user) { |param| 'web' }
end
end
context "resource found for an authenticated user" do
before do
github.oauth_token = OAUTH_TOKEN
stub_get("/user").
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
to_return(:body => fixture('users/user.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should get the resources" do
github.users.get
a_get("/user").with(:query => {:access_token => "#{OAUTH_TOKEN}"}).
should have_been_made
end
end
context "resource not found for a user" do
before do
stub_get("/users/#{user}").
to_return(:body => "", :status => [404, "Not Found"])
end
it "should return 404 with a message 'Not Found'" do
expect {
github.users.get :user => user
}.to raise_error(Github::Error::NotFound)
end
end
end # get
describe "#update" do
let(:user_params) {
{
"name" => "monalisa octocat",
"blog" => "https://github.com/blog",
"company" => "GitHub",
"location" => "San Francisco",
"hireable" => true,
"bio" => "There once..."
}
}
context "resouce updated" do
before do
github.oauth_token = OAUTH_TOKEN
stub_patch("/user?access_token=#{OAUTH_TOKEN}").with(user_params).
to_return(:body => fixture('users/user.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should create resource successfully" do
github.users.update
a_patch("/user?access_token=#{OAUTH_TOKEN}").with(user_params).should have_been_made
end
it "should return the resource" do
user_resource = github.users.update
user_resource.should be_a Hashie::Mash
end
it "should get the resource information" do
user_resource = github.users.update
user_resource.login.should == 'octocat'
end
end
context "failed to update resource" do
before do
github.oauth_token = OAUTH_TOKEN
stub_patch("/user?access_token=#{OAUTH_TOKEN}").with(user_params).
to_return(:body => fixture('users/user.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should fail to retrieve resource" do
expect {
github.users.update
}.to raise_error(Github::Error::NotFound)
end
end
end # update
end # Github::Users