fleakr 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/README.rdoc +149 -0
  2. data/Rakefile +40 -0
  3. data/lib/fleakr/api/request.rb +58 -0
  4. data/lib/fleakr/api/response.rb +35 -0
  5. data/lib/fleakr/objects/contact.rb +31 -0
  6. data/lib/fleakr/objects/error.rb +22 -0
  7. data/lib/fleakr/objects/group.rb +26 -0
  8. data/lib/fleakr/objects/image.rb +51 -0
  9. data/lib/fleakr/objects/photo.rb +55 -0
  10. data/lib/fleakr/objects/search.rb +33 -0
  11. data/lib/fleakr/objects/set.rb +45 -0
  12. data/lib/fleakr/objects/user.rb +106 -0
  13. data/lib/fleakr/support/attribute.rb +28 -0
  14. data/lib/fleakr/support/object.rb +88 -0
  15. data/lib/fleakr/version.rb +13 -0
  16. data/lib/fleakr.rb +74 -0
  17. data/test/fixtures/contacts.getPublicList.xml +7 -0
  18. data/test/fixtures/groups.pools.getPhotos.xml +7 -0
  19. data/test/fixtures/people.findByEmail.xml +6 -0
  20. data/test/fixtures/people.findByUsername.xml +6 -0
  21. data/test/fixtures/people.getInfo.xml +18 -0
  22. data/test/fixtures/people.getPublicGroups.xml +7 -0
  23. data/test/fixtures/people.getPublicPhotos.xml +7 -0
  24. data/test/fixtures/photos.getSizes.xml +10 -0
  25. data/test/fixtures/photos.search.xml +7 -0
  26. data/test/fixtures/photosets.getList.xml +13 -0
  27. data/test/fixtures/photosets.getPhotos.xml +7 -0
  28. data/test/test_helper.rb +123 -0
  29. data/test/unit/fleakr/api/request_test.rb +93 -0
  30. data/test/unit/fleakr/api/response_test.rb +49 -0
  31. data/test/unit/fleakr/objects/contact_test.rb +58 -0
  32. data/test/unit/fleakr/objects/error_test.rb +21 -0
  33. data/test/unit/fleakr/objects/group_test.rb +31 -0
  34. data/test/unit/fleakr/objects/image_test.rb +76 -0
  35. data/test/unit/fleakr/objects/photo_test.rb +101 -0
  36. data/test/unit/fleakr/objects/search_test.rb +74 -0
  37. data/test/unit/fleakr/objects/set_test.rb +71 -0
  38. data/test/unit/fleakr/objects/user_test.rb +104 -0
  39. data/test/unit/fleakr/support/attribute_test.rb +68 -0
  40. data/test/unit/fleakr/support/object_test.rb +95 -0
  41. data/test/unit/fleakr_test.rb +44 -0
  42. metadata +123 -0
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class ImageTest < Test::Unit::TestCase
5
+
6
+ describe "The Image class" do
7
+
8
+ should_find_all :images, :by => :photo_id, :call => 'photos.getSizes', :path => 'sizes/size'
9
+
10
+ end
11
+
12
+ describe "An instance of the Image class" do
13
+
14
+ context "when populating the object from an XML document" do
15
+
16
+ before do
17
+ @object = Image.new(Hpricot.XML(read_fixture('photos.getSizes')).at('sizes/size'))
18
+ end
19
+
20
+ should_have_a_value_for :size => 'Square'
21
+ should_have_a_value_for :width => '75'
22
+ should_have_a_value_for :height => '75'
23
+ should_have_a_value_for :url => 'http://farm4.static.flickr.com/3093/2409912100_71e14ed08a_s.jpg'
24
+ should_have_a_value_for :page => 'http://www.flickr.com/photos/the_decapitator/2409912100/sizes/sq/'
25
+
26
+ end
27
+
28
+ context "in general" do
29
+
30
+ it "should know its filename" do
31
+ image = Image.new
32
+ image.stubs(:url).with().returns('http://flickr.com/photos/foobar.jpg')
33
+
34
+ image.filename.should == 'foobar.jpg'
35
+ end
36
+
37
+ context "when saving the file" do
38
+
39
+ before do
40
+ @tmp_dir = create_temp_directory
41
+
42
+ @url = 'http://host.com/image.jpg'
43
+ @image_filename = 'image.jpg'
44
+
45
+ @image = Image.new
46
+ @image.stubs(:url).with().returns(@url)
47
+ @image.stubs(:filename).with().returns(@image_filename)
48
+ end
49
+
50
+ after do
51
+ FileUtils.rm_rf(@tmp_dir)
52
+ end
53
+
54
+ should "be able to save to a directory with the original filename" do
55
+ Net::HTTP.expects(:get).with(URI.parse(@url)).returns('image_data')
56
+
57
+ @image.save_to(@tmp_dir)
58
+ File.read("#{@tmp_dir}/image.jpg").should == 'image_data'
59
+ end
60
+
61
+ should "be able to save to a specified file" do
62
+ Net::HTTP.expects(:get).with(URI.parse(@url)).returns('image_data')
63
+ existing_file = "#{@tmp_dir}/existing_file.jpg"
64
+
65
+ FileUtils.touch(existing_file)
66
+
67
+ @image.save_to(existing_file)
68
+ File.read(existing_file).should == 'image_data'
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class PhotoTest < Test::Unit::TestCase
5
+
6
+ should_have_many :images
7
+
8
+ describe "The Photo class" do
9
+
10
+ should_find_all :photos, :by => :user_id, :call => 'people.getPublicPhotos', :path => 'rsp/photos/photo'
11
+ should_find_all :photos, :by => :photoset_id, :call => 'photosets.getPhotos', :path => 'rsp/photoset/photo'
12
+ should_find_all :photos, :by => :group_id, :call => 'groups.pools.getPhotos', :path => 'rsp/photos/photo'
13
+
14
+ end
15
+
16
+ describe "An instance of the Photo class" do
17
+ context "when populating from an XML document" do
18
+ before do
19
+ @object = Photo.new(Hpricot.XML(read_fixture('people.getPublicPhotos')).at('rsp/photos/photo'))
20
+ end
21
+
22
+ should_have_a_value_for :id => '2924549350'
23
+ should_have_a_value_for :title => 'Photo #1'
24
+ should_have_a_value_for :farm_id => '4'
25
+ should_have_a_value_for :server_id => '3250'
26
+ should_have_a_value_for :secret => 'cbc1804258'
27
+
28
+ end
29
+
30
+ context "in general" do
31
+
32
+ it "should have a collection of images by size" do
33
+ photo = Photo.new
34
+
35
+ small_image, large_image = [stub(:size => 'Small'), stub(:size => 'Large')]
36
+
37
+ photo.stubs(:images).returns([small_image, large_image])
38
+
39
+ expected = {
40
+ :square => nil,
41
+ :thumbnail => nil,
42
+ :small => small_image,
43
+ :medium => nil,
44
+ :large => large_image,
45
+ :original => nil
46
+ }
47
+
48
+ photo.send(:images_by_size).should == expected
49
+ end
50
+
51
+ [:square, :thumbnail, :small, :medium, :large, :original].each do |method|
52
+ it "should have a reader for the :#{method} image" do
53
+ photo = Photo.new
54
+ image = stub()
55
+
56
+ photo.stubs(:images_by_size).returns(method => image)
57
+ photo.send(method).should == image
58
+ end
59
+ end
60
+
61
+
62
+ end
63
+ end
64
+
65
+ # context "in general" do
66
+ #
67
+ # before do
68
+ # @photo = Photo.new
69
+ #
70
+ # @photo.stubs(:id).with().returns('1')
71
+ # @photo.stubs(:farm_id).with().returns('2')
72
+ # @photo.stubs(:server_id).with().returns('3')
73
+ # @photo.stubs(:secret).with().returns('secret')
74
+ # end
75
+ #
76
+ # it "should know the base URL to retrieve images" do
77
+ # @photo.send(:base_url).should == "http://farm2.static.flickr.com/3/1_secret"
78
+ # end
79
+ #
80
+ # end
81
+
82
+ # context "with a base URL" do
83
+ #
84
+ # before do
85
+ # @photo = Photo.new
86
+ # @photo.stubs(:base_url).with().returns('url')
87
+ # end
88
+ #
89
+ # [:square, :thumbnail, :small, :medium, :large].each do |size|
90
+ # it "should have a :#{size} image" do
91
+ # image = stub()
92
+ # Image.expects(:new).with('url', size).returns(image)
93
+ #
94
+ # @photo.send(size).should == image
95
+ # end
96
+ # end
97
+ #
98
+ # end
99
+ end
100
+
101
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class SearchTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the Search class" do
7
+
8
+ it "should be able to generate a list of tags from a single-valued parameter" do
9
+ search = Search.new(:tags => 'foo')
10
+ search.send(:tag_list).should == 'foo'
11
+ end
12
+
13
+ it "should be able to generate a list of tags from multi-valued parameters" do
14
+ search = Search.new(:tags => %w(foo bar))
15
+ search.send(:tag_list).should == 'foo,bar'
16
+ end
17
+
18
+ it "should be able to create parameters for the search" do
19
+ search = Search.new(:tags => %w(foo bar))
20
+ search.send(:parameters).should == {:tags => 'foo,bar'}
21
+ end
22
+
23
+ it "should preserve the original :tags parameter if it is a comma-separated string" do
24
+ search = Search.new(:tags => 'one,two')
25
+ search.send(:parameters).should == {:tags => 'one,two'}
26
+ end
27
+
28
+ it "should not have any :tags parameters if none are supplied" do
29
+ search = Search.new({})
30
+ search.send(:parameters).should == {}
31
+ end
32
+
33
+ it "should convert the search term into the appropriate parameter" do
34
+ search = Search.new(:text => 'foo')
35
+ search.send(:parameters).should == {:text => 'foo'}
36
+ end
37
+
38
+ it "should be able to search photos based on text" do
39
+ response = mock_request_cycle :for => 'photos.search', :with => {:text => 'foo'}
40
+ search = Search.new(:text => 'foo')
41
+ search.results
42
+ end
43
+
44
+ it "should be able to search photos based on tags" do
45
+ response = mock_request_cycle :for => 'photos.search', :with => {:tags => 'one,two'}
46
+
47
+ photo_1, photo_2 = [stub(), stub()]
48
+ photo_1_doc, photo_2_doc = (response.body/'rsp/photos/photo').map {|doc| doc }
49
+
50
+ Photo.expects(:new).with(photo_1_doc).returns(photo_1)
51
+ Photo.expects(:new).with(photo_2_doc).returns(photo_2)
52
+
53
+ search = Search.new(:tags => %w(one two))
54
+ search.results.should == [photo_1, photo_2]
55
+ end
56
+
57
+ should "memoize the search results" do
58
+ response = stub(:body => Hpricot.XML(read_fixture('photos.search')))
59
+ Fleakr::Api::Request.expects(:with_response!).with(kind_of(String), kind_of(Hash)).once.returns(response)
60
+
61
+ (response.body/'rsp/photos/photo').each do |doc|
62
+ Photo.expects(:new).with(doc).once
63
+ end
64
+
65
+ search = Search.new(:tags => %w(foo))
66
+
67
+ 2.times { search.results }
68
+ end
69
+
70
+
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class SetTest < Test::Unit::TestCase
5
+
6
+ should_have_many :photos, :using => 'photoset_id'
7
+
8
+ describe "The Set class" do
9
+
10
+ should_find_all :sets, :by => :user_id, :call => 'photosets.getList', :path => 'rsp/photosets/photoset'
11
+
12
+ end
13
+
14
+ describe "An instance of the Set class" do
15
+
16
+ context "when populating from an XML document" do
17
+ before do
18
+ @object = Set.new(Hpricot.XML(read_fixture('photosets.getList')).at('rsp/photosets/photoset'))
19
+ end
20
+
21
+ should_have_a_value_for :id => '72157609490909659'
22
+ should_have_a_value_for :title => 'Second Set'
23
+ should_have_a_value_for :description => 'This is the second set.'
24
+
25
+ end
26
+
27
+ context "when saving the set" do
28
+ before do
29
+ @tmp_dir = create_temp_directory
30
+ @set_title = 'set'
31
+
32
+ @set = Set.new
33
+ @set.stubs(:title).with().returns(@set_title)
34
+ end
35
+
36
+ after { FileUtils.rm_rf(@tmp_dir) }
37
+
38
+ it "should save all files of the specified size to the specified directory" do
39
+ image = mock()
40
+ image.expects(:save_to).with("#{@tmp_dir}/set")
41
+
42
+ photo = stub(:small => image)
43
+
44
+ @set.stubs(:photos).with().returns([photo])
45
+
46
+ FileUtils.expects(:mkdir).with("#{@tmp_dir}/set")
47
+
48
+ @set.save_to(@tmp_dir, :small)
49
+ end
50
+
51
+ it "should not create the directory if it already exists" do
52
+ FileUtils.mkdir("#{@tmp_dir}/set")
53
+
54
+ @set.stubs(:photos).with().returns([])
55
+
56
+ FileUtils.expects(:mkdir).with("#{@tmp_dir}/set").never
57
+
58
+ @set.save_to(@tmp_dir, :small)
59
+ end
60
+
61
+ it "should not raise errors when saving an image size that doesn't exist" do
62
+ @set.stubs(:photos).with().returns([stub(:large => nil)])
63
+ lambda { @set.save_to(@tmp_dir, :large) }.should_not raise_error
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Objects
4
+ class UserTest < Test::Unit::TestCase
5
+
6
+ def self.should_autoload_when_accessing(*attributes)
7
+ options = attributes.extract_options!
8
+ attributes.each do |accessor_name|
9
+ it "should load the additional user information when accessing the :#{accessor_name} attribute" do
10
+ user = User.new
11
+ user.expects(options[:with]).with()
12
+ user.send(accessor_name)
13
+ end
14
+ end
15
+ end
16
+
17
+ should_search_by :user_id
18
+
19
+ should_have_many :photos, :groups, :sets, :contacts
20
+
21
+ should_autoload_when_accessing :name, :photos_url, :profile_url, :photos_count, :with => :load_info
22
+ should_autoload_when_accessing :icon_server, :icon_farm, :pro, :admin, :icon_url, :with => :load_info
23
+
24
+ describe "The User class" do
25
+
26
+ should_find_one :user, :by => :username, :call => 'people.findByUsername', :path => 'rsp/user'
27
+ should_find_one :user, :by => :email, :with => :find_email, :call => 'people.findByEmail', :path => 'rsp/user'
28
+
29
+ end
30
+
31
+ describe "An instance of User" do
32
+ context "when populating the object from an XML document" do
33
+ before do
34
+ @object = User.new(Hpricot.XML(read_fixture('people.findByUsername')))
35
+ @object.populate_from(Hpricot.XML(read_fixture('people.getInfo')))
36
+ end
37
+
38
+ should_have_a_value_for :id => '31066442@N69'
39
+ should_have_a_value_for :username => 'frootpantz'
40
+ should_have_a_value_for :name => 'Sir Froot Pantz'
41
+ should_have_a_value_for :photos_url => 'http://www.flickr.com/photos/frootpantz/'
42
+ should_have_a_value_for :profile_url => 'http://www.flickr.com/people/frootpantz/'
43
+ should_have_a_value_for :photos_count => '3907'
44
+ should_have_a_value_for :icon_server => '30'
45
+ should_have_a_value_for :icon_farm => '1'
46
+ should_have_a_value_for :pro => '1'
47
+ should_have_a_value_for :admin => '0'
48
+
49
+ end
50
+
51
+ context "in general" do
52
+
53
+ before { @user = User.new }
54
+
55
+ it "should be able to retrieve additional information about the current user" do
56
+ response = mock_request_cycle :for => 'people.getInfo', :with => {:user_id => @user.id}
57
+ @user.expects(:populate_from).with(response.body)
58
+
59
+ @user.load_info
60
+ end
61
+
62
+ it "should be able to generate an icon URL when the :icon_server value is greater than zero" do
63
+ @user.stubs(:icon_server).with().returns('1')
64
+ @user.stubs(:icon_farm).with().returns('2')
65
+ @user.stubs(:id).with().returns('45')
66
+
67
+ @user.icon_url.should == 'http://farm2.static.flickr.com/1/buddyicons/45.jpg'
68
+ end
69
+
70
+ it "should return the default icon URL when the :icon_server value is zero" do
71
+ @user.stubs(:icon_server).with().returns('0')
72
+ @user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
73
+ end
74
+
75
+ it "should return the default icon URL when the :icon_server value is nil" do
76
+ @user.stubs(:icon_server).with().returns(nil)
77
+ @user.icon_url.should == 'http://www.flickr.com/images/buddyicon.jpg'
78
+ end
79
+
80
+ it "should return a boolean value for :pro?" do
81
+ @user.stubs(:pro).with().returns('0')
82
+ @user.pro?.should be(false)
83
+
84
+ @user.stubs(:pro).with().returns('1')
85
+ @user.pro?.should be(true)
86
+ end
87
+
88
+ it "should return a boolean value for :admin?" do
89
+ @user.stubs(:admin).with().returns('0')
90
+ @user.admin?.should be(false)
91
+
92
+ @user.stubs(:admin).with().returns('1')
93
+ @user.admin?.should be(true)
94
+ end
95
+
96
+
97
+
98
+
99
+
100
+ end
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Fleakr::Support
4
+ class AttributeTest < Test::Unit::TestCase
5
+ describe "An instance of the Attribute class" do
6
+
7
+ it "should know the name of the attribute" do
8
+ attr = Attribute.new('foo')
9
+ attr.name.should == :foo
10
+ end
11
+
12
+ it "should infer the xpath information from the attribute name" do
13
+ attr = Attribute.new('foo')
14
+ attr.xpath.should == 'foo'
15
+ end
16
+
17
+ it "should use a string value for the xpath from the inferred attribute name" do
18
+ attr = Attribute.new(:foo)
19
+ attr.xpath.should == 'foo'
20
+ end
21
+
22
+ it "should allow the setting of the xpath information" do
23
+ attr = Attribute.new('foo', :xpath => 'bar')
24
+ attr.xpath.should == 'bar'
25
+ end
26
+
27
+ it "should have a default attribute value of nil" do
28
+ attr = Attribute.new('foo')
29
+ attr.attribute.should be(nil)
30
+ end
31
+
32
+ it "should allow the setting of the attribute value" do
33
+ attr = Attribute.new('foo', :attribute => 'bogon')
34
+ attr.attribute.should == 'bogon'
35
+ end
36
+
37
+ it "should not infer the xpath value when the attribute is set" do
38
+ attr = Attribute.new(:foo, :attribute => 'bogon')
39
+ attr.xpath.should be(nil)
40
+ end
41
+
42
+ it "should be able to pull simple values from an XML document" do
43
+ document = Hpricot.XML('<name>Bassdrive</name>')
44
+ attr = Attribute.new('name')
45
+ attr.value_from(document).should == 'Bassdrive'
46
+ end
47
+
48
+ it "should be able to pull an attribute value from the current XML node" do
49
+ document = Hpricot.XML('<user id="1337" />').at('user')
50
+ attr = Attribute.new(:id, :attribute => 'id')
51
+ attr.value_from(document).should == '1337'
52
+ end
53
+
54
+ it "should be able to pull an attribute value for a node and attribute" do
55
+ document = Hpricot.XML('<station><genre slug="dnb">Drum & Bass</genre></station>')
56
+ attr = Attribute.new(:slug, :xpath => 'station/genre', :attribute => 'slug')
57
+ attr.value_from(document).should == 'dnb'
58
+ end
59
+
60
+ it "should return nil if it cannot find the specified node" do
61
+ document = Hpricot.XML('<user id="1" />')
62
+ attr = Attribute.new(:photoset, :attribute => 'id')
63
+ attr.value_from(document).should be(nil)
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ class EmptyObject
4
+ include Fleakr::Support::Object
5
+ end
6
+
7
+ class FlickrObject
8
+
9
+ include Fleakr::Support::Object
10
+
11
+ flickr_attribute :name
12
+ flickr_attribute :description, :xpath => 'desc'
13
+ flickr_attribute :id, :attribute => 'nsid'
14
+ flickr_attribute :photoset_id, :xpath => 'photoset', :attribute => 'id'
15
+
16
+ end
17
+
18
+ module Fleakr
19
+ class ObjectTest < Test::Unit::TestCase
20
+
21
+ describe "A class method provided by the Flickr::Object module" do
22
+
23
+ it "should have an empty list of attributes if none are supplied" do
24
+ EmptyObject.attributes.should == []
25
+ end
26
+
27
+ it "should know the names of all its attributes" do
28
+ FlickrObject.attributes.map {|a| a.name.to_s }.should == %w(name description id photoset_id)
29
+ end
30
+
31
+ end
32
+
33
+ describe "An instance method provided by the Flickr::Object module" do
34
+
35
+ it "should have default reader methods" do
36
+ [:name, :description, :id, :photoset_id].each do |method_name|
37
+ FlickrObject.new.respond_to?(method_name).should == true
38
+ end
39
+ end
40
+
41
+ context "when populating data from an XML document" do
42
+ before do
43
+ xml = <<-XML
44
+ <name>Fleakr</name>
45
+ <desc>Awesome</desc>
46
+ <photoset id="1" />
47
+ XML
48
+
49
+ @object = FlickrObject.new
50
+ @object.populate_from(Hpricot.XML(xml))
51
+ end
52
+
53
+ it "should have the correct value for :name" do
54
+ @object.name.should == 'Fleakr'
55
+ end
56
+
57
+ it "should have the correct value for :description" do
58
+ @object.description.should == 'Awesome'
59
+ end
60
+
61
+ it "should have the correct value for :photoset_id" do
62
+ @object.photoset_id.should == '1'
63
+ end
64
+
65
+ it "should have the correct value for :id" do
66
+ document = Hpricot.XML('<object nsid="1" />').at('object')
67
+ @object.populate_from(document)
68
+
69
+ @object.id.should == '1'
70
+ end
71
+ end
72
+
73
+ it "should populate its data from an XML document when initializing" do
74
+ document = stub()
75
+ FlickrObject.any_instance.expects(:populate_from).with(document)
76
+
77
+ FlickrObject.new(document)
78
+ end
79
+
80
+ it "should not attempt to populate itself from an XML document if one is not available" do
81
+ FlickrObject.any_instance.expects(:populate_from).never
82
+ FlickrObject.new
83
+ end
84
+
85
+ it "should not overwrite existing attributes when pulling in a partial new XML document" do
86
+ object = FlickrObject.new(Hpricot.XML('<name>Fleakr</name>'))
87
+ object.populate_from(Hpricot.XML('<desc>Awesome</desc>'))
88
+
89
+ object.name.should == 'Fleakr'
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class FleakrTest < Test::Unit::TestCase
4
+
5
+ describe "The Fleakr module" do
6
+
7
+ it "should be able to set an API key" do
8
+ key = 'f00b4r'
9
+ Fleakr.api_key = key
10
+
11
+ Fleakr.api_key.should == key
12
+ end
13
+
14
+ it "should provide a means to find a user by his username" do
15
+ user = stub()
16
+ Fleakr::Objects::User.expects(:find_by_username).with('username').returns(user)
17
+ Fleakr.user('username').should == user
18
+ end
19
+
20
+ it "should fall back to finding a user by email if finding by username fails" do
21
+ user = stub()
22
+ email = 'user@host.com'
23
+
24
+ Fleakr::Objects::User.stubs(:find_by_username).with(email).raises(Fleakr::Api::Request::ApiError)
25
+ Fleakr::Objects::User.expects(:find_by_email).with(email).returns(user)
26
+
27
+ Fleakr.user(email).should == user
28
+ end
29
+
30
+ it "should be able to perform text searches" do
31
+ photos = [stub()]
32
+
33
+ Fleakr::Objects::Search.expects(:new).with(:text => 'foo').returns(stub(:results => photos))
34
+ Fleakr.search('foo').should == photos
35
+ end
36
+
37
+ it "should be able to perform searches based on tags" do
38
+ Fleakr::Objects::Search.expects(:new).with(:tags => %w(one two)).returns(stub(:results => []))
39
+ Fleakr.search(:tags => %w(one two))
40
+ end
41
+
42
+ end
43
+
44
+ end