cloudapp 1.1.0 → 2.0.0.beta.1

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 (87) hide show
  1. data/CHANGELOG.md +3 -0
  2. data/Gemfile.lock +18 -34
  3. data/README.md +2 -1
  4. data/Rakefile +5 -1
  5. data/cloudapp.gemspec +50 -41
  6. data/lib/cloudapp/account.rb +111 -0
  7. data/lib/cloudapp/authorized_representation.rb +17 -0
  8. data/lib/cloudapp/collection_json/item.rb +20 -0
  9. data/lib/cloudapp/collection_json/representation.rb +74 -0
  10. data/lib/cloudapp/collection_json/template.rb +17 -0
  11. data/lib/cloudapp/collection_json/tint.rb +11 -0
  12. data/lib/cloudapp/collection_json.rb +3 -0
  13. data/lib/cloudapp/drop.rb +22 -6
  14. data/lib/cloudapp/drop_collection.rb +22 -0
  15. data/lib/cloudapp/service.rb +172 -0
  16. data/lib/cloudapp/token.rb +27 -0
  17. data/lib/cloudapp.rb +5 -1
  18. data/man/cloudapp.1 +202 -45
  19. data/man/cloudapp.1.html +114 -42
  20. data/man/cloudapp.1.ronn +125 -45
  21. data/spec/cassettes/create_bookmark.yml +255 -0
  22. data/spec/cassettes/create_bookmark_with_name.yml +266 -0
  23. data/spec/cassettes/create_bookmark_with_privacy.yml +277 -0
  24. data/spec/cassettes/delete_drop.yml +383 -0
  25. data/spec/cassettes/list_drops.yml +139 -0
  26. data/spec/cassettes/list_drops_with_bad_token.yml +57 -0
  27. data/spec/cassettes/list_drops_with_filter.yml +209 -0
  28. data/spec/cassettes/list_drops_with_href.yml +287 -0
  29. data/spec/cassettes/list_drops_with_href_and_filter.yml +287 -0
  30. data/spec/cassettes/list_drops_with_href_and_limit.yml +287 -0
  31. data/spec/cassettes/list_drops_with_limit.yml +211 -0
  32. data/spec/cassettes/list_drops_with_nil_href.yml +139 -0
  33. data/spec/cassettes/purge_drops.yml +1103 -0
  34. data/spec/cassettes/recover_drop.yml +628 -0
  35. data/spec/cassettes/rename_drop.yml +367 -0
  36. data/spec/cassettes/setup_drops.yml +968 -0
  37. data/spec/cassettes/token_for_account.yml +127 -0
  38. data/spec/cassettes/token_for_account_with_bad_credentials.yml +115 -0
  39. data/spec/cassettes/trash_drop.yml +478 -0
  40. data/spec/cassettes/update_drop_bookmark_url.yml +379 -0
  41. data/spec/cassettes/update_file.yml +573 -0
  42. data/spec/cassettes/upload_file.yml +470 -0
  43. data/spec/cassettes/upload_file_with_name.yml +484 -0
  44. data/spec/cassettes/upload_file_with_privacy.yml +495 -0
  45. data/spec/cassettes/view_drop.yml +73 -0
  46. data/spec/cloudapp/account_spec.rb +166 -0
  47. data/spec/cloudapp/authorized_representation_spec.rb +32 -0
  48. data/spec/cloudapp/collection_json/item_spec.rb +45 -0
  49. data/spec/cloudapp/collection_json/representation_spec.rb +118 -0
  50. data/spec/cloudapp/collection_json/template_spec.rb +53 -0
  51. data/spec/cloudapp/drop_collection_spec.rb +63 -0
  52. data/spec/cloudapp/drop_spec.rb +81 -51
  53. data/spec/cloudapp/service_spec.rb +357 -0
  54. data/spec/cloudapp/token_spec.rb +33 -0
  55. data/spec/integration_spec.rb +100 -0
  56. data/spec/support/stub_class_or_module.rb +6 -3
  57. data/spec/support/vcr.rb +21 -5
  58. metadata +84 -106
  59. data/bin/cloudapp +0 -184
  60. data/lib/cloudapp/config.rb +0 -39
  61. data/lib/cloudapp/drop_content.rb +0 -34
  62. data/lib/cloudapp/drop_presenter.rb +0 -80
  63. data/lib/cloudapp/drop_service.rb +0 -255
  64. data/lib/cloudapp/identity.rb +0 -14
  65. data/spec/cassettes/DropContent/download.yml +0 -116
  66. data/spec/cassettes/DropService/create_bookmark.yml +0 -105
  67. data/spec/cassettes/DropService/create_bookmark_with_bad_credentials.yml +0 -39
  68. data/spec/cassettes/DropService/create_bookmark_with_name.yml +0 -105
  69. data/spec/cassettes/DropService/create_private_bookmark.yml +0 -105
  70. data/spec/cassettes/DropService/create_public_bookmark.yml +0 -105
  71. data/spec/cassettes/DropService/drop.yml +0 -81
  72. data/spec/cassettes/DropService/list_drops.yml +0 -135
  73. data/spec/cassettes/DropService/list_drops_with_bad_credentials.yml +0 -39
  74. data/spec/cassettes/DropService/list_drops_with_limit.yml +0 -117
  75. data/spec/cassettes/DropService/list_trash.yml +0 -111
  76. data/spec/cassettes/DropService/list_trash_with_bad_credentials.yml +0 -39
  77. data/spec/cassettes/DropService/retrieve_token.yml +0 -42
  78. data/spec/cassettes/DropService/retrieve_token_with_bad_credentials.yml +0 -43
  79. data/spec/cassettes/DropService/upload_file.yml +0 -291
  80. data/spec/cassettes/DropService/upload_public_file.yml +0 -293
  81. data/spec/cloudapp/config_spec.rb +0 -59
  82. data/spec/cloudapp/drop_content_spec.rb +0 -21
  83. data/spec/cloudapp/drop_presenter_spec.rb +0 -120
  84. data/spec/cloudapp/drop_service_spec.rb +0 -400
  85. data/spec/cloudapp/identity_spec.rb +0 -27
  86. data/spec/support/fakefs_rspec.rb +0 -5
  87. data/spec/support/vcr_rspec.rb +0 -9
