ruby-trello 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4d52816b20573e0e428d30639952518f52c303e
4
+ data.tar.gz: ba52ccc7483b34f53d018cdef8be47565959c1b0
5
+ SHA512:
6
+ metadata.gz: 64d9ab9659f109dca082bf07764aa695c6487e294c6b5fd9e3e951ffc8492d24ab26e80a676648a2dd3f877f7d2c2b3c00e4bf7b8fab742d7caae67f1e1a4511
7
+ data.tar.gz: 06941e4963b76afb942927c2657e07544fa44e698655bb1d4a6d74c6457b53fec9aa695615076ff3b544bafe9a7e679918f510111358bf5c690f246254530bf4
@@ -7,8 +7,8 @@ module Trello
7
7
  @target = target
8
8
  @options = {}
9
9
  if target.is_a?(Array)
10
- target.each{|array_element| array_element.client = owner.client}
10
+ target.each { |array_element| array_element.client = owner.client }
11
11
  end
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -115,10 +115,21 @@ module Trello
115
115
  @token ||= build_token
116
116
  end
117
117
 
118
- def consumer_key; consumer_credential.key; end
119
- def consumer_secret; consumer_credential.secret; end
120
- def oauth_token; token.key; end
121
- def oauth_token_secret; token.secret; end
118
+ def consumer_key
119
+ consumer_credential.key
120
+ end
121
+
122
+ def consumer_secret
123
+ consumer_credential.secret
124
+ end
125
+
126
+ def oauth_token
127
+ token.key
128
+ end
129
+
130
+ def oauth_token_secret
131
+ token.secret
132
+ end
122
133
 
123
134
  private
124
135
 
@@ -47,7 +47,7 @@ module Trello
47
47
  # Defines the attribute getter and setters.
48
48
  class_eval do
49
49
  define_method :attributes do
50
- @attributes ||= names.inject({}) { |hash,k| hash.merge(k.to_sym => nil) }
50
+ @attributes ||= names.reduce({}) { |hash, k| hash.merge(k.to_sym => nil) }
51
51
  end
52
52
 
53
53
  names.each do |key|
data/lib/trello/card.rb CHANGED
@@ -90,7 +90,7 @@ module Trello
90
90
  def update!
91
91
  @previously_changed = changes
92
92
  # extract only new values to build payload
93
- payload = Hash[changes.map { |key, values| [key.to_sym, values[1]] }]
93
+ payload = Hash[changes.map { |key, values| [key.to_sym.eql?(:list_id) ? :idList : key.to_sym, values[1]] }]
94
94
  @changed_attributes.clear
95
95
 
96
96
  client.put("/cards/#{id}", payload)
@@ -134,9 +134,10 @@ module Trello
134
134
 
135
135
  # Move this card to the given list
136
136
  def move_to_list(list)
137
- unless list_id == list.id
137
+ list_number = list.is_a?(String) ? list : list.id
138
+ unless list_id == list_number
138
139
  client.put("/cards/#{id}/idList", {
139
- :value => list.id
140
+ value: list_number
140
141
  })
141
142
  end
142
143
  end
data/spec/action_spec.rb CHANGED
@@ -8,73 +8,73 @@ module Trello
8
8
  let(:client) { Client.new }
9
9
 
10
10
  before(:each) do
11
- client.stub(:get).with("/actions/4ee2482134a81a757a08af47", {}).
11
+ client.stub(:get).with('/actions/4ee2482134a81a757a08af47', {}).
12
12
  and_return JSON.generate(actions_details.first)
13
13
  end
14
14
 
15
- context "finding" do
15
+ context 'finding' do
16
16
  let(:client) { Trello.client }
17
17
 
18
- it "delegates to Trello.client#find" do
18
+ it 'delegates to Trello.client#find' do
19
19
  client.should_receive(:find).with(:action, '4ee2482134a81a757a08af47', {})
20
20
  Action.find('4ee2482134a81a757a08af47')
21
21
  end
22
22
 
23
- it "is equivalent to client#find" do
23
+ it 'is equivalent to client#find' do
24
24
  Action.find('4ee2482134a81a757a08af47').should eq(action)
25
25
  end
26
26
  end
27
27
 
28
- context "fields" do
28
+ context 'fields' do
29
29
  let(:detail) { actions_details.first }
30
30
 
31
- it "gets its id" do
31
+ it 'gets its id' do
32
32
  action.id.should == detail['id']
33
33
  end
