forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_spec.rb
More file actions
77 lines (63 loc) · 2.11 KB
/
Copy pathcreate_spec.rb
File metadata and controls
77 lines (63 loc) · 2.11 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
# encoding: utf-8
require 'spec_helper'
describe Github::Repos, '#create' do
let(:user) { 'peter-murach' }
let(:repo) { 'github' }
let(:inputs) { {
:name => 'web',
:description => "This is your first repo",
:homepage => "https://github.com",
:public => true,
:has_issues => true,
:has_wiki => true
} }
before {
subject.oauth_token = OAUTH_TOKEN
stub_post(request_path).with(inputs).
to_return(:body => body, :status => status,
:headers => {:content_type => "application/json; charset=utf-8"} )
}
after { reset_authentication_for subject }
context "resource created successfully" do
let(:body) { fixture('repos/repo.json') }
let(:status) { 201 }
context "for the authenticated user" do
let(:request_path) { "/user/repos?access_token=#{OAUTH_TOKEN}" }
it "should faile to create resource if 'name' inputs is missing" do
expect {
subject.create inputs.except(:name)
}.to raise_error(Github::Error::RequiredParams)
end
it "should create resource" do
subject.create inputs
a_post(request_path).with(inputs).should have_been_made
end
it "should return the resource" do
repository = subject.create inputs
repository.name.should == 'Hello-World'
end
it "should return mash type" do
repository = subject.create inputs
repository.should be_a Github::ResponseWrapper
end
end
context "for the authenticated user belonging to organization" do
let(:request_path) { "/orgs/#{org}/repos?access_token=#{OAUTH_TOKEN}" }
let(:org) { '37signals' }
it "should get the resource" do
subject.create inputs.merge(:org => org)
a_post(request_path).with(inputs).should have_been_made
end
end
end
context "failed to create" do
let(:request_path) { "/user/repos?access_token=#{OAUTH_TOKEN}" }
let(:body) { '' }
let(:status) { 404 }
it "should faile to retrieve resource" do
expect {
subject.create inputs
}.to raise_error(Github::Error::NotFound)
end
end
end # create