@@ -0,0 +1,166 @@
1
+ require 'helper'
2
+
3
+ require 'cloudapp/account'
4
+
5
+ describe CloudApp::Account do
6
+ let(:args) { stub :args }
7
+ let(:token) { 'token' }
8
+ let(:service) { stub :service, :token= => nil }
9
+ let(:service_source) { -> { service }}
10
+ let(:drop_collection) { stub :drop_collection }
11
+ before do
12
+ stub_class 'CloudApp::DropCollection'
13
+ CloudApp::Account.service_source = service_source
14
+ CloudApp::DropCollection.stub new: drop_collection
15
+ end
16
+
17
+ after do
18
+ CloudApp::Account.service_source = nil
19
+ if CloudApp::DropCollection.ancestors.include? Stubbed
20
+ CloudApp.send :remove_const, :DropCollection
21
+ end
22
+ end
23
+
24
+ describe '.using_token' do
25
+ it 'constructs and returns a new Account' do
26
+ CloudApp::Account.should_receive(:new).with(token)
27
+ CloudApp::Account.using_token(token)
28
+ end
29
+ end
30
+
31
+ describe '#drops' do
32
+ let(:drops) {[ stub(:drop) ]}
33
+ subject { CloudApp::Account.new(token).drops(args) }
34
+ before do service.stub(drops: drops) end
35
+
36
+ it { should eq(drop_collection) }
37
+
38
+ it 'delegates to the drop service' do
39
+ service.should_receive(:drops).with(args)
40
+ subject
41
+ end
42
+
43
+ it 'creates a drop collection' do
44
+ CloudApp::DropCollection.should_receive(:new).with(drops)
45
+ subject
46
+ end
47
+ end
48
+
49
+ describe '#drop_at' do
50
+ let(:drop) { stub :drop }
51
+ subject { CloudApp::Account.new(token).drop_at(args) }
52
+ before do service.stub(drop_at: drop) end
53
+
54
+ it { should eq(drop_collection) }
55
+
56
+ it 'delegates to the drop service' do
57
+ service.should_receive(:drop_at).with(args)
58
+ subject
59
+ end
60
+
61
+ it 'creates a drop collection' do
62
+ CloudApp::DropCollection.should_receive(:new).with(drop)
63
+ subject
64
+ end
65
+ end
66
+
67
+ describe '#bookmark' do
68
+ let(:drop) { stub :drop }
69
+ subject { CloudApp::Account.new(token).bookmark(args) }
70
+ before do service.stub(bookmark: drop) end
71
+
72
+ it { should eq(drop_collection) }
73
+
74
+ it 'delegates to the service' do
75
+ service.should_receive(:bookmark).with(args)
76
+ subject
77
+ end
78
+
79
+ it 'creates a drop collection' do
80
+ CloudApp::DropCollection.should_receive(:new).with(drop)
81
+ subject
82
+ end
83
+ end
84
+
85
+ describe '#upload' do
86
+ let(:drop) { stub :drop }
87
+ subject { CloudApp::Account.new(token).upload(args) }
88
+ before do service.stub(upload: drop) end
89
+
90
+ it { should eq(drop_collection) }
91
+
92
+ it 'delegates to the service' do
93
+ service.should_receive(:upload).with(args)
94
+ subject
95
+ end
96
+
97
+ it 'creates a drop collection' do
98
+ CloudApp::DropCollection.should_receive(:new).with(drop)
99
+ subject
100
+ end
101
+ end
102
+
103
+ describe '#update' do
104
+ let(:drop) { stub :drop }
105
+ subject { CloudApp::Account.new(token).update(args) }
106
+ before do service.stub(update: drop) end
107
+
108
+ it { should eq(drop_collection) }
109
+
110
+ it 'delegates to the drop service' do
111
+ service.should_receive(:update).with(args)
112
+ subject
113
+ end
114
+
115
+ it 'creates a drop collection' do
116
+ CloudApp::DropCollection.should_receive(:new).with(drop)
117
+ subject
118
+ end
119
+ end
120
+
121
+ describe '#trash_drop' do
122
+ let(:drop) { stub :drop }
123
+ subject { CloudApp::Account.new(token).trash_drop(args) }
124
+ before do service.stub(trash_drop: drop) end
125
+
126
+ it { should eq(drop_collection) }
127
+
128
+ it 'delegates to the service' do
129
+ service.should_receive(:trash_drop).with(args)
130
+ subject
131
+ end
132
+
133
+ it 'creates a drop collection' do
134
+ CloudApp::DropCollection.should_receive(:new).with(drop)
135
+ subject
136
+ end
137
+ end
138
+
139
+ describe '#recover_drop' do
140
+ let(:drop) { stub :drop }
141
+ subject { CloudApp::Account.new(token).recover_drop(args) }
142
+ before do service.stub(recover_drop: drop) end
143
+
144
+ it { should eq(drop_collection) }
145
+
146
+ it 'delegates to the service' do
147
+ service.should_receive(:recover_drop).with(args)
148
+ subject
149
+ end
150
+
151
+ it 'creates a drop collection' do
152
+ CloudApp::DropCollection.should_receive(:new).with(drop)
153
+ subject
154
+ end
155
+ end
156
+
157
+ describe '#delete_drop' do
158
+ it 'delegates to the service' do
159
+ service.should_receive(:delete_drop).with(args)
160
+ CloudApp::Account.new.delete_drop(args)
161
+ end
162
+ end
163
+
164
+ describe '#download' do
165
+ end
166
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ require 'cloudapp/authorized_representation'
4
+
5
+ describe CloudApp::AuthorizedRepresentation do
6
+ let(:representation) { stub :representation, __response__: response }
7
+ let(:response) { stub :response, status: status }
8
+ let(:status) { 200 }
9
+ let(:href) { stub }
10
+ subject { representation }
11
+ before do
12
+ representation.extend CloudApp::AuthorizedRepresentation
13
+ end
14
+
15
+ describe '#authorized?' do
16
+ it { should be_authorized }
17
+
18
+ context 'unauthorized status' do
19
+ let(:status) { 401 }
20
+ it { should_not be_authorized }
21
+ end
22
+ end
23
+
24
+ describe '#unauthorized?' do
25
+ it { should_not be_unauthorized }
26
+
27
+ context 'unauthorized status' do
28
+ let(:status) { 401 }
29
+ it { should be_unauthorized }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ require 'cloudapp/collection_json/item'
4
+
5
+ describe CloudApp::CollectionJson::Item do
6
+ let(:item_data) {{ 'data' => [] }}
7
+ subject { CloudApp::CollectionJson::Item.new item_data }
8
+
9
+ its(:href) { should be_nil }
10
+ its(:links) { should be_empty }
11
+ its(:data) { should be_empty }
12
+
13
+ context 'with an href' do
14
+ let(:href) { stub :href }
15
+ before do item_data['href'] = href end
16
+ its(:href) { should eq(href) }
17
+ end
18
+
19
+ context 'with links' do
20
+ let(:links) {[
21
+ { 'rel' => 'canonical', 'href' => 'link1' },
22
+ { 'rel' => 'alternate', 'href' => 'link2' }
23
+ ]}
24
+ before do item_data['links'] = links end
25
+
26
+ its(:links) { should have(2).items }
27
+
28
+ it 'presents links' do
29
+ subject.links.find {|link| link.rel == 'canonical' }.
30
+ href.should eq('link1')
31
+ subject.links.find {|link| link.rel == 'alternate' }.
32
+ href.should eq('link2')
33
+ end
34
+ end
35
+
36
+ context 'with data' do
37
+ let(:data) {[
38
+ { 'name' => 'attr1', 'value' => 'value1' },
39
+ { 'name' => 'attr2', 'value' => 'value2' }
40
+ ]}
41
+ before do item_data['data'] = data end
42
+
43
+ its(:data) { should eq('attr1' => 'value1', 'attr2' => 'value2') }
44
+ end
45
+ end
@@ -0,0 +1,118 @@
1
+ require 'helper'
2
+
3
+ require 'cloudapp/collection_json/representation'
4
+
5
+ describe CloudApp::CollectionJson::Representation do
6
+ let(:response) { stub :response, status: status }
7
+ let(:status) { 200 }
8
+ let(:representation) {{
9
+ 'collection' => {
10
+ 'href' => href,
11
+ 'items' => []
12
+ }
13
+ }}
14
+ let(:href) { stub }
15
+ subject { representation }
16
+ before do
17
+ representation.extend CloudApp::CollectionJson::Representation
18
+ representation.stub __response__: response
19
+ end
20
+
21
+ its(:href) { should eq(href) }
22
+
23
+ describe '#collection_links' do
24
+ its(:collection_links) { should be_empty }
25
+
26
+ context 'with collection links' do
27
+ let(:links) {[
28
+ { 'rel' => 'next', 'href' => '/next' },
29
+ { 'rel' => 'prev', 'href' => '/prev' }
30
+ ]}
31
+ before do representation['collection']['links'] = links end
32
+
33
+ its(:collection_links) { should have(2).items }
34
+
35
+ it 'presents links' do
36
+ subject.collection_links.find {|link| link.rel == 'next' }.
37
+ href.should eq('/next')
38
+ subject.collection_links.find {|link| link.rel == 'prev' }.
39
+ href.should eq('/prev')
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '#items' do
45
+ it 'is empty' do
46
+ subject.items(stub(:item_source)).should be_empty
47
+ end
48
+
49
+ context 'with items' do
50
+ let(:items) {[ stub(:item1), stub(:item2) ]}
51
+ let(:item_data) {[ stub(:item_data1), stub(:item_data2) ]}
52
+ let(:item_source) { ->(item) {
53
+ if item == item_data[0]
54
+ items[0]
55
+ elsif item == item_data[1]
56
+ items[1]
57
+ end
58
+ }}
59
+ before do representation['collection']['items'] = item_data end
60
+
61
+ it 'should have items' do
62
+ subject.items(item_source).should eq(items)
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#templates' do
68
+ it 'is nil' do
69
+ subject.template(stub(:template_source)).should be_nil
70
+ end
71
+
72
+ context 'with a template' do
73
+ let(:template) { stub :template }
74
+ let(:template_data) { stub :template_data }
75
+ let(:template_source) { ->(item) { template if item == template_data }}
76
+ before do representation['collection']['template'] = template_data end
77
+
78
+ it 'finds the template' do
79
+ subject.template(template_source).should eq(template)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#queries' do
85
+ it 'is nil' do
86
+ subject.queries(stub(:query_source)).should be_nil
87
+ end
88
+
89
+ context 'with queries' do
90
+ let(:queries) {[ stub(:query1), stub(:query2) ]}
91
+ let(:query_data) {[ stub(:query_data1), stub(:query_data2) ]}
92
+ let(:query_source) { ->(query) { queries.at(query_data.index(query)) }}
93
+ before do representation['collection']['queries'] = query_data end
94
+
95
+ it 'should have queries' do
96
+ subject.queries(query_source).should eq(queries)
97
+ end
98
+ end
99
+ end
100
+
101
+ describe '#query' do
102
+ it 'is nil' do
103
+ subject.query('rel', stub(:query_source)).should be_nil
104
+ end
105
+
106
+ context 'with queries' do
107
+ let(:queries) {[ stub(:query1, rel: 'one'),
108
+ stub(:query2, rel: 'two') ]}
109
+ let(:query_data) {[ stub(:query_data1), stub(:query_data2) ]}
110
+ let(:query_source) { ->(query) { queries.at(query_data.index(query)) }}
111
+ before do representation['collection']['queries'] = query_data end
112
+
113
+ it 'finds the query by rel' do
114
+ subject.query('one', query_source).should eq(queries.first)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,53 @@
1
+ require 'helper'
2
+ require 'cloudapp/collection_json/item'
3
+
4
+ require 'cloudapp/collection_json/template'
5
+
6
+ describe CloudApp::CollectionJson::Template do
7
+ let(:template_data) {{ 'data' => [] }}
8
+ subject { CloudApp::CollectionJson::Template.new template_data }
9
+
10
+ its(:rel) { should be_nil }
11
+ its(:enctype) { should be_nil }
12
+
13
+
14
+ context 'with a rel' do
15
+ let(:rel) { stub :rel }
16
+ before do template_data['rel'] = rel end
17
+
18
+ its(:rel) { should eq(rel) }
19
+ end
20
+
21
+ context 'with an encoding type' do
22
+ let(:enctype) { stub :enctype }
23
+ before do template_data['enctype'] = enctype end
24
+
25
+ its(:enctype) { should eq(enctype) }
26
+ end
27
+
28
+ describe '#fill' do
29
+ let(:email) { 'arthur@dent.com' }
30
+ let(:template_data) {{
31
+ 'data' => [
32
+ { 'name' => 'email', 'value' => '' },
33
+ { 'name' => 'age', 'value' => 29 }
34
+ ]
35
+ }}
36
+
37
+ it 'returns a filled template' do
38
+ expected = { 'email' => email, 'age' => 29 }
39
+ subject.fill('email' => email).should eq(expected)
40
+ end
41
+
42
+ it 'leaves data untouched' do
43
+ subject.fill('email' => email)
44
+ subject.data.should eq('email' => '', 'age' => 29)
45
+ end
46
+
47
+ it 'ignores attributes not in the template' do
48
+ expected = { 'email' => email, 'age' => 29 }
49
+ new_data = { 'email' => email, 'ignore' => 'me' }
50
+ subject.fill(new_data).should eq(expected)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+ require 'ostruct'
3
+
4
+ require 'cloudapp/drop_collection'
5
+
6
+ describe CloudApp::DropCollection do
7
+ let(:representation) { stub :representation, unauthorized?: unauthorized,
8
+ items: items }
9
+ let(:unauthorized) { nil }
10
+ let(:items) {[ stub(:item1), stub(:item2) ]}
11
+ let(:drop_class) { stub(:drop_class, new: nil) }
12
+ subject { CloudApp::DropCollection.new representation, drop_class }
13
+
14
+ describe '#authorized?' do
15
+ let(:authorized) { stub :authorized }
16
+ before do representation.stub(authorized?: authorized) end
17
+
18
+ it 'delegates to representation' do
19
+ subject.authorized?.should eq(authorized)
20
+ end
21
+ end
22
+
23
+ describe '#unauthorized?' do
24
+ let(:unauthorized) { stub :unauthorized }
25
+
26
+ it 'delegates to representation' do
27
+ subject.unauthorized?.should eq(unauthorized)
28
+ end
29
+ end
30
+
31
+ describe '#link' do
32
+ it 'delegates to representation' do
33
+ args = stub :args
34
+ representation.should_receive(:link).with(args)
35
+ subject.link(args)
36
+ end
37
+ end
38
+
39
+ describe '#links' do
40
+ it 'delegates to representation' do
41
+ args = stub :args
42
+ representation.should_receive(:links).with(args)
43
+ subject.links(args)
44
+ end
45
+ end
46
+
47
+ it 'is a collection of drops' do
48
+ subject.size.should eq(2)
49
+ end
50
+
51
+ it 'decodes each drop' do
52
+ items.each do |drop|
53
+ drop_class.should_receive(:new).with(drop)
54
+ end
55
+ subject
56
+ end
57
+
58
+ context 'unauthorized' do
59
+ let(:unauthorized) { stub :unauthorized }
60
+
61
+ it { should be_empty }
62
+ end
63
+ end
@@ -4,86 +4,116 @@ require 'cloudapp/drop'
4
4
  stub_class :DropContent