34
34
 
35
- it "gets its type" do
35
+ it 'gets its type' do
36
36
  action.type.should == detail['type']
37
37
  end
38
38
 
39
- it "has the same data" do
39
+ it 'has the same data' do
40
40
  action.data.should == detail['data']
41
41
  end
42
42
 
43
- it "gets the date" do
43
+ it 'gets the date' do
44
44
  action.date.utc.iso8601.should == detail['date']
45
45
  end
46
46
  end
47
47
 
48
- context "boards" do
49
- it "has a board" do
50
- client.stub(:get).with("/actions/4ee2482134a81a757a08af47/board").
48
+ context 'boards' do
49
+ it 'has a board' do
50
+ client.stub(:get).with('/actions/4ee2482134a81a757a08af47/board').
51
51
  and_return JSON.generate(boards_details.first)
52
52
 
53
53
  action.board.should_not be_nil
54
54
  end
55
55
  end
56
56
 
57
- context "card" do
58
- it "has a card" do
59
- client.stub(:get).with("/actions/4ee2482134a81a757a08af47/card").
57
+ context 'card' do
58
+ it 'has a card' do
59
+ client.stub(:get).with('/actions/4ee2482134a81a757a08af47/card').
60
60
  and_return JSON.generate(cards_details.first)
61
61
 
62
62
  action.card.should_not be_nil
63
63
  end
64
64
  end
65
65
 
66
- context "list" do
67
- it "has a list of lists" do
68
- client.stub(:get).with("/actions/4ee2482134a81a757a08af47/list").
66
+ context 'list' do
67
+ it 'has a list of lists' do
68
+ client.stub(:get).with('/actions/4ee2482134a81a757a08af47/list').
69
69
  and_return JSON.generate(lists_details.first)
70
70
 
71
71
  action.list.should_not be_nil
72
72
  end
73
73
  end
74
74
 
75
- context "member creator" do
76
- it "knows its member creator" do
77
- client.stub(:get).with("/members/abcdef123456789123456789", {}).and_return user_payload
75
+ context 'member creator' do
76
+ it 'knows its member creator' do
77
+ client.stub(:get).with('/members/abcdef123456789123456789', {}).and_return user_payload
78
78
 
79
79
  action.member_creator.should_not be_nil
80
80
  end
@@ -4,18 +4,18 @@ module Trello
4
4
  describe Association do
5
5
  include Helpers
6
6
 
7
- let(:organization) { client.find(:organization, "4ee7e59ae582acdec8000291") }
8
- let(:client) { Client.new(:consumer_key => "xxx") }
7
+ let(:organization) { client.find(:organization, '4ee7e59ae582acdec8000291') }
8
+ let(:client) { Client.new(:consumer_key => 'xxx') }
9
9
 
10
10
  before(:each) do
11
- client.stub(:get).with("/organizations/4ee7e59ae582acdec8000291", {}).
11
+ client.stub(:get).with('/organizations/4ee7e59ae582acdec8000291', {}).
12
12
  and_return organization_payload
13
- client.stub(:get).with("/organizations/4ee7e59ae582acdec8000291/boards/all").
13
+ client.stub(:get).with('/organizations/4ee7e59ae582acdec8000291/boards/all').
14
14
  and_return boards_payload
15
15
  end
16
16
 
17
- it "should set the proper client for all associated boards of the organization" do
18
- organization.boards.first.client.consumer_key.should == "xxx"
17
+ it 'should set the proper client for all associated boards of the organization' do
18
+ organization.boards.first.client.consumer_key.should == 'xxx'
19
19
  end
20
20
 
21
21
  end
@@ -1,19 +1,19 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  include Trello
4
4
  include Trello::Authorization
5
5
 
6
6
  describe BasicAuthPolicy do
7
7
  before do
8
- BasicAuthPolicy.developer_public_key = "xxx"
9
- BasicAuthPolicy.member_token = "xxx"
8
+ BasicAuthPolicy.developer_public_key = 'xxx'
9
+ BasicAuthPolicy.member_token = 'xxx'
10
10
  end
11
11
 
12
- it "adds key and token query parameters" do
13
- BasicAuthPolicy.developer_public_key = "xxx_developer_public_key_xxx"
14
- BasicAuthPolicy.member_token = "xxx_member_token_xxx"
12
+ it 'adds key and token query parameters' do
13
+ BasicAuthPolicy.developer_public_key = 'xxx_developer_public_key_xxx'
14
+ BasicAuthPolicy.member_token = 'xxx_member_token_xxx'
15
15
 
