Permalink
Browse files

Merge pull request #1 from ben-biddington/demeter_refactor

Demeter refactor
  • Loading branch information...
2 parents b98259b + b05a80e commit 36cd05507c479935b6f67a606d4fa32ab86551fb @jeremytregunna jeremytregunna committed Jan 14, 2012
Showing with 67 additions and 62 deletions.
  1. +14 −8 spec/action_spec.rb
  2. +17 −11 spec/board_spec.rb
  3. +23 −21 spec/card_spec.rb
  4. +5 −5 spec/list_spec.rb
  5. +7 −7 spec/member_spec.rb
  6. +1 −10 spec/spec_helper.rb
View
@@ -10,9 +10,8 @@ module Trello
end
before(:each) do
- stub_request(:get, "https://api.trello.com/1/actions/4ee2482134a81a757a08af47?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => JSON.generate(actions_details.first))
+ Client.stub(:get).with("/actions/4ee2482134a81a757a08af47").
+ and_return JSON.generate(actions_details.first)
@action = Action.find('4ee2482134a81a757a08af47')
end
@@ -37,30 +36,37 @@ module Trello
context "boards" do
it "has a board" do
- stub_trello_request!(:get, "/actions/4ee2482134a81a757a08af47/board?", nil, JSON.generate(boards_details.first))
+ Client.stub(:get).with("/actions/4ee2482134a81a757a08af47/board").
+ and_return JSON.generate(boards_details.first)
+
@action.board.should_not be_nil
end
end
context "card" do
it "has a card" do
- stub_trello_request!(:get, "/actions/4ee2482134a81a757a08af47/card?", nil, JSON.generate(cards_details.first))
+ Client.stub(:get).with("/actions/4ee2482134a81a757a08af47/card").
+ and_return JSON.generate(cards_details.first)
+
@action.card.should_not be_nil
end
end
context "list" do
it "has a list of lists" do
- stub_trello_request!(:get, "/actions/4ee2482134a81a757a08af47/list?", nil, JSON.generate(lists_details.first))
+ Client.stub(:get).with("/actions/4ee2482134a81a757a08af47/list").
+ and_return JSON.generate(lists_details.first)
+
@action.list.should_not be_nil
end
end
context "member creator" do
it "knows its member creator" do
- stub_trello_request!(:get, "/members/abcdef123456789123456789?", nil, user_payload)
+ Client.stub(:get).with("/members/abcdef123456789123456789").and_return user_payload
+
@action.member_creator.should_not be_nil
end
end
end
-end
+end
View
@@ -10,9 +10,8 @@ module Trello
end
before(:each) do
- stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => JSON.generate(boards_details.first))
+ Client.stub(:get).with("/boards/abcdef123456789123456789").
+ and_return JSON.generate(boards_details.first)
@board = Board.find('abcdef123456789123456789')
end
@@ -41,38 +40,45 @@ module Trello
context "actions" do
it "has a list of actions" do
- stub_trello_request!(:get, "/boards/abcdef123456789123456789/actions?", nil, actions_payload)
+ Client.stub(:get).with("/boards/abcdef123456789123456789/actions").
+ and_return actions_payload
+
@board.actions.count.should be > 0
end
end
context "cards" do
it "gets its list of cards" do
- stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789/cards?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => cards_payload)
+ Client.stub(:get).with("/boards/abcdef123456789123456789/cards").
+ and_return cards_payload
@board.cards.count.should be > 0
end
end
context "lists" do
it "has a list of lists" do
- stub_trello_request!(:get, "/boards/abcdef123456789123456789/lists?", { :filter => :open }, lists_payload)
+ Client.stub(:get).with("/boards/abcdef123456789123456789/lists", hash_including(:filter => :open)).
+ and_return lists_payload
+
@board.lists.count.should be > 0
end
end
context "members" do
it "has a list of members" do
- stub_trello_request!(:get, "/boards/abcdef123456789123456789/members?", { :filter => :all }, JSON.generate([user_details]))
+ Client.stub(:get).with("/boards/abcdef123456789123456789/members", hash_including(:filter => :all)).
+ and_return JSON.generate([user_details])
+
@board.members.count.should be > 0
end
end
context "organization" do
it "belongs to an organization" do
- stub_trello_request!(:get, "/organizations/abcdef123456789123456789?", nil, JSON.generate(orgs_details.first))
+ Client.stub(:get).with("/organizations/abcdef123456789123456789").
+ and_return JSON.generate(orgs_details.first)
+
@board.organization.should_not be_nil
end
end
@@ -81,4 +87,4 @@ module Trello
@board.closed?.should_not be_true
end
end
-end
+end
View
@@ -10,9 +10,8 @@ module Trello
end
before(:each) do
- stub_request(:get, "https://api.trello.com/1/cards/abcdef123456789123456789?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => JSON.generate(cards_details.first))
+ Client.stub(:get).with("/cards/abcdef123456789123456789").
+ and_return JSON.generate(cards_details.first)
@card = Card.find('abcdef123456789123456789')
end
@@ -33,13 +32,20 @@ module Trello
card.should_not be_valid
end
- it 'creates a new record and saves it on Trello' do
+ it 'creates a new record and saves it on Trello', :refactor => true do
payload = {
:name => 'Test Card',
:desc => '',
}
- stub_trello_request!(:post, '/cards', payload.merge(:idList => lists_details.first['id']), JSON.generate(cards_details.first.merge(payload.merge(:idList => lists_details.first['id']))))
+
+ result = JSON.generate(cards_details.first.merge(payload.merge(:idList => lists_details.first['id'])))
+
+ expected_payload = {:name => "Test Card", :desc => nil, :idList => "abcdef123456789123456789"}
+
+ Client.should_receive(:post).with("/cards", expected_payload).and_return result
+
card = Card.create(cards_details.first.merge(payload.merge(:list_id => lists_details.first['id'])))
+
card.class.should be Card
end
end
@@ -68,43 +74,36 @@ module Trello
context "actions" do
it "has a list of actions" do
- stub_trello_request!(:get, "/cards/abcdef123456789123456789/actions?", nil, actions_payload)
+ Client.stub(:get).with("/cards/abcdef123456789123456789/actions").and_return actions_payload
@card.actions.count.should be > 0
end
end
context "boards" do
it "has a board" do
- stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => JSON.generate(boards_details.first))
-
+ Client.stub(:get).with("/boards/abcdef123456789123456789").and_return JSON.generate(boards_details.first)
@card.board.should_not be_nil
end
end
context "checklists" do
it "has a list of checklists" do
- stub_trello_request!(:get, "/cards/abcdef123456789123456789/checklists?", { :filter => :all }, checklists_payload)
+ Client.stub(:get).with("/cards/abcdef123456789123456789/checklists", { :filter => :all }).and_return checklists_payload
@card.checklists.count.should be > 0
end
end
context "list" do
it 'has a list' do
- stub_trello_request!(:get, "/lists/abcdef123456789123456789?", nil, JSON.generate(lists_details.first))
+ Client.stub(:get).with("/lists/abcdef123456789123456789").and_return JSON.generate(lists_details.first)
@card.list.should_not be_nil
end
end
context "members" do
it "has a list of members" do
- stub_request(:get, "https://api.trello.com/1/boards/abcdef123456789123456789?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => JSON.generate(boards_details.first))
- stub_request(:get, "https://api.trello.com/1/members/abcdef123456789123456789?").
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => user_payload)
+ Client.stub(:get).with("/boards/abcdef123456789123456789").and_return JSON.generate(boards_details.first)
+ Client.stub(:get).with("/members/abcdef123456789123456789").and_return user_payload
@card.board.should_not be_nil
@card.members.should_not be_nil
@@ -113,9 +112,12 @@ module Trello
context "comments" do
it "posts a comment" do
- stub_trello_request!(:put, "/cards/abcdef123456789123456789/actions/comments", { :text => 'testing' })
- @card.add_comment("testing").should be_empty
+ Client.should_receive(:put).
+ with("/cards/abcdef123456789123456789/actions/comments", { :text => 'testing' }).
+ and_return JSON.generate(boards_details.first)
+
+ @card.add_comment "testing"
end
end
end
-end
+end
View
@@ -10,8 +10,8 @@ module Trello
end
before(:each) do
- stub_trello_request!(:get, "/lists/abcdef123456789123456789?", nil, JSON.generate(lists_details.first))
- stub_trello_request!(:get, "/boards/abcdef123456789123456789?", nil, JSON.generate(boards_details.first))
+ Client.stub(:get).with("/lists/abcdef123456789123456789").and_return JSON.generate(lists_details.first)
+ Client.stub(:get).with("/boards/abcdef123456789123456789").and_return JSON.generate(boards_details.first)
@list = List.find("abcdef123456789123456789")
end
@@ -36,14 +36,14 @@ module Trello
context "actions" do
it "has a list of actions" do
- stub_trello_request!(:get, "/lists/abcdef123456789123456789/actions?", nil, actions_payload)
+ Client.stub(:get).with("/lists/abcdef123456789123456789/actions").and_return actions_payload
@list.actions.count.should be > 0
end
end
context "cards" do
it "has a list of cards" do
- stub_trello_request!(:get, "/lists/abcdef123456789123456789/cards?", { :filter => :open }, cards_payload)
+ Client.stub(:get).with("/lists/abcdef123456789123456789/cards", { :filter => :open }).and_return cards_payload
@list.cards.count.should be > 0
end
end
@@ -52,4 +52,4 @@ module Trello
@list.closed?.should_not be_true
end
end
-end
+end
View
@@ -12,37 +12,37 @@ module Trello
end
before(:each) do
- stub_trello_request!(:get, '/members/me?', nil, user_payload)
+ Client.stub(:get).with("/members/me").and_return user_payload
@member = Member.find('me')
end
context "actions" do
- it "retrieves a list of actions" do
- stub_trello_request!(:get, '/members/me/actions?', nil, actions_payload)
+ it "retrieves a list of actions", :refactor => true do
+ Client.stub(:get).with("/members/me/actions").and_return actions_payload
@member.actions.count.should be > 0
end
end
context "boards" do
it "has a list of boards" do
- stub_trello_request!(:get, '/members/me/boards?', { :filter => :all }, boards_payload)
+ Client.stub(:get).with("/members/me/boards", { :filter => :all }).and_return boards_payload
boards = @member.boards
boards.count.should be > 0
end
end
context "cards" do
it "has a list of cards" do
- stub_trello_request!(:get, '/members/me/cards?', { :filter => :open }, cards_payload)
+ Client.stub(:get).with("/members/me/cards", { :filter => :open }).and_return cards_payload
cards = @member.cards
cards.count.should be > 0
end
end
context "organizations" do
it "has a list of organizations" do
- stub_trello_request!(:get, '/members/me/organizations?', { :filter => :all }, orgs_payload)
+ Client.stub(:get).with("/members/me/organizations", { :filter => :all }).and_return orgs_payload
orgs = @member.organizations
orgs.count.should be > 0
end
@@ -70,4 +70,4 @@ module Trello
end
end
end
-end
+end
View
@@ -21,15 +21,6 @@
require 'webmock/rspec'
module Helpers
- def stub_trello_request!(http_method, path, data, returning = '')
- uri = Addressable::URI.parse("https://api.trello.com/#{Trello::API_VERSION}#{path}")
- uri.query_values = data.kind_of?(String) ? JSON.parse(data) : data if data
-
- stub_request(http_method, uri.to_s).
- with(:headers => {'Accept'=>'*/*', 'Authorization'=>/.*/, 'User-Agent' => /.*/}).
- to_return(:status => 200, :headers => {}, :body => returning)
- end
-
def user_details
{
"id" => "abcdef123456789012345678",
@@ -147,4 +138,4 @@ def actions_details
def actions_payload
JSON.generate(actions_details)
end
-end
+end

0 comments on commit 36cd055

Please sign in to comment.