5
5
 
6
6
  describe CloudApp::Drop do
7
- describe '#display_name' do
8
- describe 'a drop with a name' do
9
- let(:name) { stub :name }
10
- subject { CloudApp::Drop.new name: name }
11
-
12
- it 'is its name' do
13
- subject.display_name.should eq(name)
14
- end
7
+ let(:href) { stub :href }
8
+ let(:links) { [] }
9
+ let(:data) { {} }
10
+ subject {
11
+ CloudApp::Drop.new stub(:drop, href: href, links: links, data: data)
12
+ }
13
+
14
+ its(:href) { should eq(href) }
15
+
16
+ describe '#data' do
17
+ let(:data) {{ name: 'Drop' }}
18
+ its(:data) { should eq(data) }
19
+
20
+ context 'with string keys' do
21
+ let(:data) {{ 'name' => 'Drop' }}
22
+ its(:data) { should eq(data) }
15
23
  end
24
+ end
16
25
 
17
- describe 'a drop with a redirect url and no a name' do
18
- let(:redirect_url) { stub :redirect_url }
19
- subject { CloudApp::Drop.new redirect_url: redirect_url }
26
+ describe '#name' do
27
+ let(:data) {{ name: 'Drop' }}
28
+ its(:name) { should eq(data[:name]) }
20
29
 
