github_api 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,178 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Github::Orgs do
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
- let(:repo) { 'github' }
9
- let(:org) { 'github' }
10
-
11
- after { reset_authentication_for github }
12
-
13
- its(:members) { should be_a Github::Orgs::Members }
14
- its(:teams) { should be_a Github::Orgs::Teams }
15
-
16
- describe "#list" do
17
- context "resource found for a user" do
18
- before do
19
- stub_get("/users/#{user}/orgs").
20
- to_return(:body => fixture('orgs/orgs.json'), :status => 200,
21
- :headers => {:content_type => "application/json; charset=utf-8"})
22
- end
23
-
24
- it "should get the resources" do
25
- github.orgs.list :user => user
26
- a_get("/users/#{user}/orgs").should have_been_made
27
- end
28
-
29
- it "should return array of resources" do
30
- orgs = github.orgs.list :user => user
31
- orgs.should be_an Array
32
- orgs.should have(1).items
33
- end
34
-
35
- it "should be a mash type" do
36
- orgs = github.orgs.list :user => user
37
- orgs.first.should be_a Hashie::Mash
38
- end
39
-
40
- it "should get org information" do
41
- orgs = github.orgs.list :user => user
42
- orgs.first.login.should == 'github'
43
- end
44
-
45
- it "should yield to a block" do
46
- github.orgs.should_receive(:list).with(:user => user).and_yield('web')
47
- github.orgs.list(:user => user) { |param| 'web' }
48
- end
49
- end
50
-
51
- context "resource found for an au user" do
52
- before do
53
- github.oauth_token = OAUTH_TOKEN
54
- stub_get("/user/orgs").
55
- with(:query => { :access_token => OAUTH_TOKEN }).
56
- to_return(:body => fixture('orgs/orgs.json'), :status => 200,
57
- :headers => {:content_type => "application/json; charset=utf-8"})
58
- end
59
-
60
- # after { github.oauth_token = nil }
61
-
62
- it "should get the resources" do
63
- github.orgs.list
64
- a_get("/user/orgs").with(:query => { :access_token => OAUTH_TOKEN }).
65
- should have_been_made
66
- end
67
- end
68
-
69
- context "resource not found for a user" do
70
- before do
71
- stub_get("/users/#{user}/orgs").
72
- to_return(:body => "", :status => [404, "Not Found"])
73
- end
74
-
75
- it "should return 404 with a message 'Not Found'" do
76
- expect {
77
- github.orgs.list :user => user
78
- }.to raise_error(Github::Error::NotFound)
79
- end
80
- end
81
- end # list
82
-
83
- describe "#get" do
84
- context "resource found" do
85
- before do
86
- stub_get("/orgs/#{org}").
87
- to_return(:body => fixture('orgs/org.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
88
- end
89
-
90
- it "should fail to get resource without org name" do
91
- expect { github.orgs.get }.to raise_error(ArgumentError)
92
- end
93
-
94
- it "should get the resource" do
95
- github.orgs.get org
96
- a_get("/orgs/#{org}").should have_been_made
97
- end
98
-
99
- it "should get org information" do
100
- organisation = github.orgs.get org
101
- organisation.id.should == 1
102
- organisation.login.should == 'github'
103
- end
104
-
105
- it "should return mash" do
106
- organisation = github.orgs.get org
107
- organisation.should be_a Hashie::Mash
108
- end
109
- end
110
-
111
- context "resource not found" do
112
- before do
113
- stub_get("/orgs/#{org}").
114
- to_return(:body => fixture('orgs/org.json'), :status => 404,
115
- :headers => {:content_type => "application/json; charset=utf-8"})
116
- end
117
-
118
- it "should fail to retrive resource" do
119
- expect {
120
- github.orgs.get org
121
- }.to raise_error(Github::Error::NotFound)
122
- end
123
- end
124
- end # get
125
-
126
- describe "#edit" do
127
- let(:inputs) do
128
- { :billing_email => 'support@github.com',
129
- :blog => "https://github.com/blog",
130
- :company => "GitHub",
131
- :email => "support@github.com",
132
- :location => "San Francisco",
133
- :name => "github" }
134
- end
135
-
136
- context "resource edited successfully" do
137
- before do
138
- stub_patch("/orgs/#{org}").with(inputs).
139
- to_return(:body => fixture("orgs/org.json"), :status => 200,
140
- :headers => { :content_type => "application/json; charset=utf-8"})
141
- end
142
-
143
- it "should fail to edit without 'user/repo' parameters" do
144
- expect { github.orgs.edit }.to raise_error(ArgumentError)
145
- end
146
-
147
- it "should edit the resource" do
148
- github.orgs.edit org
149
- a_patch("/orgs/#{org}").with(inputs).should have_been_made
150
- end
151
-
152
- it "should return resource" do
153
- organisation = github.orgs.edit org
154
- organisation.should be_a Hashie::Mash
155
- end
156
-
157
- it "should be able to retrieve information" do
158
- organisation = github.orgs.edit org
159
- organisation.name.should == 'github'
160
- end
161
- end
162
-
163
- context "failed to edit resource" do
164
- before do
165
- stub_patch("/orgs/#{org}").with(inputs).
166
- to_return(:body => fixture("orgs/org.json"), :status => 404,
167
- :headers => { :content_type => "application/json; charset=utf-8"})
168
- end
169
-
170
- it "should fail to find resource" do
171
- expect {
172
- github.orgs.edit org
173
- }.to raise_error(Github::Error::NotFound)
174
- end
175
- end
176
- end # edit
177
-
178
- end # Github::Orgs