ruby-trello 0.4.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +81 -8
- data/lib/trello.rb +25 -9
- data/lib/trello/action.rb +5 -5
- data/lib/trello/association_proxy.rb +3 -3
- data/lib/trello/authorization.rb +105 -49
- data/lib/trello/basic_data.rb +48 -4
- data/lib/trello/board.rb +10 -9
- data/lib/trello/card.rb +38 -35
- data/lib/trello/checklist.rb +10 -8
- data/lib/trello/client.rb +98 -29
- data/lib/trello/configuration.rb +68 -0
- data/lib/trello/has_actions.rb +1 -1
- data/lib/trello/list.rb +9 -7
- data/lib/trello/member.rb +3 -3
- data/lib/trello/multi_association.rb +4 -2
- data/lib/trello/notification.rb +8 -8
- data/lib/trello/organization.rb +3 -3
- data/lib/trello/token.rb +4 -4
- data/spec/action_spec.rb +30 -18
- data/spec/basic_auth_policy_spec.rb +1 -0
- data/spec/board_spec.rb +141 -120
- data/spec/card_spec.rb +104 -82
- data/spec/checklist_spec.rb +35 -6
- data/spec/client_spec.rb +56 -19
- data/spec/configuration_spec.rb +114 -0
- data/spec/integration/how_to_authorize_spec.rb +1 -1
- data/spec/list_spec.rb +74 -20
- data/spec/member_spec.rb +37 -23
- data/spec/notification_spec.rb +28 -24
- data/spec/oauth_policy_spec.rb +55 -9
- data/spec/organization_spec.rb +18 -7
- data/spec/spec_helper.rb +5 -0
- data/spec/token_spec.rb +25 -8
- data/spec/trello_spec.rb +73 -0
- metadata +10 -6
@@ -0,0 +1,68 @@
|
|
1
|
+
module Trello
|
2
|
+
class Configuration
|
3
|
+
CONFIGURABLE_ATTRIBUTES = [
|
4
|
+
:developer_public_key,
|
5
|
+
:member_token,
|
6
|
+
:consumer_key,
|
7
|
+
:consumer_secret,
|
8
|
+
:oauth_token,
|
9
|
+
:oauth_token_secret,
|
10
|
+
:callback,
|
11
|
+
:return_url
|
12
|
+
]
|
13
|
+
|
14
|
+
attr_accessor *CONFIGURABLE_ATTRIBUTES
|
15
|
+
|
16
|
+
def self.configurable_attributes
|
17
|
+
CONFIGURABLE_ATTRIBUTES
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(attrs = {})
|
21
|
+
self.attributes = attrs
|
22
|
+
end
|
23
|
+
|
24
|
+
def attributes=(attrs = {})
|
25
|
+
attrs.each { |key, value| instance_variable_set("@#{key}", value) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def credentials
|
29
|
+
case
|
30
|
+
when oauth?
|
31
|
+
oauth_credentials
|
32
|
+
when basic?
|
33
|
+
basic_credentials
|
34
|
+
else
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def oauth?
|
40
|
+
consumer_key && consumer_secret
|
41
|
+
end
|
42
|
+
|
43
|
+
def basic?
|
44
|
+
developer_public_key && member_token
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def oauth_credentials
|
50
|
+
{
|
51
|
+
:consumer_key => consumer_key,
|
52
|
+
:consumer_secret => consumer_secret,
|
53
|
+
:oauth_token => oauth_token,
|
54
|
+
:oauth_token_secret => oauth_token_secret,
|
55
|
+
:return_url => return_url,
|
56
|
+
:callback => callback,
|
57
|
+
}.delete_if { |key, value| value.nil? }
|
58
|
+
end
|
59
|
+
|
60
|
+
def basic_credentials
|
61
|
+
{
|
62
|
+
:developer_public_key => developer_public_key,
|
63
|
+
:member_token => member_token
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/trello/has_actions.rb
CHANGED
@@ -2,7 +2,7 @@ module Trello
|
|
2
2
|
module HasActions
|
3
3
|
# Returns a list of the actions associated with this object.
|
4
4
|
def actions(options = {})
|
5
|
-
actions =
|
5
|
+
actions = client.get("#{request_prefix}/actions", { :filter => :all }.merge(options)).json_into(Action)
|
6
6
|
MultiAssociation.new(self, actions).proxy
|
7
7
|
end
|
8
8
|
end
|
data/lib/trello/list.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Trello
|
2
2
|
# A List is a container which holds cards. Lists are items on a board.
|
3
3
|
class List < BasicData
|
4
|
-
register_attributes :id, :name, :closed, :board_id, :readonly => [ :id, :board_id ]
|
4
|
+
register_attributes :id, :name, :closed, :board_id, :pos, :readonly => [ :id, :board_id ]
|
5
5
|
validates_presence_of :id, :name, :board_id
|
6
6
|
validates_length_of :name, :in => 1..16384
|
7
7
|
|
@@ -10,12 +10,13 @@ module Trello
|
|
10
10
|
class << self
|
11
11
|
# Finds a specific list, given an id.
|
12
12
|
def find(id)
|
13
|
-
|
13
|
+
client.find(:list, id)
|
14
14
|
end
|
15
15
|
|
16
16
|
def create(options)
|
17
|
-
|
18
|
-
'
|
17
|
+
client.create(:list,
|
18
|
+
'name' => options[:name],
|
19
|
+
'idBoard' => options[:board_id])
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -28,13 +29,14 @@ module Trello
|
|
28
29
|
attributes[:name] = fields['name']
|
29
30
|
attributes[:closed] = fields['closed']
|
30
31
|
attributes[:board_id] = fields['idBoard']
|
32
|
+
attributes[:pos] = fields['pos']
|
31
33
|
self
|
32
34
|
end
|
33
35
|
|
34
36
|
def save
|
35
37
|
return update! if id
|
36
38
|
|
37
|
-
|
39
|
+
client.post("/lists", {
|
38
40
|
:name => name,
|
39
41
|
:closed => closed || false,
|
40
42
|
:idBoard => board_id
|
@@ -42,7 +44,7 @@ module Trello
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def update!
|
45
|
-
|
47
|
+
client.put("/lists/#{id}", {
|
46
48
|
:name => name,
|
47
49
|
:closed => closed
|
48
50
|
})
|
@@ -63,7 +65,7 @@ module Trello
|
|
63
65
|
end
|
64
66
|
|
65
67
|
# Return the board the list is connected to.
|
66
|
-
one :board, :using => :board_id
|
68
|
+
one :board, :path => :boards, :using => :board_id
|
67
69
|
|
68
70
|
# Returns all the cards on this list.
|
69
71
|
#
|
data/lib/trello/member.rb
CHANGED
@@ -13,7 +13,7 @@ module Trello
|
|
13
13
|
#
|
14
14
|
# The argument may be specified as either an _id_ or a _username_.
|
15
15
|
def find(id_or_username)
|
16
|
-
|
16
|
+
client.find(:member, id_or_username)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -32,7 +32,7 @@ module Trello
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# Retrieve a URL to the avatar.
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# Valid values for options are:
|
37
37
|
# :large (170x170)
|
38
38
|
# :small (30x30)
|
@@ -79,7 +79,7 @@ module Trello
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def update!
|
82
|
-
|
82
|
+
client.put(request_prefix, {
|
83
83
|
:fullName => full_name,
|
84
84
|
:bio => bio
|
85
85
|
}).json_into(self)
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Trello
|
2
2
|
class MultiAssociation < Association
|
3
|
-
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegator :target, :count
|
4
6
|
|
5
7
|
def initialize(owner, target = [])
|
6
8
|
super
|
7
9
|
@proxy = AssociationProxy.new(self)
|
8
10
|
end
|
9
11
|
end
|
10
|
-
end
|
12
|
+
end
|
data/lib/trello/notification.rb
CHANGED
@@ -7,7 +7,7 @@ module Trello
|
|
7
7
|
class << self
|
8
8
|
# Locate a notification by its id
|
9
9
|
def find(id)
|
10
|
-
|
10
|
+
client.find(:notification, id)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -23,26 +23,26 @@ module Trello
|
|
23
23
|
|
24
24
|
alias :unread? :unread
|
25
25
|
|
26
|
-
one :member_creator, :via => Member, :using => :member_creator_id
|
26
|
+
one :member_creator, :path => :members, :via => Member, :using => :member_creator_id
|
27
27
|
|
28
28
|
def board
|
29
|
-
|
29
|
+
client.get("/notifications/#{id}/board").json_into(Board)
|
30
30
|
end
|
31
31
|
|
32
32
|
def list
|
33
|
-
|
33
|
+
client.get("/notifications/#{id}/list").json_into(List)
|
34
34
|
end
|
35
35
|
|
36
36
|
def card
|
37
|
-
|
37
|
+
client.get("/notifications/#{id}/card").json_into(Card)
|
38
38
|
end
|
39
39
|
|
40
40
|
def member
|
41
|
-
|
41
|
+
client.get("/notifications/#{id}/member").json_into(Member)
|
42
42
|
end
|
43
43
|
|
44
44
|
def organization
|
45
|
-
|
45
|
+
client.get("/notifications/#{id}/organization").json_into(Organization)
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
data/lib/trello/organization.rb
CHANGED
@@ -10,7 +10,7 @@ module Trello
|
|
10
10
|
class << self
|
11
11
|
# Find an organization by its id.
|
12
12
|
def find(id)
|
13
|
-
|
13
|
+
client.find(:organization, id)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -29,13 +29,13 @@ module Trello
|
|
29
29
|
|
30
30
|
# Returns a list of boards under this organization.
|
31
31
|
def boards
|
32
|
-
boards =
|
32
|
+
boards = client.get("/organizations/#{id}/boards/all").json_into(Board)
|
33
33
|
MultiAssociation.new(self, boards).proxy
|
34
34
|
end
|
35
35
|
|
36
36
|
# Returns an array of members associated with the organization.
|
37
37
|
def members
|
38
|
-
members =
|
38
|
+
members = client.get("/organizations/#{id}/members/all").json_into(Member)
|
39
39
|
MultiAssociation.new(self, members).proxy
|
40
40
|
end
|
41
41
|
|
data/lib/trello/token.rb
CHANGED
@@ -2,11 +2,11 @@ module Trello
|
|
2
2
|
class Token < BasicData
|
3
3
|
register_attributes :id, :member_id, :created_at, :permissions,
|
4
4
|
:readonly => [ :id, :member_id, :created_at, :permissions ]
|
5
|
-
|
5
|
+
|
6
6
|
class << self
|
7
7
|
# Finds a token
|
8
8
|
def find(token)
|
9
|
-
|
9
|
+
client.find(:token, token)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -19,6 +19,6 @@ module Trello
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns a reference to the user who authorized the token.
|
22
|
-
one :member, :using => :member_id
|
22
|
+
one :member, :path => :members, :using => :member_id
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
data/spec/action_spec.rb
CHANGED
@@ -4,67 +4,79 @@ module Trello
|
|
4
4
|
describe Action do
|
5
5
|
include Helpers
|
6
6
|
|
7
|
+
let(:action) { client.find(:action, '4ee2482134a81a757a08af47') }
|
8
|
+
let(:client) { Client.new }
|
9
|
+
|
7
10
|
before(:each) do
|
8
|
-
|
11
|
+
client.stub(:get).with("/actions/4ee2482134a81a757a08af47").
|
9
12
|
and_return JSON.generate(actions_details.first)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "finding" do
|
16
|
+
let(:client) { Trello.client }
|
17
|
+
|
18
|
+
it "delegates to Trello.client#find" do
|
19
|
+
client.should_receive(:find).with(:action, '4ee2482134a81a757a08af47')
|
20
|
+
Action.find('4ee2482134a81a757a08af47')
|
21
|
+
end
|
10
22
|
|
11
|
-
|
23
|
+
it "is equivalent to client#find" do
|
24
|
+
Action.find('4ee2482134a81a757a08af47').should eq(action)
|
25
|
+
end
|
12
26
|
end
|
13
27
|
|
14
28
|
context "fields" do
|
15
|
-
|
16
|
-
@detail = actions_details.first
|
17
|
-
end
|
29
|
+
let(:detail) { actions_details.first }
|
18
30
|
|
19
31
|
it "gets its id" do
|
20
|
-
|
32
|
+
action.id.should == detail['id']
|
21
33
|
end
|
22
34
|
|
23
35
|
it "gets its type" do
|
24
|
-
|
36
|
+
action.type.should == detail['type']
|
25
37
|
end
|
26
38
|
|
27
39
|
it "has the same data" do
|
28
|
-
|
40
|
+
action.data.should == detail['data']
|
29
41
|
end
|
30
42
|
|
31
43
|
it "gets the date" do
|
32
|
-
|
44
|
+
action.date.utc.iso8601.should == detail['date']
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
36
48
|
context "boards" do
|
37
49
|
it "has a board" do
|
38
|
-
|
50
|
+
client.stub(:get).with("/actions/4ee2482134a81a757a08af47/board").
|
39
51
|
and_return JSON.generate(boards_details.first)
|
40
52
|
|
41
|
-
|
53
|
+
action.board.should_not be_nil
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
57
|
context "card" do
|
46
58
|
it "has a card" do
|
47
|
-
|
59
|
+
client.stub(:get).with("/actions/4ee2482134a81a757a08af47/card").
|
48
60
|
and_return JSON.generate(cards_details.first)
|
49
|
-
|
50
|
-
|
61
|
+
|
62
|
+
action.card.should_not be_nil
|
51
63
|
end
|
52
64
|
end
|
53
65
|
|
54
66
|
context "list" do
|
55
67
|
it "has a list of lists" do
|
56
|
-
|
68
|
+
client.stub(:get).with("/actions/4ee2482134a81a757a08af47/list").
|
57
69
|
and_return JSON.generate(lists_details.first)
|
58
70
|
|
59
|
-
|
71
|
+
action.list.should_not be_nil
|
60
72
|
end
|
61
73
|
end
|
62
74
|
|
63
75
|
context "member creator" do
|
64
76
|
it "knows its member creator" do
|
65
|
-
|
77
|
+
client.stub(:get).with("/members/abcdef123456789123456789").and_return user_payload
|
66
78
|
|
67
|
-
|
79
|
+
action.member_creator.should_not be_nil
|
68
80
|
end
|
69
81
|
end
|
70
82
|
end
|
data/spec/board_spec.rb
CHANGED
@@ -4,232 +4,253 @@ module Trello
|
|
4
4
|
describe Board do
|
5
5
|
include Helpers
|
6
6
|
|
7
|
+
let(:board) { client.find(:board, 'abcdef123456789123456789') }
|
8
|
+
let(:client) { Client.new }
|
9
|
+
|
7
10
|
before(:each) do
|
8
|
-
|
11
|
+
client.stub(:get).with("/boards/abcdef123456789123456789").
|
9
12
|
and_return JSON.generate(boards_details.first)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "finding" do
|
16
|
+
let(:client) { Trello.client }
|
10
17
|
|
11
|
-
|
18
|
+
it "delegates to client#find" do
|
19
|
+
client.should_receive(:find).with(:board, 'abcdef123456789123456789')
|
20
|
+
Board.find('abcdef123456789123456789')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is equivalent to client#find" do
|
24
|
+
Board.find('abcdef123456789123456789').should eq(board)
|
25
|
+
end
|
12
26
|
end
|
13
27
|
|
14
|
-
|
15
|
-
|
16
|
-
Client.stub(:get).with("/members/testuser/boards").and_return boards_payload
|
28
|
+
context "self.all" do
|
29
|
+
let(:client) { Trello.client }
|
17
30
|
|
18
|
-
|
19
|
-
|
31
|
+
it "gets all boards" do
|
32
|
+
Member.stub_chain(:find, :username).and_return "testuser"
|
33
|
+
client.stub(:get).with("/members/testuser/boards").and_return boards_payload
|
34
|
+
|
35
|
+
expected = Board.new(boards_details.first)
|
36
|
+
Board.all.first.should eq(expected)
|
37
|
+
end
|
20
38
|
end
|
21
39
|
|
22
40
|
context "fields" do
|
23
41
|
it "gets an id" do
|
24
|
-
|
42
|
+
board.id.should_not be_nil
|
25
43
|
end
|
26
44
|
|
27
45
|
it "gets a name" do
|
28
|
-
|
46
|
+
board.name.should_not be_nil
|
29
47
|
end
|
30
48
|
|
31
49
|
it "gets the description" do
|
32
|
-
|
50
|
+
board.description.should_not be_nil
|
33
51
|
end
|
34
52
|
|
35
53
|
it "knows if it is closed or open" do
|
36
|
-
|
54
|
+
board.closed?.should_not be_nil
|
37
55
|
end
|
38
56
|
|
39
57
|
it "gets its url" do
|
40
|
-
|
58
|
+
board.url.should_not be_nil
|
41
59
|
end
|
42
60
|
end
|
43
61
|
|
44
62
|
context "actions" do
|
45
63
|
it "has a list of actions" do
|
46
|
-
|
64
|
+
client.stub(:get).with("/boards/abcdef123456789123456789/actions", {:filter => :all}).
|
47
65
|
and_return actions_payload
|
48
66
|
|
49
|
-
|
67
|
+
board.actions.count.should be > 0
|
50
68
|
end
|
51
69
|
end
|
52
70
|
|
53
71
|
context "cards" do
|
54
72
|
it "gets its list of cards" do
|
55
|
-
|
73
|
+
client.stub(:get).with("/boards/abcdef123456789123456789/cards", { :filter => :open }).
|
56
74
|
and_return cards_payload
|
57
75
|
|
58
|
-
|
76
|
+
board.cards.count.should be > 0
|
59
77
|
end
|
60
78
|
end
|
61
79
|
|
62
80
|
context "find_card" do
|
63
81
|
it "gets a card" do
|
64
|
-
|
82
|
+
client.stub(:get).with("/boards/abcdef123456789123456789/cards/1").
|
65
83
|
and_return card_payload
|
66
|
-
|
84
|
+
board.find_card(1).should be_a(Card)
|
67
85
|
end
|
68
86
|
end
|
69
87
|
|
70
88
|
context "lists" do
|
71
89
|
it "has a list of lists" do
|
72
|
-
|
90
|
+
client.stub(:get).with("/boards/abcdef123456789123456789/lists", hash_including(:filter => :open)).
|
73
91
|
and_return lists_payload
|
74
92
|
|
75
|
-
|
93
|
+
board.has_lists?.should be true
|
76
94
|
end
|
77
95
|
end
|
78
96
|
|
79
97
|
context "members" do
|
80
98
|
it "has a list of members" do
|
81
|
-
|
99
|
+
client.stub(:get).with("/boards/abcdef123456789123456789/members", hash_including(:filter => :all)).
|
82
100
|
and_return JSON.generate([user_details])
|
83
101
|
|
84
|
-
|
102
|
+
board.members.count.should be > 0
|
85
103
|
end
|
86
104
|
end
|
87
105
|
|
88
106
|
context "organization" do
|
89
107
|
it "belongs to an organization" do
|
90
|
-
|
108
|
+
client.stub(:get).with("/organizations/abcdef123456789123456789").
|
91
109
|
and_return JSON.generate(orgs_details.first)
|
92
110
|
|
93
|
-
|
111
|
+
board.organization.should_not be_nil
|
94
112
|
end
|
95
113
|
end
|
96
114
|
|
97
115
|
it "is not closed" do
|
98
|
-
|
116
|
+
board.closed?.should_not be_true
|
99
117
|
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "#update_fields" do
|
103
|
-
it "does not set any fields when the fields argument is empty" do
|
104
|
-
expected = {
|
105
|
-
'id' => "id",
|
106
|
-
'name' => "name",
|
107
|
-
'desc' => "desc",
|
108
|
-
'closed' => false,
|
109
|
-
'url' => "url",
|
110
|
-
'idOrganization' => "org_id"
|
111
|
-
}
|
112
|
-
|
113
|
-
board = Board.new(expected)
|
114
118
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
119
|
+
describe "#update_fields" do
|
120
|
+
it "does not set any fields when the fields argument is empty" do
|
121
|
+
expected = {
|
122
|
+
'id' => "id",
|
123
|
+
'name' => "name",
|
124
|
+
'desc' => "desc",
|
125
|
+
'closed' => false,
|
126
|
+
'url' => "url",
|
127
|
+
'idOrganization' => "org_id"
|
128
|
+
}
|
129
|
+
|
130
|
+
board = Board.new(expected)
|
131
|
+
board.client = client
|
132
|
+
|
133
|
+
board.update_fields({})
|
134
|
+
|
135
|
+
expected.each_pair do |key, value|
|
136
|
+
if board.respond_to?(key)
|
137
|
+
board.send(key).should == value
|
138
|
+
end
|
120
139
|
end
|
140
|
+
|
141
|
+
board.description.should == expected['desc']
|
142
|
+
board.organization_id.should == expected['idOrganization']
|
121
143
|
end
|
122
144
|
|
123
|
-
|
124
|
-
board.organization_id.should == expected['idOrganization']
|
145
|
+
it "sets any attributes supplied in the fields argument"
|
125
146
|
end
|
126
147
|
|
127
|
-
|
128
|
-
|
148
|
+
describe "#save" do
|
149
|
+
let(:client) { Trello.client }
|
129
150
|
|
130
|
-
|
131
|
-
|
151
|
+
let(:any_board_json) do
|
152
|
+
JSON.generate(boards_details.first)
|
153
|
+
end
|
132
154
|
|
133
|
-
|
134
|
-
|
135
|
-
end
|
155
|
+
it "cannot currently save a new instance" do
|
156
|
+
client.should_not_receive :put
|
136
157
|
|
137
|
-
|
138
|
-
|
158
|
+
the_new_board = Board.new
|
159
|
+
lambda{the_new_board.save}.should raise_error
|
160
|
+
end
|
139
161
|
|
140
|
-
|
141
|
-
|
142
|
-
end
|
162
|
+
it "puts all fields except id" do
|
163
|
+
expected_fields = %w{name description closed}.map{|s| s.to_sym}
|
143
164
|
|
144
|
-
|
145
|
-
|
165
|
+
client.should_receive(:put) do |anything, body|
|
166
|
+
body.keys.should =~ expected_fields
|
167
|
+
any_board_json
|
168
|
+
end
|
146
169
|
|
147
|
-
|
148
|
-
|
149
|
-
any_board_json
|
170
|
+
the_new_board = Board.new 'id' => "xxx"
|
171
|
+
the_new_board.save
|
150
172
|
end
|
151
173
|
|
152
|
-
|
153
|
-
|
154
|
-
end
|
174
|
+
it "mutates the current instance" do
|
175
|
+
client.stub(:put).and_return any_board_json
|
155
176
|
|
156
|
-
|
157
|
-
Client.stub(:put).and_return any_board_json
|
177
|
+
board = Board.new 'id' => "xxx"
|
158
178
|
|
159
|
-
|
179
|
+
the_result_of_save = board.save
|
160
180
|
|
161
|
-
|
181
|
+
the_result_of_save.should equal board
|
182
|
+
end
|
162
183
|
|
163
|
-
|
164
|
-
|
184
|
+
it "uses the correct resource" do
|
185
|
+
expected_resource_id = "xxx_board_id_xxx"
|
165
186
|
|
166
|
-
|
167
|
-
|
187
|
+
client.should_receive(:put) do |path, anything|
|
188
|
+
path.should =~ /#{expected_resource_id}\/$/
|
189
|
+
any_board_json
|
190
|
+
end
|
168
191
|
|
169
|
-
|
170
|
-
|
171
|
-
any_board_json
|
192
|
+
the_new_board = Board.new 'id' => expected_resource_id
|
193
|
+
the_new_board.save
|
172
194
|
end
|
173
195
|
|
174
|
-
|
175
|
-
the_new_board.save
|
196
|
+
it "saves OR updates depending on whether or not it has an id set"
|
176
197
|
end
|
177
198
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
describe '#update!' do
|
182
|
-
include Helpers
|
199
|
+
describe '#update!' do
|
200
|
+
let(:client) { Trello.client }
|
183
201
|
|
184
|
-
|
185
|
-
|
186
|
-
|
202
|
+
let(:any_board_json) do
|
203
|
+
JSON.generate(boards_details.first)
|
204
|
+
end
|
187
205
|
|
188
|
-
|
189
|
-
|
206
|
+
it "puts basic attributes" do
|
207
|
+
board = Board.new 'id' => "board_id"
|
190
208
|
|
191
|
-
|
192
|
-
|
193
|
-
|
209
|
+
board.name = "new name"
|
210
|
+
board.description = "new description"
|
211
|
+
board.closed = true
|
194
212
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
213
|
+
client.should_receive(:put).with("/boards/#{board.id}/", {
|
214
|
+
:name => "new name",
|
215
|
+
:description => "new description",
|
216
|
+
:closed => true
|
217
|
+
}).and_return any_board_json
|
218
|
+
board.update!
|
219
|
+
end
|
201
220
|
end
|
202
|
-
end
|
203
221
|
|
204
|
-
|
205
|
-
|
222
|
+
describe "Repository" do
|
223
|
+
include Helpers
|
206
224
|
|
207
|
-
|
208
|
-
JSON.generate(boards_details.first)
|
209
|
-
end
|
225
|
+
let(:client) { Trello.client }
|
210
226
|
|
211
|
-
|
212
|
-
|
213
|
-
|
227
|
+
let(:any_board_json) do
|
228
|
+
JSON.generate(boards_details.first)
|
229
|
+
end
|
214
230
|
|
215
|
-
|
231
|
+
it "creates a new board with whatever attributes are supplied " do
|
232
|
+
expected_attributes = { :name => "Any new board name", :description => "Any new board desription" }
|
233
|
+
sent_attributes = { :name => expected_attributes[:name], :desc => expected_attributes[:description] }
|
216
234
|
|
217
|
-
|
218
|
-
end
|
235
|
+
client.should_receive(:post).with("/boards", sent_attributes).and_return any_board_json
|
219
236
|
|
220
|
-
|
221
|
-
|
237
|
+
Board.create expected_attributes
|
238
|
+
end
|
222
239
|
|
223
|
-
|
224
|
-
|
240
|
+
it "posts to the boards collection" do
|
241
|
+
client.should_receive(:post).with("/boards", anything).and_return any_board_json
|
225
242
|
|
226
|
-
|
227
|
-
|
243
|
+
Board.create :xxx => ""
|
244
|
+
end
|
228
245
|
|
229
|
-
|
230
|
-
|
231
|
-
end
|
246
|
+
it "returns a board" do
|
247
|
+
client.stub(:post).with("/boards", anything).and_return any_board_json
|
232
248
|
|
233
|
-
|
249
|
+
the_new_board = Board.create :xxx => ""
|
250
|
+
the_new_board.should be_a Board
|
251
|
+
end
|
252
|
+
|
253
|
+
it "at least name is required"
|
254
|
+
end
|
234
255
|
end
|
235
256
|
end
|