21
- it 'is its redirect url' do
22
- subject.display_name.should eq(redirect_url)
23
- end
24
- end
25
-
26
- describe 'a drop with no redirect url and name' do
27
- let(:url) { stub :url }
28
- subject { CloudApp::Drop.new url: url }
30
+ context 'when nil' do
31
+ let(:data) {{ name: nil }}
32
+ let(:links) {[ stub(:link, rel: 'canonical', href: '/canonical') ]}
29
33
 
30
- it 'is its remote url' do
31
- subject.display_name.should eq(url)
34
+ it 'returns the share url' do
35
+ subject.name.should eq('/canonical')
32
36
  end
33
37
  end
34
38
  end
35
39
 
36
40
  describe '#private?' do
37
41
  describe 'a private drop' do
38
- subject { CloudApp::Drop.new private: true }
39
-
40
- it 'is true' do
41
- subject.private?.should eq(true)
42
- end
42
+ let(:data) {{ private: true }}
43
+ it { should be_private }
43
44
  end
44
45
 
45
46
  describe 'a public drop' do
46
- subject { CloudApp::Drop.new private: false }
47
-
48
- it 'is false' do
49
- subject.private?.should eq(false)
50
- end
47
+ let(:data) {{ private: false }}
48
+ it { should_not be_private }
51
49
  end