16
- uri = Addressable::URI.parse("https://xxx/")
16
+ uri = Addressable::URI.parse('https://xxx/')
17
17
 
18
18
  request = Request.new :get, uri
19
19
 
@@ -21,31 +21,31 @@ describe BasicAuthPolicy do
21
21
 
22
22
  the_query_parameters = Addressable::URI.parse(authorized_request.uri).query_values
23
23
 
24
- the_query_parameters["key"].should === "xxx_developer_public_key_xxx"
25
- the_query_parameters["token"].should === "xxx_member_token_xxx"
24
+ the_query_parameters['key'].should === 'xxx_developer_public_key_xxx'
25
+ the_query_parameters['token'].should === 'xxx_member_token_xxx'
26
26
  end
27
27
 
28
- it "preserves other query parameters" do
29
- uri = Addressable::URI.parse("https://xxx/?name=Phil")
28
+ it 'preserves other query parameters' do
29
+ uri = Addressable::URI.parse('https://xxx/?name=Phil')
30
30
 
31
- request = Request.new :get, uri, {:example_header => "example_value"}
31
+ request = Request.new :get, uri, {:example_header => 'example_value'}
32
32
 
33
33
  authorized_request = BasicAuthPolicy.authorize request
34
34
 
35
35
  the_query_parameters = Addressable::URI.parse(authorized_request.uri).query_values
36
36
 
37
- the_query_parameters["name"].should == "Phil"
37
+ the_query_parameters['name'].should == 'Phil'
38
38
  end
39
39
 
40
- it "preserves headers" do
41
- uri = Addressable::URI.parse("https://xxx/")
40
+ it 'preserves headers' do
41
+ uri = Addressable::URI.parse('https://xxx/')
42
42
 
43
- request = Request.new :get, uri, {:example_header => "example_value"}
43
+ request = Request.new :get, uri, {:example_header => 'example_value'}
44
44
 
45
45
  authorized_request = BasicAuthPolicy.authorize request
46
46
 
47
47
  authorized_request.headers.should === request.headers
48
48
  end
49
49
 
50
- it "does what when a query parameter already exists called key or token?"
50
+ it 'does what when a query parameter already exists called key or token?'
51
51
  end
data/spec/board_spec.rb CHANGED
@@ -165,11 +165,11 @@ module Trello
165
165
  client.should_not_receive :put
166
166
 
167
167
  the_new_board = Board.new
168
- lambda{the_new_board.save}.should raise_error
168
+ -> { the_new_board.save }.should raise_error
169
169
  end
170
170
 
171
171
  it "puts all fields except id" do
172
- expected_fields = %w{name description closed}.map{|s| s.to_sym}
172
+ expected_fields = %w{ name description closed }.map { |s| s.to_sym }
173
173
 
174
174
  client.should_receive(:put) do |anything, body|
175
175
  body.keys.should =~ expected_fields
data/spec/card_spec.rb CHANGED
@@ -146,36 +146,42 @@ module Trello
146
146
  end
147
147
 
148
148
  it 'can be moved to another list' do
149
- other_list = stub(:id => '987654321987654321fedcba')
149
+ other_list = double(:id => '987654321987654321fedcba')
150
150
  payload = {:value => other_list.id}
151
151
  client.should_receive(:put).with("/cards/abcdef123456789123456789/idList", payload)
152
152
  card.move_to_list(other_list)
153
153
  end
154
154
 
155
155
  it 'should not be moved if new list is identical to old list' do
156
- other_list = stub(:id => 'abcdef123456789123456789')
157
- payload = {:value => other_list.id}
156
+ other_list = double(:id => 'abcdef123456789123456789')
157
+ payload = { :value => other_list.id }
158
158
  client.should_not_receive(:put)
159
159
  card.move_to_list(other_list)
160
160
  end
161
161
 
162
+ it "should accept a string for moving a card to list" do
163
+ payload = { value: "12345678"}
164
+ client.should_receive(:put).with("/cards/abcdef123456789123456789/idList", payload)
165
+ card.move_to_list("12345678")
166
+ end
167
+
162
168
  it 'can be moved to another board' do
163
- other_board = stub(:id => '987654321987654321fedcba')
169
+ other_board = double(:id => '987654321987654321fedcba')
164
170
  payload = {:value => other_board.id}
