Skip to content

Commit

Permalink
Use Client#find for Action; apply optionally to 'one' relation
Browse files Browse the repository at this point in the history
  • Loading branch information
rossta committed Jan 20, 2013
1 parent 4c28e2a commit d13c8cc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/trello/action.rb
Expand Up @@ -8,7 +8,7 @@ class Action < BasicData
class << self
# Locate a specific action and return a new Action object.
def find(id)
super(:actions, id)
client.find(:actions, id)
end
end

Expand Down Expand Up @@ -41,6 +41,6 @@ def list
end

# Returns the member who created the action.
one :member_creator, :via => Member, :using => :member_creator_id
one :member_creator, :via => Member, :path => :members, :using => :member_creator_id
end
end
8 changes: 7 additions & 1 deletion lib/trello/basic_data.rb
Expand Up @@ -43,7 +43,13 @@ def self.one(name, opts = {})
options = opts.dup
klass = options.delete(:via) || Trello.const_get(name.to_s.camelize)
ident = options.delete(:using) || :id
klass.find(self.send(ident))
path = options.delete(:path)

if path
client.find(path, self.send(ident))
else
klass.find(self.send(ident))
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trello/client.rb
Expand Up @@ -72,7 +72,7 @@ def auth_policy_class
end

def class_from_path(path)
Trello.const_get("#{path.to_s.singularize.titleize}")
Trello.const_get(path.to_s.singularize.camelize)
end
end
end
46 changes: 29 additions & 17 deletions spec/action_spec.rb
Expand Up @@ -4,67 +4,79 @@ module Trello
describe Action do
include Helpers

let(:action) { client.find(:actions, '4ee2482134a81a757a08af47') }
let(:client) { Client.new }

before(:each) do
Trello.client.stub(:get).with("/actions/4ee2482134a81a757a08af47").
client.stub(:get).with("/actions/4ee2482134a81a757a08af47").
and_return JSON.generate(actions_details.first)
end

@action = Action.find('4ee2482134a81a757a08af47')
context "self.find" do
let(:client) { Trello.client }

it "delegates to Trello.client#member" do
client.should_receive(:find).with(:actions, '4ee2482134a81a757a08af47')
Action.find('4ee2482134a81a757a08af47')
end

it "is equivalent to client#member" do
Action.find('4ee2482134a81a757a08af47').should eq(action)
end
end

context "fields" do
before(:all) do
@detail = actions_details.first
end
let(:detail) { actions_details.first }

it "gets its id" do
@action.id.should == @detail['id']
action.id.should == detail['id']
end

it "gets its type" do
@action.type.should == @detail['type']
action.type.should == detail['type']
end

it "has the same data" do
@action.data.should == @detail['data']
action.data.should == detail['data']
end

it "gets the date" do
@action.date.utc.iso8601.should == @detail['date']
action.date.utc.iso8601.should == detail['date']
end
end

context "boards" do
it "has a board" do
Trello.client.stub(:get).with("/actions/4ee2482134a81a757a08af47/board").
client.stub(:get).with("/actions/4ee2482134a81a757a08af47/board").
and_return JSON.generate(boards_details.first)

@action.board.should_not be_nil
action.board.should_not be_nil
end
end

context "card" do
it "has a card" do
Trello.client.stub(:get).with("/actions/4ee2482134a81a757a08af47/card").
client.stub(:get).with("/actions/4ee2482134a81a757a08af47/card").
and_return JSON.generate(cards_details.first)

@action.card.should_not be_nil
action.card.should_not be_nil
end
end

context "list" do
it "has a list of lists" do
Trello.client.stub(:get).with("/actions/4ee2482134a81a757a08af47/list").
client.stub(:get).with("/actions/4ee2482134a81a757a08af47/list").
and_return JSON.generate(lists_details.first)

@action.list.should_not be_nil
action.list.should_not be_nil
end
end

context "member creator" do
it "knows its member creator" do
Trello.client.stub(:get).with("/members/abcdef123456789123456789").and_return user_payload
client.stub(:get).with("/members/abcdef123456789123456789").and_return user_payload

@action.member_creator.should_not be_nil
action.member_creator.should_not be_nil
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions spec/member_spec.rb
Expand Up @@ -6,20 +6,18 @@ module Trello
describe Member do
include Helpers

let(:client) { Client.new }
let(:member) { client.find(:members, 'abcdef123456789012345678') }
let(:client) { Client.new }

before(:each) do
client.stub(:get).with("/members/abcdef123456789012345678").and_return user_payload
end

context "self.find" do
before do
Trello.client.stub(:get).with("/members/abcdef123456789012345678").and_return user_payload
end
let(:client) { Trello.client }

it "delegates to Trello.client#member" do
Trello.client.should_receive(:find).with(:members, 'abcdef123456789012345678')
client.should_receive(:find).with(:members, 'abcdef123456789012345678')
Member.find('abcdef123456789012345678')
end

Expand Down

0 comments on commit d13c8cc

Please sign in to comment.