52
50
  end
53
51
 
54
52
  describe '#public?' do
55
53
  describe 'a private drop' do
56
- subject { CloudApp::Drop.new private: true }
57
-
58
- it 'is false' do
59
- subject.public?.should eq(false)
60
- end
54
+ let(:data) {{ private: true }}
55
+ it { should_not be_public }
61
56
  end
62
57
 
63
58
  describe 'a public drop' do
64
- subject { CloudApp::Drop.new private: false }
59
+ let(:data) {{ private: false }}
60
+ it { should be_public }
61
+ end
62
+ end
65
63
 
66
- it 'is true' do
67
- subject.public?.should eq(true)
68
- end
64
+ describe '#created' do
65
+ let(:data) {{ created: '2012-04-01T00:00:00Z' }}
66
+ it 'parses date' do
67
+ expected = DateTime.new(2012, 4, 1)
68
+ subject.created.should eq(expected)
69
69
  end
70
70
  end
71
71
 
72
- describe '#has_content?' do
73
- describe 'an image' do
74
- subject { CloudApp::Drop.new item_type: 'image' }
72
+ describe '#share_url' do
73
+ let(:links) {[
74
+ stub(:canonical, rel: 'canonical', href: '/canonical'),
75
+ stub(:alternate, rel: 'alternate', href: '/alternate')
76
+ ]}
77
+ its(:share_url) { should eq('/canonical') }
78
+ end
79
+
80
+ describe '#thumbnail_url' do
81
+ let(:links) {[
82
+ stub(:canonical, rel: 'canonical', href: '/canonical'),
83
+ stub(:icon, rel: 'icon', href: '/icon')
84
+ ]}
75
85
 