165
171
  client.should_receive(:put).with("/cards/abcdef123456789123456789/idBoard", payload)
166
172
  card.move_to_board(other_board)
167
173
  end
168
174
 
169
175
  it 'can be moved to a list on another board' do
170
- other_board = stub(:id => '987654321987654321fedcba')
171
- other_list = stub(:id => '987654321987654321aalist')
176
+ other_board = double(:id => '987654321987654321fedcba')
177
+ other_list = double(:id => '987654321987654321aalist')
172
178
  payload = {:value => other_board.id, :idList => other_list.id}
173
179
  client.should_receive(:put).with("/cards/abcdef123456789123456789/idBoard", payload)
174
180
  card.move_to_board(other_board, other_list)
175
181
  end
176
182
 
177
183
  it 'should not be moved if new board is identical with old board', :focus => true do
178
- other_board = stub(:id => 'abcdef123456789123456789')
184
+ other_board = double(:id => 'abcdef123456789123456789')
179
185
  client.should_not_receive(:put)
180
186
  card.move_to_board(other_board)
181
187
  end
@@ -191,7 +197,7 @@ module Trello
191
197
  end
192
198
 
193
199
  it "allows a member to be added to a card" do
194
- new_member = stub(:id => '4ee7df3ce582acdec80000b2')
200
+ new_member = double(:id => '4ee7df3ce582acdec80000b2')
195
201
  payload = {
196
202
  :value => new_member.id
197
203
  }
@@ -200,7 +206,7 @@ module Trello
200
206
  end
201
207
 
202
208
  it "allows a member to be removed from a card" do
203
- existing_member = stub(:id => '4ee7df3ce582acdec80000b2')
209
+ existing_member = double(:id => '4ee7df3ce582acdec80000b2')
204
210
  client.should_receive(:delete).with("/cards/abcdef123456789123456789/members/#{existing_member.id}")
205
211
  card.remove_member(existing_member)
206
212
  end
@@ -70,7 +70,7 @@ module Trello
70
70
  }
71
71
 
72
72
  result = JSON.generate(checklists_details.first)
73
- client.should_receive(:put).once.with("/checklists/abcdef123456789123456789", payload).and_return result
73
+ client.should_receive(:put).once.with(expected_resource, payload).and_return result
74
74
 
75
75
  checklist.name = expected_new_name
76
76
  checklist.save
@@ -80,7 +80,6 @@ module Trello
80
80
  expected_item_name = "item1"
81
81
  expected_checked = true
82
82
  expected_pos = 9999
