Skip to content

Commit

Permalink
Add close methods to lists and cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBongart committed Nov 7, 2012
1 parent 44d3eb3 commit b7d078f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
15 changes: 14 additions & 1 deletion lib/trello/card.rb
Expand Up @@ -101,6 +101,20 @@ def update!
})
end

# Check if the card is not active anymore.
def closed?
closed
end

def close
self.closed = true
end

def close!
close
save
end

# Is the record valid?
def valid?
name && list_id
Expand Down Expand Up @@ -191,6 +205,5 @@ def remove_attachment(attachment)
def request_prefix
"/cards/#{id}"
end

end
end
9 changes: 9 additions & 0 deletions lib/trello/list.rb
Expand Up @@ -53,6 +53,15 @@ def closed?
closed
end

def close
self.closed = true
end

def close!
close
save
end

# Return the board the list is connected to.
one :board, :using => :board_id

Expand Down
33 changes: 33 additions & 0 deletions spec/card_spec.rb
Expand Up @@ -252,5 +252,38 @@ module Trello
@card.errors.should be_empty
end
end

describe "#closed?" do
it "returns the closed attribute" do
@card.closed?.should_not be_true
end
end

describe "#close" do
it "updates the close attribute to true" do
@card.close
@card.closed.should be_true
end
end

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)

@card.close!
end
end

end
end
29 changes: 24 additions & 5 deletions spec/list_spec.rb
Expand Up @@ -21,9 +21,8 @@ module Trello
}

Client.should_receive(:put).once.with("/lists/abcdef123456789123456789", payload)
list = @list.dup
list.name = expected_new_name
list.save
@list.name = expected_new_name
@list.save
end
end

Expand Down Expand Up @@ -59,8 +58,28 @@ module Trello
end
end

it "is not closed" do
@list.closed?.should_not be_true
describe "#closed?" do
it "returns the closed attribute" do
@list.closed?.should_not be_true
end
end

describe "#close" do
it "updates the close attribute to true" do
@list.close
@list.closed.should be_true
end
end

describe "#close!" do
it "updates the close attribute to true and saves the list" do
Client.should_receive(:put).once.with("/lists/abcdef123456789123456789", {
:name => @list.name,
:closed => true
})

@list.close!
end
end
end
end

0 comments on commit b7d078f

Please sign in to comment.