gliffy 0.0.6 → 0.0.7
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.
- checksums.yaml +15 -0
- data/LICENSE +20 -0
- data/README.md +30 -11
- data/lib/gliffy.rb +37 -33
- data/lib/gliffy/account.rb +59 -59
- data/lib/gliffy/api.rb +89 -89
- data/lib/gliffy/api/error.rb +14 -0
- data/lib/gliffy/api/facade.rb +72 -4
- data/lib/gliffy/api/response.rb +4 -0
- data/lib/gliffy/document.rb +103 -69
- data/lib/gliffy/document/presentation.rb +27 -0
- data/lib/gliffy/{document_png.rb → document/presentation/png.rb} +2 -26
- data/lib/gliffy/document/presentation/svg.rb +10 -0
- data/lib/gliffy/document/presentation/xml.rb +10 -0
- data/lib/gliffy/folder.rb +91 -71
- data/spec/fixtures/error-401.xml +1 -0
- data/spec/lib/gliffy/account_spec.rb +107 -107
- data/spec/lib/gliffy/api/error_spec.rb +35 -0
- data/spec/lib/gliffy/api/facade_spec.rb +222 -93
- data/spec/lib/gliffy/api/response_spec.rb +46 -29
- data/spec/lib/gliffy/api_spec.rb +206 -206
- data/spec/lib/gliffy/{document_png_spec.rb → document/presentation/png_spec.rb} +10 -11
- data/spec/lib/gliffy/document/presentation/svg_spec.rb +38 -0
- data/spec/lib/gliffy/document/presentation/xml_spec.rb +38 -0
- data/spec/lib/gliffy/document/presentation_spec.rb +8 -0
- data/spec/lib/gliffy/document_spec.rb +179 -108
- data/spec/lib/gliffy/folder_spec.rb +224 -175
- data/spec/spec_helper.rb +39 -35
- data/spec/support/document_presentation_shared_examples.rb +6 -0
- metadata +34 -24
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Gliffy::Document::PNG do
|
3
|
+
describe Gliffy::Document::Presentation::PNG do
|
4
4
|
let(:content) { "SAMPLE CONTENT" }
|
5
5
|
let(:document) { double(Gliffy::Document) }
|
6
|
-
let(:png) { Gliffy::Document::PNG.new(document) }
|
6
|
+
let(:png) { Gliffy::Document::Presentation::PNG.new(document) }
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
expect(png.document).to be document
|
8
|
+
it_should_behave_like "a document presentation" do
|
9
|
+
let(:presentation) { png }
|
11
10
|
end
|
12
11
|
|
13
12
|
it "has content" do
|
@@ -30,14 +29,14 @@ describe Gliffy::Document::PNG do
|
|
30
29
|
)
|
31
30
|
).and_return(content)
|
32
31
|
|
33
|
-
expect(png.content(Gliffy::Document::PNG::SIZE_THUMBNAIL)).to eq content
|
32
|
+
expect(png.content(Gliffy::Document::Presentation::PNG::SIZE_THUMBNAIL)).to eq content
|
34
33
|
end
|
35
34
|
|
36
35
|
it "has a thumbnail" do
|
37
36
|
png.stub(:content).and_return(content)
|
38
37
|
expect(png.thumbnail).to eq content
|
39
38
|
expect(png).to have_received(:content).with(
|
40
|
-
Gliffy::Document::PNG::SIZE_THUMBNAIL
|
39
|
+
Gliffy::Document::Presentation::PNG::SIZE_THUMBNAIL
|
41
40
|
)
|
42
41
|
end
|
43
42
|
|
@@ -45,7 +44,7 @@ describe Gliffy::Document::PNG do
|
|
45
44
|
png.stub(:content).and_return(content)
|
46
45
|
expect(png.small).to eq content
|
47
46
|
expect(png).to have_received(:content).with(
|
48
|
-
Gliffy::Document::PNG::SIZE_SMALL
|
47
|
+
Gliffy::Document::Presentation::PNG::SIZE_SMALL
|
49
48
|
)
|
50
49
|
end
|
51
50
|
|
@@ -53,7 +52,7 @@ describe Gliffy::Document::PNG do
|
|
53
52
|
png.stub(:content).and_return(content)
|
54
53
|
expect(png.medium).to eq content
|
55
54
|
expect(png).to have_received(:content).with(
|
56
|
-
Gliffy::Document::PNG::SIZE_MEDIUM
|
55
|
+
Gliffy::Document::Presentation::PNG::SIZE_MEDIUM
|
57
56
|
)
|
58
57
|
end
|
59
58
|
|
@@ -61,7 +60,7 @@ describe Gliffy::Document::PNG do
|
|
61
60
|
png.stub(:content).and_return(content)
|
62
61
|
expect(png.full).to eq content
|
63
62
|
expect(png).to have_received(:content).with(
|
64
|
-
Gliffy::Document::PNG::SIZE_FULL
|
63
|
+
Gliffy::Document::Presentation::PNG::SIZE_FULL
|
65
64
|
)
|
66
65
|
end
|
67
|
-
end
|
66
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gliffy::Document::Presentation::SVG do
|
4
|
+
let(:content) { "SAMPLE CONTENT" }
|
5
|
+
let(:document) { double(Gliffy::Document) }
|
6
|
+
let(:svg) { Gliffy::Document::Presentation::SVG.new(document) }
|
7
|
+
|
8
|
+
it_should_behave_like "a document presentation" do
|
9
|
+
let(:presentation) { svg }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a reference to the original document" do
|
13
|
+
expect(svg).to respond_to :document
|
14
|
+
expect(svg.document).to be document
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has content" do
|
18
|
+
expect(svg).to respond_to :content
|
19
|
+
end
|
20
|
+
|
21
|
+
it "delegates task of fetching SVG content content to the API facade" do
|
22
|
+
account = double(Gliffy::Account, :id => 11)
|
23
|
+
api = double(Gliffy::API)
|
24
|
+
document.stub(:api).and_return(api)
|
25
|
+
document.stub(:owner).and_return(account)
|
26
|
+
document.stub(:id).and_return(22)
|
27
|
+
api.should_receive(
|
28
|
+
:raw
|
29
|
+
).with(
|
30
|
+
"/accounts/11/documents/22.svg",
|
31
|
+
hash_including(
|
32
|
+
:action => "get"
|
33
|
+
)
|
34
|
+
).and_return(content)
|
35
|
+
|
36
|
+
expect(svg.content).to eq content
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gliffy::Document::Presentation::XML do
|
4
|
+
let(:content) { "SAMPLE CONTENT" }
|
5
|
+
let(:document) { double(Gliffy::Document) }
|
6
|
+
let(:xml) { Gliffy::Document::Presentation::XML.new(document) }
|
7
|
+
|
8
|
+
it_should_behave_like "a document presentation" do
|
9
|
+
let(:presentation) { xml }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a reference to the original document" do
|
13
|
+
expect(xml).to respond_to :document
|
14
|
+
expect(xml.document).to be document
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has content" do
|
18
|
+
expect(xml).to respond_to :content
|
19
|
+
end
|
20
|
+
|
21
|
+
it "delegates task of fetching XML content content to the API facade" do
|
22
|
+
account = double(Gliffy::Account, :id => 11)
|
23
|
+
api = double(Gliffy::API)
|
24
|
+
document.stub(:api).and_return(api)
|
25
|
+
document.stub(:owner).and_return(account)
|
26
|
+
document.stub(:id).and_return(22)
|
27
|
+
api.should_receive(
|
28
|
+
:raw
|
29
|
+
).with(
|
30
|
+
"/accounts/11/documents/22.xml",
|
31
|
+
hash_including(
|
32
|
+
:action => "get"
|
33
|
+
)
|
34
|
+
).and_return(content)
|
35
|
+
|
36
|
+
expect(xml.content).to eq content
|
37
|
+
end
|
38
|
+
end
|
@@ -1,108 +1,179 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Gliffy::Document do
|
4
|
-
before :each do
|
5
|
-
Gliffy::Document.clear_cache
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:api) { double(Gliffy::API) }
|
9
|
-
let(:owner) do
|
10
|
-
owner = double(Gliffy::Account)
|
11
|
-
owner.stub(:api).and_return(api)
|
12
|
-
owner
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:document_id) { 1000002 }
|
16
|
-
let(:document_name) { 'SNPP Domain Model' }
|
17
|
-
|
18
|
-
let(:response) do
|
19
|
-
Gliffy::API::Response.new(fixture(
|
20
|
-
"document",
|
21
|
-
:document_id => document_id,
|
22
|
-
:document_name => document_name
|
23
|
-
)
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:document) do
|
28
|
-
Gliffy::Document.load(owner, response.node("//g:document"))
|
29
|
-
end
|
30
|
-
|
31
|
-
it "has an id" do
|
32
|
-
expect(document).to respond_to :id
|
33
|
-
expect(document.id).to eq document_id
|
34
|
-
end
|
35
|
-
|
36
|
-
it "has a name" do
|
37
|
-
expect(document).to respond_to :name
|
38
|
-
expect(document.name).to eq document_name
|
39
|
-
end
|
40
|
-
|
41
|
-
it "has 'public access' flag" do
|
42
|
-
expect(document).to respond_to :public?
|
43
|
-
expect(document.public?).to eq(true)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "has a version number" do
|
47
|
-
expect(document).to respond_to :versions
|
48
|
-
expect(document.versions).to eq(5)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "has a modification date" do
|
52
|
-
expect(document).to respond_to :modified
|
53
|
-
expect(document.modified).to eq(DateTime.new(2008, 7, 8, 17, 31, 23))
|
54
|
-
end
|
55
|
-
|
56
|
-
it "has a creation date" do
|
57
|
-
expect(document).to respond_to :created
|
58
|
-
expect(document.created).to eq(DateTime.new(2008, 7, 8, 17, 31, 24))
|
59
|
-
end
|
60
|
-
|
61
|
-
it "has a publication date" do
|
62
|
-
expect(document).to respond_to :published
|
63
|
-
expect(document.published).to eq(DateTime.new(2008, 7, 8, 17, 31, 25))
|
64
|
-
end
|
65
|
-
|
66
|
-
it "has an owner" do
|
67
|
-
expect(document).to respond_to :owner
|
68
|
-
expect(document.owner).to be(owner)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "has a link to gliffy editor" do
|
72
|
-
return_url = "sample/url"
|
73
|
-
return_text = "RETURN TEXT"
|
74
|
-
|
75
|
-
api.should_receive(
|
76
|
-
:web
|
77
|
-
).with(
|
78
|
-
"/gliffy/",
|
79
|
-
hash_including(
|
80
|
-
:launchDiagramId => document_id,
|
81
|
-
:returnURL => return_url,
|
82
|
-
:returnButtonText => return_text
|
83
|
-
)
|
84
|
-
).and_return(
|
85
|
-
"http://www.gliffy.com/gliffy/?launchDiagramId=#{document.id}&returnURL=#{return_url}&returnButtonText=#{return_text}"
|
86
|
-
)
|
87
|
-
|
88
|
-
link = document.editor(return_url, return_text)
|
89
|
-
|
90
|
-
expect(link).to match '/gliffy/'
|
91
|
-
expect(link).to match 'launchDiagramId='
|
92
|
-
expect(link).to match document.id.to_s
|
93
|
-
expect(link).to match 'returnURL='
|
94
|
-
expect(link).to match return_url
|
95
|
-
expect(link).to match 'returnButtonText='
|
96
|
-
expect(link).to match return_text
|
97
|
-
end
|
98
|
-
|
99
|
-
it "has an PNG image" do
|
100
|
-
expect(document).to respond_to :png
|
101
|
-
expect(document.png).to be_instance_of Gliffy::Document::PNG
|
102
|
-
end
|
103
|
-
|
104
|
-
it "has
|
105
|
-
|
106
|
-
expect(
|
107
|
-
end
|
108
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gliffy::Document do
|
4
|
+
before :each do
|
5
|
+
Gliffy::Document.clear_cache
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:api) { double(Gliffy::API::Facade) }
|
9
|
+
let(:owner) do
|
10
|
+
owner = double(Gliffy::Account)
|
11
|
+
owner.stub(:api).and_return(api)
|
12
|
+
owner
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:document_id) { 1000002 }
|
16
|
+
let(:document_name) { 'SNPP Domain Model' }
|
17
|
+
|
18
|
+
let(:response) do
|
19
|
+
Gliffy::API::Response.new(fixture(
|
20
|
+
"document",
|
21
|
+
:document_id => document_id,
|
22
|
+
:document_name => document_name
|
23
|
+
)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:document) do
|
28
|
+
Gliffy::Document.load(owner, response.node("//g:document"))
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has an id" do
|
32
|
+
expect(document).to respond_to :id
|
33
|
+
expect(document.id).to eq document_id
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a name" do
|
37
|
+
expect(document).to respond_to :name
|
38
|
+
expect(document.name).to eq document_name
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has 'public access' flag" do
|
42
|
+
expect(document).to respond_to :public?
|
43
|
+
expect(document.public?).to eq(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a version number" do
|
47
|
+
expect(document).to respond_to :versions
|
48
|
+
expect(document.versions).to eq(5)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has a modification date" do
|
52
|
+
expect(document).to respond_to :modified
|
53
|
+
expect(document.modified).to eq(DateTime.new(2008, 7, 8, 17, 31, 23))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "has a creation date" do
|
57
|
+
expect(document).to respond_to :created
|
58
|
+
expect(document.created).to eq(DateTime.new(2008, 7, 8, 17, 31, 24))
|
59
|
+
end
|
60
|
+
|
61
|
+
it "has a publication date" do
|
62
|
+
expect(document).to respond_to :published
|
63
|
+
expect(document.published).to eq(DateTime.new(2008, 7, 8, 17, 31, 25))
|
64
|
+
end
|
65
|
+
|
66
|
+
it "has an owner" do
|
67
|
+
expect(document).to respond_to :owner
|
68
|
+
expect(document.owner).to be(owner)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "has a link to gliffy editor" do
|
72
|
+
return_url = "sample/url"
|
73
|
+
return_text = "RETURN TEXT"
|
74
|
+
|
75
|
+
api.should_receive(
|
76
|
+
:web
|
77
|
+
).with(
|
78
|
+
"/gliffy/",
|
79
|
+
hash_including(
|
80
|
+
:launchDiagramId => document_id,
|
81
|
+
:returnURL => return_url,
|
82
|
+
:returnButtonText => return_text
|
83
|
+
)
|
84
|
+
).and_return(
|
85
|
+
"http://www.gliffy.com/gliffy/?launchDiagramId=#{document.id}&returnURL=#{return_url}&returnButtonText=#{return_text}"
|
86
|
+
)
|
87
|
+
|
88
|
+
link = document.editor(return_url, return_text)
|
89
|
+
|
90
|
+
expect(link).to match '/gliffy/'
|
91
|
+
expect(link).to match 'launchDiagramId='
|
92
|
+
expect(link).to match document.id.to_s
|
93
|
+
expect(link).to match 'returnURL='
|
94
|
+
expect(link).to match return_url
|
95
|
+
expect(link).to match 'returnButtonText='
|
96
|
+
expect(link).to match return_text
|
97
|
+
end
|
98
|
+
|
99
|
+
it "has an PNG image" do
|
100
|
+
expect(document).to respond_to :png
|
101
|
+
expect(document.png).to be_instance_of Gliffy::Document::Presentation::PNG
|
102
|
+
end
|
103
|
+
|
104
|
+
it "has SVG representation" do
|
105
|
+
expect(document).to respond_to :svg
|
106
|
+
expect(document.svg).to be_instance_of Gliffy::Document::Presentation::SVG
|
107
|
+
end
|
108
|
+
|
109
|
+
it "has XML representation" do
|
110
|
+
expect(document).to respond_to :xml
|
111
|
+
expect(document.xml).to be_instance_of Gliffy::Document::Presentation::XML
|
112
|
+
end
|
113
|
+
|
114
|
+
it "has singleton-life behavior" do
|
115
|
+
doc1 = Gliffy::Document.load(owner, response.node("//g:document"))
|
116
|
+
expect(doc1).to be document
|
117
|
+
end
|
118
|
+
|
119
|
+
it "can be renamed" do
|
120
|
+
expect(document).to respond_to :rename
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when renamed" do
|
124
|
+
let (:new_name) { "NEW DOCUMENT NAME" }
|
125
|
+
before :each do
|
126
|
+
api.stub(:update_document_metadata)
|
127
|
+
document.rename new_name
|
128
|
+
end
|
129
|
+
|
130
|
+
it "changes the name to the new value" do
|
131
|
+
expect(document.name).to eq new_name
|
132
|
+
end
|
133
|
+
|
134
|
+
it "calls rename method of the REST API" do
|
135
|
+
expect(api).to have_received(:update_document_metadata)
|
136
|
+
.with(document_id, new_name, nil)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "can be deleted" do
|
141
|
+
expect(document).to respond_to :delete
|
142
|
+
end
|
143
|
+
|
144
|
+
it "has flag indicating whether this object has been deleted" do
|
145
|
+
expect(document).to respond_to :deleted?
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when not deleted" do
|
149
|
+
it "knows it" do
|
150
|
+
expect(document.deleted?).to be_false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "when deleted" do
|
155
|
+
let(:observer) { double(Object) }
|
156
|
+
|
157
|
+
before :each do
|
158
|
+
api.stub(:delete_document)
|
159
|
+
|
160
|
+
observer.stub(:update)
|
161
|
+
document.add_observer(observer)
|
162
|
+
|
163
|
+
document.delete
|
164
|
+
end
|
165
|
+
|
166
|
+
it "calls REST API" do
|
167
|
+
expect(api).to have_received(:delete_document)
|
168
|
+
.with(document_id)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "knows it" do
|
172
|
+
expect(document.deleted?).to be_true
|
173
|
+
end
|
174
|
+
|
175
|
+
it "notifies observers" do
|
176
|
+
expect(observer).to have_received(:update).with(:delete, document)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -1,175 +1,224 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Gliffy::Folder do
|
5
|
-
let(:account_id) { 100 }
|
6
|
-
let(:api) { double(Gliffy::API) }
|
7
|
-
let(:account) { double(Gliffy::Account, :api => api, :id => account_id) }
|
8
|
-
|
9
|
-
subject(:folder) do
|
10
|
-
Gliffy::Folder.load(
|
11
|
-
account,
|
12
|
-
Gliffy::API::Response.new(
|
13
|
-
fixture('folder')
|
14
|
-
).node("//g:folders/g:folder[1]")
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "has a name" do
|
19
|
-
expect(folder).to respond_to :name
|
20
|
-
expect(folder.name).to eq "ROOT"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "has a path" do
|
24
|
-
expect(folder).to respond_to :path
|
25
|
-
expect(folder.path).to eq "ROOT"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "has a list of documents" do
|
29
|
-
expect(folder).to respond_to :documents
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "root folder" do
|
33
|
-
it "knows it is root" do
|
34
|
-
expect(folder.root?).to be_true
|
35
|
-
end
|
36
|
-
|
37
|
-
it "has no parent" do
|
38
|
-
expect(folder.parent).to be_nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "document list" do
|
43
|
-
it "is loaded from API" do
|
44
|
-
api.should_receive(
|
45
|
-
:get
|
46
|
-
).and_return(
|
47
|
-
Gliffy::API::Response.new(fixture("documents"))
|
48
|
-
)
|
49
|
-
|
50
|
-
folder.documents
|
51
|
-
end
|
52
|
-
|
53
|
-
it "has correct length" do
|
54
|
-
api.stub(
|
55
|
-
:get
|
56
|
-
).and_return(
|
57
|
-
Gliffy::API::Response.new(fixture("documents"))
|
58
|
-
)
|
59
|
-
|
60
|
-
expect(folder.documents.length).to eq 3
|
61
|
-
end
|
62
|
-
|
63
|
-
it "is empty when API returns appropriate response" do
|
64
|
-
api.stub(
|
65
|
-
:get
|
66
|
-
).and_return(
|
67
|
-
Gliffy::API::Response.new(fixture("documents-empty"))
|
68
|
-
)
|
69
|
-
|
70
|
-
expect(folder.documents.length).to eq 0
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "has nested folders" do
|
75
|
-
expect(folder).to respond_to :folders
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "folder list" do
|
79
|
-
subject(:children) { folder.folders }
|
80
|
-
|
81
|
-
it { should respond_to :length }
|
82
|
-
it { should respond_to :[] }
|
83
|
-
it "has corrent length" do
|
84
|
-
expect(children.length).to eq 4
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "first-level folder 'Burns Top Secret'" do
|
89
|
-
subject(:first_child) { folder.folders[0] }
|
90
|
-
|
91
|
-
it "has correct parent" do
|
92
|
-
expect(first_child.parent).to be folder
|
93
|
-
end
|
94
|
-
|
95
|
-
it "has correct name" do
|
96
|
-
expect(first_child.name).to eq "Burns Top Secret"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "has correct path" do
|
100
|
-
expect(first_child.path).to eq "ROOT/Burns Top Secret"
|
101
|
-
end
|
102
|
-
|
103
|
-
it "has correct number of children" do
|
104
|
-
expect(first_child.folders).to eq []
|
105
|
-
end
|
106
|
-
|
107
|
-
it "knows it is not root" do
|
108
|
-
expect(first_child.root?).to be_false
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe "first-level folder 'Simsons Family'" do
|
113
|
-
subject(:second_child) { folder.folders[3] }
|
114
|
-
|
115
|
-
it "has correct parent" do
|
116
|
-
expect(second_child.parent).to be folder
|
117
|
-
end
|
118
|
-
|
119
|
-
it "has correct name" do
|
120
|
-
expect(second_child.name).to eq "Simpsons Family"
|
121
|
-
end
|
122
|
-
|
123
|
-
it "has correct path" do
|
124
|
-
expect(second_child.path).to eq "ROOT/Simpsons Family"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "has corrent number of children" do
|
128
|
-
expect(second_child.folders.length).to eq 2
|
129
|
-
end
|
130
|
-
|
131
|
-
it "knows it is not root" do
|
132
|
-
expect(second_child.root?).to be_false
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "second-level folder 'Maggie and Lisas Stuff'" do
|
136
|
-
subject(:nested_child) { second_child.folders[1] }
|
137
|
-
|
138
|
-
it "has corrent parent" do
|
139
|
-
expect(nested_child.parent).to be second_child
|
140
|
-
end
|
141
|
-
|
142
|
-
it "has correct name" do
|
143
|
-
expect(nested_child.name).to eq "Maggie and Lisas Stuff"
|
144
|
-
end
|
145
|
-
|
146
|
-
it "has correct path" do
|
147
|
-
expect(nested_child.path).to eq "ROOT/Simpsons Family/Maggie and Lisas Stuff"
|
148
|
-
end
|
149
|
-
|
150
|
-
it "knows it is not root" do
|
151
|
-
expect(nested_child.root?).to be_false
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context "when assigning a parent" do
|
157
|
-
context "with valid path" do
|
158
|
-
it "updates parent" do
|
159
|
-
f1 = Gliffy::Folder.new(account, "F1", "/ROOT/F1", [])
|
160
|
-
f2 = Gliffy::Folder.new(account, "F2", "/ROOT/F1/F2", [])
|
161
|
-
|
162
|
-
f2.parent = f1
|
163
|
-
expect(f2.parent).to be f1
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context "with invalid path" do
|
168
|
-
it "raises an error" do
|
169
|
-
f1 = Gliffy::Folder.new(@account, "F1", "/ROOT/F1", [])
|
170
|
-
f2 = Gliffy::Folder.new(@account, "F2", "/ROOT/F2", [])
|
171
|
-
expect { f1.parent = f2 }.to raise_error
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
1
|
+
# -*- coding: utf-8-unix -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Gliffy::Folder do
|
5
|
+
let(:account_id) { 100 }
|
6
|
+
let(:api) { double(Gliffy::API::Facade) }
|
7
|
+
let(:account) { double(Gliffy::Account, :api => api, :id => account_id) }
|
8
|
+
|
9
|
+
subject(:folder) do
|
10
|
+
Gliffy::Folder.load(
|
11
|
+
account,
|
12
|
+
Gliffy::API::Response.new(
|
13
|
+
fixture('folder')
|
14
|
+
).node("//g:folders/g:folder[1]")
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has a name" do
|
19
|
+
expect(folder).to respond_to :name
|
20
|
+
expect(folder.name).to eq "ROOT"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has a path" do
|
24
|
+
expect(folder).to respond_to :path
|
25
|
+
expect(folder.path).to eq "ROOT"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a list of documents" do
|
29
|
+
expect(folder).to respond_to :documents
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "root folder" do
|
33
|
+
it "knows it is root" do
|
34
|
+
expect(folder.root?).to be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has no parent" do
|
38
|
+
expect(folder.parent).to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "document list" do
|
43
|
+
it "is loaded from API" do
|
44
|
+
api.should_receive(
|
45
|
+
:get
|
46
|
+
).and_return(
|
47
|
+
Gliffy::API::Response.new(fixture("documents"))
|
48
|
+
)
|
49
|
+
|
50
|
+
folder.documents
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has correct length" do
|
54
|
+
api.stub(
|
55
|
+
:get
|
56
|
+
).and_return(
|
57
|
+
Gliffy::API::Response.new(fixture("documents"))
|
58
|
+
)
|
59
|
+
|
60
|
+
expect(folder.documents.length).to eq 3
|
61
|
+
end
|
62
|
+
|
63
|
+
it "is empty when API returns appropriate response" do
|
64
|
+
api.stub(
|
65
|
+
:get
|
66
|
+
).and_return(
|
67
|
+
Gliffy::API::Response.new(fixture("documents-empty"))
|
68
|
+
)
|
69
|
+
|
70
|
+
expect(folder.documents.length).to eq 0
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "has nested folders" do
|
75
|
+
expect(folder).to respond_to :folders
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "folder list" do
|
79
|
+
subject(:children) { folder.folders }
|
80
|
+
|
81
|
+
it { should respond_to :length }
|
82
|
+
it { should respond_to :[] }
|
83
|
+
it "has corrent length" do
|
84
|
+
expect(children.length).to eq 4
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "first-level folder 'Burns Top Secret'" do
|
89
|
+
subject(:first_child) { folder.folders[0] }
|
90
|
+
|
91
|
+
it "has correct parent" do
|
92
|
+
expect(first_child.parent).to be folder
|
93
|
+
end
|
94
|
+
|
95
|
+
it "has correct name" do
|
96
|
+
expect(first_child.name).to eq "Burns Top Secret"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "has correct path" do
|
100
|
+
expect(first_child.path).to eq "ROOT/Burns Top Secret"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "has correct number of children" do
|
104
|
+
expect(first_child.folders).to eq []
|
105
|
+
end
|
106
|
+
|
107
|
+
it "knows it is not root" do
|
108
|
+
expect(first_child.root?).to be_false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "first-level folder 'Simsons Family'" do
|
113
|
+
subject(:second_child) { folder.folders[3] }
|
114
|
+
|
115
|
+
it "has correct parent" do
|
116
|
+
expect(second_child.parent).to be folder
|
117
|
+
end
|
118
|
+
|
119
|
+
it "has correct name" do
|
120
|
+
expect(second_child.name).to eq "Simpsons Family"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "has correct path" do
|
124
|
+
expect(second_child.path).to eq "ROOT/Simpsons Family"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "has corrent number of children" do
|
128
|
+
expect(second_child.folders.length).to eq 2
|
129
|
+
end
|
130
|
+
|
131
|
+
it "knows it is not root" do
|
132
|
+
expect(second_child.root?).to be_false
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "second-level folder 'Maggie and Lisas Stuff'" do
|
136
|
+
subject(:nested_child) { second_child.folders[1] }
|
137
|
+
|
138
|
+
it "has corrent parent" do
|
139
|
+
expect(nested_child.parent).to be second_child
|
140
|
+
end
|
141
|
+
|
142
|
+
it "has correct name" do
|
143
|
+
expect(nested_child.name).to eq "Maggie and Lisas Stuff"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "has correct path" do
|
147
|
+
expect(nested_child.path).to eq "ROOT/Simpsons Family/Maggie and Lisas Stuff"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "knows it is not root" do
|
151
|
+
expect(nested_child.root?).to be_false
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when assigning a parent" do
|
157
|
+
context "with valid path" do
|
158
|
+
it "updates parent" do
|
159
|
+
f1 = Gliffy::Folder.new(account, "F1", "/ROOT/F1", [])
|
160
|
+
f2 = Gliffy::Folder.new(account, "F2", "/ROOT/F1/F2", [])
|
161
|
+
|
162
|
+
f2.parent = f1
|
163
|
+
expect(f2.parent).to be f1
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "with invalid path" do
|
168
|
+
it "raises an error" do
|
169
|
+
f1 = Gliffy::Folder.new(@account, "F1", "/ROOT/F1", [])
|
170
|
+
f2 = Gliffy::Folder.new(@account, "F2", "/ROOT/F2", [])
|
171
|
+
expect { f1.parent = f2 }.to raise_error
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it "allows us to create a document" do
|
177
|
+
expect(folder).to respond_to :create_document
|
178
|
+
end
|
179
|
+
|
180
|
+
context "when creating a document" do
|
181
|
+
let(:document_name) { "NEW DOCUMENT NAME" }
|
182
|
+
|
183
|
+
before :each do
|
184
|
+
api.stub(:create_document)
|
185
|
+
folder.create_document(document_name)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "calls REST API" do
|
189
|
+
expect(api).to have_received(:create_document)
|
190
|
+
.with(document_name,
|
191
|
+
Gliffy::Document::TYPE_DIAGRAM,
|
192
|
+
nil,
|
193
|
+
folder.path)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "when receives a document delete notification" do
|
198
|
+
before :each do
|
199
|
+
api.should_receive(
|
200
|
+
:get
|
201
|
+
).and_return(
|
202
|
+
Gliffy::API::Response.new(fixture("documents"))
|
203
|
+
)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "removes document from the document list" do
|
207
|
+
original_length = folder.documents.length
|
208
|
+
document = folder.documents[1]
|
209
|
+
|
210
|
+
folder.update(:delete, document)
|
211
|
+
|
212
|
+
expect(folder.documents.length).to eq original_length - 1
|
213
|
+
expect(folder.documents).to_not include document
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "when receives an unknown event" do
|
218
|
+
let(:document) { double(Gliffy::Document) }
|
219
|
+
|
220
|
+
it "throws an exception" do
|
221
|
+
expect { folder.update(:unknown, document) }.to raise_error ArgumentError
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|