83
- expected_resource = "/checklists/abcdef123456789123456789"
84
83
  payload = {
85
84
  :name => expected_item_name,
86
85
  :checked => expected_checked,
data/spec/client_spec.rb CHANGED
@@ -4,13 +4,13 @@ include Trello
4
4
  include Trello::Authorization
5
5
 
6
6
  describe Client, "and how it handles authorization" do
7
- let (:fake_ok_response) {
8
- stub "A fake OK response",
7
+ let (:fake_ok_response) do
8
+ double "A fake OK response",
9
9
  :code => 200,
10
10
  :body => "A fake response body"
11
- }
11
+ end
12
12
  let(:client) { Client.new }
13
- let(:auth_policy) { stub }
13
+ let(:auth_policy) { double }
14
14
 
15
15
  before do
16
16
  TInternet.stub(:execute).and_return fake_ok_response
@@ -47,13 +47,13 @@ describe Client, "and how it handles authorization" do
47
47
 
48
48
  it "raises an error when response has non-200 status" do
49
49
  expected_error_message = "An error response"
50
- response_with_non_200_status = stub "A fake OK response",
50
+ response_with_non_200_status = double "A fake OK response",
51
51
  :code => 404,
52
52
  :body => expected_error_message
53
53
 
54
54
  TInternet.stub(:execute).and_return response_with_non_200_status
55
55
 
56
- lambda{client.get "/xxx"}.should raise_error expected_error_message
56
+ -> { client.get "/xxx" }.should raise_error expected_error_message
57
57
  end
58
58
 
59
59
  it "uses version 1 of the API" do
@@ -103,8 +103,6 @@ describe Client, "and how it handles authorization" do
103
103
  end
104
104
 
105
105
  it "supports put" do
106
- expected_path = "/xxx"
107
-
108
106
  TInternet.should_receive(:execute).once.and_return fake_ok_response
109
107
 
110
108
  client.put "/xxx", { :phil => "T' north" }
@@ -133,14 +131,14 @@ describe Client, "and how it handles authorization" do
133
131
  end
134
132
 
135
133
  context "initialize" do
136
- let(:client) {
134
+ let(:client) do
137
135
  Client.new(
138
136
  :consumer_key => 'consumer_key',
139
137
  :consumer_secret => 'consumer_secret',
140
138
  :oauth_token => 'oauth_token',
141
139
  :oauth_token_secret => 'oauth_token_secret'
142
140
  )
143
- }
141
+ end
144
142
 
145
143
  it "is configurable" do
146
144
  client.consumer_key.should eq('consumer_key')
@@ -1,51 +1,51 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Trello::Configuration do
4
4
  let(:configuration) { Trello::Configuration.new }
5
5
 
6
- it "has a consumer_key attribute" do
6
+ it 'has a consumer_key attribute' do
7
7
  configuration.consumer_key = 'consumer_key'
8
8
  configuration.consumer_key.should eq('consumer_key')
9
9
  end
10
10
 
11
- it "has a consumer_secret attribute" do
11
+ it 'has a consumer_secret attribute' do
12
12
  configuration.consumer_secret = 'consumer_secret'
13
13
  configuration.consumer_secret.should eq('consumer_secret')
14
14
  end
15
15
 
16
- it "has a oauth_token attribute" do
16
+ it 'has a oauth_token attribute' do
17
17
  configuration.oauth_token = 'oauth_token'
18
18
  configuration.oauth_token.should eq('oauth_token')
19
19
  end
20
20
 
21
- it "has a oauth_token_secret attribute" do
21
+ it 'has a oauth_token_secret attribute' do
22
22
  configuration.oauth_token_secret = 'oauth_token_secret'
23
23
  configuration.oauth_token_secret.should eq('oauth_token_secret')
24
24
  end
25
25
 
26
- it "has a developer public key attribute" do
26
+ it 'has a developer public key attribute' do
27
27
  configuration.developer_public_key = 'developer_public_key'
28
28
  configuration.developer_public_key.should eq('developer_public_key')
29
29
  end
30
30
 
31
- it "has a member token attribute" do
31
+ it 'has a member token attribute' do
32
32
  configuration.member_token = 'member_token'
33
33
  configuration.member_token.should eq('member_token')
34
34
  end
35
35
 
36
- it "has a callback (for oauth)" do
37
- callback = lambda { 'foobar' }
36
+ it 'has a callback (for oauth)' do
37
+ callback = -> { 'foobar' }
38
38
  configuration.callback = callback
39
39
  configuration.callback.call.should eq('foobar')
40
40
  end
41
41
 
42
- it "has a return_url" do
43
- configuration.return_url = "http://www.example.com/callback"
44
- configuration.return_url.should eq("http://www.example.com/callback")
42
+ it 'has a return_url' do
43
+ configuration.return_url = 'http://www.example.com/callback'
44
+ configuration.return_url.should eq('http://www.example.com/callback')
45
45
  end
46
46
 
47
- describe "initialize" do
48
- it "sets key attributes provided as a hash" do
47
+ describe 'initialize' do
48
+ it 'sets key attributes provided as a hash' do
49
49
  configuration = Trello::Configuration.new(
50
50
  :consumer_key => 'consumer_key',
51
51
  :consumer_secret => 'consumer_secret',
@@ -59,14 +59,14 @@ describe Trello::Configuration do
59
59
  end
60
60
  end
61
61
 
62
- describe "#credentials" do
62
+ describe '#credentials' do
63
63
  let(:configuration) { Trello::Configuration.new(attributes) }
64
64
 
65
- it "returns an empty if no attributes specified" do
65
+ it 'returns an empty if no attributes specified' do
66
66
  Trello::Configuration.new({}).credentials.should eq({})
67
67
  end
68
68
 
69
- it "returns an empty if attributes incomplete" do
69
+ it 'returns an empty if attributes incomplete' do
70
70
  Trello::Configuration.new(:consumer_key => 'consumer_key').credentials.should eq({})
71
71
  end
72
72
 
@@ -100,7 +100,7 @@ describe Trello::Configuration do
100
100
  )
101
101
  end
102
102
 
103
- it "returns a hash of basic auth policy attributes" do
103
+ it 'returns a hash of basic auth policy attributes' do
104
104
  configuration = Trello::Configuration.new(
105
105
  :developer_public_key => 'developer_public_key',
106
106
  :member_token => 'member_token'