76
- it 'is true' do
77
- subject.has_content?.should eq(true)
78
- end
86
+ its(:thumbnail_url) { should eq('/icon') }
87
+
88
+ context 'without an icon link' do
89
+ let(:links) {[ stub(:canonical, rel: 'canonical', href: '/canonical') ]}
90
+ its(:thumbnail_url) { should be_nil }
79
91
  end
92
+ end
80
93
 
81
- describe 'a bookmark' do
82
- subject { CloudApp::Drop.new item_type: 'bookmark' }
94
+ describe '#embed_url' do
95
+ let(:links) {[
96
+ stub(:canonical, rel: 'canonical', href: '/canonical'),
97
+ stub(:embed, rel: 'embed', href: '/embed')
98
+ ]}
99
+ its(:embed_url) { should eq('/embed') }
83
100
 
84
- it 'is false' do
85
- subject.has_content?.should eq(false)
86
- end
101
+ context 'without an embed link' do
102
+ let(:links) {[ stub(:canonical, rel: 'canonical', href: '/canonical') ]}
103
+ its(:embed_url) { should be_nil }
104
+ end
105
+ end
106
+
107
+ describe '#download_url' do
108
+ let(:links) {[
109
+ stub(:canonical, rel: 'canonical', href: '/canonical'),
110
+ stub(:download, rel: 'download', href: '/download')
111
+ ]}
112
+ its(:download_url) { should eq('/download') }
113
+
114
+ context 'without an download link' do
115
+ let(:links) {[ stub(:canonical, rel: 'canonical', href: '/canonical') ]}
116
+ its(:download_url) { should be_nil }
87
117
  end
88
118
  end
89
119
  end