Skip to content

Commit

Permalink
added watched items specs
Browse files Browse the repository at this point in the history
  • Loading branch information
raosev committed Feb 14, 2016
1 parent 82c8161 commit 6ac57ea
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
yard (0.6.8)

PLATFORMS
ruby
Expand All @@ -71,4 +70,3 @@ DEPENDENCIES
rake (~> 0.9)
rspec (~> 2.11)
webmock (~> 1.22)
yard (~> 0.6.0)
1 change: 0 additions & 1 deletion appilf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "webmock", "~> 1.22"
s.add_development_dependency "rake", "~> 0.9"
s.add_development_dependency "rspec", "~> 2.11"
s.add_development_dependency "yard", "~> 0.6.0"
s.add_development_dependency "coveralls", "~> 0.8"
end
1 change: 1 addition & 0 deletions lib/appilf/appilf_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def method_missing(method_name, *args)
end

def add_relationships(relationships_hash)
return unless relationships_hash
self.class.instance_eval do
relationships_hash.each_pair do |k, v|
define_method(k) { Util.translate_from_response(v) }
Expand Down
13 changes: 6 additions & 7 deletions lib/appilf/client/watched_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ module WatchedItems

def create_watched_item(item_type, item_id)
response = authenticated_api_post(watched_items_path, {
item_type: item_type,
item_id: item_id
})
item_type: item_type,
item_id: item_id
})
Appilf::Util.translate_from_response(response)
end

def delete_watched_item(item_type, item_id)
authenticated_api_delete(watched_items_path, {
item_type: item_type,
item_id: item_id
})
item_type: item_type,
item_id: item_id
})
end

def watched_items_path
"#{authenticated_user_path}/watched-items"
end


end

end
Expand Down
42 changes: 42 additions & 0 deletions spec/client/watched_items_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'spec_helper'

describe Appilf::Client do
include Appilf::TestData
let(:client) { authenticated_client }
before { stub_identity_request }

describe '.create_watched_item' do
let(:watched_item) { client.create_watched_item('listing', 123) }
before { stub_api_post_request(client.watched_items_path,
'client/watched_item.json',
200,
{item_type: 'listing', item_id: '123'}) }

it 'should return an Appilf::WatchedItem instance' do
watched_item.class.should == Appilf::WatchedItem
end

it 'should respond to id' do
watched_item.id.should == '789'
end

specify '.watcher should return an Appilf::User instance' do
watched_item.watcher.class.should == Appilf::User
end

it '.item should return an Appilf::Listing instance' do
watched_item.item.class.should == Appilf::Listing
end
end

describe '.delete_watched_item' do
let(:response) { client.delete_watched_item('listing', 123) }
before { stub_api_delete_request(client.watched_items_path,
{item_type: 'listing', item_id: '123'}) }

it 'should return :success' do
response.should == :success
end
end

end
29 changes: 29 additions & 0 deletions spec/mocked_responses/client/watched_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"data": {
"type": "watched-items",
"id": "789",
"relationships": {
"watcher": {
"links": {
"self": "https://api.flippa.com/v3/users/123"
},
"data": {
"type": "users",
"id": "123"
}
},
"item": {
"links": {
"self": "https://api.flippa.com/v3/listings/456"
},
"data": {
"type": "listings",
"id": "456"
}
},
"links": {
"self": "https://api.flippa.com/v3/watched-items/789"
}
}
}
}

0 comments on commit 6ac57ea

Please sign in to comment.