Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 6 commits
  • 4 files changed
  • 0 commit comments
  • 3 contributors
Showing with 32 additions and 31 deletions.
  1. +13 −16 lib/trello/card.rb
  2. +2 −1 lib/trello/list.rb
  3. +13 −14 spec/card_spec.rb
  4. +4 −0 spec/list_spec.rb
View
29 lib/trello/card.rb
@@ -87,18 +87,11 @@ def save
# this object before making your changes, and before updating the record.
def update!
@previously_changed = changes
+ # extract only new values to build payload
+ payload = Hash[changes.map { |key, values| [key.to_sym, values[1]] }]
@changed_attributes.clear
- Client.put("/cards/#{id}", {
- :name => name,
- :desc => description,
- :due => due && due.utc.iso8601,
- :closed => closed,
- :idList => list_id,
- :idBoard => board_id,
- :idMembers => member_ids,
- :pos => pos
- })
+ Client.put("/cards/#{id}", payload)
end
# Check if the card is not active anymore.
@@ -134,16 +127,20 @@ def add_checklist(checklist)
# Move this card to the given list
def move_to_list(list)
- Client.put("/cards/#{id}/idList", {
- :value => list.id
- })
+ unless list_id == list.id
+ Client.put("/cards/#{id}/idList", {
+ :value => list.id
+ })
+ end
end
# Move this card to the given board (and optional list on this board)
def move_to_board(new_board, new_list = nil)
- payload = { :value => new_board.id }
- payload[:idList] = new_list.id if new_list
- Client.put("/cards/#{id}/idBoard", payload)
+ unless board_id == new_board.id
+ payload = { :value => new_board.id }
+ payload[:idList] = new_list.id if new_list
+ Client.put("/cards/#{id}/idBoard", payload)
+ end
end
# Add a member to this card
View
3 lib/trello/list.rb
@@ -1,7 +1,7 @@
module Trello
# A List is a container which holds cards. Lists are items on a board.
class List < BasicData
- register_attributes :id, :name, :closed, :board_id, :readonly => [ :id, :board_id ]
+ register_attributes :id, :name, :closed, :board_id, :pos, :readonly => [ :id, :board_id ]
validates_presence_of :id, :name, :board_id
validates_length_of :name, :in => 1..16384
@@ -28,6 +28,7 @@ def update_fields(fields)
attributes[:name] = fields['name']
attributes[:closed] = fields['closed']
attributes[:board_id] = fields['idBoard']
+ attributes[:pos] = fields['pos']
self
end
View
27 spec/card_spec.rb
@@ -51,13 +51,6 @@ module Trello
payload = {
:name => expected_new_name,
- :desc => "Awesome things are awesome.",
- :due => nil,
- :closed => false,
- :idList => "abcdef123456789123456789",
- :idBoard => "abcdef123456789123456789",
- :idMembers => ["abcdef123456789123456789"],
- :pos => 12
}
Client.should_receive(:put).once.with("/cards/abcdef123456789123456789", payload)
@@ -132,6 +125,13 @@ module Trello
@card.move_to_list(other_list)
end
+ it 'should not be moved if new list is identical to old list' do
+ other_list = stub(:id => 'abcdef123456789123456789')
+ payload = {:value => other_list.id}
+ Client.should_not_receive(:put)
+ @card.move_to_list(other_list)
+ end
+
it 'can be moved to another board' do
other_board = stub(:id => '987654321987654321fedcba')
payload = {:value => other_board.id}
@@ -146,6 +146,12 @@ module Trello
Client.should_receive(:put).with("/cards/abcdef123456789123456789/idBoard", payload)
@card.move_to_board(other_board, other_list)
end
+
+ it 'should not be moved if new board is identical with old board', :focus => true do
+ other_board = stub(:id => 'abcdef123456789123456789')
+ Client.should_not_receive(:put)
+ @card.move_to_board(other_board)
+ end
end
context "members" do
@@ -273,14 +279,7 @@ module Trello
describe "#close!" do
it "updates the close attribute to true and saves the list" do
payload = {
- :name => @card.name,
- :desc => "Awesome things are awesome.",
- :due => nil,
:closed => true,
- :idList => "abcdef123456789123456789",
- :idBoard => "abcdef123456789123456789",
- :idMembers => ["abcdef123456789123456789"],
- :pos => 12
}
Client.should_receive(:put).once.with("/cards/abcdef123456789123456789", payload)
View
4 spec/list_spec.rb
@@ -42,6 +42,10 @@ module Trello
it "has a board" do
@list.board.should == Board.new(boards_details.first)
end
+
+ it "gets its position" do
+ @list.pos.should == lists_details.first['pos']
+ end
end
context "actions" do

No commit comments for this range

Something went wrong with that request. Please try again.