-
Notifications
You must be signed in to change notification settings - Fork 238
/
how_to_authorize_spec.rb
80 lines (64 loc) · 2.3 KB
/
how_to_authorize_spec.rb
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
require 'spec_helper'
require 'integration/integration_test'
include Trello
include Trello::Authorization
class Container
class << self
def set(parent, name, value)
parent.send :remove_const, name
parent.const_set name, value
end
end
end
describe "Authorizing read-only requests" do
include IntegrationTest
it "Reading public resources requires just a developer public key" do
uri = Addressable::URI.parse("https://api.trello.com/1/boards/4ed7e27fe6abb2517a21383d")
uri.query_values = {
:key => @developer_public_key
}
get(uri).code.should === 200
end
it "Reading private resources requires developer public key AND a member token" do
uri = Addressable::URI.parse("https://api.trello.com/1/boards/#{@welcome_board}")
uri.query_values = {
:key => @developer_public_key,
:token => @member_token
}
get(uri).code.should === 200
end
it "can fetch the welcome board" do
BasicAuthPolicy.developer_public_key = @developer_public_key
BasicAuthPolicy.member_token = @member_token
Container.set Trello::Authorization, "AuthPolicy", BasicAuthPolicy
welcome_board = Board.find @welcome_board
welcome_board.name.should === "Welcome Board"
welcome_board.id.should === @welcome_board
end
end
describe "Authorizing read/write requests" do
include IntegrationTest
context "given a valid access token" do
before :all do
OAuthPolicy.consumer_credential = OAuthCredential.new @developer_public_key, @developer_secret
OAuthPolicy.token = OAuthCredential.new @access_token_key, @access_token_secret
Container.set Trello::Authorization, "AuthPolicy", OAuthPolicy
end
it "can add a board" do
new_board = Board.create(:name => "An example")
new_board.should_not be_nil
new_board.id.should_not be_nil
new_board.name.should == "An example"
new_board.should_not be_closed
end
it "can read the welcome board" do
welcome_board = Board.find @welcome_board
welcome_board.name.should === "Welcome Board"
welcome_board.id.should === @welcome_board
end
pending "cannot close a board yet (Client#put required)" do
new_board = Board.create(:name => "An example")
puts Client.post "/boards/#{new_board.id}/closed", { :value => true }
end
end
end